From 6c790206a898bff2a1700b018602df19d16c3724 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 7 Apr 2021 17:13:19 +0100 Subject: [PATCH] Attempting to use HBS to re-create the envoy file as needed in dev. --- .gitignore | 1 + hosting/docker-compose.dev.yaml | 2 +- hosting/{envoy.dev.yaml => envoy.dev.yaml.hbs} | 4 ++-- package.json | 4 +++- packages/server/scripts/dev/manage.js | 15 +++++++++++++++ 5 files changed, 22 insertions(+), 4 deletions(-) rename hosting/{envoy.dev.yaml => envoy.dev.yaml.hbs} (97%) diff --git a/.gitignore b/.gitignore index a84d25d46d..418c28d981 100644 --- a/.gitignore +++ b/.gitignore @@ -63,6 +63,7 @@ typings/ # dotenv environment variables file .env !hosting/.env +hosting/generated-envoy.dev.yaml # parcel-bundler cache (https://parceljs.org/) .cache diff --git a/hosting/docker-compose.dev.yaml b/hosting/docker-compose.dev.yaml index 8ee1753e11..5c6947a3e9 100644 --- a/hosting/docker-compose.dev.yaml +++ b/hosting/docker-compose.dev.yaml @@ -27,7 +27,7 @@ services: restart: always image: envoyproxy/envoy:v1.16-latest volumes: - - ./envoy.dev.yaml:/etc/envoy/envoy.yaml + - ./generated-envoy.dev.yaml:/etc/envoy/envoy.yaml ports: - "${MAIN_PORT}:10000" depends_on: diff --git a/hosting/envoy.dev.yaml b/hosting/envoy.dev.yaml.hbs similarity index 97% rename from hosting/envoy.dev.yaml rename to hosting/envoy.dev.yaml.hbs index 2ba08fe595..f7f642a244 100644 --- a/hosting/envoy.dev.yaml +++ b/hosting/envoy.dev.yaml.hbs @@ -106,7 +106,7 @@ static_resources: - endpoint: address: socket_address: - address: 172.17.0.1 + address: {{ address }} port_value: 4001 - name: builder-dev @@ -120,6 +120,6 @@ static_resources: - endpoint: address: socket_address: - address: 172.17.0.1 + address: {{ address }} port_value: 3000 diff --git a/package.json b/package.json index 42010f760a..8a0c629d94 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,9 @@ "publishdev": "lerna run publishdev", "publishnpm": "yarn build && lerna publish --force-publish", "restore": "npm run clean && npm run bootstrap && npm run build", - "nuke": "rimraf ~/.budibase && npm run restore && lerna run --parallel dev:stack:nuke", + "nuke": "npm run nuke:packages && npm run nuke:docker", + "nuke:packages": "npm run restore", + "nuke:docker": "lerna run --parallel dev:stack:nuke", "clean": "lerna clean", "kill-port": "kill-port 4001", "dev": "yarn run kill-port && lerna link && lerna run --parallel dev:builder --concurrency 1", diff --git a/packages/server/scripts/dev/manage.js b/packages/server/scripts/dev/manage.js index af4f67d23a..88967eb0b3 100644 --- a/packages/server/scripts/dev/manage.js +++ b/packages/server/scripts/dev/manage.js @@ -2,6 +2,11 @@ const compose = require("docker-compose") const path = require("path") const fs = require("fs") +const { processStringSync } = require("@budibase/string-templates") + +function isLinux() { + return process.platform !== "darwin" && process.platform !== "win32" +} // This script wraps docker-compose allowing you to manage your dev infrastructure with simple commands. const CONFIG = { @@ -17,6 +22,16 @@ const Commands = { } async function init() { + // generate envoy file, always do this incase it has changed + const hostingPath = path.join(process.cwd(), "..", "..", "hosting") + const envoyHbsPath = path.join(hostingPath, "envoy.dev.yaml.hbs") + const envoyOutputPath = path.join(hostingPath, "generated-envoy.dev.yaml") + const contents = fs.readFileSync(envoyHbsPath, "utf8") + const config = { + address: isLinux() ? "172.17.0.1" : "host.docker.internal", + } + fs.writeFileSync(envoyOutputPath, processStringSync(contents, config)) + const envFilePath = path.join(process.cwd(), ".env") if (fs.existsSync(envFilePath)) { return