Skip to content

Commit 1123da7

Browse files
authored
Merge pull request #36 from evaline-ju/fix-ci
👷🐛 Use docker for test run
2 parents b27795c + 733b841 commit 1123da7

File tree

3 files changed

+106
-28
lines changed

3 files changed

+106
-28
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Test and Lint Orchestrator
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
TEST_IMAGE_NAME: "orchestr8-tests:0"
12+
LINT_IMAGE_NAME: "orchestr8-lint:0"
13+
FMT_IMAGE_NAME: "orchestr8-fmt:0"
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
packages: write
20+
contents: read
21+
env:
22+
CACHE_TEST_IMAGE: "ghcr.io/foundation-model-stack/fms-guardrails-orchestrator:test-cache"
23+
CACHE_LINT_IMAGE: "ghcr.io/foundation-model-stack/fms-guardrails-orchestrator:lint-cache"
24+
CACHE_FMT_IMAGE: "ghcr.io/foundation-model-stack/fms-guardrails-orchestrator:fmt-cache"
25+
CACHE_REGISTRY: "ghcr.io"
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
- name: "Setup Docker Buildx"
30+
uses: docker/setup-buildx-action@v3
31+
- name: "Log in to cache image container registry"
32+
uses: docker/login-action@v3
33+
if: github.event_name != 'pull_request'
34+
with:
35+
registry: ${{ env.CACHE_REGISTRY }}
36+
username: ${{ github.actor }}
37+
password: ${{ secrets.GITHUB_TOKEN }}
38+
- name: "Set build cache target"
39+
run: |
40+
# For push to `main` (PR merged), push a new cache image with all layers (cache-mode=max).
41+
# For PR builds, use GitHub action cache which isolates cached layers by PR/branch.
42+
# to optimize builds for subsequent pushes to the same PR/branch.
43+
# Do not set a cache-to image for PR builds to not overwrite the `main` cache image and
44+
# to not ping-pong cache images for two or more different PRs.
45+
# Do not push cache images for each PR or multiple branches to not exceed GitHub package
46+
# usage and traffic limitations.
47+
# UPDATE: GHA cache appears to have issues, cannot use `cache-to: gha,mode=min`
48+
# if `cache-from: reg...,mode=max` but `cache-to: gha,mode=max` takes longer than uncached
49+
# build and exhausts GHA cache size limits, so use cache `type=inline` (no external cache).
50+
if [ "${{ github.event_name }}" == "pull_request" ]
51+
then
52+
#CACHE_TO="type=gha,mode=min"
53+
CACHE_TEST_TO="type=inline"
54+
CACHE_LINT_TO="type=inline"
55+
CACHE_FMT_TO="type=inline"
56+
else
57+
CACHE_TEST_TO="type=registry,ref=${{ env.CACHE_TEST_IMAGE }},mode=max"
58+
CACHE_LINT_TO="type=registry,ref=${{ env.CACHE_LINT_IMAGE }},mode=max"
59+
CACHE_FMT_TO="type=registry,ref=${{ env.CACHE_FMT_IMAGE }},mode=max"
60+
fi
61+
echo "CACHE_TEST_TO=$CACHE_TEST_TO" >> $GITHUB_ENV
62+
echo "CACHE_LINT_TO=$CACHE_LINT_TO" >> $GITHUB_ENV
63+
echo "CACHE_FMT_TO=$CACHE_FMT_TO" >> $GITHUB_ENV
64+
- name: Test
65+
uses: docker/build-push-action@v5
66+
with:
67+
context: .
68+
target: tests
69+
tags: ${{ env.TEST_IMAGE_NAME }}
70+
cache-from: type=registry,ref=${{ env.CACHE_TEST_IMAGE }}
71+
cache-to: ${{ env.CACHE_TEST_TO }}
72+
push: false
73+
platforms: linux/amd64
74+
- name: Lint with clippy
75+
uses: docker/build-push-action@v5
76+
with:
77+
context: .
78+
target: lint
79+
tags: ${{ env.LINT_IMAGE_NAME }}
80+
cache-from: type=registry,ref=${{ env.CACHE_LINT_IMAGE }}
81+
cache-to: ${{ env.CACHE_LINT_TO }}
82+
push: false
83+
platforms: linux/amd64
84+
- name: Format
85+
uses: docker/build-push-action@v5
86+
with:
87+
context: .
88+
target: format
89+
tags: ${{ env.FMT_IMAGE_NAME }}
90+
cache-from: type=registry,ref=${{ env.CACHE_FMT_IMAGE }}
91+
cache-to: ${{ env.CACHE_FMT_TO }}
92+
push: false
93+
platforms: linux/amd64

Dockerfile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,21 @@ WORKDIR /app
3333
# TODO: Make releases via cargo-release
3434
RUN cargo install --root /app/ --path .
3535

36+
## Tests stage ##################################################################
37+
FROM fms-guardrails-orchestr8-builder as tests
38+
RUN cargo test
39+
40+
## Lint stage ###################################################################
41+
FROM fms-guardrails-orchestr8-builder as lint
42+
RUN cargo clippy --all-targets --all-features -- -D warnings
43+
44+
## Formatting check stage #######################################################
45+
FROM fms-guardrails-orchestr8-builder as format
46+
RUN cargo fmt --check
3647

3748
## Release Image ################################################################
3849

39-
FROM ${UBI_MINIMAL_BASE_IMAGE}:${UBI_BASE_IMAGE_TAG}
50+
FROM ${UBI_MINIMAL_BASE_IMAGE}:${UBI_BASE_IMAGE_TAG} as fms-guardrails-orchestr8-release
4051

4152
COPY --from=fms-guardrails-orchestr8-builder /app/bin/ /app/bin/
4253
COPY config /app/config
@@ -53,4 +64,4 @@ USER orchestr8
5364

5465
ENV ORCHESTRATOR_CONFIG /app/config/config.yaml
5566

56-
CMD /app/bin/fms-guardrails-orchestr8
67+
CMD /app/bin/fms-guardrails-orchestr8

0 commit comments

Comments
 (0)