Skip to content

Commit

Permalink
feat: prefetch shuttle-service crates (#461)
Browse files Browse the repository at this point in the history
* feat: prefetch shuttle-service crates

* refactor: add comment to prepare.sh files
  • Loading branch information
chesedo authored Nov 4, 2022
1 parent b1eee6d commit 5fbf7c9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
18 changes: 6 additions & 12 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&\
Expand All @@ -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"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
19 changes: 19 additions & 0 deletions deployer/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/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]
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
8 changes: 8 additions & 0 deletions gateway/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +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
8 changes: 8 additions & 0 deletions provisioner/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +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

0 comments on commit 5fbf7c9

Please sign in to comment.