Skip to content

Configure builder by default #2

Configure builder by default

Configure builder by default #2

name: docker-rofl-builder
on:
push:
branches:
- master
paths:
- docker/rofl-builder/**
- .github/workflows/docker-rofl-builder.yml
tags:
- 'rofl-builder/v[0-9]+.[0-9]+*'
pull_request:
paths:
- docker/rofl-builder/**
- .github/workflows/docker-rofl-builder.yml
permissions:
contents: read
packages: write
jobs:
build-rofl-builder:
name: build-rofl-builder
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Determine tag name
id: determine-tag
shell: bash
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "tag=pr-${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT"
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
# Trim rofl-builder/v prefix from tag
TAG="${{ github.ref_name }}"
TAG="${TAG#rofl-builder/v}"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
else
echo "tag=latest" >> "$GITHUB_OUTPUT"
fi
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: "Build and push oasisprotocol/rofl-builder:${{ steps.determine-tag.outputs.tag }}"
uses: docker/build-push-action@v6
with:
context: docker/rofl-builder
file: docker/rofl-builder/Dockerfile
tags: ghcr.io/oasisprotocol/rofl-builder:${{ steps.determine-tag.outputs.tag }}
pull: true
push: true
labels: |
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ steps.determine-tag.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
prune-old-images:
name: prune-old-images
if: ${{ always() }}
needs: [build-rofl-builder]
runs-on: ubuntu-latest
steps:
- name: Prune old ghcr.io/oasisprotocol/rofl-builder images
uses: vlaurin/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
organization: oasisprotocol
container: rofl-builder
keep-younger-than: 7
keep-last: 2
prune-tags-regexes: ^pr-