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
47 changes: 34 additions & 13 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
name: CI/CD

on: [push, workflow_dispatch]
on:
push:
branches: [master]
pull_request:
workflow_dispatch:
schedule:
- cron: '23 5 * * 1'

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
version: [php, proxy, static]

Expand All @@ -16,32 +26,43 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4.2.0

- name: Cache Docker layers
uses: actions/cache@v6.1.0
with:
path: /tmp/.buildx-cache
key: docker-buildx-${{ matrix.version }}-${{ github.sha }}
restore-keys: docker-buildx-${{ matrix.version }}-

- name: Build
run: |
docker buildx build \
--cache-from type=local,src=/tmp/.buildx-cache/${{ matrix.version }} \
--cache-to type=local,dest=/tmp/.buildx-cache/${{ matrix.version }} \
--pull --no-cache \
--platform linux/amd64 \
--output type=docker \
--tag kooldev/nginx:${{ matrix.version }} \
${{ matrix.version }}

- name: Tests
run: docker run kooldev/nginx:${{ matrix.version }} nginx -v
run: bash tests/smoke.sh "${{ matrix.version }}" "kooldev/nginx:${{ matrix.version }}"

- name: Scan image
uses: anchore/scan-action@8576240a41341d866dbd7ebc72cd9fc0ef023f54 # v7.4.2
with:
image: kooldev/nginx:${{ matrix.version }}
grype-version: v0.121.3
severity-cutoff: high
only-fixed: false
output-format: json
output-file: grype-${{ matrix.version }}.json

- name: Retain vulnerability report
if: always()
uses: actions/upload-artifact@v7.0.2
with:
name: grype-${{ matrix.version }}
path: grype-${{ matrix.version }}.json
if-no-files-found: warn

- name: Login to DockerHub
uses: docker/login-action@v4.4.0
if: github.ref == 'refs/heads/master' && github.repository == 'kool-dev/docker-nginx'
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master' && github.repository == 'kool-dev/docker-nginx'
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Push to DockerHub
if: github.ref == 'refs/heads/master' && github.repository == 'kool-dev/docker-nginx'
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master' && github.repository == 'kool-dev/docker-nginx'
run: docker push kooldev/nginx:${{ matrix.version }}
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,31 @@ app:

## Contributing

### Image checks

CI builds all three variants for **linux/amd64**. ARM is not supported by the
bundled dockerize binary. Weekly Monday rebuilds pull the latest `nginx:alpine`
and refresh Alpine packages without reusing build layers.

Run the same configuration and HTTP checks locally after building an image:

```sh
docker build --pull --no-cache -t nginx-test:php php
bash tests/smoke.sh php nginx-test:php
```

Repeat for `static` and `proxy`. Tests require Docker and curl, publish only a
random loopback port, and remove their containers/network afterward. PHP uses a
real PHP-FPM fixture; proxy uses a Docker DNS upstream. Tests check default and
overridden config, invalid config rejection, static assets, routing/query
handling, denied `.ht` files and request body limits.

Before publication, Grype blocks high/critical findings (including unfixed ones).
Full JSON reports, including lower severities, are retained as workflow artifacts.
There are no vulnerability exclusions. Scan failures require investigation and
an image/package fix, not disabling the gate. A successful scan is not proof
that an image is vulnerability-free.

### Dependencies

You should change `fwd-template.json` and `template` folder.
Expand Down
3 changes: 3 additions & 0 deletions php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM nginx:alpine

# Refresh security fixes that have not yet reached the upstream image.
RUN apk upgrade --no-cache

ARG DOCKERIZE_VERSION=v0.6.1
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
Expand Down
3 changes: 3 additions & 0 deletions proxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM nginx:alpine

# Refresh security fixes that have not yet reached the upstream image.
RUN apk upgrade --no-cache

ARG DOCKERIZE_VERSION=v0.6.1
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
Expand Down
3 changes: 3 additions & 0 deletions static/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM nginx:alpine

# Refresh security fixes that have not yet reached the upstream image.
RUN apk upgrade --no-cache

ARG DOCKERIZE_VERSION=v0.6.1
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
Expand Down
3 changes: 3 additions & 0 deletions template/Dockerfile.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM nginx:alpine

# Refresh security fixes that have not yet reached the upstream image.
RUN apk upgrade --no-cache

