diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6974786ee..7e7b3a8e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -101,14 +101,6 @@ jobs: uses: dtolnay/rust-toolchain@stable with: components: rustfmt - - name: Cache Cargo intermediate products - uses: actions/cache@v3 - with: - path: |- - ~/.cargo/registry - ~/.cargo/git - ui/target - key: "${{ runner.os }}-cargo-${{ hashFiles('ui/**/Cargo.lock') }}-2" - name: Format server run: cargo fmt --manifest-path ui/Cargo.toml --all --check - name: Format top-crates @@ -116,35 +108,15 @@ jobs: - name: Format orchestrator run: cargo fmt --manifest-path compiler/base/orchestrator/Cargo.toml --check - name: Build backend - run: |- - mkdir -p ui/target; docker run --rm -v $PWD/compiler/base/asm-cleanup:/compiler/base/asm-cleanup -v $PWD/compiler/base/orchestrator:/compiler/base/orchestrator -v $PWD/compiler/base/modify-cargo-toml:/compiler/base/modify-cargo-toml -v $PWD/ui:/ui -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry --workdir /ui rust:alpine sh -c ' - apk add musl-dev openssl-dev openssl-libs-static - - # Adding -C relocation-model=static due to - # https://github.com/rust-lang/rust/issues/95926 - - # Adding this to find the statically-built version - export OPENSSL_NO_PKG_CONFIG=1 OPENSSL_STATIC=1 OPENSSL_DIR=/usr/ - - # Unit tests - cargo rustc --tests --locked -- -C relocation-model=static; - - test_bin=$(find target/debug/deps/ -name "ui*" -type f -perm -a=x); - mv "${test_bin}" target/unit_tests; - - # Primary binary - cargo rustc --locked --release -- -C relocation-model=static; - mv target/release/ui target/ui; - ' - - name: Restore permissions - run: sudo chown -R runner:docker ~/.cargo/ ui/target + run: "./ci/build-backend.sh" - name: Save backend artifact uses: actions/upload-artifact@v3 with: name: backend path: | - ui/target/ui - ui/target/unit_tests + docker-output/ui + docker-output/unit_tests_ui + docker-output/unit_tests_orchestrator build_frontend: name: Build frontend runs-on: ubuntu-latest @@ -249,8 +221,10 @@ jobs: with: name: frontend path: tests/server/build/ - - name: Run unit tests - run: chmod +x ./server/unit_tests && ./server/unit_tests + - name: Run orchestrator unit tests + run: chmod +x ./server/unit_tests_orchestrator && ./server/unit_tests_orchestrator + - name: Run ui unit tests + run: chmod +x ./server/unit_tests_ui && ./server/unit_tests_ui - name: Run tests env: PLAYGROUND_UI_ROOT: server/build/ diff --git a/ci/Dockerfile b/ci/Dockerfile new file mode 100644 index 000000000..19cd81efa --- /dev/null +++ b/ci/Dockerfile @@ -0,0 +1,37 @@ +FROM rust:alpine + +RUN apk add musl-dev openssl-dev openssl-libs-static + +# Adding -C relocation-model=static due to +# https://github.com/rust-lang/rust/issues/95926 + +# Adding this to find the statically-built version +ENV OPENSSL_NO_PKG_CONFIG=1 OPENSSL_STATIC=1 OPENSSL_DIR=/usr/ + +RUN mkdir /output + +COPY compiler/base/asm-cleanup /compiler/base/asm-cleanup +COPY compiler/base/orchestrator /compiler/base/orchestrator +COPY compiler/base/modify-cargo-toml /compiler/base/modify-cargo-toml +COPY ui /ui + +WORKDIR /compiler/base/orchestrator + +# Hackily deleting the binary sources because I don't know how to +# limit `cargo rustc` to just the library unit tests +RUN \ + rm src/bin/*; \ + cargo rustc --tests --locked -- --cfg force_docker -C relocation-model=static; \ + test_bin=$(find target/debug/deps/ -name "orchestrator*" -type f -perm -a=x); \ + mv "${test_bin}" /output/unit_tests_orchestrator; + +WORKDIR /ui + +RUN \ + cargo rustc --tests --locked -- -C relocation-model=static; \ + test_bin=$(find target/debug/deps/ -name "ui*" -type f -perm -a=x); \ + mv "${test_bin}" /output/unit_tests_ui; + +RUN \ + cargo rustc --locked --release -- -C relocation-model=static; \ + mv target/release/ui /output/ui; diff --git a/ci/Dockerfile.dockerignore b/ci/Dockerfile.dockerignore new file mode 100644 index 000000000..ce1fa91b6 --- /dev/null +++ b/ci/Dockerfile.dockerignore @@ -0,0 +1,10 @@ +* +!compiler/base/asm-cleanup/** +compiler/base/asm-cleanup/target +!compiler/base/orchestrator/** +compiler/base/orchestrator/target +!compiler/base/modify-cargo-toml/** +compiler/base/modify-cargo-toml/target +!ui/** +ui/frontend +ui/target diff --git a/ci/build-backend.sh b/ci/build-backend.sh new file mode 100755 index 000000000..53671d5cd --- /dev/null +++ b/ci/build-backend.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -eu + +IMAGE_NAME=backend-build +OUTPUT_DIR=docker-output + +docker build -t "${IMAGE_NAME}" -f ci/Dockerfile . + +mkdir -p "${OUTPUT_DIR}" + +container_id=$(docker create "${IMAGE_NAME}") +for f in unit_tests_orchestrator unit_tests_ui ui; do + docker cp "${container_id}:/output/${f}" "${OUTPUT_DIR}" +done +docker rm -f "${container_id}" diff --git a/ci/workflows.yml b/ci/workflows.yml index 5f6c73c62..9121e9ec0 100644 --- a/ci/workflows.yml +++ b/ci/workflows.yml @@ -177,15 +177,6 @@ workflows: with: components: rustfmt - - name: "Cache Cargo intermediate products" - uses: actions/cache@v3 - with: - path: |- - ~/.cargo/registry - ~/.cargo/git - ui/target - key: ${{ runner.os }}-cargo-${{ hashFiles('ui/**/Cargo.lock') }}-2 - - name: "Format server" run: cargo fmt --manifest-path ui/Cargo.toml --all --check @@ -196,50 +187,16 @@ workflows: run: cargo fmt --manifest-path compiler/base/orchestrator/Cargo.toml --check - name: "Build backend" - run: >- - mkdir -p ui/target; - docker - run - --rm - -v $PWD/compiler/base/asm-cleanup:/compiler/base/asm-cleanup - -v $PWD/compiler/base/orchestrator:/compiler/base/orchestrator - -v $PWD/compiler/base/modify-cargo-toml:/compiler/base/modify-cargo-toml - -v $PWD/ui:/ui - -v ~/.cargo/git:/root/.cargo/git - -v ~/.cargo/registry:/root/.cargo/registry - --workdir /ui - rust:alpine - sh -c ' - apk add musl-dev openssl-dev openssl-libs-static - - # Adding -C relocation-model=static due to - # https://github.com/rust-lang/rust/issues/95926 - - # Adding this to find the statically-built version - export OPENSSL_NO_PKG_CONFIG=1 OPENSSL_STATIC=1 OPENSSL_DIR=/usr/ - - # Unit tests - cargo rustc --tests --locked -- -C relocation-model=static; - - test_bin=$(find target/debug/deps/ -name "ui*" -type f -perm -a=x); - mv "${test_bin}" target/unit_tests; - - # Primary binary - cargo rustc --locked --release -- -C relocation-model=static; - mv target/release/ui target/ui; - ' - - - name: "Restore permissions" - run: >- - sudo chown -R runner:docker ~/.cargo/ ui/target + run: ./ci/build-backend.sh - name: "Save backend artifact" uses: actions/upload-artifact@v3 with: name: backend path: | - ui/target/ui - ui/target/unit_tests + docker-output/ui + docker-output/unit_tests_ui + docker-output/unit_tests_orchestrator build_frontend: name: "Build frontend" @@ -354,9 +311,13 @@ workflows: name: frontend path: tests/server/build/ - - name: "Run unit tests" + - name: "Run orchestrator unit tests" + run: |- + chmod +x ./server/unit_tests_orchestrator && ./server/unit_tests_orchestrator + + - name: "Run ui unit tests" run: |- - chmod +x ./server/unit_tests && ./server/unit_tests + chmod +x ./server/unit_tests_ui && ./server/unit_tests_ui - name: "Run tests" env: