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

Container pipeline overhaul #59

Merged
merged 8 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
74 changes: 74 additions & 0 deletions .github/workflows/build-artifacts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Release Build

on:
push:
paths-ignore:
- "*.md"
- "compose.*"
branches:
- "main"

env:
CARGO_TERM_COLOR: always

CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: aarch64-linux-gnu-gcc
CC_aarch64_unknown_linux_musl: aarch64-linux-gnu-gcc
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER: arm-linux-gnueabihf-gcc
CC_armv7_unknown_linux_musleabihf: arm-linux-gnueabihf-gcc

jobs:
build:
name: Rust project - latest
runs-on: ubuntu-latest
strategy:
matrix:
target:
- x86_64-unknown-linux-musl
- aarch64-unknown-linux-musl
- armv7-unknown-linux-musleabihf
steps:
- uses: actions/checkout@v4

- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: ${{ matrix.target }}

- if: matrix.target == 'x86_64-unknown-linux-musl'
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends musl-tools

- if: matrix.target == 'armv7-unknown-linux-musleabihf'
run: |
sudo apt update
sudo apt install -y gcc-arm-linux-gnueabihf musl-tools

- if: matrix.target == 'aarch64-unknown-linux-musl'
run: |
sudo apt update
sudo apt install -y gcc-aarch64-linux-gnu musl-tools

# Using DATE-TIME for release name
- name: Date
id: date
run: echo "DATE=$(date +%Y%m%d-%H%M)" >> "$GITHUB_OUTPUT"

# In case app version is prefered
# - name: Versions
# id: version
# run: echo "VERSION=$(cargo metadata --format-version 1 --no-deps | jq .packages[0].version -r | sed 's/^/v/')" >> "$GITHUB_OUTPUT"
sigaloid marked this conversation as resolved.
Show resolved Hide resolved

- name: Build
run: cargo build --release --target ${{ matrix.target }}

- name: Package release
run: tar czf redlib-${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release/ redlib

- name: Upload release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.date.outputs.DATE }}
files: |
redlib-${{ matrix.target }}.tar.gz


135 changes: 99 additions & 36 deletions .github/workflows/main-docker.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,112 @@
name: Docker Build
name: Container build

on:
push:
paths-ignore:
- "**.md"
branches:
- 'main'
workflow_run:
workflows: ["Release Build"]
types:
- completed
env:
REGISTRY_IMAGE: quay.io/redlib/redlib

jobs:
build-docker:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
config:
- { platform: 'linux/amd64', tag: 'latest', dockerfile: 'Dockerfile' }
- { platform: 'linux/arm64', tag: 'latest-arm', dockerfile: 'Dockerfile.arm' }
- { platform: 'linux/arm/v7', tag: 'latest-armv7', dockerfile: 'Dockerfile.armv7' }
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 sources
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
-
name: Checkout
uses: actions/checkout@v4
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
version: latest

- name: Login to Quay.io
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=sha
type=raw,value=latest,enable={{is_default_branch}}
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_ROBOT_TOKEN }}
-
name: Build and push
id: build
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
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}}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
sigaloid marked this conversation as resolved.
Show resolved Hide resolved
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
- name: Oush README to Quay.io
sigaloid marked this conversation as resolved.
Show resolved Hide resolved
uses: christian-korneck/update-container-description-action@v1
env:
DOCKER_APIKEY: ${{ secrets.APIKEY__QUAY_IO }}
Expand All @@ -47,13 +115,8 @@ jobs:
provider: quay
readme_file: 'README.md'

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./${{ matrix.config.dockerfile }}
platforms: ${{ matrix.config.platform }}
push: true
tags: quay.io/redlib/redlib:${{ matrix.config.tag }}
cache-from: type=gha
cache-to: type=gha,mode=max
-
name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

30 changes: 7 additions & 23 deletions Dockerfile
sigaloid marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
####################################################################################################
## Builder
####################################################################################################
FROM rust:alpine AS builder
FROM alpine:3.19

RUN apk add --no-cache musl-dev
ARG TARGET

WORKDIR /redlib
RUN apk add --no-cache curl

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

RUN cargo build --target x86_64-unknown-linux-musl --release

####################################################################################################
## Final image
####################################################################################################
FROM alpine:latest

# Import ca-certificates from builder
COPY --from=builder /usr/share/ca-certificates /usr/share/ca-certificates
COPY --from=builder /etc/ssl/certs /etc/ssl/certs

# Copy our build
COPY --from=builder /redlib/target/x86_64-unknown-linux-musl/release/redlib /usr/local/bin/redlib

# Use an unprivileged user.
RUN adduser --home /nonexistent --no-create-home --disabled-password redlib
USER redlib

Expand All @@ -33,4 +16,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 ["redlib"]

45 changes: 0 additions & 45 deletions Dockerfile.arm

This file was deleted.

43 changes: 0 additions & 43 deletions Dockerfile.armv7

This file was deleted.