ARG DOCKERIZE_VERSION=v0.6.1
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/.htpasswd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
must not be served
1 change: 1 addition & 0 deletions tests/fixtures/asset.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kool asset fixture
3 changes: 3 additions & 0 deletions tests/fixtures/front.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
header('Content-Type: text/plain');
echo 'kool php fixture|' . $_GET['value'] . '|' . $_SERVER['SCRIPT_FILENAME'];
1 change: 1 addition & 0 deletions tests/fixtures/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kool static fixture
95 changes: 95 additions & 0 deletions tests/smoke.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env bash
set -euo pipefail

variant=${1:?Usage: smoke.sh php|proxy|static IMAGE}
image=${2:?Usage: smoke.sh php|proxy|static IMAGE}
case "$variant" in php|proxy|static) ;; *) exit 2 ;; esac
fixtures=$(cd "$(dirname "$0")/fixtures" && pwd)
name="kool-nginx-test-${variant}-$$"
backend="${name}-backend"
network="${name}-network"
tmp=$(mktemp -d)

cleanup() {
status=$?
if (( status != 0 )); then
docker logs "$name" 2>/dev/null || true
docker logs "$backend" 2>/dev/null || true
fi
docker rm -f "$name" "$backend" >/dev/null 2>&1 || true
docker network rm "$network" >/dev/null 2>&1 || true
rm -rf "$tmp"
exit "$status"
}
trap cleanup EXIT

docker network create "$network" >/dev/null
if [[ $variant == php ]]; then
docker run -d --pull always --name "$backend" --network "$network" --network-alias app \
-v "$fixtures:/srv/site:ro" php:8.4-fpm-alpine >/dev/null
elif [[ $variant == proxy ]]; then
docker run -d --pull always --name "$backend" --network "$network" --network-alias app \
-v "$fixtures:/usr/share/nginx/html:ro" nginx:alpine >/dev/null
fi

# Validate the default rendered configuration (PHP needs a resolvable upstream).
docker run --rm --network "$network" "$image" nginx -v
docker run --rm --network "$network" "$image" nginx -t

env_args=(-e LISTEN=8080 -e DOMAIN=example.test -e CLIENT_MAX_BODY_SIZE=1k)
if [[ $variant != proxy ]]; then
env_args+=(-e ROOT=/srv/site)
fi
if [[ $variant == php ]]; then
env_args+=(-e INDEX=front.php -e PHP_FPM=app:9000 -e FASTCGI_READ_TIMEOUT=10s
-e 'FASTCGI_BUFFERS=4 16k' -e FASTCGI_BUFFER_SIZE=16k)
fi
docker run --rm --network "$network" "${env_args[@]}" "$image" nginx -t

# Invalid configuration must fail, rather than accidentally testing nginx -v again.
if docker run --rm --network "$network" -e LISTEN=not-a-port "$image" nginx -t; then
echo "Invalid LISTEN unexpectedly accepted" >&2
exit 1
fi

docker run -d --name "$name" --network "$network" "${env_args[@]}" \
-p 127.0.0.1::8080 -v "$fixtures:/srv/site:ro" "$image" >/dev/null
port=$(docker port "$name" 8080/tcp | cut -d: -f2)
url="http://127.0.0.1:$port"
host=example.test
[[ $variant != proxy ]] || host=app.example.test
request() {
curl --silent --show-error --max-time 5 -H "Host: $host" "$@"
}
ready=false
for attempt in {1..30}; do
if request --fail "$url/asset.txt" >"$tmp/body"; then
ready=true
break
fi
echo "Waiting for $variant HTTP readiness ($attempt/30)"
sleep 1
done
[[ $ready == true ]]
grep -qx 'kool asset fixture' "$tmp/body"

case "$variant" in
php)
request --fail "$url/missing-route?value=query-ok" >"$tmp/body"
grep -qx 'kool php fixture|query-ok|/srv/site/front.php' "$tmp/body"
;;
static)
request --fail -D "$tmp/headers" "$url/missing-route" >"$tmp/body"
grep -qx 'kool static fixture' "$tmp/body"
grep -qi '^X-Served-By: kool.dev' "$tmp/headers"
;;
proxy)
request --fail "$url/" >"$tmp/body"
grep -qx 'kool static fixture' "$tmp/body"
[[ $(request -o /dev/null -w '%{http_code}' "$url/missing-route") == 404 ]]
;;
esac
[[ $(request -o /dev/null -w '%{http_code}' "$url/.htpasswd") == 403 ]]
head -c 2048 /dev/zero >"$tmp/large-body"
[[ $(request -o /dev/null -w '%{http_code}' --data-binary @"$tmp/large-body" "$url/") == 413 ]]
echo "$variant: configuration and HTTP tests passed"
Loading