Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 136 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
name: Build and push lephare/frankenphp Docker image
name: Build and push lephare/frankenphp Docker images

# Adapted from the Docker documentation "Multi-platform image with GitHub Actions > With Bake": https://docs.docker.com/build/ci/github-actions/multi-platform/#with-bake
# With 2 more matrix levels: PHP version and target (dev or prod).

on:
push:
branches:
Expand All @@ -7,27 +11,149 @@ on:
branches:
- master
schedule:
- cron: '0 12 * * SUN' # every sunday
- cron: '0 12 * * SUN' # every Sunday
workflow_dispatch:

env:
REGISTRY_IMAGE: lephare/frankenphp

jobs:
build:
prepare:
runs-on: ubuntu-latest
steps:
- name: Login to DockerHub
- name: Checkout
uses: actions/checkout@v6

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}

- name: Rename meta bake definition file
run: |
mv "${{ steps.meta.outputs.bake-file }}" "${{ runner.temp }}/bake-meta.json"

- name: Upload meta bake definition
uses: actions/upload-artifact@v4
with:
name: bake-meta
path: ${{ runner.temp }}/bake-meta.json
if-no-files-found: error
retention-days: 1

build:
needs:
- prepare
strategy:
fail-fast: false
matrix:
php-version: ['8-4', '8-5']
platform: ['linux/amd64', 'linux/arm64']
tgt: ['dev', 'prod']
runs-on: ${{ startsWith(matrix.platform, 'linux/arm') && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "MATRIX_PAIR=${{ matrix.php-version }}-${{ matrix.tgt }}-${platform//\//-}" >> $GITHUB_ENV

- name: Download meta bake definition
uses: actions/download-artifact@v4
with:
name: bake-meta
path: ${{ runner.temp }}

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
- name: Build
id: bake
uses: docker/bake-action@v6
with:
push: ${{ github.event_name != 'pull_request' }}
targets: image-all
files: |
./docker-bake.hcl
cwd://${{ runner.temp }}/bake-meta.json
targets: frankenphp-${{ matrix.php-version }}-${{ matrix.tgt }}
set: |
*.cache-from=type=gha
*.cache-to=type=gha,mode=max
*.output=type=image,push-by-digest=true,name-canonical=true,push=true
*.platform=${{ matrix.platform }}
*.tags=${{ env.REGISTRY_IMAGE }}

- name: Export digest
run: |
mkdir -p ${{ runner.temp }}/digests
digest="${{ fromJSON(steps.bake.outputs.metadata)[format('frankenphp-{0}-{1}', matrix.php-version, matrix.tgt)]['containerimage.digest'] }}"
touch "${{ runner.temp }}/digests/${digest#sha256:}"

- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.MATRIX_PAIR }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1

merge:
strategy:
fail-fast: false
matrix:
php-version: ['8-4', '8-5']
tgt: ['dev', 'prod']
env:
DOCKER_BAKE_TARGET: frankenphp-${{ matrix.php-version }}-${{ matrix.tgt }}
runs-on: ubuntu-latest
needs:
- prepare
- build
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Download meta bake definition
uses: actions/download-artifact@v4
with:
name: bake-meta
path: ${{ runner.temp }}

- name: Download digests
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: digests-${{ matrix.php-version }}-${{ matrix.tgt }}-*
merge-multiple: true

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Extract Docker Bake metadata
id: bake-metadata
run: |
echo "tags=$(docker buildx bake ${{ env.DOCKER_BAKE_TARGET }} --print | jq -cr '.target."${{ env.DOCKER_BAKE_TARGET }}".tags')" >>${GITHUB_OUTPUT}

- name: Create manifest list and push
working-directory: ${{ runner.temp }}/digests
env:
DOCKER_IMAGETOOLS_ARGS: ${{ github.event_name == 'pull_request' && '--dry-run' || '' }}
run: |
docker buildx imagetools create ${{ env.DOCKER_IMAGETOOLS_ARGS}} $(echo '${{ steps.bake-metadata.outputs.tags }}' | jq -cr 'map(select(startswith("${{ env.REGISTRY_IMAGE }}")) | "-t " + .) | join(" ")') \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)

- name: Inspect image
if: ${{ github.event_name != 'pull_request' }}
run: |
docker buildx imagetools inspect $(echo '${{ steps.bake-metadata.outputs.tags }}' | jq -cr '.[0]')
36 changes: 35 additions & 1 deletion base.Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# syntax=docker/dockerfile:1
# check=error=true

FROM dunglas/frankenphp:1.11-php8.4
ARG PHP_VERSION=8.5

FROM dunglas/frankenphp:php${PHP_VERSION} AS base

WORKDIR /var/www/symfony

Expand All @@ -28,4 +30,36 @@ ENTRYPOINT ["docker-entrypoint"]

