From d38dae5404f0309d60513c1ead6e388883171fc9 Mon Sep 17 00:00:00 2001 From: chesedo Date: Thu, 3 Nov 2022 16:01:43 +0200 Subject: [PATCH 1/2] feat: prefetch shuttle-service crates --- Containerfile | 18 ++++++------------ Makefile | 2 +- deployer/prepare.sh | 14 ++++++++++++++ gateway/prepare.sh | 3 +++ provisioner/prepare.sh | 3 +++ 5 files changed, 27 insertions(+), 13 deletions(-) create mode 100755 deployer/prepare.sh create mode 100755 gateway/prepare.sh create mode 100755 provisioner/prepare.sh diff --git a/Containerfile b/Containerfile index 2989c9800..c50c13692 100644 --- a/Containerfile +++ b/Containerfile @@ -18,8 +18,8 @@ FROM shuttle-build AS builder COPY --from=planner /build/recipe.json recipe.json RUN cargo chef cook --recipe-path recipe.json COPY --from=cache /build . -ARG crate -RUN cargo build --bin ${crate} +ARG folder +RUN cargo build --bin shuttle-${folder} FROM rust:1.63.0-buster as shuttle-common RUN apt-get update &&\ @@ -28,14 +28,8 @@ RUN rustup component add rust-src COPY --from=cache /build/ /usr/src/shuttle/ FROM shuttle-common -ARG crate -SHELL ["/bin/bash", "-c"] -RUN mkdir -p $CARGO_HOME; \ -echo $'[patch.crates-io] \n\ -shuttle-service = { path = "/usr/src/shuttle/service" } \n\ -shuttle-aws-rds = { path = "/usr/src/shuttle/resources/aws-rds" } \n\ -shuttle-persist = { path = "/usr/src/shuttle/resources/persist" } \n\ -shuttle-shared-db = { path = "/usr/src/shuttle/resources/shared-db" } \n\ -shuttle-secrets = { path = "/usr/src/shuttle/resources/secrets" }' > $CARGO_HOME/config.toml -COPY --from=builder /build/target/debug/${crate} /usr/local/bin/service +ARG folder +COPY ${folder}/prepare.sh /prepare.sh +RUN /prepare.sh +COPY --from=builder /build/target/debug/shuttle-${folder} /usr/local/bin/service ENTRYPOINT ["/usr/local/bin/service"] diff --git a/Makefile b/Makefile index 9b502aa35..c41a139da 100644 --- a/Makefile +++ b/Makefile @@ -89,7 +89,7 @@ down: docker-compose.rendered.yml shuttle-%: ${SRC} Cargo.lock docker buildx build \ - --build-arg crate=shuttle-$(*) \ + --build-arg folder=$(*) \ --tag $(CONTAINER_REGISTRY)/$(*):$(COMMIT_SHA) \ --tag $(CONTAINER_REGISTRY)/$(*):$(TAG) \ --tag $(CONTAINER_REGISTRY)/$(*):latest \ diff --git a/deployer/prepare.sh b/deployer/prepare.sh new file mode 100755 index 000000000..7cc10183a --- /dev/null +++ b/deployer/prepare.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# Patch crates to be on same versions +mkdir -p $CARGO_HOME; \ +echo '[patch.crates-io] +shuttle-service = { path = "/usr/src/shuttle/service" } +shuttle-aws-rds = { path = "/usr/src/shuttle/resources/aws-rds" } +shuttle-persist = { path = "/usr/src/shuttle/resources/persist" } +shuttle-shared-db = { path = "/usr/src/shuttle/resources/shared-db" } +shuttle-secrets = { path = "/usr/src/shuttle/resources/secrets" }' > $CARGO_HOME/config.toml + +# Prefetch crates.io index +cd /usr/src/shuttle/service +cargo fetch diff --git a/gateway/prepare.sh b/gateway/prepare.sh new file mode 100755 index 000000000..38f25dacf --- /dev/null +++ b/gateway/prepare.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +# Nothing to prepare in container image here diff --git a/provisioner/prepare.sh b/provisioner/prepare.sh new file mode 100755 index 000000000..38f25dacf --- /dev/null +++ b/provisioner/prepare.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +# Nothing to prepare in container image here From 1f0e35cb89eb4089772c5b83e0f4ead6cfe1a3d5 Mon Sep 17 00:00:00 2001 From: chesedo Date: Fri, 4 Nov 2022 13:22:40 +0200 Subject: [PATCH 2/2] refactor: add comment to prepare.sh files --- deployer/prepare.sh | 5 +++++ gateway/prepare.sh | 5 +++++ provisioner/prepare.sh | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/deployer/prepare.sh b/deployer/prepare.sh index 7cc10183a..c12581b19 100755 --- a/deployer/prepare.sh +++ b/deployer/prepare.sh @@ -1,5 +1,10 @@ #!/usr/bin/env sh +############################################################################### +# This file is used by our common Containerfile incase the container for this # +# service might need some extra preparation steps for its final image # +############################################################################### + # Patch crates to be on same versions mkdir -p $CARGO_HOME; \ echo '[patch.crates-io] diff --git a/gateway/prepare.sh b/gateway/prepare.sh index 38f25dacf..6a52d3030 100755 --- a/gateway/prepare.sh +++ b/gateway/prepare.sh @@ -1,3 +1,8 @@ #!/usr/bin/env sh +############################################################################### +# This file is used by our common Containerfile incase the container for this # +# service might need some extra preparation steps for its final image # +############################################################################### + # Nothing to prepare in container image here diff --git a/provisioner/prepare.sh b/provisioner/prepare.sh index 38f25dacf..6a52d3030 100755 --- a/provisioner/prepare.sh +++ b/provisioner/prepare.sh @@ -1,3 +1,8 @@ #!/usr/bin/env sh +############################################################################### +# This file is used by our common Containerfile incase the container for this # +# service might need some extra preparation steps for its final image # +############################################################################### + # Nothing to prepare in container image here