-
Notifications
You must be signed in to change notification settings - Fork 3
Implement VERSION and COMMIT_SHA using Docker build arguments #127
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
Conversation
- Add VERSION to .gitignore - Update Dockerfiles to create default VERSION file (0.0.0) - Create generate-version.js script to read VERSION and generate version.ts - Update package.json to run version generation before builds - Update useAppStore.ts to import version from generated file instead of package.json - Add version.ts to .gitignore as it's auto-generated Co-authored-by: edenchazard <[email protected]>
- Update README.md with instructions on building with version number - Add explanatory comments to Dockerfile about VERSION file behavior Co-authored-by: edenchazard <[email protected]>
- Improve error handling in generate-version.js with specific messages - Fix Dockerfile race condition by creating VERSION after COPY - Update Dockerfile.dev with clearer comment about VERSION handling - Test fallback behavior when VERSION file is missing Co-authored-by: edenchazard <[email protected]>
edenchazard
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.
You misunderstood me. When the push image workflow is in process, and we are building the image, we should pass the version as the build arg to docker build. This workflow can be found at https://github.com/edenchazard/dc-lineage-builder/blob/main/.github/workflows/push-image.yml
Additionally, as a second requirement: also pass the commit reference as a build arg, and include the 6 digit commit reference in the footer, alongside where the version number is.
package.json
Outdated
| "vue:start": "node generate-version.js && vite --host", | ||
| "vue:preview": "vite preview", | ||
| "vue:build": "vite build", | ||
| "vue:build": "node generate-version.js && vite build", |
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.
Don't bother with the generate.js script and invoking it in these scripts.
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.
Removed generate-version.js and its script invocations. Now using Vite's define feature with build args instead. Changes in commit 04ed0bb.
Dockerfile.dev
Outdated
| WORKDIR /app | ||
| COPY package*.json ./ | ||
| RUN npm ci | ||
| # Note: VERSION file should be bind-mounted or created in docker-compose for dev |
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.
@copilot Just echo a dev to the VERSION file.
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.
Updated Dockerfile.dev to echo "dev" to VERSION file (and COMMIT_SHA as well). Changes in commit 04ed0bb.
- Remove generate-version.js script and its invocations from package.json - Use Vite's define feature to inject VERSION and COMMIT_SHA at build time - Update Dockerfile to accept VERSION and COMMIT_SHA as build arguments - Update Dockerfile.dev to echo "dev" for both VERSION and COMMIT_SHA - Update GitHub workflow to pass version and commit SHA as build args - Add commit SHA display in footer (first 6 characters) - Create vite-env.d.ts for TypeScript declarations - Update README with new build argument approach - Remove version.ts from .gitignore Co-authored-by: edenchazard <[email protected]>
Updated to pass VERSION and COMMIT_SHA as build args in the GitHub workflow. The footer now displays both the version and the first 6 characters of the commit SHA. Changes in commit 04ed0bb. |
- Add comment explaining ARG variables are available throughout the build stage - Add comment to Dockerfile.dev explaining why files are used instead of ARGs Co-authored-by: edenchazard <[email protected]>
|
Honestly, robot, you were shit at this. I've had to do it myself. |
The version number displayed in the footer was hardcoded from
package.json. Release builds need to inject the git tag (e.g.,v6.10.7) and commit SHA into the Docker image using build arguments.Changes
Build arguments approach
VERSIONandCOMMIT_SHAas build arguments (defaults:0.0.0andunknown)definefeature injects these values as build-time constants (__APP_VERSION__,__APP_COMMIT_SHA__)Docker configuration
Dockerfile: Accepts VERSION and COMMIT_SHA build args, creates VERSION and COMMIT_SHA files, passes values to Vite as environment variablesDockerfile.dev: Echoes "dev" to both VERSION and COMMIT_SHA files for developmentFrontend
useAppStore.tsto use build-time constants instead ofpackage.jsonv{version} ({first 6 chars of commit SHA})vite-env.d.tsfor TypeScript declarationsGitHub workflow
.github/workflows/push-image.ymlto extract version from git tag (strips "v" prefix)docker buildGit ignore
.gitignoreUsage
For production releases:
The GitHub workflow automatically extracts and passes these values during release builds. Version and commit SHA are statically bundled into the client JavaScript during the build process.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.