Skip to content

fix(build): embed commit timestamp & hash correctly in Docker images#30

Merged
gggxbbb merged 4 commits into
mainfrom
copilot/fix-database-connection-error
May 4, 2026
Merged

fix(build): embed commit timestamp & hash correctly in Docker images#30
gggxbbb merged 4 commits into
mainfrom
copilot/fix-database-connection-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

  • build.rs: use commit timestamp instead of build time; add env-var fallbacks for Docker builds
  • build.rs: add cargo:rerun-if-env-changed for GIT_COMMIT_HASH and GIT_COMMIT_TIME
  • build.rs: filter out GIT_COMMIT_TIME=0 (treat as invalid, fall through to SystemTime::now())
  • Dockerfile: change ARG GIT_COMMIT_TIME=0 to empty default to avoid epoch timestamp when not provided
  • entrypoint.sh: make chown conditional on directory ownership to avoid startup latency on large bind mounts
  • README.md: fix all 5 occurrences of wrong PoiCraft/motdtracker-rsPoiCraft/MotdTracker

@gggxbbb gggxbbb marked this pull request as ready for review May 4, 2026 05:18
Copilot AI review requested due to automatic review settings May 4, 2026 05:19
Copy link
Copy Markdown

Copilot AI left a 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 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.rs to derive version timestamp from git log -1 --format=%ct with env-var fallbacks for Docker builds.
  • Pass git metadata into Docker builds via ARG/build-args and GitHub Actions.
  • Add a Docker runtime entrypoint that fixes /app/data ownership before dropping privileges with gosu.

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 thread build.rs
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 thread build.rs
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 thread Dockerfile Outdated
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 thread README.md
Comment thread entrypoint.sh Outdated
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"
@gggxbbb
Copy link
Copy Markdown
Member

gggxbbb commented May 4, 2026

@copilot apply changes based on the comments in this thread,also fix some PoiCraft/motdtracker is wrongly being PoiCraft/motdtracker-rs in document

@gggxbbb gggxbbb merged commit cad85eb into main May 4, 2026
Copilot AI requested a review from gggxbbb May 4, 2026 05:28
Copilot stopped work on behalf of gggxbbb due to an error May 4, 2026 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants