|
| 1 | +name: Publish Container Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + tag: |
| 10 | + description: 'Tag to build and publish' |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + |
| 14 | +jobs: |
| 15 | + build-and-push: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + contents: read |
| 19 | + packages: write |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout repository |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref }} |
| 26 | + |
| 27 | + - name: Set up QEMU |
| 28 | + uses: docker/setup-qemu-action@v3 |
| 29 | + |
| 30 | + - name: Set up Docker Buildx |
| 31 | + uses: docker/setup-buildx-action@v3 |
| 32 | + |
| 33 | + - name: Free disk space |
| 34 | + run: | |
| 35 | + echo "Disk space before cleanup:" |
| 36 | + df -h |
| 37 | + sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL |
| 38 | + sudo docker image prune --all --force |
| 39 | + sudo docker builder prune -a -f |
| 40 | + echo "Disk space after cleanup:" |
| 41 | + df -h |
| 42 | +
|
| 43 | + - name: Log in to GitHub Container Registry |
| 44 | + uses: docker/login-action@v3 |
| 45 | + with: |
| 46 | + registry: ghcr.io |
| 47 | + username: ${{ github.actor }} |
| 48 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 49 | + |
| 50 | + - name: Extract metadata for Docker |
| 51 | + id: meta |
| 52 | + uses: docker/metadata-action@v5 |
| 53 | + with: |
| 54 | + images: ghcr.io/${{ github.repository }} |
| 55 | + tags: | |
| 56 | + type=semver,pattern={{version}} |
| 57 | + type=semver,pattern={{major}}.{{minor}} |
| 58 | + type=raw,value=latest,enable=${{ github.event_name != 'workflow_dispatch' && github.ref == format('refs/tags/{0}', github.ref_name) }} |
| 59 | + type=raw,value=${{ github.event.inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }} |
| 60 | + type=sha,prefix=,suffix=-${{ github.sha }} |
| 61 | +
|
| 62 | + - name: Build and push Docker image |
| 63 | + uses: docker/build-push-action@v5 |
| 64 | + with: |
| 65 | + context: . |
| 66 | + file: ./deploy/Dockerfile |
| 67 | + platforms: linux/amd64,linux/arm64 |
| 68 | + push: true |
| 69 | + tags: ${{ steps.meta.outputs.tags }} |
| 70 | + labels: ${{ steps.meta.outputs.labels }} |
| 71 | + build-args: | |
| 72 | + VERSION=${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }} |
0 commit comments