From eeb47bdf193d35a26ec03c04c05d2415dc7a296c Mon Sep 17 00:00:00 2001 From: buyolitsez Date: Fri, 26 Jun 2026 12:22:33 +0300 Subject: [PATCH] Embed build version metadata in production image --- .github/workflows/build-image.yml | 9 +++++++++ Dockerfile | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index 1b712bcc2..7a64c0a63 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -71,6 +71,12 @@ jobs: - name: Checkout uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # tag=v4.2.2 + - name: Compute version metadata + id: version + run: | + echo "revision=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" + echo "timestamp=$(git log -n 1 --format=%ct)" >> "$GITHUB_OUTPUT" + - name: Log in to GitHub Container Registry uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # tag=v3.4.0 with: @@ -96,6 +102,9 @@ jobs: context: . target: bewelcome_php platforms: ${{ matrix.platform }} + build-args: | + APP_VERSION=${{ steps.version.outputs.revision }} + APP_VERSION_TIMESTAMP=${{ steps.version.outputs.timestamp }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha,scope=${{ matrix.arch }} cache-to: type=gha,mode=max,scope=${{ matrix.arch }} diff --git a/Dockerfile b/Dockerfile index aa28e5024..da6ab8105 100644 --- a/Dockerfile +++ b/Dockerfile @@ -124,6 +124,9 @@ RUN set -eux; \ # Self-contained production image. FROM bewelcome_php_base AS bewelcome_php +ARG APP_VERSION=unknown +ARG APP_VERSION_TIMESTAMP= + ENV APP_ENV=prod COPY --from=bewelcome_source /srv/bewelcome/bin bin/ @@ -149,6 +152,8 @@ COPY --from=bewelcome_assets /srv/bewelcome/public/build public/build/ COPY --from=bewelcome_assets /srv/bewelcome/public/main.js /srv/bewelcome/public/service-worker.js public/ RUN set -eux; \ + printf '%s\n' "$APP_VERSION" > VERSION; \ + if [ -n "$APP_VERSION_TIMESTAMP" ]; then php -r 'touch("VERSION", (int) $argv[1]);' "$APP_VERSION_TIMESTAMP"; fi; \ mkdir -p var/cache var/log data/user/avatars data/gallery/member upload/images public/bundles /config /data; \ find public -name '*.map' -type f -delete; \ chown -R www-data:www-data var data upload public/bundles /config /data; \