Updating deployment service, checking in builder the builder settings info stored in DB before deploying.

This commit is contained in:
mike12345567 2020-12-15 17:27:45 +00:00
parent c65ed9ad46
commit cc34838f45
7 changed files with 35 additions and 27 deletions

View File

@ -8,6 +8,7 @@ import {
import { import {
allScreens, allScreens,
backendUiStore, backendUiStore,
hostingStore,
currentAsset, currentAsset,
mainLayout, mainLayout,
selectedComponent, selectedComponent,
@ -69,6 +70,7 @@ export const getFrontendStore = () => {
appInstance: pkg.application.instance, appInstance: pkg.application.instance,
})) }))
await hostingStore.actions.fetch()
await backendUiStore.actions.database.select(pkg.application.instance) await backendUiStore.actions.database.select(pkg.application.instance)
}, },
routing: { routing: {

View File

@ -10,10 +10,11 @@ export const getHostingStore = () => {
const store = writable({ ...INITIAL_BACKEND_UI_STATE }) const store = writable({ ...INITIAL_BACKEND_UI_STATE })
store.actions = { store.actions = {
fetch: async () => { fetch: async () => {
const response = await api.get("/api/hosting/") const responses = await Promise.all([api.get("/api/hosting/"), api.get("/api/hosting/urls")])
const info = await response.json() const [info, urls] = await Promise.all(responses.map(resp => resp.json()))
store.update(state => { store.update(state => {
state.hostingInfo = info state.hostingInfo = info
state.appUrl = urls.appServer
return state return state
}) })
return info return info
@ -30,6 +31,5 @@ export const getHostingStore = () => {
}) })
}, },
} }
return store return store
} }

View File

