From b1abea0f40db8c4190ca249067120943cc731d21 Mon Sep 17 00:00:00 2001 From: Sander Bruens Date: Fri, 30 Aug 2024 12:45:17 -0400 Subject: [PATCH 1/4] fix(server): fix version parsing --- src/shadowbox/webpack.config.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/shadowbox/webpack.config.js b/src/shadowbox/webpack.config.js index 10eaeedd1..894bb8ebe 100644 --- a/src/shadowbox/webpack.config.js +++ b/src/shadowbox/webpack.config.js @@ -31,7 +31,9 @@ const config = { }, plugins: [ // Used by server/version.ts. - process.env.SB_VERSION ? new webpack.DefinePlugin({'__VERSION__': JSON.stringify(process.env.SB_VERSION)}): undefined, + process.env.VERSION + ? new webpack.DefinePlugin({__VERSION__: JSON.stringify(process.env.VERSION)}) + : undefined, // WORKAROUND: some of our (transitive) dependencies use node-gently, which hijacks `require`. // Setting global.GENTLY to false makes these dependencies use standard require. new webpack.DefinePlugin({'global.GENTLY': false}), From a79949c1c07b6e7c71153fcdcac19616b48d3517 Mon Sep 17 00:00:00 2001 From: Sander Bruens Date: Fri, 30 Aug 2024 17:28:23 -0400 Subject: [PATCH 2/4] Revert to `SB_VERSION` and set it in the `Node.js` app build step. --- src/shadowbox/Taskfile.yml | 13 ++++++++----- src/shadowbox/docker/Dockerfile | 4 ++-- src/shadowbox/server/main.ts | 2 +- src/shadowbox/webpack.config.js | 4 +--- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/shadowbox/Taskfile.yml b/src/shadowbox/Taskfile.yml index f56b51005..c62da26e5 100644 --- a/src/shadowbox/Taskfile.yml +++ b/src/shadowbox/Taskfile.yml @@ -27,6 +27,9 @@ tasks: TARGET_DIR: '{{.TARGET_DIR | default (joinPath .OUTPUT_BASE .TARGET_OS .TARGET_ARCH)}}' NODE_DIR: '{{joinPath .TARGET_DIR "app"}}' BIN_DIR: '{{joinPath .TARGET_DIR "bin"}}' + SB_VERSION: '{{.SB_VERSION}}' + env: + SB_VERSION: '{{.SB_VERSION}}' cmds: - echo Target platform is {{.TARGET_OS}}/{{.TARGET_ARCH}} - rm -rf '{{.TARGET_DIR}}' @@ -64,7 +67,7 @@ tasks: - echo "Using directory {{.RUN_DIR}}" - mkdir -p '{{.STATE_DIR}}' - echo '{"hostname":"127.0.0.1"}' > "{{.STATE_CONFIG}}" - - task: make_test_certificate + - task: make_test_certificate vars: {OUTPUT_DIR: '{{.RUN_DIR}}'} - node '{{joinPath .OUTPUT_BASE .TARGET_OS .TARGET_ARCH "app/main.js"}}' @@ -82,7 +85,7 @@ tasks: (dict "x86_64" "node@sha256:a0b787b0d53feacfa6d606fb555e0dbfebab30573277f1fe25148b05b66fa097" "arm64" "node@sha256:b4b7a1dd149c65ee6025956ac065a843b4409a62068bd2b0cbafbb30ca2fab3b" - ) .TARGET_ARCH + ) .TARGET_ARCH }}' env: DOCKER_CONTENT_TRUST: '{{.DOCKER_CONTENT_TRUST | default "1"}}' @@ -91,7 +94,7 @@ tasks: cmds: - rm -rf '{{.IMAGE_ROOT}}' - mkdir -p '{{.IMAGE_ROOT}}' - - {task: build, vars: {TARGET_OS: linux, TARGET_ARCH: '{{.TARGET_ARCH}}', TARGET_DIR: '{{joinPath .IMAGE_ROOT "/opt/outline-server"}}'}} + - {task: build, vars: {SB_VERSION: '{{.VERSION}}', TARGET_OS: linux, TARGET_ARCH: '{{.TARGET_ARCH}}', TARGET_DIR: '{{joinPath .IMAGE_ROOT "/opt/outline-server"}}'}} - cp -R '{{joinPath .TASKFILE_DIR "scripts"}}' '{{.IMAGE_ROOT}}/scripts' - mkdir -p '{{joinPath .IMAGE_ROOT "/etc/periodic/weekly"}}' - cp '{{joinPath .TASKFILE_DIR "scripts" "update_mmdb.sh"}}' '{{joinPath .IMAGE_ROOT "/etc/periodic/weekly/"}}' @@ -128,7 +131,7 @@ tasks: - rm -rf '{{.RUN_DIR}}' - mkdir -p '{{.HOST_STATE_DIR}}' - echo '{"hostname":"127.0.0.1"}' > "{{.STATE_CONFIG}}" - - task: make_test_certificate + - task: make_test_certificate vars: {OUTPUT_DIR: '{{.HOST_STATE_DIR}}'} - | docker_command=( @@ -143,7 +146,7 @@ tasks: {{- end}} # Where the container keeps its persistent state. - -v "{{.HOST_STATE_DIR}}:{{.CONTAINER_STATE_DIR}}" + -v "{{.HOST_STATE_DIR}}:{{.CONTAINER_STATE_DIR}}" -e "SB_STATE_DIR={{.CONTAINER_STATE_DIR}}" # Port number and path prefix used by the server manager API. diff --git a/src/shadowbox/docker/Dockerfile b/src/shadowbox/docker/Dockerfile index b1aa160cb..c9d27db7a 100644 --- a/src/shadowbox/docker/Dockerfile +++ b/src/shadowbox/docker/Dockerfile @@ -13,9 +13,9 @@ # limitations under the License. ARG NODE_IMAGE -ARG VERSION FROM ${NODE_IMAGE} +ARG VERSION # Save metadata on the software versions we are using. LABEL shadowbox.node_version=16.18.0 @@ -36,4 +36,4 @@ RUN /etc/periodic/weekly/update_mmdb.sh # Install shadowbox. WORKDIR /opt/outline-server -CMD /cmd.sh +CMD ["/cmd.sh"] diff --git a/src/shadowbox/server/main.ts b/src/shadowbox/server/main.ts index ee5c661a0..7aba948ce 100644 --- a/src/shadowbox/server/main.ts +++ b/src/shadowbox/server/main.ts @@ -120,7 +120,7 @@ async function main() { logging.info(`Hostname: ${proxyHostname}`); logging.info(`SB_METRICS_URL: ${metricsCollectorUrl}`); - const prometheusPort = await portProvider.reserveFirstFreePort(9090); + const prometheusPort = await portProvider.reserveFirstFreePort(9080); // Use 127.0.0.1 instead of localhost for Prometheus because it's resolving incorrectly for some users. // See https://github.com/Jigsaw-Code/outline-server/issues/341 const prometheusLocation = `127.0.0.1:${prometheusPort}`; diff --git a/src/shadowbox/webpack.config.js b/src/shadowbox/webpack.config.js index 894bb8ebe..10eaeedd1 100644 --- a/src/shadowbox/webpack.config.js +++ b/src/shadowbox/webpack.config.js @@ -31,9 +31,7 @@ const config = { }, plugins: [ // Used by server/version.ts. - process.env.VERSION - ? new webpack.DefinePlugin({__VERSION__: JSON.stringify(process.env.VERSION)}) - : undefined, + process.env.SB_VERSION ? new webpack.DefinePlugin({'__VERSION__': JSON.stringify(process.env.SB_VERSION)}): undefined, // WORKAROUND: some of our (transitive) dependencies use node-gently, which hijacks `require`. // Setting global.GENTLY to false makes these dependencies use standard require. new webpack.DefinePlugin({'global.GENTLY': false}), From 1c7752f62170e8eb464a15f574a2cfa7dbc2a4c2 Mon Sep 17 00:00:00 2001 From: Sander Bruens Date: Fri, 30 Aug 2024 17:29:29 -0400 Subject: [PATCH 3/4] Revert port change. --- src/shadowbox/server/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shadowbox/server/main.ts b/src/shadowbox/server/main.ts index 7aba948ce..ee5c661a0 100644 --- a/src/shadowbox/server/main.ts +++ b/src/shadowbox/server/main.ts @@ -120,7 +120,7 @@ async function main() { logging.info(`Hostname: ${proxyHostname}`); logging.info(`SB_METRICS_URL: ${metricsCollectorUrl}`); - const prometheusPort = await portProvider.reserveFirstFreePort(9080); + const prometheusPort = await portProvider.reserveFirstFreePort(9090); // Use 127.0.0.1 instead of localhost for Prometheus because it's resolving incorrectly for some users. // See https://github.com/Jigsaw-Code/outline-server/issues/341 const prometheusLocation = `127.0.0.1:${prometheusPort}`; From 1c7e066e3cd211a77bce5bc1f6decd73e9eaab0b Mon Sep 17 00:00:00 2001 From: sbruens Date: Tue, 3 Sep 2024 12:17:44 -0400 Subject: [PATCH 4/4] Set `SB_VERSION` env variable only where it's needed. --- src/shadowbox/Taskfile.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/shadowbox/Taskfile.yml b/src/shadowbox/Taskfile.yml index c62da26e5..fb72a9b87 100644 --- a/src/shadowbox/Taskfile.yml +++ b/src/shadowbox/Taskfile.yml @@ -27,16 +27,14 @@ tasks: TARGET_DIR: '{{.TARGET_DIR | default (joinPath .OUTPUT_BASE .TARGET_OS .TARGET_ARCH)}}' NODE_DIR: '{{joinPath .TARGET_DIR "app"}}' BIN_DIR: '{{joinPath .TARGET_DIR "bin"}}' - SB_VERSION: '{{.SB_VERSION}}' - env: - SB_VERSION: '{{.SB_VERSION}}' + VERSION: '{{.VERSION}}' cmds: - echo Target platform is {{.TARGET_OS}}/{{.TARGET_ARCH}} - rm -rf '{{.TARGET_DIR}}' - mkdir -p '{{.TARGET_DIR}}' - cp '{{joinPath .TASKFILE_DIR "package.json"}}' '{{.TARGET_DIR}}' # Build Node.js app - - npx webpack --config='{{joinPath .TASKFILE_DIR "webpack.config.js"}}' --output-path='{{.NODE_DIR}}' ${BUILD_ENV:+--mode="${BUILD_ENV}"} + - SB_VERSION={{.VERSION}} npx webpack --config='{{joinPath .TASKFILE_DIR "webpack.config.js"}}' --output-path='{{.NODE_DIR}}' ${BUILD_ENV:+--mode="${BUILD_ENV}"} # Copy third_party dependencies - task: ':third_party:prometheus:copy-{{.TARGET_OS}}-{{.GOARCH}}' vars: {TARGET_DIR: '{{.BIN_DIR}}'} @@ -94,7 +92,7 @@ tasks: cmds: - rm -rf '{{.IMAGE_ROOT}}' - mkdir -p '{{.IMAGE_ROOT}}' - - {task: build, vars: {SB_VERSION: '{{.VERSION}}', TARGET_OS: linux, TARGET_ARCH: '{{.TARGET_ARCH}}', TARGET_DIR: '{{joinPath .IMAGE_ROOT "/opt/outline-server"}}'}} + - {task: build, vars: {VERSION: '{{.VERSION}}', TARGET_OS: linux, TARGET_ARCH: '{{.TARGET_ARCH}}', TARGET_DIR: '{{joinPath .IMAGE_ROOT "/opt/outline-server"}}'}} - cp -R '{{joinPath .TASKFILE_DIR "scripts"}}' '{{.IMAGE_ROOT}}/scripts' - mkdir -p '{{joinPath .IMAGE_ROOT "/etc/periodic/weekly"}}' - cp '{{joinPath .TASKFILE_DIR "scripts" "update_mmdb.sh"}}' '{{joinPath .IMAGE_ROOT "/etc/periodic/weekly/"}}'