Skip to content

Commit

Permalink
tag images with git commit, use docker build profile
Browse files Browse the repository at this point in the history
  • Loading branch information
b5 committed Nov 15, 2022
1 parent bad9bb0 commit 7521ede
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ inherits = 'release'
lto = true
panic = 'abort'
incremental = false
codegen-units = 8

[profile.docker]
inherits = 'release'
lto = true
panic = 'abort'
incremental = false
codegen-units = 8
4 changes: 2 additions & 2 deletions docker/Dockerfile.iroh-gateway
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ WORKDIR /iroh

COPY ../ .

RUN cargo build --bin iroh-gateway --release
RUN cargo build --bin iroh-gateway --profile=docker

################################################################################
## Final image
Expand All @@ -40,7 +40,7 @@ WORKDIR /iroh

# Copy our build, changing owndership to distroless-provided "nonroot" user,
# (65532:65532)
COPY --from=builder --chown=65532:65532 /iroh/target/release/iroh-gateway ./
COPY --from=builder --chown=65532:65532 /iroh/target/docker/iroh-gateway ./

# Use nonroot (unprivileged) user
USER nonroot
Expand Down
8 changes: 4 additions & 4 deletions docker/Dockerfile.iroh-one
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ WORKDIR /iroh

COPY ../ .

RUN cargo build --bin iroh-one --release
RUN cargo build --bin iroh-one --profile=docker

################################################################################
## Final image
Expand All @@ -46,12 +46,12 @@ WORKDIR /iroh

# Copy our build, changing owndership to distroless-provided "nonroot" user,
# (65532:65532)
COPY --from=builder --chown=65532:65532 /iroh/target/release/iroh-one ./
COPY --from=builder --chown=65532:65532 /iroh/target/docker/iroh-one ./

# Use nonroot (unprivileged) user
USER nonroot

# expose gateway port
EXPOSE 9050
# expose gateway, p2p & all default RPC ports
EXPOSE 4400 4401 4402 4403 4444 9050

CMD ["/iroh/iroh-one"]
6 changes: 3 additions & 3 deletions docker/Dockerfile.iroh-p2p
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ WORKDIR /iroh

COPY ../ .

RUN cargo build --bin iroh-p2p --release
RUN cargo build --bin iroh-p2p --profile=docker

################################################################################
## Final image
Expand All @@ -40,12 +40,12 @@ WORKDIR /iroh

# Copy our build, changing owndership to distroless-provided "nonroot" user,
# (65532:65532)
COPY --from=builder --chown=65532:65532 /iroh/target/release/iroh-p2p ./
COPY --from=builder --chown=65532:65532 /iroh/target/docker/iroh-p2p ./

# Use nonroot (unprivileged) user
USER nonroot

# expose the default RPC port
EXPOSE 4401
EXPOSE 4401 4444

CMD ["/iroh/iroh-p2p"]
4 changes: 2 additions & 2 deletions docker/Dockerfile.iroh-store
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ WORKDIR /iroh

COPY ../ .

RUN cargo build --bin iroh-store --release
RUN cargo build --bin iroh-store --profile=docker

################################################################################
## Final image
Expand All @@ -45,7 +45,7 @@ WORKDIR /iroh

# Copy our build, changing owndership to distroless-provided "nonroot" user,
# (65532:65532)
COPY --from=builder --chown=65532:65532 /iroh/target/release/iroh-store ./
COPY --from=builder --chown=65532:65532 /iroh/target/docker/iroh-store ./

# Use nonroot (unprivileged) user
USER nonroot
Expand Down
17 changes: 16 additions & 1 deletion xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
env, fs, io,
path::{Path, PathBuf},
process::Command,
str,
};

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -144,13 +145,18 @@ fn build_docker(all: bool, build_images: Vec<String>) -> Result<()> {
images = vec![String::from("iroh-one"), String::from("iroh-p2p")];
}

let commit = current_git_commit()?;

for image in images {
println!("building {}:{}", image, commit);
let status = Command::new("docker")
.current_dir(project_root())
.args([
"build",
"-t",
format!("{}:distroless", image).as_str(),
format!("{}:{}", image, commit).as_str(),
"-t",
format!("{}:latest", image).as_str(),
"-f",
format!("docker/Dockerfile.{}", image).as_str(),
// "--progress=plain",
Expand All @@ -165,3 +171,12 @@ fn build_docker(all: bool, build_images: Vec<String>) -> Result<()> {

Ok(())
}

fn current_git_commit() -> Result<String> {
let output = Command::new("git")
.current_dir(project_root())
.args(["log", "-1", "--pretty=%h"])
.output()?;
let commitish = str::from_utf8(&output.stdout)?.trim_end();
Ok(String::from(commitish))
}

0 comments on commit 7521ede

Please sign in to comment.