From bab28adb159978cda7786d96476349f37d6553b1 Mon Sep 17 00:00:00 2001 From: Malaber Date: Sun, 26 Apr 2026 15:36:15 +0200 Subject: [PATCH 1/2] Add version endpoint --- Dockerfile | 6 ++++++ app/controllers/version_controller.rb | 19 +++++++++++++++++++ config/routes.rb | 1 + spec/e2e/http/api_surface_spec.rb | 7 +++++++ tasks.py | 23 ++++++++++++++++++++++- 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 app/controllers/version_controller.rb diff --git a/Dockerfile b/Dockerfile index 9fb91e7..e23ba69 100644 --- a/Dockerfile +++ b/Dockerfile @@ -54,7 +54,10 @@ RUN bundle config set with 'development test' \ FROM runtime-base AS production +ARG GIT_COMMIT_SHA=unknown + 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 /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 +ARG GIT_COMMIT_SHA=unknown + ENV RAILS_ENV=test +ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA} RUN apt-get update -qq \ && apt-get install -y --no-install-recommends \ diff --git a/app/controllers/version_controller.rb b/app/controllers/version_controller.rb new file mode 100644 index 0000000..83c7bdc --- /dev/null +++ b/app/controllers/version_controller.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 7ef1030..945366d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,4 +39,5 @@ Rails.application.routes.draw do end resources :match_scores, only: %i[show update] get 'healthz', to: 'health#index' + get 'version', to: 'version#show' end diff --git a/spec/e2e/http/api_surface_spec.rb b/spec/e2e/http/api_surface_spec.rb index aebfcaf..8c92998 100644 --- a/spec/e2e/http/api_surface_spec.rb +++ b/spec/e2e/http/api_surface_spec.rb @@ -29,6 +29,13 @@ RSpec.describe 'Backend API surface HTTP E2E' do expect(response.dig(:json, :errors)).to eq([]) 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 unique = unique_suffix email = "http-e2e-#{unique}@example.com" diff --git a/tasks.py b/tasks.py index a1b8ac3..1145fdc 100644 --- a/tasks.py +++ b/tasks.py @@ -235,6 +235,13 @@ def _format_command(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): if platforms and "," in str(platforms) and not push: raise ValueError("multi-platform buildx builds require push=True") @@ -246,6 +253,8 @@ def _docker_build_command(tag, target, platforms=None, push=False): "build", "--target", target, + "--build-arg", + f"GIT_COMMIT_SHA={_git_commit_sha()}", "-t", tag, "-f", @@ -257,7 +266,19 @@ def _docker_build_command(tag, target, platforms=None, push=False): command.append(".") 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): From 51170f1b7f9d164ad676df1e7bb38c02ef2b65ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=A4dler?= Date: Sun, 26 Apr 2026 20:45:39 +0000 Subject: [PATCH 2/2] Switch from unknown to other dev version --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index e23ba69..7e7d590 100644 --- a/Dockerfile +++ b/Dockerfile @@ -54,7 +54,7 @@ RUN bundle config set with 'development test' \ FROM runtime-base AS production -ARG GIT_COMMIT_SHA=unknown +ARG GIT_COMMIT_SHA=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ENV RAILS_ENV=production ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA} @@ -78,7 +78,7 @@ CMD ["sh", "-lc", "bundle exec rails db:migrate && bundle exec rails s -p 3000 - FROM runtime-base AS test -ARG GIT_COMMIT_SHA=unknown +ARG GIT_COMMIT_SHA=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ENV RAILS_ENV=test ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA}