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

ci: CircleCI migration #277

Merged
merged 36 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f6ca939
ci: fmt
chesedo Jul 22, 2022
b4571eb
ci: cargo sort
chesedo Jul 22, 2022
2c12229
ci: install cargo-sort
chesedo Jul 22, 2022
2c20aea
ci: clippy
chesedo Jul 22, 2022
5d8ffbb
ci: clippy fixup
chesedo Jul 22, 2022
592cafb
ci: try workspace storage
chesedo Jul 22, 2022
26e5c7f
ci: paths fix
chesedo Jul 22, 2022
34b0bdb
ci: try cache
chesedo Jul 22, 2022
3fc4c52
ci: check crates not in workspace
chesedo Jul 22, 2022
94caf76
ci: try sccache
chesedo Jul 22, 2022
1a5a4f3
ci: sort Cargo.toml files
chesedo Jul 22, 2022
d55620c
ci: only install sccache if needed
chesedo Jul 22, 2022
6148bcc
refactor: clippy suggestion
chesedo Jul 22, 2022
df1f32d
ci: remove fmt GH action
chesedo Jul 22, 2022
7255244
ci: service tests
chesedo Jul 23, 2022
2daa048
refactor: split api into library and binary
chesedo Jul 25, 2022
9c8a134
ci: more platform tests
chesedo Jul 25, 2022
8945e2a
test: debug info
chesedo Jul 25, 2022
966fce8
test: debug info
chesedo Jul 25, 2022
2f72a4c
test: wait for PG restart
chesedo Jul 25, 2022
4c284d5
ci: remove test GH action
chesedo Jul 25, 2022
3d25738
ci: e2e test and pushing
chesedo Jul 26, 2022
7988c80
ci: refactor shared commands
chesedo Jul 26, 2022
bba85da
Merge remote-tracking branch 'upstream/main' into ci/circleci_migration
chesedo Jul 26, 2022
555f980
refactor: sort Cargo.toml for poem example
chesedo Jul 27, 2022
ba82e35
ci: cargo patch service
chesedo Jul 27, 2022
a470826
ci: refresh cache
chesedo Jul 27, 2022
41c2ce2
ci: install-rust command
chesedo Jul 27, 2022
9408612
ci: restore libssl1.1
chesedo Jul 27, 2022
71d6a55
docs: update batch
chesedo Jul 27, 2022
92bf6db
Merge remote-tracking branch 'upstream/main' into ci/circleci_migration
chesedo Aug 17, 2022
ec98909
ci: add mongo example
chesedo Aug 17, 2022
c381f11
ci: update to rust:1.63.0
chesedo Aug 17, 2022
cb20713
ci: collect all the executors for easier updating
chesedo Aug 17, 2022
19c7662
ci: update to rust:1.62.1
chesedo Aug 17, 2022
3b721f6
refactor: removed disabled clippy until CircleCI updates
chesedo Aug 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
262 changes: 229 additions & 33 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,61 @@ orbs:
docker-buildx: sensu/[email protected]
aws-ecr: circleci/[email protected]

jobs:
build-test-and-push:
resource_class: xlarge
executors:
docker-rust:
docker:
- image: cimg/rust:1.62.1
image-ubuntu:
machine:
image: ubuntu-2204:2022.04.1
docker_layer_caching: true

