Skip to content

Commit 5fbf7c9

Browse files
authored
feat: prefetch shuttle-service crates (#461)
* feat: prefetch shuttle-service crates * refactor: add comment to prepare.sh files
1 parent b1eee6d commit 5fbf7c9

File tree

5 files changed

+42
-13
lines changed

5 files changed

+42
-13
lines changed

Containerfile

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ FROM shuttle-build AS builder
1818
COPY --from=planner /build/recipe.json recipe.json
1919
RUN cargo chef cook --recipe-path recipe.json
2020
COPY --from=cache /build .
21-
ARG crate
22-
RUN cargo build --bin ${crate}
21+
ARG folder
22+
RUN cargo build --bin shuttle-${folder}
2323

2424
FROM rust:1.63.0-buster as shuttle-common
2525
RUN apt-get update &&\
@@ -28,14 +28,8 @@ RUN rustup component add rust-src
2828
COPY --from=cache /build/ /usr/src/shuttle/
2929

3030
FROM shuttle-common
31-
ARG crate
32-
SHELL ["/bin/bash", "-c"]
33-
RUN mkdir -p $CARGO_HOME; \
34-
echo $'[patch.crates-io] \n\
35-
shuttle-service = { path = "/usr/src/shuttle/service" } \n\
36-
shuttle-aws-rds = { path = "/usr/src/shuttle/resources/aws-rds" } \n\
37-
shuttle-persist = { path = "/usr/src/shuttle/resources/persist" } \n\
38-
shuttle-shared-db = { path = "/usr/src/shuttle/resources/shared-db" } \n\
39-
shuttle-secrets = { path = "/usr/src/shuttle/resources/secrets" }' > $CARGO_HOME/config.toml
40-
COPY --from=builder /build/target/debug/${crate} /usr/local/bin/service
31+
ARG folder
32+
COPY ${folder}/prepare.sh /prepare.sh
33+
RUN /prepare.sh
34+
COPY --from=builder /build/target/debug/shuttle-${folder} /usr/local/bin/service
4135
ENTRYPOINT ["/usr/local/bin/service"]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ down: docker-compose.rendered.yml
8989

9090
shuttle-%: ${SRC} Cargo.lock
9191
docker buildx build \
92-
--build-arg crate=shuttle-$(*) \
92+
--build-arg folder=$(*) \
9393
--tag $(CONTAINER_REGISTRY)/$(*):$(COMMIT_SHA) \
9494
--tag $(CONTAINER_REGISTRY)/$(*):$(TAG) \
9595
--tag $(CONTAINER_REGISTRY)/$(*):latest \

deployer/prepare.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env sh
2+
3+
###############################################################################
4+
# This file is used by our common Containerfile incase the container for this #
5+
# service might need some extra preparation steps for its final image #
6+
###############################################################################
7+
8+
# Patch crates to be on same versions
9+
mkdir -p $CARGO_HOME; \
10+
echo '[patch.crates-io]
11+
shuttle-service = { path = "/usr/src/shuttle/service" }
12+
shuttle-aws-rds = { path = "/usr/src/shuttle/resources/aws-rds" }
13+
shuttle-persist = { path = "/usr/src/shuttle/resources/persist" }
14+
shuttle-shared-db = { path = "/usr/src/shuttle/resources/shared-db" }
15+
shuttle-secrets = { path = "/usr/src/shuttle/resources/secrets" }' > $CARGO_HOME/config.toml
16+
17+
# Prefetch crates.io index
18+
cd /usr/src/shuttle/service
19+
cargo fetch

gateway/prepare.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env sh
2+
3+
###############################################################################
4+
# This file is used by our common Containerfile incase the container for this #
5+
# service might need some extra preparation steps for its final image #
6+
###############################################################################
7+
8+
# Nothing to prepare in container image here

provisioner/prepare.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env sh
2+
3+
###############################################################################
4+
# This file is used by our common Containerfile incase the container for this #
5+
# service might need some extra preparation steps for its final image #
6+
###############################################################################
7+
8+
# Nothing to prepare in container image here

0 commit comments

Comments
 (0)