Build and publish Docker images #35
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 publish Docker images | |
on: [workflow_dispatch] | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: true | |
matrix: | |
tag: [ '8.1', '8.2', '8.3', 'latest' ] | |
permissions: | |
contents: read | |
packages: write | |
env: | |
VERSION_PREFIX: ${{ matrix.tag == 'latest' && ' ' || format('{0}-', matrix.tag) }} | |
name: PHP ${{ matrix.tag }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: arm64 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/[email protected] | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Log in to GitHub Container Registry | |
uses: docker/[email protected] | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/[email protected] | |
with: | |
images: | | |
${{ env.IMAGE_NAME }} | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Version prefix | |
run: echo ${{ env.VERSION_PREFIX }} | |
- name: Build and push Docker image | |
id: docker_build | |
uses: docker/[email protected] | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64/v8 | |
pull: true | |
push: true | |
provenance: false | |
build-args: | | |
"VERSION_PREFIX=${{ env.VERSION_PREFIX }}" | |
cache-from: type=gha | |
cache-to: type=gha,mode=min | |
tags: | | |
${{ env.IMAGE_NAME }}:${{ matrix.tag }} | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.tag }} | |
labels: ${{ steps.meta.outputs.labels }} | |
- name: Image digest | |
run: echo ${{ steps.docker_build.outputs.digest }} | |
- name: Update Docker Hub description | |
uses: peter-evans/dockerhub-description@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
repository: ${{ env.IMAGE_NAME }} |