Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the Docker image build process #123

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 21 additions & 76 deletions .github/workflows/main-docker.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
name: Container build

on:
workflow_run:
workflows: ["Release Build"]
types:
- completed
pull_request:
push:
branches:
- "main"
workflow_dispatch:

env:
REGISTRY_IMAGE: quay.io/redlib/redlib
PLATFORMS: "linux/amd64,linux/arm64"

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- { platform: linux/amd64, target: x86_64-unknown-linux-musl}
- { platform: linux/arm64, target: aarch64-unknown-linux-musl}
- { platform: linux/arm/v7, target: armv7-unknown-linux-musleabihf}
steps:
-
name: Checkout
Expand All @@ -39,84 +37,31 @@ jobs:
uses: docker/setup-buildx-action@v3
-
name: Login to Quay.io Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_ROBOT_TOKEN }}
-
name: Build and push
id: build
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ matrix.platform }}
platforms: ${{ env.PLATFORMS }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
outputs: type=image,name=${{ env.REGISTRY_IMAGE }}
file: Dockerfile
build-args: TARGET=${{ matrix.target }}
-
name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
-
name: Upload digest
uses: actions/upload-artifact@v3
with:
name: digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
runs-on: ubuntu-latest
needs:
- build
steps:
-
name: Download digests
uses: actions/download-artifact@v3
with:
name: digests
path: /tmp/digests
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=sha
type=raw,value=latest,enable={{is_default_branch}}
push: true
-
name: Login to Quay.io Container Registry
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_ROBOT_TOKEN }}
-
name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)

- name: Push README to Quay.io
uses: christian-korneck/update-container-description-action@v1
env:
DOCKER_APIKEY: ${{ secrets.APIKEY__QUAY_IO }}
name: Build and push (Pull Request)
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v5
with:
destination_container_repo: quay.io/redlib/redlib
provider: quay
readme_file: 'README.md'

-
name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

context: .
platforms: ${{ env.PLATFORMS }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }}
file: Dockerfile
push: false
20 changes: 13 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
FROM alpine:3.19
FROM docker.io/library/rust:1.78-slim-bookworm AS builder

ARG TARGET
WORKDIR /app
COPY ./ ./

RUN apk add --no-cache curl
# RUN cargo test --release
RUN cargo build --release

RUN curl -L https://github.com/redlib-org/redlib/releases/latest/download/redlib-${TARGET}.tar.gz | \
tar xz -C /usr/local/bin/
FROM docker.io/library/debian:bookworm-slim AS release

RUN adduser --home /nonexistent --no-create-home --disabled-password redlib
WORKDIR /app
# ca-certificates are not preinstalled in the base image
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=builder --chown=600 /app/target/release/redlib /app/

RUN useradd -M redlib
USER redlib

# Tell Docker to expose port 8080
Expand All @@ -16,5 +22,5 @@ EXPOSE 8080
# Run a healthcheck every minute to make sure redlib is functional
HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider --q http://localhost:8080/settings || exit 1

CMD ["redlib"]
CMD ["/app/redlib"]

Loading