Skip to content

Commit e4227be

Browse files
authored
Pre-build docker images on GitHub Actions (#25)
This means we don't need to build at deployment time, and means releases are more obviously packaged up. It also slims down the docker image - instead of a whole ubuntu image (~600MB) we drop down to alpine.
1 parent d5ec2f4 commit e4227be

File tree

3 files changed

+42
-24
lines changed

3 files changed

+42
-24
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/release.yml

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,26 @@ on:
55
- "v[0-9]+\\.[0-9]+\\.[0-9]"
66
workflow_dispatch:
77

8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
11+
812
jobs:
9-
validate_pr_metadata:
13+
publish:
1014
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
18+
attestations: write
19+
id-token: write
1120
container:
1221
image: rust:1.88.0-alpine
1322
steps:
1423
- uses: actions/checkout@v4
15-
- name: Install gcc
16-
run: apk add gcc g++
17-
- name: Build validator
18-
run: cargo build --release --bin pr-metadata-validator
24+
- name: Install deps
25+
run: apk add docker gcc g++
26+
- name: Build binaries
27+
run: cargo build --release
1928
- name: Create release
2029
id: create_release
2130
uses: softprops/action-gh-release@v1
@@ -34,3 +43,28 @@ jobs:
3443
asset_name: pr-metadata-validator-musl-${{ github.ref_name }}
3544
asset_path: target/release/pr-metadata-validator
3645
asset_content_type: application/octet-stream
46+
- name: Log in to the Container registry
47+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
48+
with:
49+
registry: ${{ env.REGISTRY }}
50+
username: ${{ github.actor }}
51+
password: ${{ secrets.GITHUB_TOKEN }}
52+
- name: Extract metadata (tags, labels) for Docker
53+
id: meta
54+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
55+
with:
56+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
57+
- name: Build and push Docker image
58+
id: push
59+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
60+
with:
61+
context: .
62+
push: true
63+
tags: ${{ steps.meta.outputs.tags }}
64+
labels: ${{ steps.meta.outputs.labels }}
65+
- name: Generate artifact attestation
66+
uses: actions/attest-build-provenance@v3
67+
with:
68+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
69+
subject-digest: ${{ steps.push.outputs.digest }}
70+
push-to-registry: true

Dockerfile

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
1-
FROM ekidd/rust-musl-builder@sha256:c18dbd9fcf3a4c0c66b8aacea5cf977ee38193efd7e98a55ee7bf9cd9954b221 AS build
1+
# alpine:3.22.2
2+
FROM alpine@sha256:4b7ce07002c69e8f3d704a9c5d6fd3053be500b7f1c69fc0d80990c2ad8dd412
23

3-
RUN sudo chown -R rust:rust /opt/rust/rustup
4-
5-
RUN rustup install 1.88.0
6-
7-
RUN rustup +1.88.0 target add x86_64-unknown-linux-musl
8-
9-
RUN mkdir /tmp/src && chown rust:rust /tmp/src
10-
11-
COPY . /tmp/src
12-
13-
RUN cargo +1.88.0 build --release --manifest-path=/tmp/src/Cargo.toml
14-
15-
FROM ubuntu:latest
16-
17-
RUN apt-get update && apt-get install -y curl wget
18-
19-
COPY --from=build /tmp/src/target/x86_64-unknown-linux-musl/release/trainee-tracker /trainee-tracker
4+
COPY target/release/trainee-tracker /trainee-tracker
205

216
COPY config.prod.json /config.prod.json
227

0 commit comments

Comments
 (0)