# sscache steps are from this guide
# https://medium.com/@edouard.oger/rust-caching-on-circleci-using-sccache-c996344f0115
commands:
restore-cargo-cache:
steps:
# Restore cargo cache before installing anything with the cargo command (ie cargo install ...)
- restore_cache:
name: Restore cargo cache
keys:
- cargo-{{ checksum "Cargo.lock" }}
- run:
name: Install sccache
command: |
ls ~/.cargo/bin/sccache || cargo install sccache
# This configures Rust to use sccache.
echo 'export "RUSTC_WRAPPER"="sccache"' >> $BASH_ENV
sccache --version
- restore_cache:
name: Restore sccache cache
key: sccache-cache-{{ .Environment.CIRCLE_JOB }}
save-cargo-cache:
steps:
- run:
name: Sccache stats
command: sccache --show-stats
- save_cache:
name: Save sccache cache
# We use {{ epoch }} to always upload a fresh cache:
# Of course, restore_cache will not find this exact key,
# but it will fall back to the closest key (aka the most recent).
# See https://discuss.circleci.com/t/add-mechanism-to-update-existing-cache-key/9014/13
key: sccache-cache-{{ .Environment.CIRCLE_JOB }}-{{ epoch }}
paths:
- "~/.cache/sccache"
- save_cache:
name: Save cargo cache
key: cargo-{{ checksum "Cargo.lock" }}-{{ epoch }}
paths:
- ~/.cargo
restore-buildx-cache:
steps:
- checkout
- docker-buildx/install:
version: 0.8.2
qemu-user-static-version: 7.0.0-7
- restore_cache:
name: Restore buildx cache
keys:
# Try lock cache first
- docker-buildx-{{ checksum "./Cargo.lock" }}
Expand All @@ -24,54 +67,207 @@ jobs:
# Fallback to main cache
- docker-buildx-main
- run:
command: |
export BUILDX_CACHE=/tmp/cache/buildx
sudo mkdir -p $BUILDX_CACHE && sudo chown -R circleci:circleci $BUILDX_CACHE
make images
name: Configure buildx cache
command: export BUILDX_CACHE=/tmp/cache/buildx
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm no CircleCI expert, but does this do anything for other steps? I thought each step was ran in a fresh shell.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yip, each step is a fresh shell. Making this a command (line 9) allows me to reuse it for the e2e-test (line 194) and build-and-push (line 224) without needing to repeat (and maintain) it

save-buildx-cache:
steps:
- save_cache:
name: Save buildx cache
paths:
- "/tmp/cache/buildx"
key: docker-buildx-{{ checksum "./Cargo.lock" }}
key: docker-buildx-{{ checksum "./Cargo.lock" }}-{{ epoch }}
when: always
apply-patches:
steps:
- run:
name: Patch service
command: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
- run:
name: Run the E2E tests
command: |
mkdir -p ~/.cargo
cat\<< EOF > ~/.cargo/config.toml
[patch.crates-io]
shuttle-service = { path = "$PWD/service" }
EOF
install-rust:
steps:
- run:
name: Install Rust
command: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
sudo apt update && sudo apt install -y libssl1.1

