Skip to content

Commit a580952

Browse files
authored
build: build and publish docker image on release (#1297)
Hi! Finally I figured out how to automatically build docker images on every new rustic release. Closes #1083 Completes tasks discussed in #969, #1008 and #1010. Notes to the maintainers: - This requires setting Workflow permissions to write access for the GITHUB_TOKEN as described here: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#configuring-the-default-github_token-permissions - It makes sense to update the README (added docker install info) in the next rustic release (when the first image is built)
1 parent cb3903b commit a580952

File tree

3 files changed

+42
-23
lines changed

3 files changed

+42
-23
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Build and push docker image on release
2+
3+
on: [release]
4+
5+
jobs:
6+
docker:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Set up Docker Buildx
10+
uses: docker/setup-buildx-action@v3
11+
12+
- name: Login to Docker Hub
13+
uses: docker/login-action@v3
14+
with:
15+
registry: ghcr.io
16+
username: ${{ github.actor }}
17+
password: ${{ secrets.GITHUB_TOKEN }}
18+
19+
- name: Build and push
20+
uses: docker/build-push-action@v6
21+
with:
22+
push: true
23+
tags: ghcr.io/rustic-rs/rustic:latest,ghcr.io/rustic-rs/rustic:${{ github.ref_name }}
24+
build-args: RUSTIC_VERSION=${{ github.ref_name }}

Dockerfile

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
1-
# Improve build speed with cached deps
2-
ARG RUST_VERSION=1.76.0
3-
FROM lukemathwalker/cargo-chef:latest-rust-${RUST_VERSION} AS chef
4-
WORKDIR /app
5-
6-
FROM chef AS planner
7-
COPY . .
8-
RUN cargo chef prepare --recipe-path recipe.json
9-
10-
FROM chef AS builder
11-
COPY --from=planner /app/recipe.json recipe.json
12-
# Build dependencies - this is the caching Docker layer!
13-
RUN cargo chef cook --release --recipe-path recipe.json
14-
# Build application
15-
COPY . .
16-
RUN cargo build --release
17-
18-
# why we dont use alpine for base image - https://andygrove.io/2020/05/why-musl-extremely-slow/
19-
FROM debian:bookworm-slim as runtime
20-
21-
COPY --from=builder /app/target/release/rustic /usr/local/bin
22-
23-
ENTRYPOINT ["/usr/local/bin/rustic"]
1+
FROM alpine AS builder
2+
ARG RUSTIC_VERSION
3+
RUN wget https://github.com/rustic-rs/rustic/releases/download/${RUSTIC_VERSION}/rustic-${RUSTIC_VERSION}-x86_64-unknown-linux-musl.tar.gz && \
4+
tar -xzf rustic-${RUSTIC_VERSION}-x86_64-unknown-linux-musl.tar.gz && \
5+
mkdir /etc_files && \
6+
touch /etc_files/passwd && \
7+
touch /etc_files/group
8+
9+
FROM scratch
10+
COPY --from=builder /rustic /
11+
COPY --from=builder /etc_files/ /etc/
12+
ENTRYPOINT ["/rustic"]

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ Or you can check out the
9797
Nightly binaries are available
9898
[here](https://rustic.cli.rs/docs/nightly_builds.html).
9999

100+
### Docker
101+
102+
```bash
103+
docker pull ghcr.io/rustic-rs/rustic
104+
```
105+
100106
### From source
101107

102108
**Beware**: This installs the latest development version, which might be

0 commit comments

Comments
 (0)