-
Notifications
You must be signed in to change notification settings - Fork 2
proof of concept for setting version number env variable #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: paige-docker-testing
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a proof of concept for dynamically setting the application version number via environment variables, enabling the version to be displayed in the Django admin site header based on GitHub release tags.
- Modified settings to read version from
APP_VERSIONenvironment variable instead of hardcoded value - Updated docker-compose configuration to pass
APP_VERSIONas both a build argument and runtime environment variable - Added GitHub Actions workflow to automate Docker image builds with version information
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| TEKDB/docker-compose.yml | Added APP_VERSION as a build arg and environment variable to pass version information to the container |
| TEKDB/TEKDB/settings.py | Changed VERSION from hardcoded string to read from APP_VERSION environment variable with fallback to "unknown" |
| .github/workflows/build-docker-image.yaml | Added new workflow to build Docker images with version information extracted from Git ref names |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set version | ||
| run: echo "APP_VERSION=${GITHUB_REF_NAME#v}" >> .env |
Copilot
AI
Nov 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Writing APP_VERSION to a .env file won't make it available to docker-compose. The .env file created here is in the GitHub Actions runner's working directory, but docker-compose looks for .env in the build context.
Instead, you should either:
- Export it as an environment variable:
echo "APP_VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV - Or pass it directly when running docker-compose (as shown in the commented line 22)
Additionally, when the workflow is triggered by push events (as currently configured), GITHUB_REF_NAME will be the branch name, not a version tag. This will only work correctly when triggered by release events.
| run: echo "APP_VERSION=${GITHUB_REF_NAME#v}" >> .env | |
| run: echo "APP_VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV |
| args: | ||
| APP_VERSION: ${APP_VERSION} |
Copilot
AI
Nov 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Dockerfile needs to accept the APP_VERSION build argument and set it as an environment variable. Add these lines near the top of the Dockerfile (after the base image):
ARG APP_VERSION=unknown
ENV APP_VERSION=${APP_VERSION}Without these lines, the build arg passed from docker-compose.yml won't be captured, and the environment variable won't be available at runtime.
| name: Build Docker Image on Release | ||
|
|
||
| on: | ||
| push |
Copilot
AI
Nov 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing colon after push. The on trigger syntax requires a colon. This should be:
on:
push:or to trigger on all pushes:
on: pushThe current syntax is invalid and will cause the workflow to fail.
| push | |
| push: |
rhodges
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to solve for not breaking the VERSION setting in a non-Docker deployment.
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we run on:
- ubuntu-latest
- ubuntu 24.04 LTS
- ubuntu 22.04 LTS
We may also have partners on Ubuntu 20.04 LTS, which is now EOL, but I don't think we'll be dockerizing them - instead we'll migrate.
|
|
||
| # Add Version to the admin site header | ||
| VERSION = "2.2.2" | ||
| VERSION = os.getenv("APP_VERSION", "unknown") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like if this is launched any way other than with Docker (looking at this variable in build-docker-image.yml and referenced again in docker-compose.yml) then the admin header will read 'unknown'. I don't think this is appropriate. I appreciate the goal of only setting this once: it's DRY and prevents conflict from potential future mis-matches, but the canonical source for this value must be platform agnostic -- at least until all deployments adopt a Docker-based system.
For now I recommend either replacing "unknown" with something meaningful like "2.2.2+" or "2.3+" or "2.3.x" or even "2.x" until the appropriate single source that works for all deployments is solved for.
pollardld
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit over my head and am excited to learn more about how it works.
proof of concept on triggering a docker image build on release, using the release number as a build arg, and using the arg as an env variable to display in the admin site.