diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ef6dbe94..062d11b9 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -82,3 +82,4 @@ jobs: provenance: false # https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#adding-a-description-to-multi-arch-images outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=A multi-arch Docker image for the Maybe Rails app + build-args: BUILD_COMMIT_SHA=${{ github.sha }} diff --git a/Dockerfile b/Dockerfile index ff2d8d30..d98833b3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,14 +9,16 @@ WORKDIR /rails # Install base packages RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y curl libvips postgresql-client git + apt-get install --no-install-recommends -y curl libvips postgresql-client # Set production environment +ARG BUILD_COMMIT_SHA ENV RAILS_ENV="production" \ BUNDLE_DEPLOYMENT="1" \ BUNDLE_PATH="/usr/local/bundle" \ - BUNDLE_WITHOUT="development" - + BUNDLE_WITHOUT="development" \ + BUILD_COMMIT_SHA=${BUILD_COMMIT_SHA} + # Throw-away build stage to reduce size of final image FROM base AS build diff --git a/config/initializers/version.rb b/config/initializers/version.rb index 385ca36d..40a27790 100644 --- a/config/initializers/version.rb +++ b/config/initializers/version.rb @@ -5,7 +5,11 @@ module Maybe end def commit_sha - `git rev-parse HEAD`.chomp + if Rails.env.production? + ENV["BUILD_COMMIT_SHA"] + else + `git rev-parse HEAD`.chomp + end end private