Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
allow-expect-in-tests = true
3 changes: 3 additions & 0 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ fail-fast = false
path = "junit.xml"
store-success-output = true
store-failure-output = true

[profile.e2e]
default-filter = "test(#e2e::*)"
51 changes: 0 additions & 51 deletions .github/actions/rust-prepare/action.yml

This file was deleted.

5 changes: 0 additions & 5 deletions .github/actions/rust-prepare/prepare_git.sh

This file was deleted.

31 changes: 0 additions & 31 deletions .github/actions/rust-prepare/prepare_rust.sh

This file was deleted.

18 changes: 0 additions & 18 deletions .github/actions/rust-prepare/prepare_ssh.sh

This file was deleted.

17 changes: 11 additions & 6 deletions .github/workflows/publish-crate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@ jobs:
# Enforce only publishing tagged commits
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container: docker-oss.nexus.famedly.de/rust-container:nightly
container:
image: docker-nightly.nexus.famedly.de/rust-container:dev-tlater-entrypoint
credentials:
username: ${{ vars.NEXUS_REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
steps:
- name: Run container entrypoint
run: /entrypoint.sh
env:
FRC_SSH_KEY: ${{ secrets.CI_SSH_PRIVATE_KEY }}
FRC_CRATES_REGISTRY: ${{ inputs.registry-name }}
FRC_CRATES_REGISTRY_INDEX: ${{ inputs.registry-index }}
- uses: actions/checkout@v4
- uses: famedly/backend-build-workflows/.github/actions/rust-prepare@main
with:
gitlab_ssh: ${{ secrets.CI_SSH_PRIVATE_KEY }}
famedly_crates_registry: ${{ inputs.registry-name }}
famedly_crates_registry_index: ${{ inputs.registry-index }}
- name: Install registry token
# Uses `echo` (bash built-in) to prevent leaking the token
# through CLI args in /proc
Expand Down
86 changes: 54 additions & 32 deletions .github/workflows/rust-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,28 @@ on:
type: boolean
default: true

run-e2e-tests:
description: |
Whether to run e2e tests.
required: false
type: boolean
default: false

additional_packages:
required: false
description: |
Additional ubuntu packages to install before running any
commands.
type: string

container:
type: string
default: docker-nightly.nexus.famedly.de/rust-container:dev-tlater-entrypoint

clippy_args: {required: false, type: string, default: ""}
test_args: {required: false, type: string, default: ""}
testcov_args: {required: false, type: string, default: ""}
udeps_args: {required: false, type: string, default: ""}
ref:
description: "The ref/version of this workflow; used to pull the correct dependency versions"
type: string

secrets:
CI_SSH_PRIVATE_KEY:
Expand All @@ -41,32 +56,29 @@ on:
will fail, however requiring secrets means that the
`inherit` syntax does not work.

# Environment variables for all jobs.
env:
CARGO_TERM_COLOR: always
ADDITIONAL_PACKAGES: ""

# Defined CI jobs.
jobs:
rust-lints:
runs-on: ${{ inputs.runs-on }}
container: docker-oss.nexus.famedly.de/rust-container:nightly
container:
image: ${{ inputs.container }}
credentials:
username: ${{ vars.NEXUS_REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
steps:
- name: Checkout workflow dependencies
uses: actions/checkout@v4
with:
repository: famedly/backend-build-workflows
ref: ${{ inputs.ref }}
- name: Run container entrypoint
run: /entrypoint.sh
env:
FRC_SSH_KEY: ${{ secrets.CI_SSH_PRIVATE_KEY }}
Comment thread
tlater-famedly marked this conversation as resolved.
FRC_ADDITIONAL_PACKAGES: ${{ inputs.additional_packages }}

- uses: ./.github/actions/rust-prepare
with:
gitlab_ssh: ${{ secrets.CI_SSH_PRIVATE_KEY}}
gitlab_user: ${{ secrets.GITLAB_USER }}
gitlab_pass: ${{ secrets.GITLAB_PASS }}

- name: Checkout the repository to test
uses: actions/checkout@v4

- name: Tell git that the repo is safe
run: git config --global --add safe.directory $(pwd)

- name: Caching
uses: Swatinem/rust-cache@68b3cb7503c78e67dae8373749990a220eb65352

Expand All @@ -88,30 +100,40 @@ jobs:

rust-tests:
runs-on: ${{ inputs.runs-on }}
container: docker-oss.nexus.famedly.de/rust-container:nightly
container:
image: ${{ inputs.container }}
credentials:
username: ${{ vars.NEXUS_REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
volumes:
# This permits running docker inside the container
- /var/run/docker.sock:/var/run/docker.sock
steps:
- name: Checkout workflow dependencies
uses: actions/checkout@v4
with:
repository: famedly/backend-build-workflows
ref: ${{ inputs.ref }}

- uses: ./.github/actions/rust-prepare
with:
gitlab_ssh: ${{ secrets.CI_SSH_PRIVATE_KEY}}
gitlab_user: ${{ secrets.GITLAB_USER }}
gitlab_pass: ${{ secrets.GITLAB_PASS }}
- name: Run container entrypoint
run: /entrypoint.sh
env:
FRC_SSH_KEY: ${{ secrets.CI_SSH_PRIVATE_KEY }}
FRC_ADDITIONAL_PACKAGES: ${{ inputs.additional_packages }}

- name: Checkout the repository to test
uses: actions/checkout@v4

- name: Tell git that the repo is safe
run: git config --global --add safe.directory $(pwd)

- name: Caching
uses: Swatinem/rust-cache@68b3cb7503c78e67dae8373749990a220eb65352

- name: Test
- name: Unit and integration tests
shell: bash
run: cargo llvm-cov nextest --profile ci --workspace --lcov --output-path lcov.info ${{inputs.testcov_args}}

- name: E2E tests
if: inputs.run-e2e-tests
run: |
docker build --target test -t famedly-workflow-tests:latest .
docker compose --project-directory tests/e2e/env up --quiet-pull --build --exit-code-from tests

- name: Doc-test
shell: bash
if: inputs.run-doctests
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/~test-rust-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ env:
jobs:
test-rust-workflow:
uses: ./.github/workflows/rust-workflow.yml
with:
ref: ${{ github.ref }}
secrets: inherit
with:
run-e2e-tests: true
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
FROM docker-nightly.nexus.famedly.de/rust-container:dev-tlater-entrypoint AS test-builder

# TODO: We currently cannot mount the repo because of
# https://github.com/nextest-rs/nextest/issues/2066
#
# In the future, it would however be nice to use `--mount=target/repo`
# instead of copying.
COPY . /repo
WORKDIR /repo
RUN \
--mount=type=cache,target=/build \
--mount=type=cache,target=/cargo \
export CARGO_TARGET_DIR=/build && \
export CARGO_HOME=/cargo && \
git archive HEAD --output=/git.tar && \
cargo nextest archive --profile e2e --archive-file /tests.tar.zst

FROM docker-nightly.nexus.famedly.de/rust-container:dev-tlater-entrypoint AS test

RUN \
--mount=from=test-builder,source=/git.tar,target=/git.tar \
mkdir -p /repo && \
tar xf /git.tar -C /repo
COPY --from=test-builder /tests.tar.zst /tests.tar.zst

CMD cargo nextest run --profile e2e --archive-file /tests.tar.zst --workspace-remap /repo

FROM debian:bookworm-slim
CMD ["/usr/local/bin/bash"]
60 changes: 55 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# Docker action
# Backend team CI actions and reusable workflows

To use the docker build, you can follow the example in [test](./.github/workflows/docker-test.yml)
This repository currently offers the following workflows:

We have two main use cases
## docker-publish

## Simple service with no subfolders
Publishes a docker image for a service to the correct docker registry.

### Examples

We have two main use cases:

#### Simple service with no subfolders

```yaml
jobs:
Expand All @@ -17,7 +23,7 @@ jobs:

should take care of everything

## Complex service with subfolders
#### Complex service with subfolders

```yaml
jobs:
Expand All @@ -28,3 +34,47 @@ jobs:
path: ./foo/bar # path to where the Dockerfile resides
name: bar # name of service
```

See also the [test case](.github/workflows/~test-docker-backend.yml).

## rust-tests

Runs basic rust lint checks, followed by the repository's test suite
(using `cargo nextest`), and reports code test coverage.

### Using docker containers for test environments

We pretty regularly use `docker compose` to set up test environments,
using `cargo nextest`'s startup script features.

Since the CI environment uses a docker container, this requires a bit
of trickery. The CI env mounts the host docker socket, which *allows*
using docker containers, however to set up volume bind mounts paths
need to be set to their *host* location.

As such, these invocations need to be changed a bit in CI. `cargo
nextest` allows adding scripts in specific profiles, this can be used
to add a setup step to the `ci` profile (though *not* to override the
default scripts). Order is determined by the order in which scripts
are defined.

This sed line may be helpful:

```
sed 's|./|/home/runner/work/<repo>/<repo>|g' -i tests/environment/docker-compose.yaml
```

### Examples

#### Common, simple use case

```yaml
jobs:
rust-tests:
uses: famedly/backend-build-workflows@v2
secrets: inherit
```

#### Specifying various additional arguments

See also the [test case](.github/workflows/~test-rust-workflow.yml)
Loading