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 fd1d7e3aa1
commit f63466f1d1
7 changed files with 35 additions and 27 deletions

View File

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

View File

@ -10,10 +10,11 @@ export const getHostingStore = () => {
const store = writable({ ...INITIAL_BACKEND_UI_STATE })
store.actions = {
fetch: async () => {
const response = await api.get("/api/hosting/")
const info = await response.json()
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()))
store.update(state => {
state.hostingInfo = info
state.appUrl = urls.appServer
return state
})
return info
@ -30,6 +31,5 @@ export const getHostingStore = () => {
})
},
}
return store
}

View File

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

View File

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

View File

@ -1,21 +1,20 @@
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 {
getHostingInfo,
HostingTypes,
} = require("../../../utilities/builder/hosting")
// the max time we can wait for an invalidation to complete before considering it failed
const MAX_PENDING_TIME_MS = 30 * 60000
const DeploymentStatus = {
SUCCESS: "SUCCESS",
PENDING: "PENDING",
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
@ -66,17 +65,19 @@ async function deployApp(deployment) {
const appId = deployment.getAppId()
try {
await deployment.init()
deployment.setVerification(await preDeployment(deployment))
deployment.setVerification(
await deploymentService.preDeployment(deployment)
)
console.log(`Uploading assets for appID ${appId}..`)
await deploy(deployment)
await deploymentService.deploy(deployment)
// replicate the DB to the main couchDB cluster
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)
await storeLocalDeploymentHistory(deployment)
@ -118,6 +119,12 @@ 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.user.appId)
deployment.setStatus(DeploymentStatus.PENDING)
deployment = await storeLocalDeploymentHistory(deployment)

View File

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

View File

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