Skip to content

Docker Image CI

Docker Image CI #49

Workflow file for this run

name: Docker Image CI
on:
workflow_dispatch:
inputs:
version:
description: 'PHP Version to build'
required: false
default: ''
latest:
description: 'Create tag "latest" for the build'
type: boolean
required: true
default: true
env:
# IMAGE_NAME: ${{ github.repository }}
IMAGE_NAME: ${{ github.repository_owner }}/php-fpm
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
# Checkout the repository
# https://github.com/actions/checkout
- name: Checkout repository
uses: actions/checkout@v3
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Login to Docker Hub registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
# Get the PHP version if not specified
- name: Get the PHP version
id: php
run: |
if [[ -n "${{ github.event.inputs.version }}" ]]; then
export PHPVERSION="${{ github.event.inputs.version }}"
else
export PHPVERSION=$(grep 'PHP_VERSION=' Dockerfile | cut -d'=' -f2)
fi
echo "full_version=${PHPVERSION}" >> $GITHUB_OUTPUT
echo "mino_version=${PHPVERSION%.*}" >> $GITHUB_OUTPUT
echo "majo_version=${PHPVERSION%%.*}" >> $GITHUB_OUTPUT
# Prepare Docker tags
# https://github.com/docker/metadata-action
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
docker.io/${{ env.IMAGE_NAME }}
ghcr.io/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.event.inputs.latest }}
type=raw,value=${{ steps.php.outputs.full_version }}
type=raw,value=${{ steps.php.outputs.mino_version }}
type=raw,value=${{ steps.php.outputs.majo_version }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
build-args: PHP_VERSION=${{ steps.php.outputs.full_version }}
tags: ${{ steps.meta.outputs.tags }}