jobs:
workspace-fmt:
executor: docker-rust
steps:
- checkout
- restore-cargo-cache
- run: cargo fmt --all --check
- run: cargo install cargo-sort
- run: cargo sort --check --workspace
- run: cargo check --workspace --all-targets
- save-cargo-cache
workspace-clippy:
parameters:
framework:
description: "Framework to activate"
type: string
executor: docker-rust
steps:
- checkout
- restore-cargo-cache
- run: |
cargo clippy --tests \
--all-targets \
--features="codegen,loader,sqlx-integration,sqlx-postgres,mongodb-integration,secrets,<< parameters.framework >>" \
--no-deps -- \
--D warnings \
-A clippy::let-unit-value \
-A clippy::format-push-string
- save-cargo-cache
check-standalone:
parameters:
path:
description: "Path to crate external from workspace"
type: string
executor: docker-rust
steps:
- checkout
- restore-cargo-cache
- apply-patches
- run: cargo fmt --all --check --manifest-path << parameters.path >>/Cargo.toml
- run: cargo install cargo-sort
- run: cargo sort --check << parameters.path >>
- run: |
cargo clippy --tests \
--all-targets \
--manifest-path << parameters.path >>/Cargo.toml \
--no-deps -- \
--D warnings \
-A clippy::let-unit-value \
-A clippy::format-push-string
- save-cargo-cache
service-test:
# Using an image since tests will start a docker container
executor: image-ubuntu
steps:
- install-rust
- checkout
- restore-cargo-cache
- run:
name: Run unit tests
command: cargo test --package shuttle-service --features="codegen,loader,secrets" --lib -- --nocapture
- run:
name: Run integration tests
command: cargo test --package shuttle-service --features="codegen,loader,secrets" --test '*' -- --nocapture
- save-cargo-cache
platform-test:
parameters:
crate:
description: "Crate to test"
type: string
# Using an image since tests will start a docker container
executor: image-ubuntu
steps:
- install-rust
- checkout
- restore-cargo-cache
- apply-patches
- run:
name: Run unit tests
command: cargo test --package << parameters.crate >> --all-features --lib -- --nocapture
- run:
name: Run integration tests
# Only run integration tests if there are any
command: |
set +o pipefail
(cargo test --package << parameters.crate >> --all-features --test '*' -- --list 2>&1 | grep -q "no test target matches pattern") && echo "nothing to test" || cargo test --package << parameters.crate >> --all-features --test '*' -- --nocapture
- save-cargo-cache
e2e-test:
resource_class: xlarge
executor: image-ubuntu
steps:
- install-rust
- checkout
- restore-buildx-cache
- run:
name: Make images for tests
command: |
sudo mkdir -p $BUILDX_CACHE && sudo chown -R circleci:circleci $BUILDX_CACHE
make images
- save-buildx-cache
- apply-patches
- run:
name: Run the E2E tests
command: |
make down
docker volume create shuttle-backend-vol
cd e2e; BUILDX_CACHE=/tmp/cache/buildx SHUTTLE_API_KEY=test-key cargo test -- --nocapture
- when:
condition:
equal: [ main, << pipeline.git.branch >> ]
steps:
- aws-ecr/ecr-login:
aws-access-key-id: AWS_ACCESS_KEY_ID
aws-secret-access-key: AWS_SECRET_ACCESS_KEY
public-registry: true
- run:
command: |
make clean
PUSH=true BUILDX_CACHE=/tmp/cache/buildx PLATFORMS=linux/amd64,linux/arm64 make images
- save_cache:
paths:
- "/tmp/cache/buildx"
key: docker-buildx-{{ checksum "./Cargo.lock" }}
when: always
- save_cache:
paths:
- "/tmp/cache/buildx"
key: docker-buildx-{{ .Branch }}
when: always
build-and-push:
resource_class: xlarge
executor: image-ubuntu
steps:
- checkout
- restore-buildx-cache
- aws-ecr/ecr-login:
aws-access-key-id: AWS_ACCESS_KEY_ID
aws-secret-access-key: AWS_SECRET_ACCESS_KEY
public-registry: true
- run:
name: Make and push images
command: |
make clean
PUSH=true PLATFORMS=linux/amd64,linux/arm64 make images
- save-buildx-cache

workflows:
version: 2
build-test-and-push:
ci:
jobs:
- build-test-and-push
- workspace-fmt
- workspace-clippy:
name: workspace-clippy-<< matrix.framework >>
requires:
- workspace-fmt
matrix:
parameters:
framework: ["web-axum", "web-rocket", "web-poem", "web-tide", "web-tower"]
- check-standalone:
matrix:
parameters:
path:
- examples/axum/hello-world
- examples/axum/websocket
- examples/poem/hello-world
- examples/poem/mongodb
- examples/poem/postgres
- examples/rocket/authentication
- examples/rocket/hello-world
- examples/rocket/postgres
- examples/rocket/url-shortener
- examples/tide/hello-world
- examples/tide/postgres
- examples/tower/hello-world
- service-test:
requires:
- workspace-clippy
- platform-test:
requires:
- workspace-clippy
matrix:
parameters:
crate: ["shuttle-api", "cargo-shuttle", "shuttle-codegen", "shuttle-common", "shuttle-proto", "shuttle-provisioner"]
- e2e-test:
requires:
- service-test
- platform-test
- check-standalone
- build-and-push:
requires:
- e2e-test
filters:
branches:
only: main
62 changes: 0 additions & 62 deletions .github/workflows/fmt.yml

This file was deleted.

Loading