-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Workflow to check, build and publish oci image
Builds the service as a docker image and upload it to ghcr.io. We want to use a rock in the future but using a rocks right now will slow our progress. I've refined the check jobs to include cargo audit and clippy and make their output available in github's ui. In time we can evolve this to trigger another action (like create an issue for a security vulnerability).
- Loading branch information
Tim Holmes-Mitra
committed
Feb 23, 2024
1 parent
500a937
commit b69ee20
Showing
5 changed files
with
125 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
name: Check, build and publish | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
checks: | ||
name: Test and lint | ||
runs-on: ubuntu-22.04 | ||
permissions: | ||
checks: write | ||
steps: | ||
- name: Install build dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y libssl-dev pkg-config protobuf-compiler libprotobuf-dev | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup rust toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: # seems to ignore rust-toolchain but it should be supported | ||
toolchain: "1.76.0" | ||
components: rustfmt, clippy | ||
|
||
- name: Check code formatting | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: fmt | ||
args: --check | ||
|
||
- name: Clippy linting | ||
uses: giraffate/clippy-action@v1 | ||
with: | ||
reporter: "github-pr-review" | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Dependencies security audit | ||
uses: actions-rust-lang/audit@v1 | ||
with: | ||
ignore: RUSTSEC-2023-0071 # patch not available att | ||
|
||
- name: Run tests | ||
run: | | ||
cp example.env .env | ||
cargo install cargo-make | ||
cargo make db-up | ||
cargo make full-test | ||
publish: | ||
name: Publish to ghcr.io | ||
runs-on: ubuntu-22.04 | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install build dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y libssl-dev pkg-config protobuf-compiler libprotobuf-dev | ||
- name: Setup rust toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: # seems to ignore rust-toolchain but it should be supported | ||
toolchain: "1.76.0" | ||
|
||
- name: Build release binary | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: build | ||
args: --release | ||
|
||
- name: Log in to gchr.io | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata for image labels and tags | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ghcr.io/${{ github.repository }} | ||
tags: | | ||
type=semver,pattern={{version}} | ||
type=sha,format=short | ||
- name: Build and push image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
file: ./docker/ratings/Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM ubuntu:22.04 | ||
|
||
RUN apt-get update && apt-get upgrade -y && rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /app | ||
COPY target/release/ratings /app/ratings | ||
|
||
EXPOSE 8080 | ||
ENTRYPOINT ["/app/ratings"] |
This file was deleted.
Oops, something went wrong.