Skip to content

Commit

Permalink
Change (docker): Combine nginx and php to a single image for ASP wi…
Browse files Browse the repository at this point in the history
…th env var support for configuration

In <= v3.2.0, `asp` had separate `nginx` and `php` images.

Now: `asp` image containing both `nginx` and `php`, with environment variable support, and entrypoint that sets the correct permissions.

Benefits:

- Easier to deploy / upgrade. No need to separate `nginx` and `php` containers
- Environment variable configuration means no more need to mount config into `asp` container
- Entrypoint script sets permissions on volumes. `init-container` should only need to set permissions for `db` volume

Notable changes:
- Add documentation for upgrading docker images to v3.3.x from prior versions
- Update `./docs/examples`
- Add tests for production builds for examples in `./docs/examples`

Closes #69
  • Loading branch information
leojonathanoh committed Nov 22, 2023
1 parent 29a0927 commit 0deb8c6
Show file tree
Hide file tree
Showing 52 changed files with 1,372 additions and 2,060 deletions.
83 changes: 41 additions & 42 deletions .github/workflows/ci-master-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,25 @@ jobs:
matrix:
testenv:
- dev
- prod
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
# This is commented out, so we use the default 'docker' driver instead of the 'docker-container' driver. When using 'docker-container' driver, there appears to be a rate limit on writes on Github CI which causes buildx to fail with error code 17 when it is exporting to cache
# - name: Set up Docker Buildx
# id: buildx
# uses: docker/setup-buildx-action@v2

- name: Cache Docker layers (nginx)
uses: actions/cache@v3
- name: Cache Docker layers
uses: actions/cache/restore@v3 # Restore cache but don't save it at end of job
with:
path: /tmp/.buildx-cache-nginx
key: ${{ runner.os }}-buildx-nginx-${{ github.sha }}
path: /tmp/.buildx-cache-asp
key: ${{ runner.os }}-buildx-asp-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-nginx-
${{ runner.os }}-buildx-
- name: Cache Docker layers (php)
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache-php
key: ${{ runner.os }}-buildx-php-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-php-
${{ runner.os }}-buildx-
${{ runner.os }}-buildx-asp
${{ runner.os }}-buildx
- name: Print buildx and compose
run: |
Expand All @@ -53,15 +46,22 @@ jobs:
if: matrix.testenv == 'dev'
run: |
set -eux
docker compose -f docker-compose.yml -f docker-compose.build.yml up --build -d
docker compose -f docker-compose.test.yml up
./test/test.sh dev 1 1
- name: Integration test (prod)
if: matrix.testenv == 'prod'
run: |
set -eux
# Don't publish coredns ports to prevent conflict with system-resolved on github CI
# sed -i '$!N;s@ports:\n - 53:53.*@@;P;D' docker-compose.yml
# Make coredns listen on localhost only to prevent conflict with system-resolved on github CI
sed -i 's/- 53:53/- 127.0.0.1:53:53/' docs/full-bf2-stack-example/docker-compose.yml
./test/test.sh prod 1 1
build:
strategy:
matrix:
variant:
- nginx
- php
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -91,10 +91,9 @@ jobs:
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache-${{ matrix.variant }}
key: ${{ runner.os }}-buildx-${{ matrix.variant }}-${{ github.sha }}
path: /tmp/.buildx-cache-asp
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ matrix.variant }}-
${{ runner.os }}-buildx-
# This step generates the docker tags
Expand All @@ -108,12 +107,12 @@ jobs:
# type=ref,event=branch generates tag(s) on branch only. E.g. 'master-<variant>', 'master-abc0123-<variant>'
# type=ref,event=tag generates tag(s) on tags only. E.g. 'v0.0.0-<variant>', 'v0.0.0-abc0123-<variant>'
tags: |
type=ref,suffix=-${{ matrix.variant }},event=pr
type=ref,suffix=-{{sha}}-${{ matrix.variant }},event=pr
type=ref,suffix=-${{ matrix.variant }},event=branch
type=ref,suffix=-{{sha}}-${{ matrix.variant }},event=branch
type=ref,suffix=-${{ matrix.variant }},event=tag
type=ref,suffix=-{{sha}}-${{ matrix.variant }},event=tag
type=ref,suffix=,event=pr
type=ref,suffix=-{{sha}},event=pr
type=ref,suffix=,event=branch
type=ref,suffix=-{{sha}},event=branch
type=ref,suffix=,event=tag
type=ref,suffix=-{{sha}},event=tag
# Disable 'latest' tag
flavor: |
latest=false
Expand All @@ -131,36 +130,36 @@ jobs:
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v3
with:
file: Dockerfile.${{ matrix.variant }}
file: Dockerfile
context: '.'
target: prod
platforms: linux/amd64
push: false
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache-${{ matrix.variant }}
cache-to: type=local,dest=/tmp/.buildx-cache-${{ matrix.variant }}-new,mode=max
cache-from: type=local,src=/tmp/.buildx-cache-asp
cache-to: type=local,dest=/tmp/.buildx-cache-asp-new,mode=max

