|
| 1 | +name: docker-rofl-container-builder |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + paths: |
| 8 | + - docker/rofl-container-builder/** |
| 9 | + - .github/workflows/docker-rofl-container-builder.yml |
| 10 | + tags: |
| 11 | + - 'rofl-container-builder/v[0-9]+.[0-9]+*' |
| 12 | + pull_request: |
| 13 | + paths: |
| 14 | + - docker/rofl-container-builder/** |
| 15 | + - .github/workflows/docker-rofl-container-builder.yml |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + packages: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + build-rofl-container-builder: |
| 23 | + name: build-rofl-container-builder |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: Checkout code |
| 27 | + uses: actions/checkout@v4 |
| 28 | + |
| 29 | + - name: Determine tag name |
| 30 | + id: determine-tag |
| 31 | + shell: bash |
| 32 | + run: | |
| 33 | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then |
| 34 | + echo "tag=pr-${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT" |
| 35 | + elif [[ "${{ github.ref }}" == refs/tags/* ]]; then |
| 36 | + # Trim rofl-container-builder/v prefix from tag |
| 37 | + TAG="${{ github.ref_name }}" |
| 38 | + TAG="${TAG#rofl-container-builder/v}" |
| 39 | + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" |
| 40 | + else |
| 41 | + echo "tag=latest" >> "$GITHUB_OUTPUT" |
| 42 | + fi |
| 43 | + echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT" |
| 44 | +
|
| 45 | + - name: Set up Docker Buildx |
| 46 | + uses: docker/setup-buildx-action@v3 |
| 47 | + |
| 48 | + - name: Login to ghcr.io |
| 49 | + uses: docker/login-action@v3 |
| 50 | + with: |
| 51 | + registry: ghcr.io |
| 52 | + username: ${{ github.actor }} |
| 53 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + |
| 55 | + - name: "Build and push oasisprotocol/rofl-container-builder:${{ steps.determine-tag.outputs.tag }}" |
| 56 | + uses: docker/build-push-action@v6 |
| 57 | + with: |
| 58 | + context: docker/rofl-container-builder |
| 59 | + file: docker/rofl-container-builder/Dockerfile |
| 60 | + tags: ghcr.io/oasisprotocol/rofl-container-builder:${{ steps.determine-tag.outputs.tag }} |
| 61 | + pull: true |
| 62 | + push: true |
| 63 | + labels: | |
| 64 | + org.opencontainers.image.source=${{ github.event.repository.html_url }} |
| 65 | + org.opencontainers.image.created=${{ steps.determine-tag.outputs.created }} |
| 66 | + org.opencontainers.image.revision=${{ github.sha }} |
| 67 | +
|
| 68 | + prune-old-images: |
| 69 | + name: prune-old-images |
| 70 | + if: ${{ always() }} |
| 71 | + needs: [build-rofl-container-builder] |
| 72 | + runs-on: ubuntu-latest |
| 73 | + steps: |
| 74 | + - name: Prune old ghcr.io/oasisprotocol/rofl-container-builder images |
| 75 | + |
| 76 | + with: |
| 77 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 78 | + organization: oasisprotocol |
| 79 | + container: rofl-container-builder |
| 80 | + keep-younger-than: 7 |
| 81 | + keep-last: 2 |
| 82 | + prune-tags-regexes: ^pr- |
0 commit comments