Skip to content

Commit

Permalink
Optimize container pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
nohoster committed Feb 24, 2024
1 parent 0a93d5d commit 7d2771a
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 32 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/build-artifacts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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
- name: Date
id: date
run: echo "DATE=$(date +%Y%m%d-%H%M)" >> "$GITHUB_OUTPUT"

- 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
19 changes: 10 additions & 9 deletions .github/workflows/main-docker.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
name: Container build

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

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
- linux/arm/v7
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 Down Expand Up @@ -54,6 +54,7 @@ jobs:
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: |
Expand Down
28 changes: 5 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
####################################################################################################
## Builder
####################################################################################################

FROM alpine:3.19 AS builder

RUN apk add --no-cache cargo git g++

WORKDIR /redlib

COPY . .

RUN cargo build --config net.git-fetch-with-cli=true --release

####################################################################################################
## Final image
####################################################################################################

FROM alpine:3.19

COPY --from=builder /usr/share/ca-certificates /usr/share/ca-certificates
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
ARG TARGET

RUN apk add --no-cache curl

# Copy our build
COPY --from=builder /redlib/target/release/redlib /usr/local/bin/redlib
RUN curl -L https://github.com/nohoster/redlib/releases/latest/download/redlib-${TARGET}.tar.gz | \
tar xz -C /usr/local/bin/

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

Expand Down

0 comments on commit 7d2771a

Please sign in to comment.