Skip to content

Build and publish containers #116

Build and publish containers

Build and publish containers #116

Workflow file for this run

name: Build and publish containers
on:
push:
workflow_dispatch:
schedule: [ cron: '0 4 * * *' ]
permissions:
packages: write
contents: write
jobs:
build:
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
CC_aarch64_unknown_linux_gnu: aarch64-linux-gnu-gcc
outputs:
commit: ${{ steps.metadata.outputs.commit }}
continue: ${{ steps.metadata.outputs.continue }}
strategy:
fail-fast: false
matrix:
architecture: [ amd64, arm64v8 ]
include:
- architecture: amd64
platform: linux/amd64
target: x86_64-unknown-linux-gnu
- architecture: arm64v8
platform: linux/arm64
target: aarch64-unknown-linux-gnu
steps:
- uses: actions/checkout@v4
- id: metadata
run: echo "commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- uses: actions-rust-lang/setup-rust-toolchain@v1
with: { cache: false, target: "${{ matrix.target }}" }
- uses: Swatinem/rust-cache@v2
with: { prefix-key: "${{ matrix.architecture }}", cache-directories: "bin" }
- if: ${{ !contains(github.event.head_commit.message, '[build-image-only]') }}
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: nasm gcc-aarch64-linux-gnu
- if: ${{ !contains(github.event.head_commit.message, '[build-image-only]') }}
run: RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --target=${{ matrix.target }}
- if: ${{ !contains(github.event.head_commit.message, '[build-image-only]') }}
run: tar czfv piped-proxy-${{ matrix.architecture }}.tgz -C target/${{ matrix.target }}/release/ piped-proxy
- if: ${{ !contains(github.event.head_commit.message, '[build-image-only]') }}
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: piped-proxy-${{ matrix.architecture }}.tgz
- if: ${{ !contains(github.event.head_commit.message, '[build-image-only]') }}
run: |
mkdir -p ./bin
cp -fv ./target/${{ matrix.target }}/release/piped-proxy ./bin/piped-proxy
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/metadata-action@v5
id: image-meta
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=${{ matrix.architecture }}-${{ steps.metadata.outputs.commit }},enable={{is_default_branch}}
type=raw,value=${{ matrix.architecture }},enable={{is_default_branch}}
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v5
with:
push: true
context: .
file: Dockerfile.mod
tags: ${{ steps.image-meta.outputs.tags }}
platforms: ${{ matrix.platform }}
cache-from: type=gha
cache-to: type=gha,mode=max
merge:
runs-on: ubuntu-20.04
needs: [ build ]
env:
IMAGE: ghcr.io/${{ github.repository }}
COMMIT: ${{ needs.build.outputs.commit }}
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- run: |
docker buildx imagetools create \
--tag ${IMAGE}:${COMMIT} ${IMAGE}:{amd64,arm64v8}-${COMMIT}
docker buildx imagetools create \
--tag ${IMAGE}:latest ${IMAGE}:{amd64,arm64v8}