|
| 1 | +name: Build container |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - master |
| 6 | + pull_request: |
| 7 | + |
| 8 | + # Allow for manually running |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + container_tag: |
| 12 | + description: Tag for container |
| 13 | + default: "latest" |
| 14 | + required: true |
| 15 | + |
| 16 | +permissions: |
| 17 | + packages: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + container: |
| 21 | + runs-on: ubuntu-20.04 |
| 22 | + |
| 23 | + env: |
| 24 | + CONTAINER_NAME: ghcr.io/${{ github.repository }} |
| 25 | + BUILD_PLATFORMS: linux/amd64,linux/arm,linux/arm64,linux/ppc64le,linux/s390x |
| 26 | + RAW_CONTAINER_TAG: ${{ github.event.inputs.container_tag || github.event.pull_request.head.ref || 'latest' }} |
| 27 | + RAW_REF_NAME: ${{ github.event.pull_request.head.ref || github.ref }} |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Set up QEMU |
| 31 | + uses: docker/setup-qemu-action@v2 |
| 32 | + |
| 33 | + - name: Set up Docker Buildx |
| 34 | + id: buildx |
| 35 | + uses: docker/setup-buildx-action@v2.0.0 |
| 36 | + |
| 37 | + - name: Login to GitHub Container Registry |
| 38 | + uses: docker/login-action@v2 |
| 39 | + with: |
| 40 | + registry: ghcr.io |
| 41 | + username: ${{ github.actor }} |
| 42 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + |
| 44 | + - uses: actions/checkout@v3 |
| 45 | + with: |
| 46 | + submodules: recursive |
| 47 | + |
| 48 | + # Needed for buildx gha cache to work |
| 49 | + - name: Expose GitHub Runtime |
| 50 | + uses: crazy-max/ghaction-github-runtime@v2 |
| 51 | + |
| 52 | + - name: Build container |
| 53 | + env: |
| 54 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + run: | |
| 56 | + CONTAINER_TAG=$(echo "$RAW_CONTAINER_TAG" | sed 's/[^a-zA-Z0-9]\+/-/') |
| 57 | + REF_NAME=$(echo "$RAW_REF_NAME" | sed -r 's#^refs/(heads|tags)/##') |
| 58 | +
|
| 59 | + docker buildx build \ |
| 60 | + --platform "$BUILD_PLATFORMS" \ |
| 61 | + --tag "$CONTAINER_NAME:$CONTAINER_TAG" \ |
| 62 | + --label "org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}" \ |
| 63 | + --label "org.opencontainers.image.documentation=${{ github.server_url }}/${{ github.repository }}" \ |
| 64 | + --label "org.opencontainers.image.url=${{ github.server_url }}/${{ github.repository }}/packages" \ |
| 65 | + --label "org.opencontainers.image.ref.name=$REF_NAME" \ |
| 66 | + --label "org.opencontainers.image.revision=${{ github.sha }}" \ |
| 67 | + --label "org.opencontainers.image.vendor=${{ github.repository_owner }}" \ |
| 68 | + --label "org.opencontainers.image.created=$(date -u --rfc-3339=seconds)" \ |
| 69 | + --cache-from type=gha \ |
| 70 | + --cache-to type=gha,mode=max \ |
| 71 | + --pull ${{ github.event_name == 'push' && '--push' || '' }} . |
0 commit comments