Skip to content

Commit 3f4526d

Browse files
authored
Container pipeline overhaul (#59)
* Simplified docker image building * minor name fix * Optimize container pipeline * Change config to redlib-org account * Added README push to Quay.io * Fixes
1 parent 5de171b commit 3f4526d

File tree

5 files changed

+180
-146
lines changed

5 files changed

+180
-146
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Release Build
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- "*.md"
7+
- "compose.*"
8+
branches:
9+
- "main"
10+
11+
env:
12+
CARGO_TERM_COLOR: always
13+
14+
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: aarch64-linux-gnu-gcc
15+
CC_aarch64_unknown_linux_musl: aarch64-linux-gnu-gcc
16+
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER: arm-linux-gnueabihf-gcc
17+
CC_armv7_unknown_linux_musleabihf: arm-linux-gnueabihf-gcc
18+
19+
jobs:
20+
build:
21+
name: Rust project - latest
22+
runs-on: ubuntu-latest
23+
strategy:
24+
matrix:
25+
target:
26+
- x86_64-unknown-linux-musl
27+
- aarch64-unknown-linux-musl
28+
- armv7-unknown-linux-musleabihf
29+
steps:
30+
- uses: actions/checkout@v4
31+
32+
- uses: actions-rust-lang/setup-rust-toolchain@v1
33+
with:
34+
target: ${{ matrix.target }}
35+
36+
- if: matrix.target == 'x86_64-unknown-linux-musl'
37+
run: |
38+
sudo apt-get update
39+
sudo apt-get install -y --no-install-recommends musl-tools
40+
41+
- if: matrix.target == 'armv7-unknown-linux-musleabihf'
42+
run: |
43+
sudo apt update
44+
sudo apt install -y gcc-arm-linux-gnueabihf musl-tools
45+
46+
- if: matrix.target == 'aarch64-unknown-linux-musl'
47+
run: |
48+
sudo apt update
49+
sudo apt install -y gcc-aarch64-linux-gnu musl-tools
50+
51+
- name: Versions
52+
id: version
53+
run: echo "VERSION=$(cargo metadata --format-version 1 --no-deps | jq .packages[0].version -r | sed 's/^/v/')" >> "$GITHUB_OUTPUT"
54+
55+
- name: Build
56+
run: cargo build --release --target ${{ matrix.target }}
57+
58+
- name: Package release
59+
run: tar czf redlib-${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release/ redlib
60+
61+
- name: Upload release
62+
uses: softprops/action-gh-release@v1
63+
if: github.base_ref != 'main' && github.event_name == 'release'
64+
with:
65+
tag_name: ${{ steps.version.outputs.VERSION }}
66+
name: ${{ steps.version.outputs.VERSION }} - ${{ github.event.head_commit.message }}
67+
draft: true
68+
files: |
69+
redlib-${{ matrix.target }}.tar.gz
70+
body: |
71+
- ${{ github.event.head_commit.message }} ${{ github.sha }}
72+
generate_release_notes: true
73+
74+
75+

.github/workflows/main-docker.yml

Lines changed: 98 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,112 @@
1-
name: Docker Build
1+
name: Container build
22

33
on:
4-
push:
5-
paths-ignore:
6-
- "**.md"
7-
branches:
8-
- 'main'
4+
workflow_run:
5+
workflows: ["Release Build"]
6+
types:
7+
- completed
8+
env:
9+
REGISTRY_IMAGE: quay.io/redlib/redlib
910

1011
jobs:
11-
build-docker:
12+
build:
1213
runs-on: ubuntu-latest
1314
strategy:
15+
fail-fast: false
1416
matrix:
15-
config:
16-
- { platform: 'linux/amd64', tag: 'latest', dockerfile: 'Dockerfile' }
17-
- { platform: 'linux/arm64', tag: 'latest-arm', dockerfile: 'Dockerfile.arm' }
18-
- { platform: 'linux/arm/v7', tag: 'latest-armv7', dockerfile: 'Dockerfile.armv7' }
17+
include:
18+
- { platform: linux/amd64, target: x86_64-unknown-linux-musl}
19+
- { platform: linux/arm64, target: aarch64-unknown-linux-musl}
20+
- { platform: linux/arm/v7, target: armv7-unknown-linux-musleabihf}
1921
steps:
20-
- name: Checkout sources
21-
uses: actions/checkout@v3
22-
23-
- name: Set up QEMU
24-
uses: docker/setup-qemu-action@v2
22+
-
23+
name: Checkout
24+
uses: actions/checkout@v4
25+
-
26+
name: Docker meta
27+
id: meta
28+
uses: docker/metadata-action@v5
2529
with:
26-
platforms: all
27-
28-
- name: Set up Docker Buildx
29-
id: buildx
30-
uses: docker/setup-buildx-action@v2
30+
images: ${{ env.REGISTRY_IMAGE }}
31+
tags: |
32+
type=sha
33+
type=raw,value=latest,enable={{is_default_branch}}
34+
-
35+
name: Set up QEMU
36+
uses: docker/setup-qemu-action@v3
37+
-
38+
name: Set up Docker Buildx
39+
uses: docker/setup-buildx-action@v3
40+
-
41+
name: Login to Quay.io Container Registry
42+
uses: docker/login-action@v3
3143
with:
32-
version: latest
33-
34-
- name: Login to Quay.io
44+
registry: quay.io
45+
username: ${{ secrets.QUAY_USERNAME }}
46+
password: ${{ secrets.QUAY_ROBOT_TOKEN }}
47+
-
48+
name: Build and push
49+
id: build
50+
uses: docker/build-push-action@v5
51+
with:
52+
context: .
53+
platforms: ${{ matrix.platform }}
54+
labels: ${{ steps.meta.outputs.labels }}
55+
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
56+
file: Dockerfile
57+
build-args: TARGET=${{ matrix.target }}
58+
-
59+
name: Export digest
60+
run: |
61+
mkdir -p /tmp/digests
62+
digest="${{ steps.build.outputs.digest }}"
63+
touch "/tmp/digests/${digest#sha256:}"
64+
-
65+
name: Upload digest
66+
uses: actions/upload-artifact@v3
67+
with:
68+
name: digests
69+
path: /tmp/digests/*
70+
if-no-files-found: error
71+
retention-days: 1
72+
merge:
73+
runs-on: ubuntu-latest
74+
needs:
75+
- build
76+
steps:
77+
-
78+
name: Download digests
79+
uses: actions/download-artifact@v3
80+
with:
81+
name: digests
82+
path: /tmp/digests
83+
-
84+
name: Set up Docker Buildx
85+
uses: docker/setup-buildx-action@v3
86+
-
87+
name: Docker meta
88+
id: meta
89+
uses: docker/metadata-action@v5
90+
with:
91+
images: ${{ env.REGISTRY_IMAGE }}
92+
tags: |
93+
type=sha
94+
type=raw,value=latest,enable={{is_default_branch}}
95+
-
96+
name: Login to Quay.io Container Registry
3597
uses: docker/login-action@v3
3698
with:
3799
registry: quay.io
38100
username: ${{ secrets.QUAY_USERNAME }}
39101
password: ${{ secrets.QUAY_ROBOT_TOKEN }}
102+
-
103+
name: Create manifest list and push
104+
working-directory: /tmp/digests
105+
run: |
106+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
107+
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
40108
41-
- name: push README to Quay.io
109+
- name: Push README to Quay.io
42110
uses: christian-korneck/update-container-description-action@v1
43111
env:
44112
DOCKER_APIKEY: ${{ secrets.APIKEY__QUAY_IO }}
@@ -47,13 +115,8 @@ jobs:
47115
provider: quay
48116
readme_file: 'README.md'
49117

50-
- name: Build and push
51-
uses: docker/build-push-action@v5
52-
with:
53-
context: .
54-
file: ./${{ matrix.config.dockerfile }}
55-
platforms: ${{ matrix.config.platform }}
56-
push: true
57-
tags: quay.io/redlib/redlib:${{ matrix.config.tag }}
58-
cache-from: type=gha
59-
cache-to: type=gha,mode=max
118+
-
119+
name: Inspect image
120+
run: |
121+
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
122+

Dockerfile

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
1-
####################################################################################################
2-
## Builder
3-
####################################################################################################
4-
FROM rust:alpine AS builder
1+
FROM alpine:3.19
52

6-
RUN apk add --no-cache musl-dev
3+
ARG TARGET
74

8-
WORKDIR /redlib
5+
RUN apk add --no-cache curl
96

10-
COPY . .
7+
RUN curl -L https://github.com/redlib-org/redlib/releases/latest/download/redlib-${TARGET}.tar.gz | \
8+
tar xz -C /usr/local/bin/
119

12-
RUN cargo build --target x86_64-unknown-linux-musl --release
13-
14-
####################################################################################################
15-
## Final image
16-
####################################################################################################
17-
FROM alpine:latest
18-
19-
# Import ca-certificates from builder
20-
COPY --from=builder /usr/share/ca-certificates /usr/share/ca-certificates
21-
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
22-
23-
# Copy our build
24-
COPY --from=builder /redlib/target/x86_64-unknown-linux-musl/release/redlib /usr/local/bin/redlib
25-
26-
# Use an unprivileged user.
2710
RUN adduser --home /nonexistent --no-create-home --disabled-password redlib
2811
USER redlib
2912

@@ -33,4 +16,5 @@ EXPOSE 8080
3316
# Run a healthcheck every minute to make sure redlib is functional
3417
HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider --q http://localhost:8080/settings || exit 1
3518

36-
CMD ["redlib"]
19+
CMD ["redlib"]
20+

Dockerfile.arm

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

Dockerfile.armv7

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

0 commit comments

Comments
 (0)