Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dockerfile and ci improvements #989

Merged
merged 12 commits into from
Jun 26, 2023
100 changes: 50 additions & 50 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 >>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -645,7 +645,7 @@ workflows:
"shuttle-proto",
"shuttle-provisioner",
"shuttle-runtime",
"shuttle-service"
"shuttle-service",
]
- e2e-test:
requires:
Expand Down Expand Up @@ -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:
Expand All @@ -833,20 +833,20 @@ 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",
"services/shuttle-serenity",
"services/shuttle-thruster",
"services/shuttle-tide",
"services/shuttle-tower",
"services/shuttle-warp"
"services/shuttle-warp",
]
name: publish-<< matrix.path >>
requires:
Expand Down
28 changes: 16 additions & 12 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -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
jonaro00 marked this conversation as resolved.
Show resolved Hide resolved

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 .
Expand All @@ -22,25 +23,28 @@ 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
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}
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -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
Expand Down
44 changes: 25 additions & 19 deletions deployer/prepare.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
#!/bin/bash

###############################################################################
# This file is used by our common Containerfile incase the container for this #
Expand All @@ -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" }

Expand All @@ -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" }
Expand All @@ -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
jonaro00 marked this conversation as resolved.
Show resolved Hide resolved

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]
Expand All @@ -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"
jonaro00 marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 1 addition & 2 deletions extras/postgres/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading