Docker #670
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: | |
branches: | |
- "*" | |
- "**" | |
# See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request | |
# pull_request: | |
# See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule | |
schedule: | |
# ┌───────────── minute (0 - 59) | |
# │ ┌───────────── hour (0 - 23) | |
# │ │ ┌───────────── day of the month (1 - 31) | |
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC) | |
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT) | |
# │ │ │ │ │ | |
# │ │ │ │ │ | |
# │ │ │ │ │ | |
- cron: "30 8 * * *" # run at 8:30 AM UTC | |
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 | |
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 | |
debian_release: | |
- bookworm | |
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 }}-${{ matrix.debian_release }} | |
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 | |
# 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 | |
flavor: | | |
suffix=-${{ matrix.php_version }}-${{ matrix.php_base }}-${{ matrix.debian_release }} | |
tags: | | |
# schedule | |
type=schedule,pattern=nightly | |
type=schedule,pattern=nightly-{{ date 'YYYY-MM-DD' tz='UTC' }} | |
# default behavior | |
type=ref,event=branch,prefix=branch/ | |
type=ref,event=pr,prefix=pr/ | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v6 | |
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 | |
build-args: | | |
PHP_BASE_TYPE=${{ matrix.php_base }} | |
PHP_VERSION=${{ matrix.php_version }} | |
PHP_DEBIAN_RELEASE=${{ matrix.debian_release }} | |
# Cache from 'main' branch and the current branch, e.x., 'my-cool-branch' | |
cache-from: | | |
type=gha,scope=php/branch/main/${{ matrix.php_base }}-${{ matrix.php_version }}-${{ matrix.debian_release }} | |
type=gha,scope=php/branch/${{ github.ref_name }}/${{ matrix.php_base }}-${{ matrix.php_version }}-${{ matrix.debian_release }} | |
# Cache to the branch specific cache (e.x., 'my-cool-branch') | |
cache-to: | | |
type=gha,mode=max,ignore-error=true,scope=php/branch/${{ github.ref_name }}/${{ matrix.php_base }}-${{ matrix.php_version }}-${{ matrix.debian_release }} | |
pixelfed: | |
name: pixelfed | |
runs-on: ubuntu-latest | |
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 | |
pixelfed_branch: | |
- staging | |
- dev | |
debian_release: | |
- bookworm | |
php_base: | |
- apache | |
- fpm | |
target_runtime: | |
- apache | |
- nginx | |
# 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 [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 }}-${{ matrix.pixelfed_branch }} | |
cancel-in-progress: true | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
# checout this repo | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
# checkout pixelfed source code into src/ | |
- name: Checkout pixelfed/pixelfed | |
uses: actions/checkout@v4 | |
with: | |
repository: "pixelfed/pixelfed" | |
ref: "${{ matrix.pixelfed_branch }}" | |
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 | |
# 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: | | |
suffix=-${{ matrix.pixelfed_branch }}-${{ matrix.target_runtime }}-${{ matrix.php_version }}-${{ matrix.debian_release }} | |
tags: | | |
# schedule | |
type=schedule,pattern=nightly | |
type=schedule,pattern=nightly-{{ date 'YYYY-MM-DD' tz='UTC' }} | |
# default behavior | |
type=ref,event=branch,prefix=branch/ | |
type=ref,event=pr,prefix=pr/ | |
- name: Build and push image | |
uses: docker/build-push-action@v6 | |
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 | |
build-args: | | |
PHP_VERSION=${{ matrix.php_version }} | |
PHP_BASE_TYPE=${{ matrix.php_base }} | |
PHP_DEBIAN_RELEASE=${{ matrix.debian_release }} | |
# Cache from 'main' branch and the current branch name, e.x., 'my-cool-branch' | |
cache-from: | | |
type=gha,scope=pixelfed/branch/main/${{ matrix.target_runtime }}-${{ matrix.php_base }}-${{ matrix.php_version }}-${{ matrix.debian_release }} | |
type=gha,scope=pixelfed/branch/${{ github.ref_name }}/${{ matrix.target_runtime }}-${{ matrix.php_base }}-${{ matrix.php_version }}-${{ matrix.debian_release }} | |
# Cache to the branch cache version (e.x., 'my-cool-branch') | |
cache-to: | | |
type=gha,mode=max,ignore-error=true,scope=pixelfed/branch/${{ github.ref_name }}/${{ matrix.target_runtime }}-${{ matrix.php_base }}-${{ matrix.php_version }}-${{ matrix.debian_release }} | |
# 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: tests/goss.sh | |
working-directory: images/pixelfed | |
env: | |
TAGS: "${{ steps.meta.outputs.tags }}" | |
DOCKER_APP_PHP_VERSION: ${{ matrix.php_version }} | |
PHP_BASE_TYPE: ${{ matrix.php_base }} | |
- if: matrix.target_runtime == 'apache' && matrix.pixelfed_branch == 'staging' | |
name: "Setup NodeJS" | |
uses: actions/setup-node@v4 | |
with: | |
cache: "npm" | |
cache-dependency-path: "package-lock.json" | |
- if: matrix.target_runtime == 'apache' && matrix.pixelfed_branch == 'staging' | |
name: Run E2E tests | |
run: images/pixelfed/tests/e2e.sh | |
env: | |
CI: true | |
DOCKER_APP_TAG: "${{ steps.meta.outputs.version }}" | |
NGROK_AUTHTOKEN: ${{ secrets.NGROK_AUTHTOKEN }} | |
- if: always() && matrix.target_runtime == 'apache' && matrix.pixelfed_branch == 'staging' | |
name: Show ngrok logs | |
run: | | |
docker logs ngrok | |
docker rm -f ngrok | |
- if: always() && matrix.target_runtime == 'apache' && matrix.pixelfed_branch == 'staging' | |
name: Show docker compose config | |
run: docker compose config | |
- if: always() && matrix.target_runtime == 'apache' && matrix.pixelfed_branch == 'staging' | |
name: Show docker compose logs | |
run: | | |
docker compose logs | |
docker compose down -v | |
- if: always() && matrix.target_runtime == 'apache' && matrix.pixelfed_branch == 'staging' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: playwright-report-${{ matrix.target_runtime }} | |
path: test-results/ | |
retention-days: 30 |