Skip to content

check "latest" build again #92

check "latest" build again

check "latest" build again #92

name: Build and Push Docker Image
on:
push:
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 <account>/<repo>
IMAGE_NAME: geschke/php-fpm-swrm
# was: ${{ github.repository }}
# GitHub repository is named as "docker-<image_name>" to differ Docker images from other contents
jobs:
build-and-push-image:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- directory: ./ubuntu-22.04/
tagging: 8.1-fpm
setlatest: false
- directory: ./ubuntu-24.04/
tagging: 8.3-fpm
setlatest: true
- directory: ./ubuntu-22.04-sury-8.1/
tagging: 8.1-fpm-ubuntu22.04-sury
setlatest: false
- directory: ./ubuntu-22.04-sury-8.2/
tagging: 8.2-fpm-ubuntu22.04-sury
setlatest: false
- directory: ./ubuntu-22.04-sury-8.3/
tagging: 8.3-fpm-ubuntu22.04-sury
setlatest: false
- directory: ./ubuntu-24.04-sury-8.2/
tagging: 8.2-fpm-ubuntu24.04-sury
setlatest: false
- directory: ./ubuntu-24.04-sury-8.3/
tagging: 8.3-fpm-ubuntu24.04-sury
setlatest: false
permissions:
contents: read
packages: write
steps:
-
name: Checkout
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: 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: |
cp ./install-composer.sh ./${{ matrix.directory }}
-
name: Build full tag based on version file
id: generate_tag
run: |
version_file="${{ matrix.directory }}version.txt"
if [[ -f "$version_file" ]]; then
version=$(cat "$version_file")
full_tag="${{ matrix.tagging }}-${version}"
echo "Full tag is: $full_tag"
echo "full_tag=$full_tag" >> "$GITHUB_OUTPUT"
fi
- name: Query existing Docker image tags
if: github.event_name != 'pull_request'
id: query_tag
run: |
echo "full tag built in previous step:"
echo "Tag ${{ steps.generate_tag.outputs.full_tag }}"
TAG_EXISTS=$(curl -s "https://hub.docker.com/v2/repositories/${{ env.IMAGE_NAME }}/tags/?page_size=100" | jq -r '.results[].name' | grep -w "${{ steps.generate_tag.outputs.full_tag }}" || true)
if [ -n "$TAG_EXISTS" ]; then
echo "Tag ${{ steps.generate_tag.outputs.full_tag }} already exists, so don't build the docker image!"
echo "run_build=false" >> "$GITHUB_OUTPUT"
else
echo "Tag ${{ steps.generate_tag.outputs.full_tag }} does not exist, proceed with building the image."
echo "run_build=true" >> "$GITHUB_OUTPUT"
fi
- name: Test build image
if: "${{ steps.query_tag.outputs.run_build == 'true' && steps.generate_tag.outputs.full_tag != '' }}"
run: |
echo "build docker image ${{ matrix.directory }} ${{ env.IMAGE_NAME }} here... with tag ${{ steps.generate_tag.outputs.full_tag }} "
echo "set to latest tag? ${{ matrix.setlatest }} - ${{ steps.query_tag.outputs.run_build }} full check: ${{ matrix.setlatest == 'true' && steps.query_tag.outputs.run_build == 'true' }}"
-
name: Build and push
if: "${{ steps.query_tag.outputs.run_build == 'true' && steps.generate_tag.outputs.full_tag != '' }}"
uses: docker/build-push-action@v6
with:
context: .
file: ${{ matrix.directory }}/Dockerfile
push: true
tags: |
${{ env.IMAGE_NAME }}:${{ steps.generate_tag.outputs.full_tag }}
${{ env.REGISTRY_GITHUB }}/${{ env.IMAGE_NAME }}:${{ steps.generate_tag.outputs.full_tag }}
- name: Tag as latest if applicable
if: "${{ matrix.setlatest == 'true' && steps.query_tag.outputs.run_build == 'true' && steps.generate_tag.outputs.full_tag != '' }}"
uses: docker/build-push-action@v6
with:
context: ./${{ matrix.directory }}
file: ${{ matrix.directory }}/Dockerfile
push: true
tags: |
${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY_GITHUB }}/${{ env.IMAGE_NAME }}:latest