Merge branch 'fix_version_in_built_image' into 'master'

Fix version reporting ACME-122

See merge request turniere/turniere-backend!64
This commit is contained in:
Daniel Schädler 2026-04-27 10:25:52 +00:00
commit 7a97a17940
3 changed files with 14 additions and 14 deletions

View File

@ -2,6 +2,7 @@
ARG RUBY_VERSION=3.1.2 ARG RUBY_VERSION=3.1.2
ARG BUNDLER_VERSION=2.3.13 ARG BUNDLER_VERSION=2.3.13
ARG base_commit=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
FROM ruby:${RUBY_VERSION}-slim AS runtime-base FROM ruby:${RUBY_VERSION}-slim AS runtime-base
@ -54,13 +55,14 @@ RUN bundle config set with 'development test' \
FROM runtime-base AS production FROM runtime-base AS production
ARG GIT_COMMIT_SHA=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ARG base_commit=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
ENV RAILS_ENV=production ENV RAILS_ENV=production \
ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA} GIT_COMMIT_SHA=${base_commit}
COPY --from=bundle-production /usr/local/bundle /usr/local/bundle COPY --from=bundle-production /usr/local/bundle /usr/local/bundle
COPY --from=bundle-production /app/vendor/bundle /app/vendor/bundle COPY --from=bundle-production /app/vendor/bundle /app/vendor/bundle
COPY Gemfile Gemfile.lock /app/ COPY Gemfile Gemfile.lock /app/
COPY app /app/app COPY app /app/app
COPY bin /app/bin COPY bin /app/bin
@ -69,6 +71,7 @@ COPY db /app/db
COPY public /app/public COPY public /app/public
COPY script /app/script COPY script /app/script
COPY config.ru Rakefile /app/ COPY config.ru Rakefile /app/
# Duplicate production environment to beta environment # Duplicate production environment to beta environment
COPY config/environments/production.rb /app/config/environments/beta.rb COPY config/environments/production.rb /app/config/environments/beta.rb
@ -78,10 +81,10 @@ CMD ["sh", "-lc", "bundle exec rails db:migrate && bundle exec rails s -p 3000 -
FROM runtime-base AS test FROM runtime-base AS test
ARG GIT_COMMIT_SHA=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ARG base_commit=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
ENV RAILS_ENV=test ENV RAILS_ENV=test \
ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA} GIT_COMMIT_SHA=${base_commit}
RUN apt-get update -qq \ RUN apt-get update -qq \
&& apt-get install -y --no-install-recommends \ && apt-get install -y --no-install-recommends \
@ -93,6 +96,7 @@ RUN apt-get update -qq \
COPY --from=bundle-test /usr/local/bundle /usr/local/bundle COPY --from=bundle-test /usr/local/bundle /usr/local/bundle
COPY --from=bundle-test /app/vendor/bundle /app/vendor/bundle COPY --from=bundle-test /app/vendor/bundle /app/vendor/bundle
COPY Gemfile Gemfile.lock /app/ COPY Gemfile Gemfile.lock /app/
COPY app /app/app COPY app /app/app
COPY bin /app/bin COPY bin /app/bin

View File

@ -8,12 +8,6 @@ class VersionController < ApplicationController
private private
def git_commit_sha def git_commit_sha
ENV['GIT_COMMIT_SHA'].presence || local_git_commit_sha || 'unknown' ENV['GIT_COMMIT_SHA'].presence || 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
end
def local_git_commit_sha
Rails.root.join('.git').exist? ? `git rev-parse HEAD`.strip.presence : nil
rescue StandardError
nil
end end
end end

View File

@ -33,7 +33,9 @@ RSpec.describe 'Backend API surface HTTP E2E' do
response = anonymous_client.get('/version') response = anonymous_client.get('/version')
expect(response[:status]).to eq(200) expect(response[:status]).to eq(200)
expect(response.dig(:json, :git_commit_sha)).to match(/\A[0-9a-f]{40}\z/) sha = response.dig(:json, :git_commit_sha)
expect(sha).to match(/\A[0-9a-f]{40}\z/)
expect(sha).not_to eq("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
end end
it 'supports registration for new users and still requires confirmation for login' do it 'supports registration for new users and still requires confirmation for login' do