|
| 1 | +name: Container Build and Publish |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + dockerfile: |
| 7 | + description: 'Dockerfile path' |
| 8 | + required: false |
| 9 | + default: Dockerfile |
| 10 | + type: string |
| 11 | + context: |
| 12 | + description: 'Build context' |
| 13 | + required: false |
| 14 | + default: . |
| 15 | + type: string |
| 16 | + platforms: |
| 17 | + description: 'Target platforms' |
| 18 | + required: false |
| 19 | + default: linux/amd64,linux/arm64 |
| 20 | + type: string |
| 21 | + registry: |
| 22 | + description: 'Container registry' |
| 23 | + required: false |
| 24 | + default: ghcr.io |
| 25 | + type: string |
| 26 | + image_name: |
| 27 | + description: 'Image name' |
| 28 | + required: false |
| 29 | + default: ${{ github.repository }} |
| 30 | + type: string |
| 31 | + min_versions_to_keep: |
| 32 | + description: 'Minimum versions to keep for package deletion' |
| 33 | + required: false |
| 34 | + default: 5 |
| 35 | + type: number |
| 36 | + secrets: |
| 37 | + GITHUB_TOKEN: |
| 38 | + required: true |
| 39 | + |
| 40 | +jobs: |
| 41 | + container-build: |
| 42 | + runs-on: ubuntu-latest |
| 43 | + steps: |
| 44 | + - name: Checkout |
| 45 | + uses: actions/checkout@v4 |
| 46 | + |
| 47 | + - name: Docker meta |
| 48 | + id: meta |
| 49 | + uses: docker/metadata-action@v5 |
| 50 | + with: |
| 51 | + images: ${{ inputs.registry }}/${{ inputs.image_name }} |
| 52 | + tags: | |
| 53 | + type=ref,event=branch |
| 54 | + type=semver,pattern={{version}} |
| 55 | + type=semver,pattern={{major}}.{{minor}} |
| 56 | + type=semver,pattern={{major}} |
| 57 | + type=raw,value=latest,enable={{is_default_branch}} |
| 58 | +
|
| 59 | + - name: Set up QEMU |
| 60 | + uses: docker/setup-qemu-action@v3 |
| 61 | + |
| 62 | + - name: Set up Docker Buildx |
| 63 | + uses: docker/setup-buildx-action@v3 |
| 64 | + |
| 65 | + - name: Login to Container Registry |
| 66 | + if: github.event_name != 'pull_request' |
| 67 | + uses: docker/login-action@v3 |
| 68 | + with: |
| 69 | + registry: ${{ inputs.registry }} |
| 70 | + username: ${{ github.repository_owner }} |
| 71 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 72 | + |
| 73 | + - name: Build and push |
| 74 | + uses: docker/build-push-action@v6 |
| 75 | + with: |
| 76 | + context: ${{ inputs.context }} |
| 77 | + file: ${{ inputs.dockerfile }} |
| 78 | + platforms: ${{ inputs.platforms }} |
| 79 | + push: ${{ github.event_name != 'pull_request' }} |
| 80 | + tags: ${{ steps.meta.outputs.tags }} |
| 81 | + labels: ${{ steps.meta.outputs.labels }} |
| 82 | + cache-from: type=gha |
| 83 | + cache-to: type=gha,mode=max |
| 84 | + |
| 85 | + - uses: actions/delete-package-versions@v5 |
| 86 | + if: ${{ github.event_name != 'pull_request' }} |
| 87 | + with: |
| 88 | + package-name: ${{ github.event.repository.name }} |
| 89 | + package-type: container |
| 90 | + min-versions-to-keep: ${{ inputs.min_versions_to_keep }} |
| 91 | + delete-only-untagged-versions: true |
0 commit comments