Skip to content

Commit

Permalink
Merge pull request #32 from shyim/add-fpm-base-image
Browse files Browse the repository at this point in the history
feat: add nginx base image
  • Loading branch information
shyim authored Apr 7, 2024
2 parents 3e8b4a5 + e4b6bc8 commit 328897a
Show file tree
Hide file tree
Showing 13 changed files with 158 additions and 30 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,39 @@ jobs:

- name: Sign image
run: cosign sign --yes ghcr.io/shyim/wolfi-php/fpm:${{ matrix.php }}

nginx:
runs-on: ubuntu-latest
needs: fpm
strategy:
matrix:
php:
- 8.2
- 8.3
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Cosign
uses: sigstore/cosign-installer@v3

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

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

- name: Login into Github Docker Registery
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- uses: docker/build-push-action@v5
with:
tags: ghcr.io/shyim/wolfi-php/nginx:${{ matrix.php }}
platforms: linux/amd64,linux/arm64
context: images/nginx
build-args: PHP_VERSION=${{ matrix.php }}
push: true
provenance: false

- name: Sign image
run: cosign sign --yes ghcr.io/shyim/wolfi-php/nginx:${{ matrix.php }}
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ To learn more about FrankenPHP, [see here](./images/frankenphp)
We provide also base image for ready to start without touching configuration:

- [FrankenPHP](./images/frankenphp)
- [FPM](./images/fpm)
- [Nginx + PHP-FPM](./images/nginx)
- [FPM standalone](./images/fpm)

### Pinning package versions

Expand All @@ -119,6 +120,6 @@ To get the excact current version of a package, you can run `apk info php-8.2`.

## Examples

- [Symfony Demo with FrankenPHP](examples/frankenphp-symfony-demo/README.md)
- [Symfony demo with FPM](examples/fpm-symfony-demo/README.md)
- [Nginx + PHP-FPM](examples/nginx-php-fpm/README.md)
- [Symfony Demo with FrankenPHP](examples/frankenphp-symfony-demo/)
- [Symfony Demo with FPM](examples/fpm-symfony-demo/)
- [Symfony Demo with Nginx](examples/nginx-symfony-demo/)
18 changes: 0 additions & 18 deletions examples/nginx-php-fpm/Dockerfile

This file was deleted.

5 changes: 0 additions & 5 deletions examples/nginx-php-fpm/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions examples/nginx-php-fpm/rootfs/etc/php/php-fpm.d/zz-user.conf

This file was deleted.

38 changes: 38 additions & 0 deletions examples/nginx-symfony-demo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# runtime dependencies
FROM ghcr.io/shyim/wolfi-php/nginx:8.2 as base
ENV APP_ENV=prod

RUN apk add --no-cache \
php-8.2-intl \
php-8.2-simplexml \
php-8.2-iconv \
php-8.2-dom \
php-8.2-xml \
php-8.2-simplexml \
php-8.2-pdo \
php-8.2-pdo_sqlite

# download symfony demo and build it
FROM base as composer

RUN apk add --no-cache \
git \
composer \
unzip \
php-8.2 \
php-8.2-curl \
php-8.2-openssl \
php-8.2-phar

WORKDIR /app
RUN git clone https://github.com/symfony/demo.git --depth=1 .
RUN composer install
RUN bin/console asset-map:compile
RUN rm -rf .git

# build final image

FROM base

# uid 82 is www-data
COPY --from=composer --chown=82 /app /var/www/html
12 changes: 12 additions & 0 deletions examples/nginx-symfony-demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Symfony Demo with Nginx

This is a Dockerfile to set up a Symfony Demo application with Nginx.

This example is using this [Nginx image](../../images/nginx/).

```bash
docker build -t symfony-demo .
docker run -p 8000:8000 symfony-demo
```

and then open http://localhost:8000 in your browser.
2 changes: 2 additions & 0 deletions images/fpm/rootfs/etc/php/php-fpm.d/zz-b-default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
user = ${PHP_FPM_USER}
group = ${PHP_FPM_GROUP}
listen = ${PHP_FPM_LISTEN}
listen.owner = ${PHP_FPM_USER}
listen.group = ${PHP_FPM_GROUP}
pm = ${PHP_FPM_PM}
pm.max_children = ${PHP_FPM_PM_MAX_CHILDREN}
pm.start_servers = ${PHP_FPM_PM_START_SERVERS}
Expand Down
16 changes: 16 additions & 0 deletions images/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ARG PHP_VERSION=8.3
FROM ghcr.io/shyim/wolfi-php/fpm:${PHP_VERSION}

ENV PHP_FPM_LISTEN=/tmp/php-fpm.sock

RUN <<EOF
set -eo pipefail
apk add --no-cache \
overmind \
nginx
EOF

COPY --link rootfs /
EXPOSE 8000

ENTRYPOINT ["/usr/bin/overmind", "start", "-f", "/etc/Procfile", "-s", "/tmp/overmind.sock"]
44 changes: 44 additions & 0 deletions images/nginx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Nginx + PHP-FPM

This image contains Nginx and PHP-FPM in the same container. To run both processes in the same container, we use overmind a Procfile compatible process manager.

## Usage

```dockerfile
FROM ghcr.io/shyim/wolfi-php/fpm:8.3

# Install missing extensions
RUN apk add --no-cache php-8.3-redis php-8.3-gd

# Copy your files
COPY . /var/www/html
```

```shell
docker build -t my-image .
docker run -p 8080:8080 my-image
```

You can run it for testing purposes also directly, `docker run --rm -p 8080:8080 ghcr.io/shyim/wolfi-php/fpm:8.3` and you should see at `http://localhost:8000` the php info page.

## PHP Extensions / PHP Configuration

As this image bases on [fpm](../fpm/), you can check out there how to configure PHP / PHP-FPM and install php extensions.

## Overwrite Nginx Configuration

You can overwrite the Nginx configuration by copying your own configuration to `/etc/nginx/nginx.conf`:

```dockerfile
COPY nginx.conf /etc/nginx/nginx.conf
```

You can find the default configuration [here](./rootfs/etc/nginx/nginx.conf).

## Running rootless

You can run the container as a non-root user. The image has a user `www-data` with UID 82. You can use it like this:

```dockerfile
USER www-data
```
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
worker_processes auto;
pid /tmp/nginx.pid;
daemon off;
user www-data;

events {
worker_connections 1024;
Expand All @@ -22,6 +23,10 @@ http {
index index.php;
include /etc/nginx/mime.types;

location / {
try_files $uri /index.php$is_args$args;
}

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi.conf;
Expand Down

0 comments on commit 328897a

Please sign in to comment.