let's try a real push... #87
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
- directory: ./ubuntu-22.04-sury-8.2/ | |
tagging: 8.2-fpm-ubuntu22.04-sury | |
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 | |
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' }}" | |
run: | | |
echo "build docker image ${{ matrix.directory }} ${{ env.IMAGE_NAME }} here... with tag ${{ steps.generate_tag.outputs.full_tag }} " | |
- | |
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: true | |
tags: | | |
${{ env.IMAGE_NAME }}:${{ steps.generate_tag.outputs.full_tag }} | |
${{ env.REGISTRY_GITHUB }}/${{ env.IMAGE_NAME }}:${{ steps.generate_tag.outputs.full_tag }} |