Skip to content

Commit

Permalink
Run the orchestrator unit tests in CI
Browse files Browse the repository at this point in the history
Rework the build to use a separate Dockerfile — it was simply too
complicated to have the nested scripts in YAML.
  • Loading branch information
shepmaster committed Nov 17, 2023
1 parent 13e53f9 commit 710e3f5
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 83 deletions.
42 changes: 8 additions & 34 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,50 +101,22 @@ 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
run: cargo fmt --manifest-path top-crates/Cargo.toml --check
- 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
Expand Down Expand Up @@ -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/
Expand Down
37 changes: 37 additions & 0 deletions ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -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;
10 changes: 10 additions & 0 deletions ci/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions ci/build-backend.sh
Original file line number Diff line number Diff line change
@@ -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}"
59 changes: 10 additions & 49 deletions ci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 710e3f5

Please sign in to comment.