Skip to content

Commit

Permalink
Build a versioned OCI image in CI build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
milliams committed Aug 7, 2024
1 parent a70c13c commit ce6f951
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
uses: dtolnay/rust-toolchain@stable
- name: Build
run: cargo build --release
- name: Build OCI image
run: oci/build.sh --release
- name: Store build artefacts
uses: actions/upload-artifact@v4
with:
Expand Down
72 changes: 72 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ name = "conch"
version = "0.0.0"
edition = "2021"
license = "MIT"
build = "build.rs"

[dependencies]
anyhow = "1.0"
Expand All @@ -26,6 +27,9 @@ tracing = "0.1"
tracing-subscriber = "0.3"
url = "2.5.2"

[build-dependencies]
built = { version = "0.7", default-features = false, features = ["git2"] }

[lints.rust]
unsafe_code = "forbid"
unused_crate_dependencies = "warn"
Expand Down
7 changes: 7 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-FileCopyrightText: © 2024 Matt Williams <[email protected]>
// SPDX-License-Identifier: MIT

fn main() {
#[allow(clippy::expect_used)]
built::write_built_file().expect("Failed to acquire build-time information");
}
3 changes: 3 additions & 0 deletions oci/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
# SPDX-License-Identifier: MIT

FROM gcr.io/distroless/cc-debian12
LABEL org.opencontainers.image.source=https://github.com/isambard-sc/conch
LABEL org.opencontainers.image.description="Conch SSH CA"
LABEL org.opencontainers.image.licenses=MIT
COPY conch /
ENTRYPOINT ["/conch"]
3 changes: 2 additions & 1 deletion oci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ cp "$(artifact_path "${out}" "conch")" oci

cd oci

image_id=$(podman build . --tag=conch | tee /dev/fd/2 | tail -n1)
version=$(./conch --version | tail -n1 | cut -d' ' -f 2)
image_id=$(podman build . --tag=conch:latest --tag=conch:"${version}" | tee /dev/fd/2 | tail -n1)
rm conch
echo "Built conch image:" 1>&2
echo "${image_id}"
10 changes: 9 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ use serde_json::json;
use tokio_retry::{strategy::FixedInterval, Retry};
use tracing::info;

pub mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}

fn version() -> &'static str {
built_info::GIT_VERSION.unwrap_or(built_info::PKG_VERSION)
}

#[derive(Parser)]
#[command(version, about, long_about = None)]
#[command(version = version(), about, long_about = None)]
/// Conch SSH CA
struct Args {
/// the config file
Expand Down

0 comments on commit ce6f951

Please sign in to comment.