Adding a digital ocean startup init process which makes use of the user_data system.

This commit is contained in:
mike12345567 2021-03-19 10:02:29 +00:00
parent 60ab217386
commit 8549764db4
5 changed files with 28 additions and 2 deletions

View File

@ -14,6 +14,7 @@
"chalk": "^4.1.0",
"commander": "^7.1.0",
"docker-compose": "^0.23.6",
"envfile": "^6.14.0",
"inquirer": "^8.0.0",
"lookpath": "^1.1.0",
"pkg": "^4.4.9",

View File

@ -5,4 +5,5 @@ exports.CommandWords = {
exports.InitTypes = {
QUICK: "quick",
DIGITAL_OCEAN: "do",
}

View File

@ -6,6 +6,8 @@ const { confirmation } = require("../questions")
const fs = require("fs")
const compose = require("docker-compose")
const envFile = require("./makeEnv")
const { parse } = require("envfile")
const axios = require("axios")
const BUDIBASE_SERVICES = ["app-service", "worker-service"]
const ERROR_FILE = "docker-error.log"
@ -13,6 +15,7 @@ const FILE_URLS = [
"https://raw.githubusercontent.com/Budibase/budibase/master/hosting/docker-compose.yaml",
"https://raw.githubusercontent.com/Budibase/budibase/master/hosting/envoy.yaml",
]
const DO_USER_DATA_URL = "http://169.254.169.254/metadata/v1/user-data"
async function downloadFiles() {
const promises = []
@ -50,8 +53,8 @@ async function handleError(func) {
}
}
async function init(info) {
const isQuick = info === InitTypes.QUICK
async function init(type) {
const isQuick = type === InitTypes.QUICK || type === InitTypes.DIGITAL_OCEAN
await checkDockerConfigured()
if (!isQuick) {
const shouldContinue = await confirmation(
@ -64,6 +67,18 @@ async function init(info) {
}
await downloadFiles()
const config = isQuick ? envFile.QUICK_CONFIG : {}
if (type === InitTypes.DIGITAL_OCEAN) {
try {
const response = parse(await axios.get(DO_USER_DATA_URL))
for (let [key, value] of Object.entries(envFile.ConfigMap)) {
if (response[key]) {
config[value] = response[key]
}
}
} catch (err) {
// don't need to handle error, just don't do anything
}
}
await envFile.make(config)
}

View File

@ -30,6 +30,10 @@ BUDIBASE_ENVIRONMENT=PRODUCTION`
}
module.exports.filePath = FILE_PATH
module.exports.ConfigMap = {
HOSTING_KEY: "key",
MAIN_PORT: "port",
}
module.exports.QUICK_CONFIG = {
key: "budibase",
port: 10000,

View File

@ -391,6 +391,11 @@ enquirer@^2.3.5:
dependencies:
ansi-colors "^4.1.1"
envfile@^6.14.0:
version "6.14.0"
resolved "https://registry.yarnpkg.com/envfile/-/envfile-6.14.0.tgz#8dab1ab915a4c6567087a6bb9e732b1f164c2b30"
integrity sha512-JxpcaOgJQB/x0XFmNiqFu0BLK22PlI3F0d95of5SOqcLvBlGC0ug7MHYDWnmZqmx9svIue8v0cVcqAygPTyXHQ==
escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"