ci: fix build #8
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: Docker | |
on: | |
# See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch | |
workflow_dispatch: | |
# See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push | |
push: | |
# See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#release | |
release: | |
# See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request | |
pull_request: | |
jobs: | |
bats: | |
name: Bats Testing | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Run bats | |
run: docker run -v "$PWD/images/pixelfed:/var/www" bats/bats:latest /var/www/tests/bats | |
hadolint: | |
name: hadolint | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: PHP | |
uses: hadolint/[email protected] | |
with: | |
dockerfile: images/php/Dockerfile | |
failure-threshold: error | |
- name: Pixelfed | |
uses: hadolint/[email protected] | |
with: | |
dockerfile: images/pixelfed/Dockerfile | |
failure-threshold: error | |
changes: | |
outputs: | |
should-build-php: ${{ steps.changes.outputs.php }} | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dorny/paths-filter@v3 | |
id: changes | |
with: | |
filters: | | |
php: | |
- 'images/php/**' | |
- '.github/workflows/docker.yml' | |
php: | |
needs: [changes] | |
if: needs.changes.outputs.should-build-php | |
name: PHP | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
# See: https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs | |
matrix: | |
php_version: | |
- 8.3 | |
php_base: | |
- apache | |
# - fpm | |
# See: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-concurrency-and-the-default-behavior | |
concurrency: | |
group: php-${{ github.ref }}-${{ matrix.php_base }}-${{ matrix.php_version }} | |
cancel-in-progress: true | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
id: buildx | |
with: | |
version: latest | |
# See: https://github.com/docker/login-action?tab=readme-ov-file#github-container-registry | |
- name: Log in to the GitHub Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Docker meta | |
uses: docker/metadata-action@v5 | |
id: meta | |
with: | |
images: | | |
name=ghcr.io/${{ github.repository }}-php,enable=true | |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} | |
flavor: | | |
latest=auto | |
suffix=-${{ matrix.php_version }} | |
tags: | | |
type=ref,event=branch | |
type=ref,event=tag | |
type=ref,event=pr | |
env: | |
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./images/php | |
file: ./images/php/Dockerfile | |
platforms: linux/amd64,linux/arm64 | |
builder: ${{ steps.buildx.outputs.name }} | |
tags: ${{ steps.meta.outputs.tags }} | |
annotations: ${{ steps.meta.outputs.annotations }} | |
push: true | |
sbom: true | |
provenance: true | |
build-args: | | |
PHP_BASE_TYPE=${{ matrix.php_base }} | |
PHP_VERSION=${{ matrix.php_version }} | |
cache-from: | | |
type=gha,scope=php-${{ matrix.php_base }}-${{ matrix.php_version }} | |
cache-to: | | |
type=gha,mode=max,ignore-error=true,scope=php-${{ matrix.php_base }}-${{ matrix.php_version }} | |
pixelfed: | |
name: pixelfed | |
runs-on: ubuntu-latest | |
# always run the pixelfed step | |
if: ${{ always() }} | |
needs: [php] | |
strategy: | |
fail-fast: false | |
# See: https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs | |
matrix: | |
php_version: | |
- 8.3 | |
target_runtime: | |
- apache | |
# - fpm | |
# - nginx | |
php_base: | |
- apache | |
# - fpm | |
# See: https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#excluding-matrix-configurations | |
# See: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrixexclude | |
exclude: | |
# targeting [apache] runtime with [fpm] base type doesn't make sense | |
- target_runtime: apache | |
php_base: fpm | |
# targeting [fpm] runtime with [apache] base type doesn't make sense | |
- target_runtime: fpm | |
php_base: apache | |
# targeting [nginx] runtime with [apache] base type doesn't make sense | |
- target_runtime: nginx | |
php_base: apache | |
# See: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-concurrency-and-the-default-behavior | |
concurrency: | |
group: pixelfed-${{ github.ref }}-${{ matrix.php_base }}-${{ matrix.php_version }}-${{ matrix.target_runtime }} | |
cancel-in-progress: true | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
# checout this repo | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
# checkout pixelfed source code | |
- name: Checkout pixelfed/pixelfed | |
uses: actions/checkout@v4 | |
with: | |
repository: "pixelfed/pixelfed" | |
ref: "staging" | |
path: "src/" | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
id: buildx | |
with: | |
version: v0.12.0 # *or* newer, needed for annotations to work | |
# See: https://github.com/docker/login-action?tab=readme-ov-file#github-container-registry | |
- name: Log in to the GitHub Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Docker meta | |
uses: docker/metadata-action@v5 | |
id: meta | |
with: | |
images: | | |
name=ghcr.io/${{ github.repository }},enable=true | |
flavor: | | |
latest=auto | |
suffix=-${{ matrix.target_runtime }}-${{ matrix.php_version }} | |
tags: | | |
type=raw,value=dev,enable=${{ github.ref == format('refs/heads/{0}', 'dev') }} | |
type=raw,value=staging,enable=${{ github.ref == format('refs/heads/{0}', 'staging') }} | |
type=pep440,pattern={{ raw }} | |
type=pep440,pattern=v{{ major }}.{{ minor }} | |
type=ref,event=branch,prefix=branch- | |
type=ref,event=pr,prefix=pr- | |
type=ref,event=tag | |
env: | |
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index | |
- name: list files | |
run: ls -al | |
- name: Build and push image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: images/pixelfed/Dockerfile | |
target: ${{ matrix.target_runtime }}-runtime | |
platforms: linux/amd64,linux/arm64 | |
builder: ${{ steps.buildx.outputs.name }} | |
tags: ${{ steps.meta.outputs.tags }} | |
annotations: ${{ steps.meta.outputs.annotations }} | |
push: true | |
sbom: true | |
provenance: true | |
build-args: | | |
PHP_VERSION=${{ matrix.php_version }} | |
PHP_BASE_TYPE=${{ matrix.php_base }} | |
cache-from: | | |
type=gha,scope=pixelfed-${{ matrix.target_runtime }}-${{ matrix.php_base }}-${{ matrix.php_version }} | |
cache-to: | | |
type=gha,mode=max,scope=pixelfed-${{ matrix.target_runtime }}-${{ matrix.php_base }}-${{ matrix.php_version }} | |
# goss validate the image | |
# | |
# See: https://github.com/goss-org/goss | |
- uses: e1himself/goss-installation-action@v1 | |
with: | |
version: "v0.4.4" | |
- name: Execute Goss tests | |
run: | | |
dgoss run \ | |
-v "./.env.testing:/var/www/.env" \ | |
-e "EXPECTED_PHP_VERSION=${{ matrix.php_version }}" \ | |
-e "PHP_BASE_TYPE=${{ matrix.php_base }}" \ | |
${{ steps.meta.outputs.tags }} |