HEALTHCHECK --start-period=60s CMD curl -f http://localhost:2019/metrics || exit 1

FROM base AS dev

ENV APP_ENV=dev
ENV CADDY_FRANKENPHP_WORKER_CONFIG=watch
ENV XDEBUG_MODE=off

USER root

RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

RUN set -eux; install-php-extensions xdebug

USER php

COPY --link conf.d/20-app.dev.ini $PHP_INI_DIR/app.conf.d/
COPY --link --chmod=755 docker-entrypoint-dev.sh /usr/local/bin/docker-entrypoint

CMD [ "frankenphp", "run", "--watch" ]

FROM base AS prod

ENV APP_ENV=prod

USER root

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

USER php

COPY --link conf.d/20-app.prod.ini $PHP_INI_DIR/app.conf.d/
COPY --link --chmod=755 docker-entrypoint-prod.sh /usr/local/bin/docker-entrypoint

CMD [ "frankenphp", "run" ]
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
build:
docker buildx bake --pull
docker buildx bake --pull --set '*.platform=linux/amd64' 'frankenphp-*'

build-all:
build-arm:
docker run --privileged --rm tonistiigi/binfmt --install all
docker buildx bake --pull image-all
docker buildx bake --pull --set '*.platform=linux/arm64' 'frankenphp-*'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Pre-configured Docker image that follows [Le Phare](https://www.lephare.com) pro
| Version | Supported until |
|---------|-----------------|
| 8.4 | 31 Dec. 2028 |
| 8.5 | 31 Dec. 2029 |

## Environment variables

Expand Down
23 changes: 0 additions & 23 deletions dev.Dockerfile

This file was deleted.

80 changes: 34 additions & 46 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -1,77 +1,65 @@
variable "PHP_VERSION" {
default = "8.4"
}

variable "REPO" {
variable "IMAGE_NAME" {
default = "lephare/frankenphp"
}

// Special target: https://github.com/docker/metadata-action#bake-definition
target "docker-metadata-action" {}

group "default" {
targets = ["dev-local", "prod-local"]
variable "PHP_LATEST_VERSION" {
default = "8.5"
}

group "image-all" {
targets = ["dev-all", "prod-all"]
// Special target: https://github.com/docker/metadata-action#bake-definition
target "docker-metadata-action" {
platforms = [
"linux/amd64",
"linux/arm64"
]
}

target "base" {
inherits = ["docker-metadata-action"]
args = {
PHP_EXTENSIONS = "@composer apcu exif gd imagick intl memcached opcache pdo_mysql pdo_pgsql pgsql soap zip"
}
dockerfile = "base.Dockerfile"
target = "base"
}

target "dev" {
target "frankenphp-8-4" {
inherits = ["docker-metadata-action"]
name = "frankenphp-8-4-${tgt}"
matrix = {
tgt = ["dev", "prod"]
}
args = {
PHP_EXTENSIONS = "xdebug"
PHP_EXTENSIONS = tgt == "dev" ? "xdebug" : null,
}
contexts = {
base = "target:base"
}
dockerfile = "dev.Dockerfile"
tags = [
"${REPO}:${PHP_VERSION}-dev",
"${REPO}:dev",
"${IMAGE_NAME}:8.4-${tgt}",
tgt == "prod" ? "${IMAGE_NAME}:8.4" : "",
]
target = tgt
}

target "dev-local" {
inherits = ["dev"]
output = ["type=docker"]
}

target "dev-all" {
inherits = ["dev"]
platforms = [
"linux/amd64",
"linux/arm64"
]
}

target "prod" {
target "frankenphp-8-5" {
inherits = ["docker-metadata-action"]
name = "frankenphp-8-5-${tgt}"
matrix = {
tgt = ["dev", "prod"]
}
args = {
PHP_EXTENSIONS = tgt == "dev" ? "xdebug" : null,
}
contexts = {
base = "target:base"
}
dockerfile = "prod.Dockerfile"
tags = [
"${REPO}:${PHP_VERSION}-prod",
"${REPO}:prod",
"${REPO}:${PHP_VERSION}",
"${REPO}:latest",
"${IMAGE_NAME}:8.5-${tgt}",
tgt == "prod" ? "${IMAGE_NAME}:8.5" : "",
"${IMAGE_NAME}:8-${tgt}",
tgt == "prod" ? "${IMAGE_NAME}:8" : "",
"${IMAGE_NAME}:${tgt}",
tgt == "prod" ? "${IMAGE_NAME}:latest" : "",
]
}

target "prod-local" {
inherits = ["prod"]
output = ["type=docker"]
}

target "prod-all" {
inherits = ["prod"]
target = tgt
}
15 changes: 0 additions & 15 deletions prod.Dockerfile

This file was deleted.