diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 3ae3dff..735adc2 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -5,6 +5,19 @@ on: branches: - main +env: + # Use GitHub Container Repository + REGISTRY_GITHUB: ghcr.io + + # Use docker.io for Docker Hub if empty + REGISTRY_DOCKER_HUB: docker.io + + # github.repository as / + IMAGE_NAME: geschke/php-fpm-swrm + # was: ${{ github.repository }} + # GitHub repository is named as "docker-" to differ Docker images from other contents + + jobs: build-and-push-image: runs-on: ubuntu-latest @@ -14,10 +27,8 @@ jobs: include: - directory: ./ubuntu-22.04/ tagging: 8.1-fpm - image: geschke/php-fpm-swrm - directory: ./ubuntu-22.04-sury-8.2/ tagging: 8.2-fpm-ubuntu22.04-sury - image: geschke/php-fpm-swrm permissions: contents: read packages: write @@ -33,10 +44,21 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Login to Docker Hub + if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} + + # Login to GitHub Container Repository + - name: Log into registry ${{ env.REGISTRY_GITHUB }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY_GITHUB }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Copy composer installation file run: | @@ -68,16 +90,20 @@ jobs: echo "run_build=true" >> "$GITHUB_OUTPUT" fi - - name: Test step after query + - name: Test build image if: "${{ steps.query_tag.outputs.run_build == 'true' }}" run: | echo "build docker image ${{ matrix.directory }} ${{ matrix.image }} here... with tag ${{ steps.generate_tag.outputs.full_tag }} " - #- - # name: Build and push - # uses: docker/build-push-action@v6 - # with: - # context: . - # file: ${{ matrix.directory }}/Dockerfile - # push: false - # load: true - # tags: ${{ matrix.tagging }} + + - + name: Build and push + if: "${{ steps.query_tag.outputs.run_build == 'true' }}" + uses: docker/build-push-action@v6 + with: + context: . + file: ${{ matrix.directory }}/Dockerfile + push: false + load: true + tags: | + ${{ env.IMAGE_NAME }}:${{ steps.generate_tag.outputs.full_tag }} + ${{ env.REGISTRY_GITHUB }}/${{ env.IMAGE_NAME }}:${{ steps.generate_tag.outputs.full_tag }}