name: Build and publish Docker image on: push: branches: - dev - master tags: - '*.*.*' workflow_dispatch: env: IMAGE_NAME: rocky-dev jobs: build-and-push: runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to registry uses: docker/login-action@v3 with: registry: ${{ vars.REGISTRY }} username: ${{ vars.USERNAME }} password: ${{ secrets.PASS }} - name: Extract Docker metadata id: meta uses: docker/metadata-action@v5 with: images: ${{ vars.REGISTRY }}/${{ vars.USERNAME }}/${{ env.IMAGE_NAME }} tags: | # Only tag with version and latest on tag push type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/') }} type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }} # Optionally, tag dev/master builds with branch name (for testing) type=ref,event=branch,enable=${{ !startsWith(github.ref, 'refs/tags/') }} - name: Build and push Docker image uses: docker/build-push-action@v6 with: context: . file: ./Dockerfile push: true platforms: linux/amd64,linux/arm64 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max