From 4442dd860b57e29e1c041de2e25eaa0fcfd8a855 Mon Sep 17 00:00:00 2001 From: Aaron Fenyes Date: Fri, 7 Mar 2025 01:25:30 -0800 Subject: [PATCH] Run continuous integration on a custom image Write a Dockerfile that describes a Debian image with our build environment set up in it. Write a script that builds and tags the custom image. Set the continuous integration workflow to run on the custom image, pulled from Docker's local image store. Running the examples on the custom image takes the same steps as running them on a development machine, so we no longer gain anything from factoring out the `cargo run --example` steps. That means we can get rid of the `run-examples` action. Since the build environment is now set up ahead of time, we can get rid of the `setup-rust` action too. --- .forgejo/run-examples/action.yaml | 12 ------ .forgejo/setup-rust/action.yaml | 10 ----- .../workflows/continuous-integration.yaml | 39 +++++++++++++++---- tools/ci-image/Dockerfile | 4 ++ tools/ci-image/build | 5 +++ 5 files changed, 40 insertions(+), 30 deletions(-) delete mode 100644 .forgejo/run-examples/action.yaml delete mode 100644 .forgejo/setup-rust/action.yaml create mode 100644 tools/ci-image/Dockerfile create mode 100755 tools/ci-image/build diff --git a/.forgejo/run-examples/action.yaml b/.forgejo/run-examples/action.yaml deleted file mode 100644 index 815e936..0000000 --- a/.forgejo/run-examples/action.yaml +++ /dev/null @@ -1,12 +0,0 @@ -# run all Cargo examples, as described here: -# -# Karol Kuczmarski. "Add examples to your Rust libraries" -# http://xion.io/post/code/rust-examples.html -# -runs: - using: "composite" - steps: - - run: cd app-proto; cargo run --example irisawa-hexlet - - run: cd app-proto; cargo run --example three-spheres - - run: cd app-proto; cargo run --example point-on-sphere - - run: cd app-proto; cargo run --example kaleidocycle \ No newline at end of file diff --git a/.forgejo/setup-rust/action.yaml b/.forgejo/setup-rust/action.yaml deleted file mode 100644 index 6960dc4..0000000 --- a/.forgejo/setup-rust/action.yaml +++ /dev/null @@ -1,10 +0,0 @@ -# set up the Rust toolchain. based on David Tolnay's more general -# `rust-toolchain` action for GitHub -# -# https://github.com/dtolnay/rust-toolchain -# -runs: - using: "composite" - steps: - - run: curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused --location --silent --show-error --fail 'https://sh.rustup.rs' | sh -s -- -y --profile minimal - - run: echo $HOME/.cargo/bin >> $GITHUB_PATH \ No newline at end of file diff --git a/.forgejo/workflows/continuous-integration.yaml b/.forgejo/workflows/continuous-integration.yaml index f821b1d..d200b53 100644 --- a/.forgejo/workflows/continuous-integration.yaml +++ b/.forgejo/workflows/continuous-integration.yaml @@ -3,23 +3,46 @@ on: push: branches: [main] jobs: + # build the application, reporting success if the build completes build: runs-on: docker + container: + image: dyna3:ci + defaults: + run: + working-directory: app-proto steps: - uses: https://code.forgejo.org/actions/checkout@v4 - - uses: ./.forgejo/setup-rust - - run: rustup target add wasm32-unknown-unknown - - run: cargo install trunk - - run: cd app-proto; trunk build + - run: trunk build + + # run the automated tests, reporting success if the tests pass test: runs-on: docker + container: + image: dyna3:ci + defaults: + run: + working-directory: app-proto steps: - uses: https://code.forgejo.org/actions/checkout@v4 - - uses: ./.forgejo/setup-rust - - run: cd app-proto; cargo test + - run: cargo test + + # run the Cargo examples, as described here: + # + # Karol Kuczmarski. "Add examples to your Rust libraries" + # http://xion.io/post/code/rust-examples.html + # + # report success if the examples build and run without errors run-examples: runs-on: docker + container: + image: dyna3:ci + defaults: + run: + working-directory: app-proto steps: - uses: https://code.forgejo.org/actions/checkout@v4 - - uses: ./.forgejo/setup-rust - - uses: ./.forgejo/run-examples \ No newline at end of file + - run: cargo run --example irisawa-hexlet + - run: cargo run --example three-spheres + - run: cargo run --example point-on-sphere + - run: cargo run --example kaleidocycle \ No newline at end of file diff --git a/tools/ci-image/Dockerfile b/tools/ci-image/Dockerfile new file mode 100644 index 0000000..de4668e --- /dev/null +++ b/tools/ci-image/Dockerfile @@ -0,0 +1,4 @@ +FROM rust:1.85-slim-bookworm +RUN rustup target add wasm32-unknown-unknown +RUN cargo install trunk +WORKDIR /home \ No newline at end of file diff --git a/tools/ci-image/build b/tools/ci-image/build new file mode 100755 index 0000000..d1a90dc --- /dev/null +++ b/tools/ci-image/build @@ -0,0 +1,5 @@ +#!/bin/sh + +# build and tag the Docker image we use for continuous integration + +docker build . --tag dyna3:ci \ No newline at end of file