From 882cfa700bc76ff8a24e2c5b71d9b04a08147ff8 Mon Sep 17 00:00:00 2001
From: mike12345567
Date: Wed, 6 Jan 2021 16:58:29 +0000
Subject: [PATCH] Updating worker to support using a self host key, a basic
level of security, stopping builder from asking for API key if currently
configured for self hosting, made the default values for self hosting make
sense for a basic local installation, this should be final.
---
hosting/docker-compose.yaml | 8 ++--
hosting/envoy.yaml | 2 +-
hosting/hosting.properties | 23 +++++++++---
hosting/start.sh | 2 +-
.../start/BuilderSettingsModal.svelte | 29 +++++++++++----
.../components/start/CreateAppModal.svelte | 30 +++++++++------
.../src/api/controllers/deploy/index.js | 5 ++-
.../src/api/controllers/deploy/selfDeploy.js | 37 +++++++++++--------
.../src/api/controllers/deploy/utils.js | 3 +-
.../server/src/api/controllers/hosting.js | 16 +++++---
.../src/api/controllers/static/index.js | 2 +-
packages/server/src/environment.js | 2 +-
.../server/src/utilities/builder/hosting.js | 10 ++++-
packages/worker/src/api/controllers/deploy.js | 21 ++++++-----
packages/worker/src/environment.js | 1 +
packages/worker/src/middleware/check-key.js | 9 ++++-
16 files changed, 133 insertions(+), 67 deletions(-)
diff --git a/hosting/docker-compose.yaml b/hosting/docker-compose.yaml
index cf86d3cd98..cfdbc48e5f 100644
--- a/hosting/docker-compose.yaml
+++ b/hosting/docker-compose.yaml
@@ -14,8 +14,8 @@ services:
LOGO_URL: ${LOGO_URL}
PORT: 4002
HOSTING_URL: ${HOSTING_URL}
- MINIO_PORT: ${MINIO_PORT}
JWT_SECRET: ${JWT_SECRET}
+ PROXY_PORT: ${MAIN_PORT}
depends_on:
- worker-service
@@ -33,6 +33,7 @@ services:
COUCH_DB_USERNAME: ${COUCH_DB_USER}
COUCH_DB_PASSWORD: ${COUCH_DB_PASSWORD}
RAW_COUCH_DB_URL: http://couchdb-service:5984
+ SELF_HOST_KEY: ${HOSTING_KEY}
depends_on:
- minio-service
- couch-init
@@ -40,7 +41,7 @@ services:
minio-service:
image: minio/minio
volumes:
- - data1:/data
+ - minio_data:/data
ports:
- "${MINIO_PORT}:9000"
environment:
@@ -89,4 +90,5 @@ services:
volumes:
couchdb_data:
driver: local
- data1:
+ minio_data:
+ driver: local
diff --git a/hosting/envoy.yaml b/hosting/envoy.yaml
index a6b110428e..4e0e233430 100644
--- a/hosting/envoy.yaml
+++ b/hosting/envoy.yaml
@@ -33,8 +33,8 @@ static_resources:
- match: { prefix: "/db/" }
route:
- prefix_rewrite: "/"
cluster: couchdb-service
+ prefix_rewrite: "/"
# minio is on the default route because this works
# best, minio + AWS SDK doesn't handle path proxy
diff --git a/hosting/hosting.properties b/hosting/hosting.properties
index 4f57f0278d..5907d62819 100644
--- a/hosting/hosting.properties
+++ b/hosting/hosting.properties
@@ -1,14 +1,27 @@
+# Use the main port in the builder for your self hosting URL, e.g. localhost:10000
+MAIN_PORT=10000
+
+# Use this password when configuring your self hosting settings
+# This should be updated
+HOSTING_KEY=budibase
+
+# This section contains customisation options
+HOSTING_URL=http://localhost
+LOGO_URL=https://logoipsum.com/logo/logo-15.svg
+HOSTING_URL=http://localhost
+
+# This section contains all secrets pertaining to the system
+# These should be updated
+JWT_SECRET=testsecret
MINIO_ACCESS_KEY=budibase
MINIO_SECRET_KEY=budibase
COUCH_DB_PASSWORD=budibase
COUCH_DB_USER=budibase
WORKER_API_KEY=budibase
-BUDIBASE_ENVIRONMENT=PRODUCTION
-HOSTING_URL=http://localhost
-LOGO_URL=https://logoipsum.com/logo/logo-15.svg
-MAIN_PORT=10000
+
+# This section contains variables that do not need to be altered under normal circumstances
APP_PORT=4002
WORKER_PORT=4003
MINIO_PORT=4004
COUCH_DB_PORT=4005
-JWT_SECRET=testsecret
+BUDIBASE_ENVIRONMENT=PRODUCTION
diff --git a/hosting/start.sh b/hosting/start.sh
index b32098a3b7..803db51eda 100755
--- a/hosting/start.sh
+++ b/hosting/start.sh
@@ -1,2 +1,2 @@
#!/bin/bash
-docker-compose --env-file hosting.properties up
+docker-compose --env-file hosting.properties up --build
diff --git a/packages/builder/src/components/start/BuilderSettingsModal.svelte b/packages/builder/src/components/start/BuilderSettingsModal.svelte
index 6ddad0c787..0199069f73 100644
--- a/packages/builder/src/components/start/BuilderSettingsModal.svelte
+++ b/packages/builder/src/components/start/BuilderSettingsModal.svelte
@@ -6,14 +6,18 @@
import analytics from "analytics"
import { onMount } from "svelte"
- let selfhosted = false
let hostingInfo
+ let selfhosted = false
async function save() {
- if (!selfhosted) {
- return
- }
hostingInfo.type = selfhosted ? "self" : "cloud"
+ if (!selfhosted && hostingInfo._rev) {
+ hostingInfo = {
+ type: hostingInfo.type,
+ _id: hostingInfo._id,
+ _rev: hostingInfo._rev,
+ }
+ }
try {
await hostingStore.actions.save(hostingInfo)
notifier.success(`Settings saved.`)
@@ -22,6 +26,15 @@
}
}
+ function updateSelfHosting(event) {
+
+ if (hostingInfo.type === "cloud" && event.target.checked) {
+ hostingInfo.hostingUrl = "localhost:10000"
+ hostingInfo.useHttps = false
+ hostingInfo.selfHostKey = "budibase"
+ }
+ }
+
onMount(async () => {
hostingInfo = await hostingStore.actions.fetch()
selfhosted = hostingInfo.type === "self"
@@ -31,8 +44,7 @@
+ onConfirm={save}>
Theme
Hosting
@@ -40,9 +52,10 @@
This section contains settings that relate to the deployment and hosting of
apps made in this builder.
-
+
{#if selfhosted}
-
+
+
{/if}
diff --git a/packages/builder/src/components/start/CreateAppModal.svelte b/packages/builder/src/components/start/CreateAppModal.svelte
index b88397b6c4..39ca5032a4 100644
--- a/packages/builder/src/components/start/CreateAppModal.svelte
+++ b/packages/builder/src/components/start/CreateAppModal.svelte
@@ -1,6 +1,6 @@