Skip to content

Commit

Permalink
Fix: revision in CI Docker image (#1119)
Browse files Browse the repository at this point in the history
* Fix: get correct `git` revision in CI Docker images

* Correctly set build arguments

* Make it an env variable as well

* Check `rev-parse` exit code

* Also check that it's not empty

* Address nit
  • Loading branch information
aldur authored Dec 16, 2024
1 parent 017dad3 commit 946cb29
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
11 changes: 7 additions & 4 deletions .github/actions/dockerfiles/Dockerfile.signer.debian
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM rust:1.81.0-slim-bookworm AS build

ARG GIT_COMMIT
RUN test -n "$GIT_COMMIT" || (echo "GIT_COMMIT not set" && false)

ARG CARGO_BUILD_ARGS="--release"

# Install dependencies.
Expand All @@ -14,10 +17,10 @@ RUN apt-get install -y --no-install-recommends \
npm \
default-jre \
g++ && \
apt-get clean && rm -rf /var/lib/apt/lists/*
apt-get clean && rm -rf /var/lib/apt/lists/*

RUN npm install -g pnpm@9
RUN npm install -g @openapitools/openapi-generator-cli
RUN npm install -g pnpm@9 && \
npm install -g @openapitools/openapi-generator-cli

WORKDIR /code/sbtc
COPY . .
Expand All @@ -32,5 +35,5 @@ COPY --from=build /code/sbtc/target/debug/signer /usr/local/bin/signer
# gettext provides envsubst

RUN apt-get update && apt-get install -y ca-certificates gettext --no-install-recommends && \
apt-get clean && rm -rf /var/lib/apt/lists/*
apt-get clean && rm -rf /var/lib/apt/lists/*
CMD ["/usr/local/bin/signer --config /signer-config.toml --migrate-db"]
2 changes: 2 additions & 0 deletions .github/workflows/image-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,5 @@ jobs:
labels: ${{ steps.docker_metadata.outputs.labels }}
target: ${{ matrix.docker_target }}
push: true
build-args: |
GIT_COMMIT=${{ github.ref_name }}
15 changes: 11 additions & 4 deletions signer/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::env;

fn main() {
set_up_build_info();
// compile_protos();
Expand All @@ -11,11 +13,16 @@ pub fn set_up_build_info() {

let version = String::from_utf8_lossy(&output.stdout);

let git_hash = std::process::Command::new("git")
let git_output = std::process::Command::new("git")
.args(["rev-parse", "HEAD"])
.output()
.map(|output| String::from_utf8_lossy(&output.stdout).to_string())
.unwrap_or_default();
.output();

let git_hash = match git_output {
Ok(output) if output.status.success() && !output.stdout.is_empty() => {
String::from_utf8_lossy(&output.stdout).to_string()
}
_ => std::env::var("GIT_COMMIT").unwrap_or_default(),
};

let env_abi = std::env::var("CARGO_CFG_TARGET_ENV").unwrap();
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
Expand Down

0 comments on commit 946cb29

Please sign in to comment.