name: Docker Image
on:
push:
branches: [main]
tags-ignore:
- "**"
pull_request:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
docker:
name: Build & Push
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' }}
type=sha,format=short
type=ref,event=branch
type=ref,event=pr
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name == 'push' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
benchmark:
name: Benchmarks
if: github.event_name == 'push' || github.event_name == 'pull_request'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-bench-${{ hashFiles('Dockerfile.bench', 'Cargo.lock') }}
restore-keys: |
${{ runner.os }}-buildx-bench-
- name: Cache criterion baseline
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/criterion-data
key: criterion-${{ github.ref }}
restore-keys: |
criterion-refs/heads/main
criterion-
- name: Build benchmark image
run: |
mkdir -p /tmp/.buildx-cache
docker buildx build \
--cache-from type=local,src=/tmp/.buildx-cache \
--cache-to type=local,dest=/tmp/.buildx-cache-new,mode=max \
--load \
-t liven-bench \
-f Dockerfile.bench \
.
- name: Run benchmarks
run: |
mkdir -p criterion-data
docker run --rm \
-v "${{ github.workspace }}/criterion-data:/app/target/criterion" \
liven-bench | tee bench-output.txt
- name: Upload benchmark log
if: always()
uses: actions/upload-artifact@v4
with:
name: bench-output-${{ github.sha }}
path: bench-output.txt
retention-days: 90
- name: Upload criterion report
if: always()
uses: actions/upload-artifact@v4
with:
name: criterion-report-${{ github.sha }}
path: criterion-data
retention-days: 30
- name: Move docker layer cache
if: always()
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache