Merge branch 'codex/tur-112-version-endpoint' into 'master'

TUR-112: Version endpoint

See merge request turniere/turniere-backend!58
This commit is contained in:
Daniel Schädler 2026-04-26 20:59:07 +00:00
commit 988171097c
5 changed files with 55 additions and 1 deletions

View File

@ -54,7 +54,10 @@ RUN bundle config set with 'development test' \
FROM runtime-base AS production FROM runtime-base AS production
ARG GIT_COMMIT_SHA=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
ENV RAILS_ENV=production ENV RAILS_ENV=production
ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA}
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
@ -75,7 +78,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
ENV RAILS_ENV=test ENV RAILS_ENV=test
ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA}
RUN apt-get update -qq \ RUN apt-get update -qq \
&& apt-get install -y --no-install-recommends \ && apt-get install -y --no-install-recommends \

View File

@ -0,0 +1,19 @@
# frozen_string_literal: true
class VersionController < ApplicationController
def show
render json: { git_commit_sha: }
end
private
def git_commit_sha
ENV['GIT_COMMIT_SHA'].presence || local_git_commit_sha || 'unknown'
end
def local_git_commit_sha
Rails.root.join('.git').exist? ? `git rev-parse HEAD`.strip.presence : nil
rescue StandardError
nil
end
end

View File

@ -39,4 +39,5 @@ Rails.application.routes.draw do
end end
resources :match_scores, only: %i[show update] resources :match_scores, only: %i[show update]
get 'healthz', to: 'health#index' get 'healthz', to: 'health#index'
get 'version', to: 'version#show'
end end

View File

@ -29,6 +29,13 @@ RSpec.describe 'Backend API surface HTTP E2E' do
expect(response.dig(:json, :errors)).to eq([]) expect(response.dig(:json, :errors)).to eq([])
end end
it 'reports running version' do
response = anonymous_client.get('/version')
expect(response[:status]).to eq(200)
expect(response.dig(:json, :git_commit_sha)).to match(/\A[0-9a-f]{40}\z/)
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
unique = unique_suffix unique = unique_suffix
email = "http-e2e-#{unique}@example.com" email = "http-e2e-#{unique}@example.com"

View File

@ -235,6 +235,13 @@ def _format_command(command):
return " ".join(shlex.quote(part) for part in command) return " ".join(shlex.quote(part) for part in command)
def _git_commit_sha():
try:
return subprocess.check_output(["git", "rev-parse", "HEAD"], text=True).strip()
except subprocess.CalledProcessError:
return "unknown"
def _docker_build_command(tag, target, platforms=None, push=False): def _docker_build_command(tag, target, platforms=None, push=False):
if platforms and "," in str(platforms) and not push: if platforms and "," in str(platforms) and not push:
raise ValueError("multi-platform buildx builds require push=True") raise ValueError("multi-platform buildx builds require push=True")
@ -246,6 +253,8 @@ def _docker_build_command(tag, target, platforms=None, push=False):
"build", "build",
"--target", "--target",
target, target,
"--build-arg",
f"GIT_COMMIT_SHA={_git_commit_sha()}",
"-t", "-t",
tag, tag,
"-f", "-f",
@ -257,7 +266,19 @@ def _docker_build_command(tag, target, platforms=None, push=False):
command.append(".") command.append(".")
return _format_command(command) return _format_command(command)
return f"docker build --target {target} -t {tag} -f {DOCKERFILE_PATH} ." return _format_command([
"docker",
"build",
"--target",
target,
"--build-arg",
f"GIT_COMMIT_SHA={_git_commit_sha()}",
"-t",
tag,
"-f",
DOCKERFILE_PATH,
".",
])
def _rspec_command(*paths): def _rspec_command(*paths):