@ -1,16 +1,17 @@
<script> <script>
import { notifier } from "builderStore/store/notifications" import { notifier } from "builderStore/store/notifications"
import { Input } from "@budibase/bbui" import { Input } from "@budibase/bbui"
import { store } from "builderStore" import { store, hostingStore } from "builderStore"
export let value export let value
export let production = false export let production = false
$: appId = $store.appId $: appId = $store.appId
$: appUrl = $hostingStore.appUrl
function fullWebhookURL(uri) { function fullWebhookURL(uri) {
if (production) { if (production) {
return `https://${appId}.app.budi.live/${uri}` return `${appUrl}/${uri}`
} else { } else {
return `http://localhost:4001/${uri}` return `http://localhost:4001/${uri}`
} }

View File

@ -6,6 +6,7 @@
import api from "builderStore/api" import api from "builderStore/api"
import { notifier } from "builderStore/store/notifications" import { notifier } from "builderStore/store/notifications"
import CreateWebhookDeploymentModal from "./CreateWebhookDeploymentModal.svelte" import CreateWebhookDeploymentModal from "./CreateWebhookDeploymentModal.svelte"
import { hostingStore } from "builderStore"
const DeploymentStatus = { const DeploymentStatus = {
SUCCESS: "SUCCESS", SUCCESS: "SUCCESS",
@ -35,7 +36,7 @@
let errorReason let errorReason
let poll let poll
let deployments = [] let deployments = []
let deploymentUrl = `https://${appId}.app.budi.live/${appId}` let deploymentUrl = `${$hostingStore.appUrl}/${appId}`
const formatDate = (date, format) => const formatDate = (date, format) =>
Intl.DateTimeFormat("en-GB", DATE_OPTIONS[format]).format(date) Intl.DateTimeFormat("en-GB", DATE_OPTIONS[format]).format(date)
@ -95,7 +96,7 @@
<h4>Deployment History</h4> <h4>Deployment History</h4>
<div class="deploy-div"> <div class="deploy-div">
{#if deployments.some(deployment => deployment.status === DeploymentStatus.SUCCESS)} {#if deployments.some(deployment => deployment.status === DeploymentStatus.SUCCESS)}
<a target="_blank" href={`https://${appId}.app.budi.live/${appId}`}> <a target="_blank" href={deploymentUrl}>
View Your Deployed App → View Your Deployed App →
</a> </a>
<Button primary on:click={() => modal.show()}>View webhooks</Button> <Button primary on:click={() => modal.show()}>View webhooks</Button>

View File

@ -1,21 +1,20 @@
const PouchDB = require("../../../db") const PouchDB = require("../../../db")
const env = require("../../../environment")
const deployment = env.SELF_HOSTED
? require("./selfDeploy")
: require("./awsDeploy")
const { deploy, preDeployment, postDeployment, replicateDb } = deployment
const Deployment = require("./Deployment") const Deployment = require("./Deployment")
const {
getHostingInfo,
HostingTypes,
} = require("../../../utilities/builder/hosting")
// the max time we can wait for an invalidation to complete before considering it failed // the max time we can wait for an invalidation to complete before considering it failed
const MAX_PENDING_TIME_MS = 30 * 60000 const MAX_PENDING_TIME_MS = 30 * 60000
const DeploymentStatus = { const DeploymentStatus = {
SUCCESS: "SUCCESS", SUCCESS: "SUCCESS",
PENDING: "PENDING", PENDING: "PENDING",
FAILURE: "FAILURE", 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 // checks that deployments are in a good state, any pending will be updated
async function checkAllDeployments(deployments) { async function checkAllDeployments(deployments) {
let updated = false let updated = false
@ -66,17 +65,19 @@ async function deployApp(deployment) {
const appId = deployment.getAppId() const appId = deployment.getAppId()
try { try {
await deployment.init() await deployment.init()
deployment.setVerification(await preDeployment(deployment)) deployment.setVerification(
await deploymentService.preDeployment(deployment)
)
console.log(`Uploading assets for appID ${appId}..`) console.log(`Uploading assets for appID ${appId}..`)
await deploy(deployment) await deploymentService.deploy(deployment)
// replicate the DB to the main couchDB cluster // replicate the DB to the main couchDB cluster
console.log("Replicating local PouchDB to CouchDB..") console.log("Replicating local PouchDB to CouchDB..")
await replicateDb(deployment) await deploymentService.replicateDb(deployment)
await postDeployment(deployment) await deploymentService.postDeployment(deployment)
deployment.setStatus(DeploymentStatus.SUCCESS) deployment.setStatus(DeploymentStatus.SUCCESS)
await storeLocalDeploymentHistory(deployment) await storeLocalDeploymentHistory(deployment)
@ -118,6 +119,12 @@ exports.deploymentProgress = async function(ctx) {
} }
exports.deployApp = 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.user.appId) let deployment = new Deployment(ctx.user.appId)
deployment.setStatus(DeploymentStatus.PENDING) deployment.setStatus(DeploymentStatus.PENDING)
deployment = await storeLocalDeploymentHistory(deployment) deployment = await storeLocalDeploymentHistory(deployment)

View File

@ -14,18 +14,14 @@ exports.fetchInfo = async ctx => {
exports.save = async ctx => { exports.save = async ctx => {
const db = new CouchDB(BUILDER_CONFIG_DB) const db = new CouchDB(BUILDER_CONFIG_DB)
const { type, appServerUrl, objectStoreUrl, useHttps } = ctx.request.body const { type } = ctx.request.body
if (type === HostingTypes.CLOUD) { if (type === HostingTypes.CLOUD) {
ctx.throw(400, "Cannot update Cloud hosting information") ctx.throw(400, "Cannot update Cloud hosting information")
} }
const response = await db.put({ ctx.body = await db.put({
...ctx.request.body,
_id: HOSTING_DOC, _id: HOSTING_DOC,
type,
appServerUrl,
objectStoreUrl,
useHttps,
}) })
ctx.body = response
} }
exports.fetch = async ctx => { exports.fetch = async ctx => {
@ -34,6 +30,6 @@ exports.fetch = async ctx => {
exports.fetchUrls = async ctx => { exports.fetchUrls = async ctx => {
ctx.body = { ctx.body = {
appServer: getAppServerUrl(ctx.appId), appServer: await getAppServerUrl(ctx.appId),
} }
} }

View File

@ -7,6 +7,7 @@ const router = Router()
router router
.get("/api/hosting/info", authorized(BUILDER), controller.fetchInfo) .get("/api/hosting/info", authorized(BUILDER), controller.fetchInfo)
.get("/api/hosting/urls", authorized(BUILDER), controller.fetchUrls)
.get("/api/hosting", authorized(BUILDER), controller.fetch) .get("/api/hosting", authorized(BUILDER), controller.fetch)
.post("/api/hosting", authorized(BUILDER), controller.save) .post("/api/hosting", authorized(BUILDER), controller.save)