Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dockerfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ generate_build_command() {
# .yarnrc.yml writes use `printf` at build time (POSIX printf interprets \n in
# every shell), not `echo` (whose \n handling depends on the builder's /bin/sh).
local h="/home/${BUILDER_USER}"
printf '%s\n' "# Application version, injected from the build host (image context has no .git)"
printf '%s\n' "ARG APP_VERSION"
printf '%s\n' 'ENV APP_VERSION=${APP_VERSION}'
printf '%s\n' "# Build with npm auth mounted as a secret (token never persists in a layer)"
printf '%s\n' "RUN --mount=type=secret,id=npm_access_token,mode=0444 set -eu && \\"
printf '%s\n' " NPM_ACCESS_TOKEN=\$(cat /run/secrets/npm_access_token) && \\"
Expand Down
16 changes: 10 additions & 6 deletions scripts/build-prod-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
# On error exit
set -euo pipefail

git config --global --add safe.directory /home/ubuntu/app

# Compute version info
REV=$(git rev-parse --short HEAD)
TAG=$(git tag --points-at HEAD 2>/dev/null || echo "")
CWD=$(pwd)
APP_VERSION="${REV} (${TAG:-undefined})"

# APP_VERSION is normally injected from the build host (the image build context
# has no .git, so git cannot run here). Fall back to git only when this script
# is run locally inside a real repository.
if [ -z "${APP_VERSION:-}" ]; then
git config --global --add safe.directory "$CWD" 2>/dev/null || true
REV=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
TAG=$(git tag --points-at HEAD 2>/dev/null || echo "")
APP_VERSION="${REV} (${TAG:-undefined})"
fi

echo "Building: ${APP_VERSION}"

Expand Down
Loading