|
| 1 | +name: 🐳 Docker Build & Push |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["main"] |
| 6 | + tags: ["v*.*.*"] |
| 7 | + pull_request: |
| 8 | + branches: ["main"] |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + packages: write |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +env: |
| 19 | + REGISTRY: ghcr.io |
| 20 | + GO_VERSION: "1.24" |
| 21 | + |
| 22 | +jobs: |
| 23 | + docker: |
| 24 | + name: 🐳 Build & Push Docker Image |
| 25 | + runs-on: ubuntu-latest |
| 26 | + timeout-minutes: 30 |
| 27 | + |
| 28 | + strategy: |
| 29 | + fail-fast: false |
| 30 | + matrix: |
| 31 | + os: |
| 32 | + - alpine |
| 33 | + - rocky-8 |
| 34 | + - rocky-9 |
| 35 | + - ubuntu-focal |
| 36 | + - ubuntu-jammy |
| 37 | + - ubuntu-noble |
| 38 | + |
| 39 | + steps: |
| 40 | + - name: 📂 Checkout code |
| 41 | + uses: actions/checkout@v4 |
| 42 | + with: |
| 43 | + fetch-depth: 0 |
| 44 | + |
| 45 | + - name: 🐳 Set up Docker Buildx |
| 46 | + uses: docker/setup-buildx-action@v3 |
| 47 | + |
| 48 | + - name: 🔐 Log in to GitHub Container Registry |
| 49 | + if: github.event_name != 'pull_request' |
| 50 | + uses: docker/login-action@v3 |
| 51 | + with: |
| 52 | + registry: ${{ env.REGISTRY }} |
| 53 | + username: ${{ github.actor }} |
| 54 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + |
| 56 | + - name: 🔐 Log in to Docker Hub |
| 57 | + if: >- |
| 58 | + github.event_name != 'pull_request' && |
| 59 | + secrets.DOCKER_USERNAME != '' |
| 60 | + uses: docker/login-action@v3 |
| 61 | + with: |
| 62 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 63 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 64 | + |
| 65 | + - name: 📋 Extract metadata |
| 66 | + id: meta |
| 67 | + uses: docker/metadata-action@v5 |
| 68 | + with: |
| 69 | + images: | |
| 70 | + ${{ env.REGISTRY }}/${{ github.repository }}-${{ matrix.os }} |
| 71 | + ${{ secrets.DOCKER_USERNAME != '' && |
| 72 | + format('m0rf30/yap-{0}', matrix.os) || '' }} |
| 73 | + labels: | |
| 74 | + maintainer=M0Rf30 |
| 75 | + org.opencontainers.image.authors=M0Rf30 |
| 76 | + org.opencontainers.image.title=yap-${{ matrix.os }} |
| 77 | + org.opencontainers.image.description=YAP - Yet Another Packager for |
| 78 | + ${{ matrix.os }} |
| 79 | + org.opencontainers.image.vendor=M0Rf30 |
| 80 | + tags: | |
| 81 | + type=ref,event=branch |
| 82 | + type=ref,event=pr |
| 83 | + type=raw,value=latest,enable={{is_default_branch}} |
| 84 | + type=semver,pattern={{version}} |
| 85 | + type=semver,pattern={{major}}.{{minor}} |
| 86 | + type=semver,pattern={{major}} |
| 87 | +
|
| 88 | + - name: 🔨 Build and push Docker image |
| 89 | + uses: docker/build-push-action@v6 |
| 90 | + with: |
| 91 | + context: . |
| 92 | + file: build/deploy/${{ matrix.os }}/Dockerfile |
| 93 | + platforms: linux/amd64,linux/arm64 |
| 94 | + push: ${{ github.event_name != 'pull_request' }} |
| 95 | + tags: ${{ steps.meta.outputs.tags }} |
| 96 | + labels: ${{ steps.meta.outputs.labels }} |
| 97 | + cache-from: type=gha |
| 98 | + cache-to: type=gha,mode=max |
| 99 | + build-args: | |
| 100 | + VERSION=${{ github.ref_name }} |
| 101 | + BUILD_TIME=${{ github.run_id }} |
| 102 | + COMMIT=${{ github.sha }} |
| 103 | +
|
| 104 | + - name: 📝 Output image details |
| 105 | + run: | |
| 106 | + echo "## 🐳 Docker Image Built" >> $GITHUB_STEP_SUMMARY |
| 107 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 108 | + echo "**OS:** ${{ matrix.os }}" >> $GITHUB_STEP_SUMMARY |
| 109 | + echo "**Tags:** ${{ steps.meta.outputs.tags }}" >> |
| 110 | + $GITHUB_STEP_SUMMARY |
| 111 | + echo "**Labels:** ${{ steps.meta.outputs.labels }}" >> |
| 112 | + $GITHUB_STEP_SUMMARY |
0 commit comments