See the best posts from any Bluesky account
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add git commit hash versioning to Docker image and HTTP responses

Tag Docker images with the short SHA and expose it via X-Version response
header so the deployed version is verifiable with a single curl.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+25 -3
+3
Dockerfile
··· 27 27 RUN apk add --no-cache tini 28 28 WORKDIR /app 29 29 30 + ARG GIT_SHA="" 31 + ENV GIT_SHA=${GIT_SHA} 32 + 30 33 # The build directory is self-contained (JS + package.json + lockfile). 31 34 # Copy it as the application root and install only production dependencies. 32 35 COPY --from=build --chown=node:node /app/build ./
+14
app/middleware/version_header_middleware.ts
··· 1 + import { type HttpContext } from '@adonisjs/core/http' 2 + import { type NextFn } from '@adonisjs/core/types/http' 3 + import env from '#start/env' 4 + 5 + export default class VersionHeaderMiddleware { 6 + handle({ response }: HttpContext, next: NextFn) { 7 + const sha = env.get('GIT_SHA') 8 + if (sha) { 9 + response.header('X-Version', sha) 10 + } 11 + 12 + return next() 13 + } 14 + }
+3 -2
deploy.sh
··· 6 6 echo "Pulling latest code..." 7 7 git pull origin main 8 8 9 - echo "Building image..." 10 - docker build -t favs-blue:latest . 9 + GIT_SHA=$(git rev-parse --short HEAD) 10 + echo "Building image (${GIT_SHA})..." 11 + docker build --build-arg GIT_SHA="${GIT_SHA}" -t favs-blue:latest -t "favs-blue:${GIT_SHA}" . 11 12 12 13 echo "Deploying stack..." 13 14 while IFS= read -r line || [[ -n "$line" ]]; do
+1 -1
resources/views/components/layout.edge
··· 15 15 <meta name="csrf-token" content="{{ csrfToken }}"> 16 16 @if(posthogApiKey) 17 17 <meta name="posthog-api-key" content="{{ posthogApiKey }}"> 18 - @if(auth.isAuthenticated) 18 + @if(auth && auth.isAuthenticated) 19 19 <meta name="posthog-distinct-id" content="{{ auth.user.did }}"> 20 20 <meta name="posthog-handle" content="{{ auth.user.handle }}"> 21 21 @endif
+3
start/env.ts
··· 47 47 POSTHOG_API_KEY: Env.schema.string.optional(), 48 48 POSTHOG_HOST: Env.schema.string.optional(), 49 49 50 + // Version 51 + GIT_SHA: Env.schema.string.optional(), 52 + 50 53 // OpenTelemetry 51 54 OTEL_EXPORTER_OTLP_ENDPOINT: Env.schema.string.optional(), 52 55 OTEL_EXPORTER_OTLP_HEADERS: Env.schema.string.optional(),
+1
start/kernel.ts
··· 25 25 server.use([ 26 26 () => import('#middleware/container_bindings_middleware'), 27 27 () => import('#middleware/theme_middleware'), 28 + () => import('#middleware/version_header_middleware'), 28 29 () => import('@adonisjs/static/static_middleware'), 29 30 () => import('@adonisjs/vite/vite_middleware'), 30 31 ])