From 6db30045ad1c880d39dee852682652c9a2c68fd5 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 10 May 2021 18:07:57 +0100 Subject: [PATCH 01/25] Some cleanup. --- .../src/api/controllers/deploy/awsDeploy.js | 80 ------------------- .../src/api/controllers/deploy/index.js | 14 +--- .../src/api/controllers/static/index.js | 8 +- 3 files changed, 7 insertions(+), 95 deletions(-) delete mode 100644 packages/server/src/api/controllers/deploy/awsDeploy.js diff --git a/packages/server/src/api/controllers/deploy/awsDeploy.js b/packages/server/src/api/controllers/deploy/awsDeploy.js deleted file mode 100644 index c9fc1e9e52..0000000000 --- a/packages/server/src/api/controllers/deploy/awsDeploy.js +++ /dev/null @@ -1,80 +0,0 @@ -const AWS = require("aws-sdk") -const fetch = require("node-fetch") -const env = require("../../../environment") -const { - deployToObjectStore, - performReplication, - fetchCredentials, -} = require("./utils") - -/** - * Verifies the users API key and - * Verifies that the deployment fits within the quota of the user - * Links to the "check-api-key" lambda. - * @param {object} deployment - information about the active deployment, including the appId and quota. - */ -exports.preDeployment = async function (deployment) { - const json = await fetchCredentials(env.DEPLOYMENT_CREDENTIALS_URL, { - apiKey: env.BUDIBASE_API_KEY, - appId: deployment.getAppId(), - quota: deployment.getQuota(), - }) - - // set credentials here, means any time we're verified we're ready to go - if (json.credentials) { - AWS.config.update({ - accessKeyId: json.credentials.AccessKeyId, - secretAccessKey: json.credentials.SecretAccessKey, - sessionToken: json.credentials.SessionToken, - }) - } - - return json -} - -/** - * Finalises the deployment, updating the quota for the user API key - * The verification process returns the levels to update to. - * Calls the "deployment-success" lambda. - * @param {object} deployment information about the active deployment, including the quota info. - * @returns {Promise} The usage has been updated against the user API key. - */ -exports.postDeployment = async function (deployment) { - const DEPLOYMENT_SUCCESS_URL = - env.DEPLOYMENT_CREDENTIALS_URL + "deploy/success" - - const response = await fetch(DEPLOYMENT_SUCCESS_URL, { - method: "POST", - body: JSON.stringify({ - apiKey: env.BUDIBASE_API_KEY, - quota: deployment.getQuota(), - }), - headers: { - "Content-Type": "application/json", - Accept: "application/json", - }, - }) - - if (response.status !== 200) { - throw new Error(`Error updating deployment quota for API Key`) - } - - return await response.json() -} - -exports.deploy = async function (deployment) { - const appId = deployment.getAppId() - const { bucket, accountId } = deployment.getVerification() - const metadata = { accountId } - await deployToObjectStore(appId, bucket, metadata) -} - -exports.replicateDb = async function (deployment) { - const appId = deployment.getAppId() - const verification = deployment.getVerification() - return performReplication( - appId, - verification.couchDbSession, - env.DEPLOYMENT_DB_URL - ) -} diff --git a/packages/server/src/api/controllers/deploy/index.js b/packages/server/src/api/controllers/deploy/index.js index 1152b56db8..1fee54ef80 100644 --- a/packages/server/src/api/controllers/deploy/index.js +++ b/packages/server/src/api/controllers/deploy/index.js @@ -1,9 +1,6 @@ const PouchDB = require("../../../db") const Deployment = require("./Deployment") -const { - getHostingInfo, - HostingTypes, -} = require("../../../utilities/builder/hosting") +const deploymentService = require("./selfDeploy") // the max time we can wait for an invalidation to complete before considering it failed const MAX_PENDING_TIME_MS = 30 * 60000 const DeploymentStatus = { @@ -12,9 +9,6 @@ const DeploymentStatus = { FAILURE: "FAILURE", } -// default to AWS deployment, this will be updated before use (if required) -let deploymentService = require("./awsDeploy") - // checks that deployments are in a good state, any pending will be updated async function checkAllDeployments(deployments) { let updated = false @@ -122,12 +116,6 @@ exports.deploymentProgress = async function (ctx) { } exports.deployApp = async function (ctx) { - // start by checking whether to deploy local or to cloud - const hostingInfo = await getHostingInfo() - deploymentService = - hostingInfo.type === HostingTypes.CLOUD - ? require("./awsDeploy") - : require("./selfDeploy") let deployment = new Deployment(ctx.appId) deployment.setStatus(DeploymentStatus.PENDING) deployment = await storeLocalDeploymentHistory(deployment) diff --git a/packages/server/src/api/controllers/static/index.js b/packages/server/src/api/controllers/static/index.js index 7a6d6c7e39..35a6ce4bd7 100644 --- a/packages/server/src/api/controllers/static/index.js +++ b/packages/server/src/api/controllers/static/index.js @@ -95,10 +95,14 @@ exports.serveComponentLibrary = async function (ctx) { if (env.isDev() || env.isTest()) { const componentLibraryPath = join( budibaseTempDir(), - decodeURI(ctx.query.library), + appId, + "node_modules", + "@budibase", + "standard-components", + "package", "dist" ) - return send(ctx, "/awsDeploy.js", { root: componentLibraryPath }) + return send(ctx, "/index.js", { root: componentLibraryPath }) } const db = new CouchDB(appId) const appInfo = await db.get(appId) From c0d1f5ef8c39ad3d199877c0e63d5ee87ae219c4 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 10 May 2021 18:14:18 +0100 Subject: [PATCH 02/25] Fixing an issue that occurred in a merge. --- .../src/components/common/bindings/ServerBindingPanel.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/components/common/bindings/ServerBindingPanel.svelte b/packages/builder/src/components/common/bindings/ServerBindingPanel.svelte index ca6d211a2a..835069ea9c 100644 --- a/packages/builder/src/components/common/bindings/ServerBindingPanel.svelte +++ b/packages/builder/src/components/common/bindings/ServerBindingPanel.svelte @@ -50,7 +50,7 @@
{#each categories as [categoryName, bindings]} {categoryName} - {#each bindableProperties.filter(binding => + {#each bindings.filter(binding => binding.label.match(searchRgx) ) as binding}
Date: Tue, 11 May 2021 17:49:26 +0100 Subject: [PATCH 03/25] General cleanup, doing away with the concept of hosting in the builder and the generally confusing difference between cloud, self hosting and running locally - server is simply always a server now. --- packages/auth/src/constants.js | 7 ++ .../builder/src/builderStore/store/hosting.js | 21 +--- .../deploy/DeploymentHistory.svelte | 3 +- .../components/settings/tabs/General.svelte | 51 +++++----- .../start/BuilderSettingsModal.svelte | 51 +--------- .../components/start/CreateAppModal.svelte | 29 +++--- .../app/[application]/deploy/index.svelte | 23 +---- .../server/src/api/controllers/application.js | 2 +- .../src/api/controllers/deploy/Deployment.js | 29 ------ .../src/api/controllers/deploy/index.js | 7 -- .../src/api/controllers/deploy/quota.js | 39 -------- .../src/api/controllers/deploy/selfDeploy.js | 38 -------- .../server/src/api/controllers/hosting.js | 46 +++------ packages/server/src/api/controllers/script.js | 10 +- .../src/api/controllers/static/index.js | 2 +- packages/server/src/api/routes/hosting.js | 3 - packages/server/src/api/routes/script.js | 2 +- .../src/api/routes/tests/hosting.spec.js | 95 +------------------ packages/server/src/db/utils.js | 5 - .../server/src/utilities/builder/hosting.js | 86 ----------------- .../server/src/utilities/workerRequests.js | 3 - packages/worker/package.json | 2 +- packages/worker/src/constants/index.js | 9 +- 23 files changed, 72 insertions(+), 491 deletions(-) delete mode 100644 packages/server/src/api/controllers/deploy/quota.js delete mode 100644 packages/server/src/utilities/builder/hosting.js diff --git a/packages/auth/src/constants.js b/packages/auth/src/constants.js index 8ca05066c9..230c80b609 100644 --- a/packages/auth/src/constants.js +++ b/packages/auth/src/constants.js @@ -14,3 +14,10 @@ exports.GlobalRoles = { BUILDER: "builder", GROUP_MANAGER: "group_manager", } + +exports.Configs = { + SETTINGS: "settings", + ACCOUNT: "account", + SMTP: "smtp", + GOOGLE: "google", +} diff --git a/packages/builder/src/builderStore/store/hosting.js b/packages/builder/src/builderStore/store/hosting.js index f180d4157a..fb174c2663 100644 --- a/packages/builder/src/builderStore/store/hosting.js +++ b/packages/builder/src/builderStore/store/hosting.js @@ -2,7 +2,6 @@ import { writable } from "svelte/store" import api, { get } from "../api" const INITIAL_HOSTING_UI_STATE = { - hostingInfo: {}, appUrl: "", deployedApps: {}, deployedAppNames: [], @@ -13,28 +12,12 @@ export const getHostingStore = () => { const store = writable({ ...INITIAL_HOSTING_UI_STATE }) store.actions = { fetch: async () => { - const responses = await Promise.all([ - api.get("/api/hosting/"), - api.get("/api/hosting/urls"), - ]) - const [info, urls] = await Promise.all(responses.map(resp => resp.json())) + const response = await api.get("/api/hosting/urls") + const urls = await response.json() store.update(state => { - state.hostingInfo = info state.appUrl = urls.app return state }) - return info - }, - save: async hostingInfo => { - const response = await api.post("/api/hosting", hostingInfo) - const revision = (await response.json()).rev - store.update(state => { - state.hostingInfo = { - ...hostingInfo, - _rev: revision, - } - return state - }) }, fetchDeployedApps: async () => { let deployments = await (await get("/api/hosting/apps")).json() diff --git a/packages/builder/src/components/deploy/DeploymentHistory.svelte b/packages/builder/src/components/deploy/DeploymentHistory.svelte index fd098235be..dc90acf435 100644 --- a/packages/builder/src/components/deploy/DeploymentHistory.svelte +++ b/packages/builder/src/components/deploy/DeploymentHistory.svelte @@ -36,8 +36,7 @@ let errorReason let poll let deployments = [] - let urlComponent = - $hostingStore.hostingInfo.type === "self" ? $store.url : `/${appId}` + let urlComponent = $store.url || `/${appId}` let deploymentUrl = `${$hostingStore.appUrl}${urlComponent}` const formatDate = (date, format) => diff --git a/packages/builder/src/components/settings/tabs/General.svelte b/packages/builder/src/components/settings/tabs/General.svelte index d5829f9e72..4a8d24ed58 100644 --- a/packages/builder/src/components/settings/tabs/General.svelte +++ b/packages/builder/src/components/settings/tabs/General.svelte @@ -49,27 +49,22 @@ onMount(async () => { const nameError = "Your application must have a name.", urlError = "Your application must have a URL." - let hostingInfo = await hostingStore.actions.fetch() - if (hostingInfo.type === "self") { - await hostingStore.actions.fetchDeployedApps() - const existingAppNames = get(hostingStore).deployedAppNames - const existingAppUrls = get(hostingStore).deployedAppUrls - const nameIdx = existingAppNames.indexOf(get(store).name) - const urlIdx = existingAppUrls.indexOf(get(store).url) - if (nameIdx !== -1) { - existingAppNames.splice(nameIdx, 1) - } - if (urlIdx !== -1) { - existingAppUrls.splice(urlIdx, 1) - } - nameValidation = { - name: string().required(nameError).notOneOf(existingAppNames), - } - urlValidation = { - url: string().required(urlError).notOneOf(existingAppUrls), - } - } else { - nameValidation = { name: string().required(nameError) } + await hostingStore.actions.fetchDeployedApps() + const existingAppNames = get(hostingStore).deployedAppNames + const existingAppUrls = get(hostingStore).deployedAppUrls + const nameIdx = existingAppNames.indexOf(get(store).name) + const urlIdx = existingAppUrls.indexOf(get(store).url) + if (nameIdx !== -1) { + existingAppNames.splice(nameIdx, 1) + } + if (urlIdx !== -1) { + existingAppUrls.splice(urlIdx, 1) + } + nameValidation = { + name: string().required(nameError).notOneOf(existingAppNames), + } + urlValidation = { + url: string().required(urlError).notOneOf(existingAppUrls), } }) @@ -81,14 +76,12 @@ error={nameError} label="App Name" /> - {#if $hostingStore.hostingInfo.type === "self"} - updateApplication({ url: e.detail })} - value={$store.url} - error={urlError} - label="App URL" - /> - {/if} + updateApplication({ url: e.detail })} + value={$store.url} + error={urlError} + label="App URL" + />