- name: Build and push
# Run on master and tags
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v3
with:
file: Dockerfile.${{ matrix.variant }}
file: Dockerfile
context: '.'
target: prod
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache-${{ matrix.variant }}
cache-to: type=local,dest=/tmp/.buildx-cache-${{ matrix.variant }}-new,mode=max
cache-from: type=local,src=/tmp/.buildx-cache-asp
cache-to: type=local,dest=/tmp/.buildx-cache-asp-new,mode=max

# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache-${{ matrix.variant }}
mv /tmp/.buildx-cache-${{ matrix.variant }}-new /tmp/.buildx-cache-${{ matrix.variant }}
rm -rf /tmp/.buildx-cache-asp
mv /tmp/.buildx-cache-asp-new /tmp/.buildx-cache-asp
update-draft-release:
needs: [test, build]
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
"*.ai.add": "bat",
"*.con": "ini",
},
// "editor.trimAutoWhitespace": false
}
25 changes: 25 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Test (dev)",
"type": "shell",
"command": "./test/test.sh dev 1",
"group": "build"
},
{
"label": "Test (prod)",
"type": "shell",
"command": "./test/test.sh prod 1 1",
"group": "build"
},
{
"label": "Test (dns)",
"type": "shell",
"command": "./test/test.sh dns",
"group": "build"
},
]
}
37 changes: 32 additions & 5 deletions Dockerfile.php → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
FROM $IMAGE AS build

# Set permissions for 'www-data' user
COPY ./src /src
WORKDIR /src
COPY ./src/ASP /src/ASP
WORKDIR /src/ASP
RUN chown -R www-data:www-data . \
&& find . -type d -exec chmod 750 {} \; \
&& find . -type f -exec chmod 640 {} \;

FROM $IMAGE AS dev

# Install nginx and supervisor for multi-process container
RUN apk add --no-cache ca-certificates nginx supervisor

# opcache
RUN docker-php-ext-install opcache

Expand Down Expand Up @@ -37,9 +40,33 @@
php -i; \
php -m

# Add default configs
COPY ./config/ASP/php/conf.d/php.ini /usr/local/etc/php/conf.d/php.ini
COPY ./config/ASP/php-fpm.d/www.conf /usr/local/etc/php-fpm.d/www.conf
# Add configs
COPY ./config/ASP/. /
COPY ./src/ASP/system/config /config.sample
RUN chmod +x /docker-entrypoint.sh;
RUN set -eux; \
chmod +x /docker-entrypoint.sh; \
chmod +x /tail.sh; \
# Symlink nginx logs
ln -sfn /dev/stdout /var/log/nginx/access.log; \
ln -sfn /dev/stderr /var/log/nginx/error.log; \
# Disable the built-in php-fpm configs, since we're using our own config
mv -v /usr/local/etc/php-fpm.d/docker.conf /usr/local/etc/php-fpm.d/docker.conf.disabled; \
mv -v /usr/local/etc/php-fpm.d/www.conf /usr/local/etc/php-fpm.d/www.conf.disabled; \
mv -v /usr/local/etc/php-fpm.d/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf.disabled;

# In docker, IPs may be dynamic. This ensures we get access
ENV ADMIN_HOSTS=0.0.0.0/0
VOLUME /src/ASP/system/backups
VOLUME /src/ASP/system/cache
VOLUME /src/ASP/system/config
VOLUME /src/ASP/system/logs
VOLUME /src/ASP/system/snapshots
EXPOSE 80
EXPOSE 9000
WORKDIR /src/ASP
ENTRYPOINT []
CMD ["/docker-entrypoint.sh"]

FROM dev AS prod

Expand Down
18 changes: 0 additions & 18 deletions Dockerfile.nginx

This file was deleted.

Loading

0 comments on commit 0deb8c6

Please sign in to comment.