Skip to content

Commit

Permalink
feat(builder): update tracing logs (shuttle-hq#1252)
Browse files Browse the repository at this point in the history
* feat(builder): add some tracing logs

* fix builder docker build
  • Loading branch information
jonaro00 authored and iulianbarbu committed Sep 27, 2023
1 parent 9b5b7af commit dd02956
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
39 changes: 21 additions & 18 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ WORKDIR /build


# Stores source cache and cargo chef recipe
FROM cargo-chef as planner
FROM cargo-chef as chef-planner
WORKDIR /src
COPY . .
# Select only the essential files for copying into next steps
Expand All @@ -31,15 +31,15 @@ RUN cargo chef prepare --recipe-path /recipe.json

# Builds crate according to cargo chef recipe.
# This step is skipped if the recipe is unchanged from previous build (no dependencies changed).
FROM cargo-chef AS builder
FROM cargo-chef AS chef-builder
ARG CARGO_PROFILE
COPY --from=planner /recipe.json /
COPY --from=chef-planner /recipe.json /
# https://i.imgflip.com/2/74bvex.jpg
RUN cargo chef cook \
--all-features \
$(if [ "$CARGO_PROFILE" = "release" ]; then echo --release; fi) \
--recipe-path /recipe.json
COPY --from=planner /build .
COPY --from=chef-planner /build .
# Building all at once to share build artifacts in the "cook" layer
RUN cargo build \
$(if [ "$CARGO_PROFILE" = "release" ]; then echo --release; fi) \
Expand Down Expand Up @@ -68,9 +68,17 @@ ENTRYPOINT ["/usr/local/bin/service"]

FROM shuttle-crate-base AS shuttle-auth
ARG CARGO_PROFILE
COPY --from=builder /build/target/${CARGO_PROFILE}/shuttle-auth /usr/local/bin/service
COPY --from=chef-builder /build/target/${CARGO_PROFILE}/shuttle-auth /usr/local/bin/service
FROM shuttle-auth AS shuttle-auth-dev

FROM shuttle-crate-base AS shuttle-builder
ARG CARGO_PROFILE
ARG prepare_args
COPY builder/prepare.sh /prepare.sh
RUN /prepare.sh "${prepare_args}"
COPY --from=chef-builder /build/target/${CARGO_PROFILE}/shuttle-builder /usr/local/bin/service
FROM shuttle-builder AS shuttle-builder-dev

FROM shuttle-crate-base AS shuttle-deployer
ARG CARGO_PROFILE
ARG prepare_args
Expand All @@ -81,38 +89,33 @@ ENV RUSTUP_TOOLCHAIN=${RUSTUP_TOOLCHAIN}
ARG PROD
COPY deployer/prepare.sh /prepare.sh
RUN /prepare.sh "${prepare_args}"
COPY --from=builder /build/target/${CARGO_PROFILE}/shuttle-deployer /usr/local/bin/service
COPY --from=builder /build/target/${CARGO_PROFILE}/shuttle-next /usr/local/cargo/bin/
COPY --from=chef-builder /build/target/${CARGO_PROFILE}/shuttle-deployer /usr/local/bin/service
COPY --from=chef-builder /build/target/${CARGO_PROFILE}/shuttle-next /usr/local/cargo/bin/
FROM shuttle-deployer AS shuttle-deployer-dev
# Source code needed for compiling with [patch.crates-io]
COPY --from=planner /build /usr/src/shuttle/
COPY --from=chef-planner /build /usr/src/shuttle/
FROM shuttle-crate-base AS shuttle-gateway
ARG CARGO_PROFILE
ARG folder
# Some crates need additional libs
COPY ${folder}/*.so /usr/lib/
ENV LD_LIBRARY_PATH=/usr/lib/
COPY --from=builder /build/target/${CARGO_PROFILE}/shuttle-gateway /usr/local/bin/service
COPY --from=chef-builder /build/target/${CARGO_PROFILE}/shuttle-gateway /usr/local/bin/service
FROM shuttle-gateway AS shuttle-gateway-dev
# For testing certificates locally
COPY --from=planner /build/*.pem /usr/src/shuttle/
COPY --from=chef-planner /build/*.pem /usr/src/shuttle/

FROM shuttle-crate-base AS shuttle-logger
ARG CARGO_PROFILE
COPY --from=builder /build/target/${CARGO_PROFILE}/shuttle-logger /usr/local/bin/service
COPY --from=chef-builder /build/target/${CARGO_PROFILE}/shuttle-logger /usr/local/bin/service
FROM shuttle-logger AS shuttle-logger-dev

FROM shuttle-crate-base AS shuttle-provisioner
ARG CARGO_PROFILE
COPY --from=builder /build/target/${CARGO_PROFILE}/shuttle-provisioner /usr/local/bin/service
COPY --from=chef-builder /build/target/${CARGO_PROFILE}/shuttle-provisioner /usr/local/bin/service
FROM shuttle-provisioner AS shuttle-provisioner-dev

FROM shuttle-crate-base AS shuttle-resource-recorder
ARG CARGO_PROFILE
COPY --from=builder /build/target/${CARGO_PROFILE}/shuttle-resource-recorder /usr/local/bin/service
COPY --from=chef-builder /build/target/${CARGO_PROFILE}/shuttle-resource-recorder /usr/local/bin/service
FROM shuttle-resource-recorder AS shuttle-resource-recorder-dev

FROM shuttle-crate-base AS shuttle-builder
ARG CARGO_PROFILE
COPY --from=builder /build/target/${CARGO_PROFILE}/shuttle-builder /usr/local/bin/service
FROM shuttle-builder AS shuttle-builder-dev
9 changes: 5 additions & 4 deletions builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Service {
Self
}

#[instrument(skip(self, archive))]
#[instrument(name = "Building deployment", skip(self, archive))]
async fn build(
&self,
deployment_id: String,
Expand All @@ -60,7 +60,7 @@ impl Service {
build_flake_file(path)?;

let mut cmd = Command::new("nix");
let output_path = tmp_dir.path().join("_archive");
let output_path = path.join("_archive");
cmd.args([
"build",
"--no-write-lock-file",
Expand All @@ -78,15 +78,16 @@ impl Service {

let mut reader = BufReader::new(stdout).lines();

let id = deployment_id.clone();
tokio::spawn(async move {
while let Some(line) = reader.next_line().await.expect("to get line") {
info!("{line}");
info!(deployment_id = %id, "{line}");
}
});

let status = child.wait().await.expect("build to finish");

debug!("{status}");
debug!(deployment_id, "{status}");

let archive = fs::read(output_path)?;

Expand Down

0 comments on commit dd02956

Please sign in to comment.