From 2893437718b7006d8cdada7a868e4668366d3e99 Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Thu, 3 Feb 2022 08:54:50 -0600 Subject: [PATCH] fix(build): interpolate bundle with version metadata --- Dockerfile.alpine | 2 +- Dockerfile.stretch | 3 +-- config/esbuild.mjs | 6 ------ config/node.mk | 7 +++++-- src/version.ts | 14 +++++++------- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Dockerfile.alpine b/Dockerfile.alpine index aa59942..aa6cb01 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -14,7 +14,7 @@ COPY docs/config-docker.yml /root/.salty-dog.yml # copy package first, to invalidate other layers when version changes COPY package.json /salty-dog/package.json COPY yarn.lock /salty-dog/yarn.lock -RUN yarn install --development +RUN yarn install --production # copy chunks, largest to smallest (entrypoint) COPY out/src/ /salty-dog/out/ diff --git a/Dockerfile.stretch b/Dockerfile.stretch index dcb414b..8990418 100644 --- a/Dockerfile.stretch +++ b/Dockerfile.stretch @@ -15,8 +15,7 @@ COPY docs/config-docker.yml /root/.salty-dog.yml # copy package first, to invalidate other layers when version changes COPY package.json /salty-dog/package.json COPY yarn.lock /salty-dog/yarn.lock -RUN yarn install --development -# --production +RUN yarn install --production # copy build COPY out/src/ /salty-dog/out/ diff --git a/config/esbuild.mjs b/config/esbuild.mjs index 005de10..d3e5ebf 100644 --- a/config/esbuild.mjs +++ b/config/esbuild.mjs @@ -16,12 +16,6 @@ build({ '.js': '.cjs', }, platform: 'node', - plugins: [ - IgnorePlugin([{ - resourceRegExp: /(dtrace-provider|ink|mv|node-fetch)/, - contextRegExp: /node_modules/, - }]), - ], }).catch((err) => { console.error(err); process.exit(1); diff --git a/config/node.mk b/config/node.mk index b88c8e9..d5d2914 100644 --- a/config/node.mk +++ b/config/node.mk @@ -1,9 +1,10 @@ # node options -NODE_BIN = $(ROOT_PATH)node_modules/.bin NODE_CMD ?= $(shell env node) NODE_DEBUG ?= --inspect-brk=$(DEBUG_BIND):$(DEBUG_PORT) --nolazy -export NODE_VERSION := $(shell node -v 2>/dev/null || echo "none") +export NODE_VERSION := $(shell node -v 2>/dev/null || echo "none") +export PACKAGE_NAME := $(shell jq -r '.name' package.json) +export PACKAGE_VERSION := $(shell jq -r '.version' package.json) # directory targets node_modules: deps @@ -14,6 +15,8 @@ out: build build: ## build the app build: node_modules yarn tsc + cat $(TARGET_PATH)/src/version.js | envsubst > $(TARGET_PATH)/src/version-out.js + mv $(TARGET_PATH)/src/version-out.js $(TARGET_PATH)/src/version.js bundle: build node config/esbuild.mjs diff --git a/src/version.ts b/src/version.ts index 03518c3..87ae948 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,15 +1,15 @@ export const VERSION_INFO = { build: { - job: '{{ BUILD_JOB }}', - node: '{{ NODE_VERSION }}', - runner: '{{ BUILD_RUNNER }}', + job: '${BUILD_JOB}', + node: '${NODE_VERSION}', + runner: '${BUILD_RUNNER}', }, git: { - branch: '{{ GIT_BRANCH }}', - commit: '{{ GIT_COMMIT }}', + branch: '${GIT_BRANCH}', + commit: '${GIT_COMMIT}', }, package: { - name: '{{ PACKAGE_NAME }}', - version: '{{ PACKAGE_VERSION }}', + name: '${PACKAGE_NAME}', + version: '${PACKAGE_VERSION}', }, };