Skip to content

Commit 8fca8ad

Browse files
Add CI to publish official container (#117)
Adds a Github Actions workflow to publish containers on merges to main and when new tags are pushed. As part of the change, cargo will now use the release when building the published containers, but default to the dev profile when building the container locally. Signed-off-by: Danny Seymour [email protected]
1 parent 9ee99cd commit 8fca8ad

File tree

2 files changed

+83
-7
lines changed

2 files changed

+83
-7
lines changed

.github/workflows/docker.yaml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# GitHub actions workflow which builds and publishes the docker images.
2+
3+
name: Build and push docker images
4+
5+
on:
6+
push:
7+
tags: ["v*"]
8+
branches: [ main ]
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
packages: write
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Set up QEMU
20+
id: qemu
21+
uses: docker/setup-qemu-action@v2
22+
with:
23+
platforms: arm64
24+
25+
- name: Set up Docker Buildx
26+
id: buildx
27+
uses: docker/setup-buildx-action@v2
28+
29+
- name: Inspect builder
30+
run: docker buildx inspect
31+
32+
- name: Log in to DockerHub
33+
uses: docker/login-action@v2
34+
with:
35+
username: ${{ secrets.DOCKERHUB_USERNAME }}
36+
password: ${{ secrets.DOCKERHUB_TOKEN }}
37+
38+
- name: Log in to GHCR
39+
uses: docker/login-action@v2
40+
with:
41+
registry: ghcr.io
42+
username: ${{ github.repository_owner }}
43+
password: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Calculate docker image tag
46+
id: set-tag
47+
uses: docker/metadata-action@master
48+
with:
49+
images: |
50+
ghcr.io/${{ github.repository }}
51+
docker.io/${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}
52+
flavor: |
53+
latest=false
54+
tags: |
55+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
56+
type=semver,pattern=v{{version}}
57+
type=semver,pattern=v{{major}}.{{minor}}
58+
59+
- name: Build and push all platforms
60+
uses: docker/build-push-action@v4
61+
with:
62+
push: true
63+
labels: "gitsha1=${{ github.sha }}"
64+
tags: "${{ steps.set-tag.outputs.tags }}"
65+
platforms: linux/amd64,linux/arm64
66+
67+
# arm64 builds OOM without the git fetch setting. c.f.
68+
# https://github.com/rust-lang/cargo/issues/10583
69+
build-args: |
70+
CARGO_NET_GIT_FETCH_WITH_CLI=true
71+
BUILD_PROFILE=release

Dockerfile

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
FROM docker.io/rust:alpine AS builder
22

3-
RUN apk add python3 musl-dev pkgconfig openssl-dev make
4-
5-
ENV RUSTFLAGS="-C target-feature=-crt-static"
3+
RUN apk add python3 musl-dev pkgconfig openssl-dev make git
64

75
WORKDIR /opt/synapse-compressor/
8-
96
COPY . .
107

11-
RUN cargo build
8+
ENV RUSTFLAGS="-C target-feature=-crt-static"
9+
10+
# arm64 builds consume a lot of memory if `CARGO_NET_GIT_FETCH_WITH_CLI` is not
11+
# set to true, so we expose it as a build-arg.
12+
ARG CARGO_NET_GIT_FETCH_WITH_CLI=false
13+
ENV CARGO_NET_GIT_FETCH_WITH_CLI=$CARGO_NET_GIT_FETCH_WITH_CLI
14+
ARG BUILD_PROFILE=dev
15+
16+
RUN cargo build --profile=$BUILD_PROFILE
1217

1318
WORKDIR /opt/synapse-compressor/synapse_auto_compressor/
1419

@@ -18,5 +23,5 @@ FROM docker.io/alpine
1823

1924
RUN apk add --no-cache libgcc
2025

21-
COPY --from=builder /opt/synapse-compressor/target/debug/synapse_compress_state /usr/local/bin/synapse_compress_state
22-
COPY --from=builder /opt/synapse-compressor/target/debug/synapse_auto_compressor /usr/local/bin/synapse_auto_compressor
26+
COPY --from=builder /opt/synapse-compressor/target/*/synapse_compress_state /usr/local/bin/synapse_compress_state
27+
COPY --from=builder /opt/synapse-compressor/target/*/synapse_auto_compressor /usr/local/bin/synapse_auto_compressor

0 commit comments

Comments
 (0)