Skip to content
name: Build and publish docker images for PHP Composer
on:
push:
branches:
- "*"
schedule:
- cron: "0 2 1 * *"
jobs:
build:
name: Build & push docker image
runs-on: ubuntu-latest
permissions:
packages: write
security-events: write
contents: read
strategy:
fail-fast: false
matrix:
include:
- context: ./php8.1-composer
image: ghcr.io/xima-media/php8.1-composer
sarif: php8.1-composer.sarif
- context: ./php8.2-composer
image: ghcr.io/xima-media/php8.2-composer
sarif: php8.2-composer.sarif
- context: ./php8.3-composer
image: ghcr.io/xima-media/php8.3-composer
sarif: php8.2-composer.sarif
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Composer version
id: composer
run: |
VERSION=$(curl --silent https://api.github.com/repos/composer/composer/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
echo "::set-output name=version::$(echo ${VERSION})"
- name: Log in to GitHub packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ matrix.image }}
- name: Build and publish docker image
uses: docker/build-push-action@v5
with:
context: ${{ matrix.context }}
push: true
tags: ${{ matrix.image }}:${{ steps.composer.outputs.version }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
COMPOSER_VERSION=${{ steps.composer.outputs.version }}
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ matrix.image }}:${{ steps.composer.outputs.version }}
format: 'sarif'
output: '${{ matrix.sarif }}'
exit-code: '1'
ignore-unfixed: true
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: '${{ matrix.sarif }}'