Skip to content

Commit 466c578

Browse files
author
Luke
committed
initial commit
0 parents  commit 466c578

File tree

5 files changed

+135
-0
lines changed

5 files changed

+135
-0
lines changed

.github/workflows/build-image.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Builds the specified image using the Dockerfile, targeting the provided `docker_target`. This image is then published in GitHub Container Registry.
2+
name: Build docker image
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
docker_target:
8+
required: true
9+
type: string
10+
description: The target in the Dockerfile that should be built. Either "dev" or "main".
11+
php_version:
12+
required: true
13+
type: string
14+
description: The PHP version contained within the image, used for tagging the image.
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
steps:
20+
# Checkout a copy of the Dockerfile from the repository from the tag associated with the release that triggered
21+
# this workflow.
22+
- name: Check out repository code
23+
uses: actions/checkout@v3
24+
with:
25+
ref: ${{ github.event.release.tag_name }}
26+
27+
# Login to the GitHub Container Registry.
28+
- name: Login to GitHub Container Registry
29+
uses: docker/login-action@v2
30+
with:
31+
registry: ghcr.io
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
35+
# Configure buildx as our preferred builder.
36+
- name: Setup docker buildx
37+
uses: docker/setup-buildx-action@v2
38+
id: buildx
39+
with:
40+
install: true
41+
42+
# Generate the tags that should accompany the image.
43+
# For the dev image, this is expected to be `dev-latest` and `dev-[PHP_VERSION]-latest`, and `dev-[PHP_VERSION]-[SCHEDULE].
44+
- name: Generate tags
45+
id: meta
46+
uses: docker/metadata-action@v4
47+
with:
48+
images: ghcr.io/bluewing/php-docker-image
49+
flavor: |
50+
latest=true
51+
prefix=${{ inputs.docker_target }}-,onlatest=true
52+
tags: |
53+
type=raw,value=${{ inputs.php_version }}-latest
54+
type=raw,value=${{ inputs.php_version }}-{{ date 'YYYYMMDD' }}
55+
56+
# Build the docker image and publish it to GCR.
57+
- name: Build and push
58+
uses: docker/build-push-action@v3
59+
with:
60+
context: .
61+
target: ${{ inputs.docker_target }}
62+
push: true
63+
tags: ${{ steps.meta.outputs.tags }}
64+
labels: ${{ steps.meta.outputs.labels }}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# When a GitHub release event occurs, build both the development and production images contained within the `Dockerfile` using the `build-image.yaml` reusable workflow. Both images will then be published to GitHub Container Registry so they can be used as part of Bluewing application images.
2+
# This workflow run can take up to 20 minutes or more because the PHP extensions needed must be built from source.
3+
name: Build images on release
4+
5+
on:
6+
release:
7+
types: [released]
8+
9+
jobs:
10+
build-images:
11+
strategy:
12+
matrix:
13+
docker_target: [dev, main]
14+
php_version: [8.1.4]
15+
uses: ./.github/workflows/build-image.yaml
16+
with:
17+
docker_target: ${{ matrix.docker_target }}
18+
php_version: ${{ matrix.php_version }}
19+
secrets: inherit

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea/

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# syntax = docker/dockerfile:1.2
2+
3+
# This `Dockerfile` has two possible build outputs: `dev` and `main`.
4+
5+
FROM php:8.1.4-fpm-alpine3.15 as base
6+
LABEL maintainer="lukedavia@icloud.com"
7+
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
8+
9+
10+
FROM base as main
11+
RUN install-php-extensions pdo_pgsql redis-5.3.7;
12+
13+
FROM main as dev
14+
RUN install-php-extensions xdebug-3.1.5;

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# `php-docker-image`
2+
3+
This repository contains a general-purpose base PHP docker image for use in Bluewing applications that combines the lightweight base image of Alpine Linux with the speed-wins normally gained through using Debian.
4+
5+
## Rationale
6+
7+
Alpine Linux PHP docker images are typically 6× smaller in size or more, which makes them an excellent choice due to their lightweight footprint. They do however come with the disadvantage that [they ship with musl libc instead of glib and friends](https://hub.docker.com/_/php). This means that the PHP extensions we need as part of our application stack must be compiled from source, installed of installed from a precompiled binary, which significantly slows the build time—up to 800 seconds or more to build a base image with the dependencies we need.
8+
9+
We have extracted these long build times to an infrequently-modified Docker image that can be built once in CI and pulled as much as necessary.
10+
11+
## Available tags
12+
13+
Two image variants are available, a primary image that requires in `pdo_pgsql` and `phpredis` so we can use a development image tagged `dev` which additionally includes `xdebug`.
14+
15+
| Tag | PHP version | Alpine Version | Extensions | Build size |
16+
|---------------------|-------------|----------------|-------------------------------------------|------------|
17+
| `dev-8.1.4-latest` | 8.1.4 | 3.15 | `pdo_pgsql`,`redis-5.3.7`, `xdebug-3.1.5` | |
18+
| `main-8.1.4-latest` | 8.1.4 | 3.15 | `pdo_pgsql`, `redis-5.3.7`, | |
19+
20+
Each flavour of image is tagged three times, making it possible to select images based purely on the latest version, the latest version of a specific PHP release, or a specific image entirely:
21+
22+
* `FLAVOR-latest`
23+
* `FLAVOR-PHP_VERSION-latest`
24+
* `FLAVOR-PHP_VERSION-DATE`
25+
26+
PHP extensions are installed using the [thecodingmachine/docker-images-php](https://github.com/thecodingmachine/docker-images-php) Docker image.
27+
28+
## Building
29+
30+
Each image is built when a release occurs, using GitHub Actions, and published to GitHub Container Registry. To use these images in your `Dockerfile`, reference them as follows:
31+
32+
```Dockerfile
33+
# Development, includes xdebug along with other extensions.
34+
FROM ghcr.io/bluewing/php-docker-image:dev-latest
35+
# Production, only pdo_pgsql and redis
36+
FROM ghcr.io/bluewing/php-docker-image:main-latest
37+
```

0 commit comments

Comments
 (0)