Skip to content

Commit

Permalink
fix: Include git commit id while building docker image if possible (q…
Browse files Browse the repository at this point in the history
…drant#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
  • Loading branch information
KShivendu authored and generall committed Mar 5, 2024
1 parent f6b081d commit de5d120
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
3 changes: 1 addition & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ lib/collection/target
lib/storage/target
openapi/tests/
*.tar
.git
.github/
.github/
1 change: 1 addition & 0 deletions .github/workflows/dev-docker-image-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
4 changes: 3 additions & 1 deletion lib/api/src/grpc/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}
}
}
Expand Down

0 comments on commit de5d120

Please sign in to comment.