-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dockerfile: updated bases to 4.0 (#78)
* Dockerfile: updated bases to 4.0 * Github actions: replace Hub build with multi-arch * Traivs: multi-arch, GH action CI * CI: separated out publish from PR action * CI: localhost port publishing networking * CI: working action and documentation * CI: work around mounted docker sockets * Review: tweaks * Dockerfile: consolidated woff fixes, ubuntu + cent * Dockerfile-centos: upgrading nginx, TLS 1.3 support * README: X64 warning * Woff: newline for @bossjones Co-authored-by: Bryan Latten <[email protected]>
- Loading branch information
1 parent
41248ef
commit 7f68f49
Showing
10 changed files
with
237 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
name: ci | ||
|
||
on: | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
props: | ||
- Dockerfile: Dockerfile | ||
- Dockerfile: Dockerfile-alpine | ||
- Dockerfile: Dockerfile-centos | ||
platform: | ||
- linux/amd64 | ||
- linux/arm64 | ||
env: | ||
TEST_MATCH: Welcome to nginx! | ||
steps: | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v2 | ||
- | ||
name: Detect host configuration | ||
run: | | ||
# NOTE: Docker host configuration determines the networking target for integration testing | ||
v=$(mount | grep "/run/docker.sock") | ||
TARGET_HOST= | ||
if [ -n "$v" ]; then | ||
echo "Injected docker socket detected" | ||
TARGET_HOST="host.docker.internal" | ||
elif [ -S /var/run/docker.sock ]; then | ||
TARGET_HOST="localhost" | ||
else | ||
echo "No Docker socket detected, fail" | ||
exit 1 | ||
fi | ||
echo "TARGET_HOST=${TARGET_HOST}" >> $GITHUB_ENV | ||
- | ||
# Build and execute in multiple configurations: vanilla, with env overrides, with TLS enabled | ||
name: Build and test | ||
run: | | ||
# NOTE: docker qemu and buildx setup actions create a black hole for build cache layers, avoid unless pushing externally | ||
# Setup multi-arch platforms, noop if already installed for builder | ||
docker run --privileged --rm tonistiigi/binfmt --install arm64,amd64 | ||
TARGET_PLATFORM=${{ matrix.platform }} | ||
TARGET_DOCKERFILE=${{ matrix.props.Dockerfile }} | ||
# Since containers may or may not be against the same docker engine, create a matrix-unique tag name for outputs | ||
TAG_NAME="docker-nginx-${TARGET_DOCKERFILE}-${TARGET_PLATFORM}" | ||
# Formats as lowercase | ||
TAG_NAME=$(echo $TAG_NAME | tr '[:upper:]' '[:lower:]') | ||
# Removes slashes | ||
TAG_NAME=$(echo $TAG_NAME | sed 's/\///') | ||
echo $TAG_NAME | ||
docker buildx build --platform $TARGET_PLATFORM --iidfile $TAG_NAME -t $TAG_NAME -f $TARGET_DOCKERFILE . | ||
# NOTE: multi-arch builds may not be accessible by docker tag, instead target by ID | ||
BUILD_SHA=$(cat ./$TAG_NAME) | ||
# Remove sha256: from tag identifier | ||
BUILD_SHA=$(echo $BUILD_SHA | sed 's/sha256\://') | ||
# Generate self-signed certificates | ||
mkdir -p certs | ||
openssl genrsa -out ./certs/ca.key 2048 | ||
openssl req -new -key ./certs/ca.key -out ./certs/ca.csr -subj '/CN=localhost' | ||
openssl x509 -req -days 365 -in ./certs/ca.csr -signkey ./certs/ca.key -out ./certs/ca.crt | ||
# Run various configurations of containers | ||
CONTAINER_VANILLA=$(docker run --platform $TARGET_PLATFORM --rm -p 8080 -d $BUILD_SHA) | ||
CONTAINER_ENV_FILE=$(docker run --platform $TARGET_PLATFORM --rm -p 8080 -d --env-file ./.test.env $BUILD_SHA) | ||
CONTAINER_HTTPS=$(docker run --platform $TARGET_PLATFORM --rm -p 8080 -d -e SERVER_ENABLE_HTTPS=true -v $(pwd)/certs:/etc/nginx/certs:ro $BUILD_SHA) | ||
# Retrieve dynamically-allocated host port | ||
VANILLA_PORT=$(docker inspect --format '{{ (index (index .NetworkSettings.Ports "8080/tcp") 0).HostPort }}' $CONTAINER_VANILLA) | ||
ENV_FILE_PORT=$(docker inspect --format '{{ (index (index .NetworkSettings.Ports "8080/tcp") 0).HostPort }}' $CONTAINER_ENV_FILE) | ||
HTTPS_PORT=$(docker inspect --format '{{ (index (index .NetworkSettings.Ports "8080/tcp") 0).HostPort }}' $CONTAINER_HTTPS) | ||
# Wait for containers to boot (in background) | ||
sleep 5 | ||
TARGET_HOST=${{ env.TARGET_HOST }} | ||
echo "HOSTING ${TARGET_HOST}" | ||
# Check for nginx test page response | ||
curl ${TARGET_HOST}:${VANILLA_PORT} | grep "${{ env.TEST_MATCH }}" | ||
curl ${TARGET_HOST}:${ENV_FILE_PORT} | grep "${{ env.TEST_MATCH }}" | ||
curl -k https://${TARGET_HOST}:${HTTPS_PORT} | grep "${{ env.TEST_MATCH }}" | ||
# Cleanup | ||
docker kill $CONTAINER_VANILLA | ||
docker kill $CONTAINER_ENV_FILE | ||
docker kill $CONTAINER_HTTPS | ||
docker rmi $BUILD_SHA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: publish | ||
|
||
on: | ||
push: | ||
tags: | ||
- '*' | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
env: | ||
IMAGE_BASE: behance/docker-nginx | ||
strategy: | ||
matrix: | ||
props: | ||
# This is the default variant-less distribution (ex. 3.2.1) | ||
- Dockerfile: Dockerfile | ||
# Variant distributions below all have semantic versions + suffix (ex. 3.2.1-alpine) | ||
- Dockerfile: Dockerfile-alpine | ||
suffix: alpine | ||
- Dockerfile: Dockerfile-centos | ||
suffix: centos | ||
steps: | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v2 | ||
- | ||
name: Add tag suffix | ||
if: matrix.props.suffix | ||
run: | | ||
echo TAG_SUFFIX="-${{ matrix.props.suffix }}" >> $GITHUB_ENV | ||
- | ||
name: Docker meta | ||
id: meta | ||
if: github.event_name != 'pull_request' | ||
uses: docker/metadata-action@v3 | ||
with: | ||
images: ${{ env.IMAGE_BASE }} | ||
tags: | | ||
type=semver,pattern={{major}}.{{minor}}.{{patch}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
type=semver,pattern={{major}} | ||
flavor: | | ||
latest=auto | ||
suffix=${{ env.TAG_SUFFIX }} | ||
- | ||
name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
- | ||
name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
- | ||
name: Login to DockerHub | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
- | ||
name: Build + push | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
file: ${{ matrix.props.Dockerfile }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
push: ${{ github.event_name != 'pull_request' }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,6 @@ | |
# SASS | ||
.sass-cache | ||
*.css.map | ||
|
||
# Certificates | ||
certs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash -e | ||
|
||
# Removes legacy woff type | ||
sed -i "/application\/font-woff/d" /etc/nginx/mime.types | ||
|
||
# Detects if woff support is already present | ||
if grep -Fxq "font/woff" /etc/nginx/mime.types | ||
then | ||
echo "Woff type detected, no changes necessary" | ||
else | ||
echo "Woff type not detected, adding..." | ||
sed -i "s/}/\n font\/woff woff;&/" /etc/nginx/mime.types | ||
sed -i "s/}/\n font\/woff2 woff2;\n&/g" /etc/nginx/mime.types | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters