Skip to content

Build images

Build images #90

Workflow file for this run

name: Build images
on:
push:
schedule:
- cron: '0 5 * * 0'
workflow_dispatch:
inputs:
use_cache:
type: boolean
description: "Cache layers"
default: true
permissions:
packages: write
env:
USE_CACHE: ${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.use_cache) }}
jobs:
get-images:
name: Get list of images to build
runs-on: ubuntu-latest
outputs:
images: ${{ steps.get-images.outputs.images }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate list
id: get-images
run: |
images=$(scripts/get-images.sh | jq --compact-output --raw-input --slurp 'split("\n") | del(.[] | select(. == ""))')
echo "images=${images}" >> ${GITHUB_OUTPUT}
env:
PREVIOUS_PUSH: ${{ github.event.before }}
EXCLUDE_IMAGES: generic-web
build:
name: Build images
needs: get-images
runs-on: ubuntu-latest
if: ${{ needs.get-images.outputs.images != '[]' && needs.get-images.outputs.images != '' }}
strategy:
fail-fast: false
matrix:
image: ${{ fromJSON(needs.get-images.outputs.images) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate metadata
id: metadata
uses: docker/metadata-action@v5
with:
images: ghcr.io/programie/dockerimages/${{ matrix.image }}
- name: Build image ${{ matrix.image }}
uses: docker/build-push-action@v5
with:
context: images/${{ matrix.image }}
push: true
cache-from: ${{ env.USE_CACHE == 'true' && 'type=gha' || '' }}
cache-to: type=gha,mode=max
tags: ghcr.io/programie/dockerimages/${{ matrix.image }}
labels: |
org.opencontainers.image.source=${{ fromJSON(steps.metadata.outputs.json).labels['org.opencontainers.image.source'] }}
org.opencontainers.image.revision=${{ fromJSON(steps.metadata.outputs.json).labels['org.opencontainers.image.revision'] }}
org.opencontainers.image.created=${{ fromJSON(steps.metadata.outputs.json).labels['org.opencontainers.image.created'] }}
build-generic-web:
name: Build generic-web images
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php_version:
- "7.4"
- "8.1"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate metadata
id: metadata
uses: docker/metadata-action@v5
with:
images: ghcr.io/programie/dockerimages/generic-web:php${{ matrix.php_version }}
- name: Build image for PHP ${{ matrix.php_version }}
uses: docker/build-push-action@v5
with:
context: images/generic-web
push: true
cache-from: ${{ env.USE_CACHE == 'true' && 'type=gha' || '' }}
cache-to: type=gha,mode=max
build-args: PHP_VERSION=${{ matrix.php_version }}
tags: ghcr.io/programie/dockerimages/generic-web:php${{ matrix.php_version }}
labels: |
org.opencontainers.image.source=${{ fromJSON(steps.metadata.outputs.json).labels['org.opencontainers.image.source'] }}
org.opencontainers.image.revision=${{ fromJSON(steps.metadata.outputs.json).labels['org.opencontainers.image.revision'] }}
org.opencontainers.image.created=${{ fromJSON(steps.metadata.outputs.json).labels['org.opencontainers.image.created'] }}