fix(build): embed commit timestamp & hash correctly in Docker images#30
Merged
Conversation
…unts Agent-Logs-Url: https://github.com/PoiCraft/MotdTracker/sessions/bda16920-ffa7-4459-b1e1-0200ecb9645d Co-authored-by: gggxbbb <39845709+gggxbbb@users.noreply.github.com>
…ard tabs Agent-Logs-Url: https://github.com/PoiCraft/MotdTracker/sessions/0a447b0f-c9fe-41ef-85e5-7963f40a55a2 Co-authored-by: gggxbbb <39845709+gggxbbb@users.noreply.github.com>
Agent-Logs-Url: https://github.com/PoiCraft/MotdTracker/sessions/611ba5ac-d9bd-4bd6-99fa-2206fde9cecf Co-authored-by: gggxbbb <39845709+gggxbbb@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
gggxbbb
May 4, 2026 05:14
View session
There was a problem hiding this comment.
Pull request overview
This PR improves build/release reproducibility by embedding the commit timestamp and hash into the app version string even when building Docker images without a .git/ directory, and adjusts the Docker runtime to handle bind-mounted data directory ownership.
Changes:
- Update
build.rsto derive version timestamp fromgit log -1 --format=%ctwith env-var fallbacks for Docker builds. - Pass git metadata into Docker builds via
ARG/build-argsand GitHub Actions. - Add a Docker runtime entrypoint that fixes
/app/dataownership before dropping privileges withgosu.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| entrypoint.sh | New entrypoint to chown /app/data then exec as motdtracker via gosu. |
| build.rs | Version string now uses commit time/hash with Docker-friendly env var fallbacks. |
| README.md | Updates Docker image name and reindents Docker/Docker Compose examples. |
| Dockerfile | Adds git metadata build args, installs gosu, and uses the new entrypoint. |
| .github/workflows/release.yml | Captures git metadata on the runner and forwards it as Docker build args. |
Comment on lines
+44
to
+55
| .or_else(|| { | ||
| std::env::var("GIT_COMMIT_TIME") | ||
| .ok() | ||
| .and_then(|s| s.parse::<u64>().ok()) | ||
| }) | ||
| .unwrap_or_else(|| { | ||
| use std::time::{SystemTime, UNIX_EPOCH}; | ||
| SystemTime::now() | ||
| .duration_since(UNIX_EPOCH) | ||
| .unwrap() | ||
| .as_secs() | ||
| }); |
Comment on lines
18
to
30
| // Generate pseudo version: vA.B.C-yyyyMMddhhmmss-{git-hash-short} | ||
| // Falls back to GIT_COMMIT_HASH / GIT_COMMIT_TIME env vars when the .git | ||
| // directory is absent (e.g. Docker builds where .git is in .dockerignore). | ||
| let pkg_version = std::env::var("CARGO_PKG_VERSION").unwrap(); | ||
|
|
||
| let git_hash = Command::new("git") | ||
| .args(["rev-parse", "--short", "HEAD"]) | ||
| .output() | ||
| .ok() | ||
| .filter(|o| o.status.success()) | ||
| .map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string()) | ||
| .or_else(|| std::env::var("GIT_COMMIT_HASH").ok()) | ||
| .unwrap_or_else(|| "unknown".to_string()); |
Comment on lines
+29
to
+30
| ARG GIT_COMMIT_TIME=0 | ||
| RUN GIT_COMMIT_HASH=${GIT_COMMIT_HASH} GIT_COMMIT_TIME=${GIT_COMMIT_TIME} cargo build --release |
Comment on lines
+6
to
+8
| # database. Fix ownership here (runs as root before privilege drop). | ||
| chown -R motdtracker:motdtracker /app/data || \ | ||
| echo "Warning: could not chown /app/data – database writes may fail if the directory is root-owned" |
Member
|
@copilot apply changes based on the comments in this thread,also fix some PoiCraft/motdtracker is wrongly being PoiCraft/motdtracker-rs in document |
…nd README Agent-Logs-Url: https://github.com/PoiCraft/MotdTracker/sessions/5b47c25e-fa90-4785-90df-4fb89ce304e9 Co-authored-by: gggxbbb <39845709+gggxbbb@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
build.rs: use commit timestamp instead of build time; add env-var fallbacks for Docker buildsbuild.rs: addcargo:rerun-if-env-changedforGIT_COMMIT_HASHandGIT_COMMIT_TIMEbuild.rs: filter outGIT_COMMIT_TIME=0(treat as invalid, fall through toSystemTime::now())Dockerfile: changeARG GIT_COMMIT_TIME=0to empty default to avoid epoch timestamp when not providedentrypoint.sh: makechownconditional on directory ownership to avoid startup latency on large bind mountsREADME.md: fix all 5 occurrences of wrongPoiCraft/motdtracker-rs→PoiCraft/MotdTracker