Skip to content
This repository was archived by the owner on Sep 12, 2023. It is now read-only.

Commit 2608407

Browse files
authored
✨ Add multiple PHP versions, including version 8 (#9)
1 parent 0b91741 commit 2608407

File tree

6 files changed

+113
-69
lines changed

6 files changed

+113
-69
lines changed

.github/workflows/build.yml

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build Image
1+
name: Build Images For Commit
22

33
on:
44
push:
@@ -8,35 +8,39 @@ on:
88
jobs:
99
build:
1010
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
php: ['7', '7.4', '8', '8.0']
1114
steps:
12-
- uses: actions/checkout@v2
13-
- name: Login to GitHub Container Registry
14-
uses: docker/login-action@v1
15-
with:
16-
registry: ghcr.io
17-
username: ${{ github.repository_owner }}
18-
password: ${{ secrets.GHCR_PAT }}
19-
- uses: docker/setup-buildx-action@v1
20-
- name: Cache Docker layers
21-
uses: actions/cache@v2
22-
with:
23-
path: /tmp/.buildx-cache
24-
key: ${{ runner.os }}-buildx-${{ github.sha }}
25-
restore-keys: ${{ runner.os }}-buildx
26-
- id: push
27-
run: |
28-
echo ::set-output name=sha::sha-${GITHUB_SHA:0:7}
29-
echo ::set-output name=at::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
30-
- name: Build Image
31-
uses: docker/build-push-action@v2
32-
with:
33-
cache-from: type=local,src=/tmp/.buildx-cache
34-
cache-to: type=local,dest=/tmp/.buildx-cache
35-
push: true
36-
tags: ghcr.io/${{ github.repository }}:${{ steps.push.outputs.sha }}
37-
labels: |
38-
org.opencontainers.image.title=${{ github.repository }}
39-
org.opencontainers.image.url=${{ github.event.repository.html_url }}
40-
org.opencontainers.image.source=${{ github.event.repository.html_url }}
41-
org.opencontainers.image.created=${{ steps.push.outputs.at }}
42-
org.opencontainers.image.revision=${{ steps.push.outputs.sha }}
15+
- uses: actions/checkout@v2
16+
- name: Login to GitHub Container Registry
17+
uses: docker/login-action@v1
18+
with:
19+
registry: ghcr.io
20+
username: ${{ github.repository_owner }}
21+
password: ${{ secrets.GHCR_PAT }}
22+
- uses: docker/setup-buildx-action@v1
23+
- name: Cache Docker layers
24+
uses: actions/cache@v2
25+
with:
26+
path: /tmp/.buildx-cache
27+
key: ${{ runner.os }}-${{ matrix.php }}-buildx-${{ github.sha }}
28+
restore-keys: ${{ runner.os }}-${{ matrix.php }}-buildx
29+
- id: push
30+
run: |
31+
echo ::set-output name=sha::sha-${GITHUB_SHA:0:7}-${{ matrix.php }}
32+
echo ::set-output name=at::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
33+
- name: Build Image
34+
uses: docker/build-push-action@v2
35+
with:
36+
cache-from: type=local,src=/tmp/.buildx-cache
37+
cache-to: type=local,dest=/tmp/.buildx-cache
38+
build-args: PHP=${{ matrix.php }}
39+
push: true
40+
tags: ghcr.io/${{ github.repository }}:${{ steps.push.outputs.sha }}
41+
labels: |
42+
org.opencontainers.image.title=${{ github.repository }}
43+
org.opencontainers.image.url=${{ github.event.repository.html_url }}
44+
org.opencontainers.image.source=${{ github.event.repository.html_url }}
45+
org.opencontainers.image.created=${{ steps.push.outputs.at }}
46+
org.opencontainers.image.revision=${{ steps.push.outputs.sha }}

.github/workflows/release.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Tag Released Images
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
php: ['7', '7.4', '8', '8.0']
13+
steps:
14+
- id: push
15+
run: echo ::set-output name=sha::sha-${GITHUB_SHA:0:7}-${{ matrix.php }}
16+
- name: Publish Tag
17+
uses: shrink/actions-docker-registry-tag@v1
18+
with:
19+
registry: ghcr.io
20+
token: ${{ secrets.GHCR_PAT }}
21+
repository: ${{ github.repository }}
22+
target: ${{ steps.push.outputs.sha }}
23+
tags: ${{ matrix.php }}

.github/workflows/tag.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
FROM php:7.4.10-fpm-alpine3.12
1+
ARG PHP=8.0
2+
ARG ALPINE=3.12
3+
4+
FROM php:${PHP}-fpm-alpine${ALPINE}
25

36
LABEL Maintainer="Samuel Ryan <sam@samryan.co.uk>"
47

5-
RUN apk --no-cache add fcgi busybox nginx tini
8+
ARG NGINX=~1.18
9+
RUN apk --no-cache add fcgi busybox nginx=$NGINX tini
610

711
COPY config/nginx.conf /etc/nginx/nginx.conf
812
COPY config/fastcgi.conf /etc/nginx/fastcgi.conf
@@ -20,5 +24,5 @@ COPY ./entrypoint.sh /
2024

2125
ENTRYPOINT ["/sbin/tini", "--", "/entrypoint.sh"]
2226

23-
HEALTHCHECK --interval=2s --timeout=1s --retries=3 \
27+
HEALTHCHECK --interval=10s --timeout=1s --retries=3 \
2428
CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:8080/.container/status || exit 1

README.md

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,60 @@
22

33
Docker Image for PHP API applications.
44

5-
**Alpine** [`3.12`][alpine-3.12] + **nginx** [`1.18.0`][nginx-1.18.0] +
6-
**PHP** [`7.4.10`][php-7.4.10]
5+
**Alpine** [`3.12`][alpine-3.12] + **nginx** [`1.18`][nginx-1.18] +
6+
**PHP** [`8.0`][php-8.0]
77

88
```dockerfile
9-
FROM ghcr.io/shrink/docker-php-api:7.4
9+
FROM ghcr.io/shrink/docker-php-api:8
1010
```
1111

1212
* **All** requests are routed to `public/index.php`
1313
* `xml` and `json` responses are gzipped
1414
* nginx runs on port `8080`
1515
* PHP-FPM status is exposed via `/.container/status` and `/.container/ping`
16-
* "Optimized" PHP-FPM configuration based on
17-
[TrafeX/docker-php-nginx][TrafeX/docker-php-nginx]
16+
* Available for [PHP 7 &darr;](#php-versions)
17+
18+
See an example usage in
19+
[Laravel Strict `shrink/laravel-strict`][shrink/laravel-strict].
20+
21+
## Immutability by Digest Pinning
22+
23+
Docker tags are **mutable** and could change the image represented at any time:
24+
in this project the version tag represents the PHP version included in the
25+
image, it **does not** represent an immutable version of the image itself. PHP
26+
version tags should be considered a discoverability aide, not an immutable image
27+
reference.
28+
29+
Most production use-cases are best served by
30+
[Digest Pinning][docker-digest-pinning] which uses the **immutable** image
31+
digest to guarantee reproducibility, e.g:
32+
33+
```dockerfile
34+
FROM ghcr.io/shrink/docker-php-api@sha256:637a6ff82d27001b8137e807f6da49d2a8c6d1e234e757945454069ebdec0720
35+
```
36+
37+
## PHP Versions
38+
39+
All [Supported Versions of PHP][php/supported-versions] are tagged with the
40+
major and minor version (e.g: `7` and `7.4`).
41+
42+
```dockerfile
43+
FROM ghcr.io/shrink/docker-php-api:7
44+
```
45+
46+
A full list of available image versions can be found in
47+
the [GitHub Container Registry][ghcr/shrink/docker-php-api].
48+
49+
## Credits
50+
51+
Optimized PHP-FPM configuration based on
52+
[TrafeX/docker-php-nginx][TrafeX/docker-php-nginx].
1853

1954
[TrafeX/docker-php-nginx]: https://github.com/TrafeX/docker-php-nginx
2055
[alpine-3.12]: https://alpinelinux.org/posts/Alpine-3.12.0-released.html
21-
[nginx-1.18.0]: http://nginx.org/en/CHANGES-1.18
22-
[php-7.4.10]: https://www.php.net/ChangeLog-7.php#7.4.10
56+
[nginx-1.18]: http://nginx.org/en/CHANGES-1.18
57+
[php-8.0]: https://www.php.net/ChangeLog-8.php#PHP_8_0
58+
[shrink/laravel-strict]: https://github.com/shrink/laravel-strict
59+
[docker-digest-pinning]: https://docs.docker.com/engine/reference/commandline/pull/#pull-an-image-by-digest-immutable-identifier
60+
[ghcr/shrink/docker-php-api]: https://github.com/users/shrink/packages/container/package/docker-php-api
61+
[php/supported-versions]: https://www.php.net/supported-versions.php

config/nginx.conf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
worker_processes auto;
12
error_log stderr warn;
23
pid /run/nginx.pid;
34

4-
events {}
5-
65
http {
76
error_log /dev/stderr notice;
87
access_log /dev/stdout;

0 commit comments

Comments
 (0)