Skip to content

Commit ba8d908

Browse files
authored
Merge pull request #1371 from makeabilitylab/1366-version-build-info
fix(version): populate /version/ git_sha and built_at in deployed envs (#1366)
2 parents 09d6f2f + fa1d7cd commit ba8d908

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ RUN pip install --upgrade pip
2626
# - imagemagick: Image processing for thumbnails and conversions
2727
# - ghostscript: PDF processing (required by imagemagick for PDFs)
2828
# - sqlite3: Useful for debugging, though we use PostgreSQL in production
29+
# - git: lets docker-entrypoint.sh capture the deployed commit SHA into
30+
# build-info.json for the /version/ endpoint (#1366)
2931
#
3032
# We clean up the apt cache afterward to reduce the final image size.
3133
RUN apt-get update \
3234
&& apt-get --assume-yes install --no-install-recommends \
3335
imagemagick \
3436
ghostscript \
3537
sqlite3 \
38+
git \
3639
&& apt-get clean \
3740
&& rm -rf /var/lib/apt/lists/*
3841

docker-entrypoint.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,15 @@ echo ""
5252
# capture the short SHA + a timestamp ONCE here (not per request) into a small
5353
# build-info.json that website/views/version.py reads. Falls back to "unknown"
5454
# if git isn't available (the view also tolerates a missing file).
55+
#
56+
# On the servers /code is a bind-mount whose .git is owned by apache:makelab
57+
# while this script runs as root, so git's "dubious ownership" guard would
58+
# otherwise refuse to run -- mark /code safe first (-c is process-local, no
59+
# global config side effects). git is installed in the Dockerfile.
5560
echo "****************** STEP -1/5: docker-entrypoint.sh ************************"
5661
echo "-1. Writing build-info.json (git sha + build timestamp) for /version/"
5762
echo "******************************************"
58-
GIT_SHA=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
63+
GIT_SHA=$(git -c safe.directory=/code -C /code rev-parse --short HEAD 2>/dev/null || echo "unknown")
5964
BUILT_AT=$(date --iso-8601=seconds 2>/dev/null || echo "unknown")
6065
printf '{"git_sha": "%s", "built_at": "%s"}\n' "$GIT_SHA" "$BUILT_AT" > build-info.json
6166
cat build-info.json

makeabilitylab/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@
8686
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
8787

8888
# Makeability Lab Global Variables, including Makeability Lab version
89-
ML_WEBSITE_VERSION = "2.17.1" # Keep this updated with each release and also change the short description below
90-
ML_WEBSITE_VERSION_DESCRIPTION = "Add an admin Data Health check, 'Artifacts not linked to a project' (/admin/data-health/), that surfaces every talk, paper, video, and poster with no project assigned so the backlog stays visible and shrinks over time. Pre-Makeability-Lab work (before settings.DATE_MAKEABILITYLAB_FORMED) is excluded, rows whose parent publication is already linked are flagged as quick wins (inherit its projects), and each row deep-links to its admin edit page. Read-only with CSV export. Also keeps data-health row-action buttons from wrapping mid-word in narrow columns (#649)."
89+
ML_WEBSITE_VERSION = "2.17.2" # Keep this updated with each release and also change the short description below
90+
ML_WEBSITE_VERSION_DESCRIPTION = "Fix the /version/ endpoint reporting git_sha and built_at as 'unknown' in deployed environments. The build-info capture in docker-entrypoint.sh needs git (it wasn't installed in the image) and trips git's 'dubious ownership' guard because /code/.git is apache:makelab-owned while the container runs as root. Installs git in the Dockerfile and runs rev-parse with -c safe.directory=/code. The Dockerfile change also forces an image rebuild on deploy, so the entrypoint actually re-runs and writes build-info.json (#1366)."
9191
DATE_MAKEABILITYLAB_FORMED = datetime.date(2012, 1, 1) # Date Makeability Lab was formed
9292
MAX_BANNERS = 7 # Maximum number of banners on a page
9393

0 commit comments

Comments
 (0)