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

Commit

Permalink
✨ Add multiple PHP versions, including version 8 (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
shrink authored Dec 22, 2020
1 parent 0b91741 commit 2608407
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 69 deletions.
68 changes: 36 additions & 32 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Image
name: Build Images For Commit

on:
push:
Expand All @@ -8,35 +8,39 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7', '7.4', '8', '8.0']
steps:
- uses: actions/checkout@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_PAT }}
- uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: ${{ runner.os }}-buildx
- id: push
run: |
echo ::set-output name=sha::sha-${GITHUB_SHA:0:7}
echo ::set-output name=at::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Build Image
uses: docker/build-push-action@v2
with:
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
push: true
tags: ghcr.io/${{ github.repository }}:${{ steps.push.outputs.sha }}
labels: |
org.opencontainers.image.title=${{ github.repository }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ steps.push.outputs.at }}
org.opencontainers.image.revision=${{ steps.push.outputs.sha }}
- uses: actions/checkout@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_PAT }}
- uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-${{ matrix.php }}-buildx-${{ github.sha }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-buildx
- id: push
run: |
echo ::set-output name=sha::sha-${GITHUB_SHA:0:7}-${{ matrix.php }}
echo ::set-output name=at::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Build Image
uses: docker/build-push-action@v2
with:
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
build-args: PHP=${{ matrix.php }}
push: true
tags: ghcr.io/${{ github.repository }}:${{ steps.push.outputs.sha }}
labels: |
org.opencontainers.image.title=${{ github.repository }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ steps.push.outputs.at }}
org.opencontainers.image.revision=${{ steps.push.outputs.sha }}
23 changes: 23 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Tag Released Images

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7', '7.4', '8', '8.0']
steps:
- id: push
run: echo ::set-output name=sha::sha-${GITHUB_SHA:0:7}-${{ matrix.php }}
- name: Publish Tag
uses: shrink/actions-docker-registry-tag@v1
with:
registry: ghcr.io
token: ${{ secrets.GHCR_PAT }}
repository: ${{ github.repository }}
target: ${{ steps.push.outputs.sha }}
tags: ${{ matrix.php }}
25 changes: 0 additions & 25 deletions .github/workflows/tag.yml

This file was deleted.

10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
FROM php:7.4.10-fpm-alpine3.12
ARG PHP=8.0
ARG ALPINE=3.12

FROM php:${PHP}-fpm-alpine${ALPINE}

LABEL Maintainer="Samuel Ryan <[email protected]>"

RUN apk --no-cache add fcgi busybox nginx tini
ARG NGINX=~1.18
RUN apk --no-cache add fcgi busybox nginx=$NGINX tini

COPY config/nginx.conf /etc/nginx/nginx.conf
COPY config/fastcgi.conf /etc/nginx/fastcgi.conf
Expand All @@ -20,5 +24,5 @@ COPY ./entrypoint.sh /

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

HEALTHCHECK --interval=2s --timeout=1s --retries=3 \
HEALTHCHECK --interval=10s --timeout=1s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:8080/.container/status || exit 1
53 changes: 46 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,60 @@

Docker Image for PHP API applications.

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

```dockerfile
FROM ghcr.io/shrink/docker-php-api:7.4
FROM ghcr.io/shrink/docker-php-api:8
```

* **All** requests are routed to `public/index.php`
* `xml` and `json` responses are gzipped
* nginx runs on port `8080`
* PHP-FPM status is exposed via `/.container/status` and `/.container/ping`
* "Optimized" PHP-FPM configuration based on
[TrafeX/docker-php-nginx][TrafeX/docker-php-nginx]
* Available for [PHP 7 &darr;](#php-versions)

See an example usage in
[Laravel Strict `shrink/laravel-strict`][shrink/laravel-strict].

## Immutability by Digest Pinning

Docker tags are **mutable** and could change the image represented at any time:
in this project the version tag represents the PHP version included in the
image, it **does not** represent an immutable version of the image itself. PHP
version tags should be considered a discoverability aide, not an immutable image
reference.

Most production use-cases are best served by
[Digest Pinning][docker-digest-pinning] which uses the **immutable** image
digest to guarantee reproducibility, e.g:

```dockerfile
FROM ghcr.io/shrink/docker-php-api@sha256:637a6ff82d27001b8137e807f6da49d2a8c6d1e234e757945454069ebdec0720
```

## PHP Versions

All [Supported Versions of PHP][php/supported-versions] are tagged with the
major and minor version (e.g: `7` and `7.4`).

```dockerfile
FROM ghcr.io/shrink/docker-php-api:7
```

A full list of available image versions can be found in
the [GitHub Container Registry][ghcr/shrink/docker-php-api].

## Credits

Optimized PHP-FPM configuration based on
[TrafeX/docker-php-nginx][TrafeX/docker-php-nginx].

[TrafeX/docker-php-nginx]: https://github.com/TrafeX/docker-php-nginx
[alpine-3.12]: https://alpinelinux.org/posts/Alpine-3.12.0-released.html
[nginx-1.18.0]: http://nginx.org/en/CHANGES-1.18
[php-7.4.10]: https://www.php.net/ChangeLog-7.php#7.4.10
[nginx-1.18]: http://nginx.org/en/CHANGES-1.18
[php-8.0]: https://www.php.net/ChangeLog-8.php#PHP_8_0
[shrink/laravel-strict]: https://github.com/shrink/laravel-strict
[docker-digest-pinning]: https://docs.docker.com/engine/reference/commandline/pull/#pull-an-image-by-digest-immutable-identifier
[ghcr/shrink/docker-php-api]: https://github.com/users/shrink/packages/container/package/docker-php-api
[php/supported-versions]: https://www.php.net/supported-versions.php
3 changes: 1 addition & 2 deletions config/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
worker_processes auto;
error_log stderr warn;
pid /run/nginx.pid;

events {}

http {
error_log /dev/stderr notice;
access_log /dev/stdout;
Expand Down

0 comments on commit 2608407

Please sign in to comment.