name: 'Build & Publish Container Image' on: push: pull_request: permissions: contents: 'read' jobs: test-scripts: runs-on: 'ubuntu-latest' steps: - name: 'Checkout Repository ๐Ÿ›Ž๏ธ' uses: 'actions/checkout@v3' - name: 'Test ๐Ÿงช' run: 'ruby .github/workflows/scripts/test/get-image-tags.unit.rb' container-build: needs: 'test-scripts' runs-on: 'ubuntu-latest' steps: - name: 'Checkout Repository ๐Ÿ›Ž๏ธ' uses: 'actions/checkout@v3' - uses: 'docker/setup-buildx-action@v2' - name: 'Get image tag names ๐Ÿท๏ธ' id: 'tag-image' run: | echo "image_tags=$( .github/workflows/scripts/get-image-tags.rb \ "${{ github.repository }}" \ "${{ github.ref_name }}" \ "${{ github.ref_type }}" \ "${{ github.event.repository.default_branch }}" \ )" >> "$GITHUB_OUTPUT" - name: 'Set up QEMU ๐Ÿฆ…' id: 'qemu' uses: 'docker/setup-qemu-action@v2' with: platforms: 'arm64' - name: 'Set target build platforms ๐Ÿ“' id: 'target-platforms' run: | echo "target_platforms=linux/amd64,linux/${{ steps.qemu.outputs.platforms }}" >> "$GITHUB_OUTPUT" - name: 'Build container ๐Ÿณ' id: 'build' uses: 'docker/build-push-action@v3' with: file: 'Dockerfile' tags: '${{ steps.tag-image.outputs.image_tags }}' platforms: '${{ steps.target-platforms.outputs.target_platforms }}' cache-from: 'type=gha' cache-to: 'type=gha,mode=max' outputs: image_tags: '${{ steps.tag-image.outputs.image_tags }}' qemu_platforms: '${{ steps.qemu.outputs.platforms }}' docker_platforms: '${{ steps.target-platforms.outputs.target_platforms }}' publish: needs: - 'container-build' if: contains(needs.container-build.outputs.image_tags, ':latest') runs-on: 'ubuntu-latest' permissions: packages: 'write' steps: - name: 'Checkout Repository ๐Ÿ›Ž๏ธ' uses: 'actions/checkout@v3' - uses: 'docker/setup-buildx-action@v2' - name: 'Login to GitHub Container Registry ๐Ÿ”‘' uses: 'docker/login-action@v2' with: registry: 'ghcr.io' username: '${{ github.repository_owner }}' password: '${{ secrets.GITHUB_TOKEN }}' - name: 'Set up QEMU ๐Ÿฆ…' uses: 'docker/setup-qemu-action@v2' with: platforms: '${{ needs.container-build.outputs.qemu_platforms }}' - name: 'Publish to Registry ๐Ÿ’จ' uses: 'docker/build-push-action@v3' with: file: 'Dockerfile' push: true tags: '${{ needs.container-build.outputs.image_tags }}' platforms: '${{ needs.container-build.outputs.docker_platforms }}' cache-from: 'type=gha'