Skip to content

build

build #45

Workflow file for this run

name: build
on:
workflow_dispatch:
schedule:
- cron: "0 3 1 * *"
push:
branches:
- "main"
tags:
- "*"
paths-ignore:
- "**.md"
pull_request:
branches:
- "main"
paths-ignore:
- "**.md"
env:
DOCKERHUB_SLUG: imoize/nginx-fpm
GHCR_SLUG: ghcr.io/imoize/nginx-fpm
LATEST_VERSION: 8.3
jobs:
build:
strategy:
fail-fast: false
matrix:
php_version:
- 8.1
- 8.2
- 8.3
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Preparation
id: prep
run: |
PHP_VERSION=${{ matrix.php_version }}
BUILD_ARG="${PHP_VERSION//./}"
IMAGE_VERSION=$(curl -s "https://api.github.com/repos/${{ github.repository }}/tags" | jq -r '.[0].name')
LATEST=""
if [ "$PHP_VERSION" = "${{ env.LATEST_VERSION }}" ]; then
LATEST="true"
else
LATEST="false"
fi
echo "image_version=$IMAGE_VERSION" >> "$GITHUB_OUTPUT"
echo "php_version=$PHP_VERSION" >> "$GITHUB_OUTPUT"
echo "latest=$LATEST" >> "$GITHUB_OUTPUT"
echo "build_arg=$BUILD_ARG" >> "$GITHUB_OUTPUT"
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v3
- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to DOCKERHUB
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract Docker Metadata
if: ${{ github.event_name != 'pull_request' }}
id: meta
uses: docker/metadata-action@v5
with:
flavor: latest=${{ steps.prep.outputs.latest }}
images: |
${{ env.GHCR_SLUG }}
${{ env.DOCKERHUB_SLUG }}
labels: |
maintainer=Imoize
org.opencontainers.image.vendor=Imoize
org.opencontainers.image.title=nginx-fpm
org.opencontainers.image.version=${{ steps.prep.outputs.image_version }}
tags: |
${{ steps.prep.outputs.php_version }}
fpm-${{ steps.prep.outputs.php_version }}
php-${{ steps.prep.outputs.php_version }}
- name: Build and Push Docker Image
if: ${{ github.event_name != 'pull_request' }}
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
build-args: PHP_VERSION=${{ steps.prep.outputs.build_arg }}
push: ${{ github.event_name != 'pull_request' }}
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}
- name: Docker Hub Description
if: github.event_name != 'pull_request'
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: ${{ env.DOCKERHUB_SLUG }}
short-description: ${{ github.event.repository.description }}
- name: Check Manifest
if: github.event_name != 'pull_request'
run: |
docker buildx imagetools inspect ${{ env.DOCKERHUB_SLUG }}:${{ steps.meta.outputs.version }}
docker buildx imagetools inspect ${{ env.GHCR_SLUG }}:${{ steps.meta.outputs.version }}
- name: Check Pull
if: github.event_name != 'pull_request'
run: |
docker pull ${{ env.DOCKERHUB_SLUG }}:${{ steps.meta.outputs.version }}
docker image inspect ${{ env.DOCKERHUB_SLUG }}:${{ steps.meta.outputs.version }}
docker pull ${{ env.GHCR_SLUG }}:${{ steps.meta.outputs.version }}
docker image inspect ${{ env.GHCR_SLUG }}:${{ steps.meta.outputs.version }}