fix: Include git commit id while building docker image if possible (#3419)

* feat: Print commit id in dev container build workflow

* fix: Keep .git while building Qdrant binary in docker

* fix: Remove redundant printing of git commit id

* fix: Copy only git files first

* fix: Docker build should have commit id if present

* refactor: Use fewer lines of code
This commit is contained in:
Kumar Shivendu
2024-01-25 23:24:19 +05:30
committed by generall
parent f6b081d967
commit de5d120197
5 changed files with 9 additions and 6 deletions

View File

@@ -8,5 +8,4 @@ lib/collection/target
lib/storage/target
openapi/tests/
*.tar
.git
.github/
.github/

View File

@@ -14,6 +14,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
- name: Build the Docker image
run: |
# Create build container
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx create --use

View File

@@ -62,7 +62,7 @@ RUN case "$BUILDPLATFORM" in \
ARG TARGETPLATFORM
ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64}
RUN xx-apt-get install -y pkg-config gcc g++ libc6-dev libunwind-dev
RUN xx-apt-get install -y pkg-config gcc g++ libc6-dev libunwind-dev git
# Select Cargo profile (e.g., `release`, `dev` or `ci`)
ARG PROFILE=release
@@ -77,6 +77,7 @@ ARG RUSTFLAGS
ARG LINKER=mold
COPY --from=planner /qdrant/recipe.json recipe.json
COPY . .
# `PKG_CONFIG=...` is a workaround for `xx-cargo` bug for crates based on `pkg-config`!
#
# https://github.com/tonistiigi/xx/issues/107

View File

@@ -26,11 +26,11 @@ fn main() -> std::io::Result<()> {
// Fetch git commit ID and pass it to the compiler
match Command::new("git").args(["rev-parse", "HEAD"]).output() {
Ok(output) => {
Ok(output) if output.status.success() => {
let git_commit_id = str::from_utf8(&output.stdout).unwrap().trim();
println!("cargo:rustc-env=GIT_COMMIT_ID={git_commit_id}");
}
Err(_) => println!("cargo:warning=current git commit hash could not be determined"),
Ok(_) | Err(_) => println!("cargo:warning=current git commit hash could not be determined"),
}
Ok(())

View File

@@ -17,7 +17,9 @@ impl Default for VersionInfo {
VersionInfo {
title: "qdrant - vector search engine".to_string(),
version: env!("CARGO_PKG_VERSION").to_string(),
commit: option_env!("GIT_COMMIT_ID").map(ToString::to_string),
commit: option_env!("GIT_COMMIT_ID")
.map(ToString::to_string)
.filter(|s| !s.trim().is_empty()),
}
}
}