-
Notifications
You must be signed in to change notification settings - Fork 254
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
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
f6ca939
ci: fmt
chesedo b4571eb
ci: cargo sort
chesedo 2c12229
ci: install cargo-sort
chesedo 2c20aea
ci: clippy
chesedo 5d8ffbb
ci: clippy fixup
chesedo 592cafb
ci: try workspace storage
chesedo 26e5c7f
ci: paths fix
chesedo 34b0bdb
ci: try cache
chesedo 3fc4c52
ci: check crates not in workspace
chesedo 94caf76
ci: try sccache
chesedo 1a5a4f3
ci: sort Cargo.toml files
chesedo d55620c
ci: only install sccache if needed
chesedo 6148bcc
refactor: clippy suggestion
chesedo df1f32d
ci: remove fmt GH action
chesedo 7255244
ci: service tests
chesedo 2daa048
refactor: split api into library and binary
chesedo 9c8a134
ci: more platform tests
chesedo 8945e2a
test: debug info
chesedo 966fce8
test: debug info
chesedo 2f72a4c
test: wait for PG restart
chesedo 4c284d5
ci: remove test GH action
chesedo 3d25738
ci: e2e test and pushing
chesedo 7988c80
ci: refactor shared commands
chesedo bba85da
Merge remote-tracking branch 'upstream/main' into ci/circleci_migration
chesedo 555f980
refactor: sort Cargo.toml for poem example
chesedo ba82e35
ci: cargo patch service
chesedo a470826
ci: refresh cache
chesedo 41c2ce2
ci: install-rust command
chesedo 9408612
ci: restore libssl1.1
chesedo 71d6a55
docs: update batch
chesedo 92bf6db
Merge remote-tracking branch 'upstream/main' into ci/circleci_migration
chesedo ec98909
ci: add mongo example
chesedo c381f11
ci: update to rust:1.63.0
chesedo cb20713
ci: collect all the executors for easier updating
chesedo 19c7662
ci: update to rust:1.62.1
chesedo 3b721f6
refactor: removed disabled clippy until CircleCI updates
chesedo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" }} | ||
|
@@ -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 | ||
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 |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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