From 1a8de53a3f94717f4feb588629c5638da5fbc68c Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Fri, 9 Jun 2023 14:41:25 +0200 Subject: [PATCH 01/11] cleanup in dockerfiles and ci --- .circleci/config.yml | 100 +++++++++++++++++----------------- Containerfile | 28 ++++++---- extras/postgres/Containerfile | 3 +- 3 files changed, 67 insertions(+), 64 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6b9419072..a4a3737cb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -29,7 +29,7 @@ commands: - run: name: Install sccache command: | - export SCCACHE_VERSION='v0.4.2' + export SCCACHE_VERSION='v0.5.3' ls ~/.cargo/bin/sccache || curl -L https://github.com/mozilla/sccache/releases/download/$SCCACHE_VERSION/sccache-$SCCACHE_VERSION-x86_64-unknown-linux-musl.tar.gz | tar -xOz sccache-$SCCACHE_VERSION-x86_64-unknown-linux-musl/sccache > ~/.cargo/bin/sccache && chmod +x ~/.cargo/bin/sccache # This configures Rust to use sccache. echo 'export "RUSTC_WRAPPER"="sccache"' >> $BASH_ENV @@ -299,7 +299,7 @@ jobs: default: false steps: - checkout - - run: + - run: name: Set git tag in bash_env command: | echo TAG=$(git describe --tags --abbrev=0) >> $BASH_ENV @@ -342,40 +342,40 @@ jobs: type: boolean default: false steps: - - checkout - - run: - name: Set git tag in bash_env - command: | - echo TAG=$(git describe --tags --abbrev=0) >> $BASH_ENV - - add_ssh_keys: - fingerprints: - - << parameters.ssh-fingerprint >> - - run: - name: Generate ssh config - command: ./.circleci/<< parameters.ssh-config-script >> - - run: - name: Deploy images - command: | - DOCKER_HOST=ssh://ec2-user@master.<< parameters.ssh-host >> USE_TLS=enable PROD=<< parameters.production >> DD_API_KEY=$DD_API_KEY \ - POSTGRES_PASSWORD=${<< parameters.postgres-password >>} \ - MONGO_INITDB_ROOT_PASSWORD=${<< parameters.mongodb-password >>} \ - TAG=$TAG \ - make deploy - - when: - condition: << parameters.production >> - steps: - - run: - name: Pull new deployer image on prod - command: | - ssh ec2-user@controller.<< parameters.ssh-host >> "docker pull public.ecr.aws/shuttle/deployer:$TAG" - - when: - condition: - not: << parameters.production >> - steps: - - run: - name: Pull new deployer image on dev - command: | - ssh ec2-user@controller.<< parameters.ssh-host >> "docker pull public.ecr.aws/shuttle-dev/deployer:$TAG" + - checkout + - run: + name: Set git tag in bash_env + command: | + echo TAG=$(git describe --tags --abbrev=0) >> $BASH_ENV + - add_ssh_keys: + fingerprints: + - << parameters.ssh-fingerprint >> + - run: + name: Generate ssh config + command: ./.circleci/<< parameters.ssh-config-script >> + - run: + name: Deploy images + command: | + DOCKER_HOST=ssh://ec2-user@master.<< parameters.ssh-host >> USE_TLS=enable PROD=<< parameters.production >> DD_API_KEY=$DD_API_KEY \ + POSTGRES_PASSWORD=${<< parameters.postgres-password >>} \ + MONGO_INITDB_ROOT_PASSWORD=${<< parameters.mongodb-password >>} \ + TAG=$TAG \ + make deploy + - when: + condition: << parameters.production >> + steps: + - run: + name: Pull new deployer image on prod + command: | + ssh ec2-user@controller.<< parameters.ssh-host >> "docker pull public.ecr.aws/shuttle/deployer:$TAG" + - when: + condition: + not: << parameters.production >> + steps: + - run: + name: Pull new deployer image on dev + command: | + ssh ec2-user@controller.<< parameters.ssh-host >> "docker pull public.ecr.aws/shuttle-dev/deployer:$TAG" build-binaries-linux: machine: image: << parameters.image >> @@ -482,7 +482,7 @@ jobs: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - run: name: "Install Shuttle" - command: cargo install cargo-shuttle --path ./cargo-shuttle + command: cargo install cargo-shuttle --path ./cargo-shuttle - run: cargo shuttle --version - run: name: Login @@ -513,7 +513,7 @@ jobs: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - run: name: "Install Shuttle" - command: cargo install cargo-shuttle --path ./cargo-shuttle + command: cargo install cargo-shuttle --path ./cargo-shuttle - run: cargo shuttle --version - run: name: Login @@ -558,7 +558,7 @@ jobs: C:\rustup-init.exe -y --default-toolchain 1.70.0 --target x86_64-pc-windows-msvc - run: name: "Install Shuttle" - command: ..\.cargo\bin\cargo.exe install cargo-shuttle --path ./cargo-shuttle + command: ..\.cargo\bin\cargo.exe install cargo-shuttle --path ./cargo-shuttle - run: ..\.cargo\bin\cargo.exe shuttle --version - run: name: Login @@ -618,8 +618,8 @@ workflows: - services/shuttle-tower - services/shuttle-warp - check-standalone: - # shuttle-shared-db has mutually exclusive features - # so we run checks for each feature separately + # shuttle-shared-db has mutually exclusive features + # so we run checks for each feature separately name: "resources/shared-db: << matrix.features >>" matrix: alias: check-standalone-shared-db @@ -645,7 +645,7 @@ workflows: "shuttle-proto", "shuttle-provisioner", "shuttle-runtime", - "shuttle-service" + "shuttle-service", ] - e2e-test: requires: @@ -808,13 +808,13 @@ workflows: - publish-crates: matrix: parameters: - path: + path: [ "resources/aws-rds", "resources/shared-db", "resources/secrets", "resources/persist", - "resources/static-folder" + "resources/static-folder", ] name: publish-<< matrix.path >> requires: @@ -833,12 +833,12 @@ workflows: - publish-crates: matrix: parameters: - path: + path: [ - "services/shuttle-actix-web", - "services/shuttle-axum", - "services/shuttle-next", - "services/shuttle-poem", + "services/shuttle-actix-web", + "services/shuttle-axum", + "services/shuttle-next", + "services/shuttle-poem", "services/shuttle-poise", "services/shuttle-rocket", "services/shuttle-salvo", @@ -846,7 +846,7 @@ workflows: "services/shuttle-thruster", "services/shuttle-tide", "services/shuttle-tower", - "services/shuttle-warp" + "services/shuttle-warp", ] name: publish-<< matrix.path >> requires: diff --git a/Containerfile b/Containerfile index 325e360fa..ef54d72c6 100644 --- a/Containerfile +++ b/Containerfile @@ -1,19 +1,20 @@ -#syntax=docker/dockerfile-upstream:1.4.0-rc1 +#syntax=docker/dockerfile-upstream:1.4 ARG RUSTUP_TOOLCHAIN FROM docker.io/library/rust:${RUSTUP_TOOLCHAIN}-buster as shuttle-build -RUN apt-get update &&\ - apt-get install -y curl +RUN apt update && apt install -y curl -RUN cargo install cargo-chef +RUN cargo install cargo-chef --locked WORKDIR /build FROM shuttle-build as cache WORKDIR /src COPY . . +ARG CARGO_PROFILE RUN find ${SRC_CRATES} \( -name "*.proto" -or -name "*.rs" -or -name "*.toml" -or -name "Cargo.lock" -or -name "README.md" -or -name "*.sql" \) -type f -exec install -D \{\} /build/\{\} \; -# This is used to carry over in the docker images any *.pem files from shuttle root directory, to be used for TLS testing, as described -# here in the admin README.md. -RUN [ "$CARGO_PROFILE" != "release" ] && find ${SRC_CRATES} -name "*.pem" -type f -exec install -D \{\} /build/\{\} \; +# This is used to carry over in the docker images any *.pem files from shuttle root directory, +# to be used for TLS testing, as described here in the admin README.md. +RUN [ "$CARGO_PROFILE" != "release" ] && \ + find ${SRC_CRATES} -name "*.pem" -type f -exec install -D \{\} /build/\{\} \; FROM shuttle-build AS planner COPY --from=cache /build . @@ -22,11 +23,14 @@ RUN cargo chef prepare --recipe-path recipe.json FROM shuttle-build AS builder COPY --from=planner /build/recipe.json recipe.json ARG CARGO_PROFILE -RUN cargo chef cook $(if [ "$CARGO_PROFILE" = "release" ]; then echo --${CARGO_PROFILE}; fi) --recipe-path recipe.json +RUN cargo chef cook \ + # if CARGO_PROFILE is release, pass --release, else use default debug profile + $(if [ "$CARGO_PROFILE" = "release" ]; then echo --release; fi) \ + --recipe-path recipe.json COPY --from=cache /build . ARG folder -# if CARGO_PROFILE is release, pass --release, else use default debug profile -RUN cargo build --bin shuttle-${folder} $(if [ "$CARGO_PROFILE" = "release" ]; then echo --${CARGO_PROFILE}; fi) +RUN cargo build --bin shuttle-${folder} \ + $(if [ "$CARGO_PROFILE" = "release" ]; then echo --release; fi) ARG RUSTUP_TOOLCHAIN FROM rust:${RUSTUP_TOOLCHAIN}-buster as shuttle-common @@ -34,13 +38,13 @@ RUN rustup component add rust-src COPY --from=cache /build/ /usr/src/shuttle/ -FROM shuttle-common +FROM shuttle-common as shuttle-deployer ARG folder ARG prepare_args ARG PROD +ARG CARGO_PROFILE COPY ${folder}/prepare.sh /prepare.sh RUN /prepare.sh "${prepare_args}" -ARG CARGO_PROFILE COPY --from=builder /build/target/${CARGO_PROFILE}/shuttle-${folder} /usr/local/bin/service ARG RUSTUP_TOOLCHAIN ENV RUSTUP_TOOLCHAIN=${RUSTUP_TOOLCHAIN} diff --git a/extras/postgres/Containerfile b/extras/postgres/Containerfile index 9e5047169..11d400668 100644 --- a/extras/postgres/Containerfile +++ b/extras/postgres/Containerfile @@ -2,8 +2,7 @@ ARG POSTGRES_TAG= FROM docker.io/postgres:${POSTGRES_TAG} -RUN apt-get update &&\ - apt-get install --yes curl python3 python3-aiohttp +RUN apt update && apt install -y curl python3 python3-aiohttp COPY watch /usr/sbin/watch COPY shuttle-entrypoint.sh /usr/local/bin/shuttle-entrypoint.sh From 267ae4e2209a5d6ec0b2e61a67041a57f2868dee Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Fri, 9 Jun 2023 14:41:44 +0200 Subject: [PATCH 02/11] minor builder fixes --- service/src/builder.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/service/src/builder.rs b/service/src/builder.rs index 498fb7c96..6d104299f 100644 --- a/service/src/builder.rs +++ b/service/src/builder.rs @@ -142,12 +142,13 @@ pub async fn clean_crate(project_path: &Path, release_mode: bool) -> anyhow::Res let project_path = project_path.to_owned(); let manifest_path = project_path.join("Cargo.toml"); if !manifest_path.exists() { - return Err(anyhow!("failed to read the Shuttle project manifest")); - } - let mut profile = "dev"; - if release_mode { - profile = "release"; + bail!("failed to read the Shuttle project manifest"); } + let profile = if release_mode { + "release" + } else { + "dev" + }; let output = tokio::process::Command::new("cargo") .arg("clean") .arg("--manifest-path") @@ -218,6 +219,9 @@ async fn compile( tx: Sender, ) -> anyhow::Result> { let manifest_path = project_path.join("Cargo.toml"); + if !manifest_path.exists() { + bail!("failed to read the Shuttle project manifest"); + } let mut cargo = tokio::process::Command::new("cargo"); @@ -236,14 +240,13 @@ async fn compile( cargo.arg("--package").arg(package.name.clone()); } - let mut profile = "debug"; - - if release_mode { - profile = "release"; + let profile = if release_mode { cargo.arg("--profile").arg("release"); + "release" } else { cargo.arg("--profile").arg("dev"); - } + "debug" + }; if wasm { cargo.arg("--target").arg("wasm32-wasi"); @@ -279,8 +282,7 @@ async fn compile( "target".into(), "wasm32-wasi".into(), profile.into(), - #[allow(clippy::single_char_pattern)] - package.clone().name.replace("-", "_").into(), + package.name.replace('-', "_").into(), ] .iter() .collect(); From 5c9e12d04e22a02ed895614e3f5da0b57432284e Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Fri, 9 Jun 2023 14:44:17 +0200 Subject: [PATCH 03/11] add sccache to deployer + cleanup --- deployer/prepare.sh | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/deployer/prepare.sh b/deployer/prepare.sh index 30259267b..d4a991d39 100755 --- a/deployer/prepare.sh +++ b/deployer/prepare.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/bin/bash ############################################################################### # This file is used by our common Containerfile incase the container for this # @@ -7,8 +7,10 @@ # Patch crates to be on same versions mkdir -p $CARGO_HOME +touch $CARGO_HOME/config.toml if [[ $PROD != "true" ]]; then - echo '[patch.crates-io] + echo ' + [patch.crates-io] shuttle-service = { path = "/usr/src/shuttle/service" } shuttle-runtime = { path = "/usr/src/shuttle/runtime" } @@ -18,8 +20,8 @@ if [[ $PROD != "true" ]]; then shuttle-secrets = { path = "/usr/src/shuttle/resources/secrets" } shuttle-static-folder = { path = "/usr/src/shuttle/resources/static-folder" } - shuttle-axum = { path = "/usr/src/shuttle/services/shuttle-axum" } shuttle-actix-web = { path = "/usr/src/shuttle/services/shuttle-actix-web" } + shuttle-axum = { path = "/usr/src/shuttle/services/shuttle-axum" } shuttle-next = { path = "/usr/src/shuttle/services/shuttle-next" } shuttle-poem = { path = "/usr/src/shuttle/services/shuttle-poem" } shuttle-poise = { path = "/usr/src/shuttle/services/shuttle-poise" } @@ -30,26 +32,24 @@ if [[ $PROD != "true" ]]; then shuttle-tide = { path = "/usr/src/shuttle/services/shuttle-tide" } shuttle-tower = { path = "/usr/src/shuttle/services/shuttle-tower" } shuttle-warp = { path = "/usr/src/shuttle/services/shuttle-warp" }' > $CARGO_HOME/config.toml -else - touch $CARGO_HOME/config.toml fi -# Install protoc since some users may need it -ARCH="linux-x86_64" && \ -VERSION="22.2" && \ -curl -OL "https://github.com/protocolbuffers/protobuf/releases/download/v$VERSION/protoc-$VERSION-$ARCH.zip" && \ - unzip -o "protoc-$VERSION-$ARCH.zip" bin/protoc "include/*" -d /usr/local && \ - rm -f "protoc-$VERSION-$ARCH.zip" - # Add the wasm32-wasi target rustup target add wasm32-wasi -# Install the shuttle runtime -cargo install shuttle-runtime --path "/usr/src/shuttle/runtime" --bin shuttle-next --features next +# Set up sccache for build caching +export SCCACHE_VERSION='v0.5.3' +curl -L https://github.com/mozilla/sccache/releases/download/$SCCACHE_VERSION/sccache-$SCCACHE_VERSION-x86_64-unknown-linux-musl.tar.gz \ + | tar -xOz sccache-$SCCACHE_VERSION-x86_64-unknown-linux-musl/sccache \ + > /usr/local/cargo/bin/sccache \ + && chmod +x /usr/local/cargo/bin/sccache +echo ' +[build] +rustc-wrapper = "/usr/local/cargo/bin/sccache"' >> $CARGO_HOME/config.toml while getopts "p," o; do case $o in - "p") + "p") # if panamax is used, the '-p' parameter is passed # Make future crates requests to our own mirror echo ' [source.shuttle-crates-io-mirror] @@ -62,12 +62,18 @@ replace-with = "shuttle-crates-io-mirror"' >> $CARGO_HOME/config.toml esac done -# Prefetch crates.io index from our mirror -# TODO: restore when we know how to prefetch from our mirror -# cd /usr/src/shuttle/service -# cargo fetch +# Install the shuttle runtime +# This also warms the sccache with shuttle crates and deps +cargo install shuttle-runtime --path "/usr/src/shuttle/runtime" --bin shuttle-next --features next # Install common build tools for external crates # The image should already have these: https://github.com/docker-library/buildpack-deps/blob/65d69325ad741cea6dee20781c1faaab2e003d87/debian/buster/Dockerfile apt update apt install -y llvm-dev libclang-dev clang cmake + +# Install protoc since some users may need it +ARCH="linux-x86_64" && \ +VERSION="22.2" && \ +curl -OL "https://github.com/protocolbuffers/protobuf/releases/download/v$VERSION/protoc-$VERSION-$ARCH.zip" && \ + unzip -o "protoc-$VERSION-$ARCH.zip" bin/protoc "include/*" -d /usr/local && \ + rm -f "protoc-$VERSION-$ARCH.zip" From f872653a34f97377d2488c14e8a7e69941e2a535 Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Fri, 9 Jun 2023 14:57:01 +0200 Subject: [PATCH 04/11] fmt --- service/src/builder.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/service/src/builder.rs b/service/src/builder.rs index 6d104299f..b7edf9240 100644 --- a/service/src/builder.rs +++ b/service/src/builder.rs @@ -144,11 +144,7 @@ pub async fn clean_crate(project_path: &Path, release_mode: bool) -> anyhow::Res if !manifest_path.exists() { bail!("failed to read the Shuttle project manifest"); } - let profile = if release_mode { - "release" - } else { - "dev" - }; + let profile = if release_mode { "release" } else { "dev" }; let output = tokio::process::Command::new("cargo") .arg("clean") .arg("--manifest-path") From f89591d51cff9187e82d818c3e7db91bfb80fc19 Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Sat, 10 Jun 2023 03:13:27 +0200 Subject: [PATCH 05/11] docs: install with --locked --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 19ed07242..4afeabb38 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ which will automatically install the correct target for your system. To install with `cargo-binstall`, run: ```sh +cargo install binstall cargo binstall cargo-shuttle ``` @@ -75,6 +76,8 @@ Although a bit slower, you can also install directly with cargo: cargo install cargo-shuttle ``` +*If installing binstall or cargo-shuttle fails, try adding `--locked`.* + After installing, log in with: ```sh From 0856e569a82cdb7623a92e6bef3ab07e5e3744b1 Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Fri, 16 Jun 2023 20:14:32 +0200 Subject: [PATCH 06/11] Add comments, move arg statements --- Containerfile | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/Containerfile b/Containerfile index ef54d72c6..126ada6c5 100644 --- a/Containerfile +++ b/Containerfile @@ -1,51 +1,63 @@ #syntax=docker/dockerfile-upstream:1.4 + + +# Base image ARG RUSTUP_TOOLCHAIN FROM docker.io/library/rust:${RUSTUP_TOOLCHAIN}-buster as shuttle-build RUN apt update && apt install -y curl - RUN cargo install cargo-chef --locked WORKDIR /build + +# Stores source cache FROM shuttle-build as cache +ARG CARGO_PROFILE WORKDIR /src COPY . . -ARG CARGO_PROFILE RUN find ${SRC_CRATES} \( -name "*.proto" -or -name "*.rs" -or -name "*.toml" -or -name "Cargo.lock" -or -name "README.md" -or -name "*.sql" \) -type f -exec install -D \{\} /build/\{\} \; # This is used to carry over in the docker images any *.pem files from shuttle root directory, # to be used for TLS testing, as described here in the admin README.md. RUN [ "$CARGO_PROFILE" != "release" ] && \ find ${SRC_CRATES} -name "*.pem" -type f -exec install -D \{\} /build/\{\} \; + +# Stores cargo chef recipe FROM shuttle-build AS planner COPY --from=cache /build . RUN cargo chef prepare --recipe-path recipe.json + +# Stores cargo chef recipe FROM shuttle-build AS builder -COPY --from=planner /build/recipe.json recipe.json ARG CARGO_PROFILE +ARG folder +COPY --from=planner /build/recipe.json recipe.json RUN cargo chef cook \ # if CARGO_PROFILE is release, pass --release, else use default debug profile $(if [ "$CARGO_PROFILE" = "release" ]; then echo --release; fi) \ --recipe-path recipe.json COPY --from=cache /build . -ARG folder RUN cargo build --bin shuttle-${folder} \ $(if [ "$CARGO_PROFILE" = "release" ]; then echo --release; fi) + +# Middle step ARG RUSTUP_TOOLCHAIN FROM rust:${RUSTUP_TOOLCHAIN}-buster as shuttle-common RUN rustup component add rust-src +COPY --from=cache /build /usr/src/shuttle/ -COPY --from=cache /build/ /usr/src/shuttle/ -FROM shuttle-common as shuttle-deployer +# The final image for this shuttle-* crate +FROM shuttle-common as shuttle-crate ARG folder ARG prepare_args +# used as env variable in prepare script ARG PROD ARG CARGO_PROFILE +ARG RUSTUP_TOOLCHAIN +ENV RUSTUP_TOOLCHAIN=${RUSTUP_TOOLCHAIN} COPY ${folder}/prepare.sh /prepare.sh RUN /prepare.sh "${prepare_args}" COPY --from=builder /build/target/${CARGO_PROFILE}/shuttle-${folder} /usr/local/bin/service -ARG RUSTUP_TOOLCHAIN -ENV RUSTUP_TOOLCHAIN=${RUSTUP_TOOLCHAIN} ENTRYPOINT ["/usr/local/bin/service"] From b8bcd63916cf91b3ec1ec198ab9a5a525e717e69 Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Sat, 17 Jun 2023 17:37:39 +0200 Subject: [PATCH 07/11] Leave out the sccache --- deployer/prepare.sh | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/deployer/prepare.sh b/deployer/prepare.sh index d4a991d39..96f7e1621 100755 --- a/deployer/prepare.sh +++ b/deployer/prepare.sh @@ -37,16 +37,6 @@ fi # Add the wasm32-wasi target rustup target add wasm32-wasi -# Set up sccache for build caching -export SCCACHE_VERSION='v0.5.3' -curl -L https://github.com/mozilla/sccache/releases/download/$SCCACHE_VERSION/sccache-$SCCACHE_VERSION-x86_64-unknown-linux-musl.tar.gz \ - | tar -xOz sccache-$SCCACHE_VERSION-x86_64-unknown-linux-musl/sccache \ - > /usr/local/cargo/bin/sccache \ - && chmod +x /usr/local/cargo/bin/sccache -echo ' -[build] -rustc-wrapper = "/usr/local/cargo/bin/sccache"' >> $CARGO_HOME/config.toml - while getopts "p," o; do case $o in "p") # if panamax is used, the '-p' parameter is passed @@ -63,7 +53,6 @@ replace-with = "shuttle-crates-io-mirror"' >> $CARGO_HOME/config.toml done # Install the shuttle runtime -# This also warms the sccache with shuttle crates and deps cargo install shuttle-runtime --path "/usr/src/shuttle/runtime" --bin shuttle-next --features next # Install common build tools for external crates From 4d44778f5882f9eb77a7aac76271ae4d157ec6db Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Sat, 17 Jun 2023 17:40:23 +0200 Subject: [PATCH 08/11] clarify --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4afeabb38..db4b13c57 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ Although a bit slower, you can also install directly with cargo: cargo install cargo-shuttle ``` -*If installing binstall or cargo-shuttle fails, try adding `--locked`.* +*If installing binstall or cargo-shuttle fails, try adding `--locked` to the install command.* After installing, log in with: From 2a6e64d141cc817a25bfedbc1524fa733a7db0cf Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Sat, 17 Jun 2023 21:23:26 +0200 Subject: [PATCH 09/11] Run prepare script before loading src cache --- Containerfile | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Containerfile b/Containerfile index 126ada6c5..c6c25e9c1 100644 --- a/Containerfile +++ b/Containerfile @@ -1,9 +1,9 @@ #syntax=docker/dockerfile-upstream:1.4 -# Base image +# Base image for builds and cache ARG RUSTUP_TOOLCHAIN -FROM docker.io/library/rust:${RUSTUP_TOOLCHAIN}-buster as shuttle-build +FROM rust:${RUSTUP_TOOLCHAIN}-buster as shuttle-build RUN apt update && apt install -y curl RUN cargo install cargo-chef --locked WORKDIR /build @@ -27,7 +27,7 @@ COPY --from=cache /build . RUN cargo chef prepare --recipe-path recipe.json -# Stores cargo chef recipe +# Builds crate according to cargo chef recipe FROM shuttle-build AS builder ARG CARGO_PROFILE ARG folder @@ -41,15 +41,9 @@ RUN cargo build --bin shuttle-${folder} \ $(if [ "$CARGO_PROFILE" = "release" ]; then echo --release; fi) -# Middle step +# The final image for this "shuttle-..." crate ARG RUSTUP_TOOLCHAIN -FROM rust:${RUSTUP_TOOLCHAIN}-buster as shuttle-common -RUN rustup component add rust-src -COPY --from=cache /build /usr/src/shuttle/ - - -# The final image for this shuttle-* crate -FROM shuttle-common as shuttle-crate +FROM rust:${RUSTUP_TOOLCHAIN}-buster as shuttle-crate ARG folder ARG prepare_args # used as env variable in prepare script @@ -57,7 +51,10 @@ ARG PROD ARG CARGO_PROFILE ARG RUSTUP_TOOLCHAIN ENV RUSTUP_TOOLCHAIN=${RUSTUP_TOOLCHAIN} + COPY ${folder}/prepare.sh /prepare.sh RUN /prepare.sh "${prepare_args}" + +COPY --from=cache /build /usr/src/shuttle/ COPY --from=builder /build/target/${CARGO_PROFILE}/shuttle-${folder} /usr/local/bin/service ENTRYPOINT ["/usr/local/bin/service"] From c8001c05ca2f7fafdbcd95012f972720d337745c Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Sun, 18 Jun 2023 00:19:59 +0200 Subject: [PATCH 10/11] Delay src-dependent preparation to after cache --- Containerfile | 4 ++++ auth/prepare.sh | 5 +++++ deployer/prepare.sh | 14 +++++++++++--- gateway/prepare.sh | 5 +++++ provisioner/prepare.sh | 5 +++++ 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Containerfile b/Containerfile index c6c25e9c1..49f3b905d 100644 --- a/Containerfile +++ b/Containerfile @@ -56,5 +56,9 @@ COPY ${folder}/prepare.sh /prepare.sh RUN /prepare.sh "${prepare_args}" COPY --from=cache /build /usr/src/shuttle/ + +# Any prepare steps that depend on the COPY from src cache +RUN /prepare.sh --after-src "${prepare_args}" + COPY --from=builder /build/target/${CARGO_PROFILE}/shuttle-${folder} /usr/local/bin/service ENTRYPOINT ["/usr/local/bin/service"] diff --git a/auth/prepare.sh b/auth/prepare.sh index 6a52d3030..f764443ec 100755 --- a/auth/prepare.sh +++ b/auth/prepare.sh @@ -5,4 +5,9 @@ # service might need some extra preparation steps for its final image # ############################################################################### +# Stuff that depends on local source files +if [ "$1" = "--after-src" ]; then + exit 0 +fi + # Nothing to prepare in container image here diff --git a/deployer/prepare.sh b/deployer/prepare.sh index 96f7e1621..8d91225dd 100755 --- a/deployer/prepare.sh +++ b/deployer/prepare.sh @@ -5,6 +5,17 @@ # service might need some extra preparation steps for its final image # ############################################################################### + +# Stuff that depends on local source files +if [ "$1" = "--after-src" ]; then + + # Install the shuttle runtime + cargo install shuttle-runtime --path "/usr/src/shuttle/runtime" --bin shuttle-next --features next + + exit 0 +fi + + # Patch crates to be on same versions mkdir -p $CARGO_HOME touch $CARGO_HOME/config.toml @@ -52,9 +63,6 @@ replace-with = "shuttle-crates-io-mirror"' >> $CARGO_HOME/config.toml esac done -# Install the shuttle runtime -cargo install shuttle-runtime --path "/usr/src/shuttle/runtime" --bin shuttle-next --features next - # Install common build tools for external crates # The image should already have these: https://github.com/docker-library/buildpack-deps/blob/65d69325ad741cea6dee20781c1faaab2e003d87/debian/buster/Dockerfile apt update diff --git a/gateway/prepare.sh b/gateway/prepare.sh index 6a52d3030..f764443ec 100755 --- a/gateway/prepare.sh +++ b/gateway/prepare.sh @@ -5,4 +5,9 @@ # service might need some extra preparation steps for its final image # ############################################################################### +# Stuff that depends on local source files +if [ "$1" = "--after-src" ]; then + exit 0 +fi + # Nothing to prepare in container image here diff --git a/provisioner/prepare.sh b/provisioner/prepare.sh index 6a52d3030..f764443ec 100755 --- a/provisioner/prepare.sh +++ b/provisioner/prepare.sh @@ -5,4 +5,9 @@ # service might need some extra preparation steps for its final image # ############################################################################### +# Stuff that depends on local source files +if [ "$1" = "--after-src" ]; then + exit 0 +fi + # Nothing to prepare in container image here From 068e7658fab67016fb1a0573fcaf34427e24249b Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Sat, 24 Jun 2023 02:17:01 +0200 Subject: [PATCH 11/11] explicit docker.io, move curl installation --- Containerfile | 5 ++--- deployer/prepare.sh | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Containerfile b/Containerfile index 49f3b905d..96197c5fd 100644 --- a/Containerfile +++ b/Containerfile @@ -3,8 +3,7 @@ # Base image for builds and cache ARG RUSTUP_TOOLCHAIN -FROM rust:${RUSTUP_TOOLCHAIN}-buster as shuttle-build -RUN apt update && apt install -y curl +FROM docker.io/library/rust:${RUSTUP_TOOLCHAIN}-buster as shuttle-build RUN cargo install cargo-chef --locked WORKDIR /build @@ -43,7 +42,7 @@ RUN cargo build --bin shuttle-${folder} \ # The final image for this "shuttle-..." crate ARG RUSTUP_TOOLCHAIN -FROM rust:${RUSTUP_TOOLCHAIN}-buster as shuttle-crate +FROM docker.io/library/rust:${RUSTUP_TOOLCHAIN}-buster as shuttle-crate ARG folder ARG prepare_args # used as env variable in prepare script diff --git a/deployer/prepare.sh b/deployer/prepare.sh index 8d91225dd..8b987316c 100755 --- a/deployer/prepare.sh +++ b/deployer/prepare.sh @@ -66,7 +66,7 @@ done # Install common build tools for external crates # The image should already have these: https://github.com/docker-library/buildpack-deps/blob/65d69325ad741cea6dee20781c1faaab2e003d87/debian/buster/Dockerfile apt update -apt install -y llvm-dev libclang-dev clang cmake +apt install -y curl llvm-dev libclang-dev clang cmake # Install protoc since some users may need it ARCH="linux-x86_64" && \