Skip to content

Commit

Permalink
Change (docker): Combine nginx and php to a single image for both `AS…
Browse files Browse the repository at this point in the history
…P` and `bf2sclone` with env var support for configuration

Previous: In <= v2.5.x, `asp` and `bf2sclone` each had separate `nginx` and `php` images.

Now: Single `asp` and `bf2sclone` images 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 `asp-nginx` and `asp-php` containers
- Environment variable configuration means no more need to mount `config.php` into `asp` and `bf2sclone` containers
- 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 v2.6.x from prior versions
- Update `./docs/examples`
- Add tests for production builds for examples in `./docs/examples`

Closes #132
  • Loading branch information
leojonathanoh committed Nov 22, 2023
1 parent 3c7cc05 commit fe94cf4
Show file tree
Hide file tree
Showing 67 changed files with 1,234 additions and 1,441 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/.github
/.vscode
/docs
/src/python
/test
/Tools
/docker-compose.*.yml
/docker-compose.yml
74 changes: 37 additions & 37 deletions .github/workflows/ci-master-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,33 @@ 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

- name: Cache Docker layers (asp-nginx)
uses: actions/cache@v3
with:
path: /tmp/.buildx-asp-cache-nginx
key: ${{ runner.os }}-buildx-asp-nginx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-asp-nginx-
${{ runner.os }}-buildx-
- name: Cache Docker layers (asp-php)
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache-asp-php
key: ${{ runner.os }}-buildx-asp-php-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-asp-php-
${{ runner.os }}-buildx-
# 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 (bf2sclone-nginx)
uses: actions/cache@v3
- name: Cache Docker layers (asp)
uses: actions/cache/restore@v3 # Restore cache but don't save it at end of job
with:
path: /tmp/.buildx-bf2sclone-cache-nginx
key: ${{ runner.os }}-buildx-bf2sclone-nginx-${{ github.sha }}
path: /tmp/.buildx-cache-asp
key: ${{ runner.os }}-buildx-asp-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-bf2sclone-nginx-
${{ runner.os }}-buildx-asp-
${{ runner.os }}-buildx-
- name: Cache Docker layers (bf2sclone-php)
uses: actions/cache@v3
- name: Cache Docker layers (bf2sclone)
uses: actions/cache/restore@v3 # Restore cache but don't save it at end of job
with:
path: /tmp/.buildx-cache-bf2sclone-php
key: ${{ runner.os }}-buildx-bf2sclone-php-${{ github.sha }}
path: /tmp/.buildx-cache-bf2sclone
key: ${{ runner.os }}-buildx-bf2sclone-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-bf2sclone-php-
${{ runner.os }}-buildx-bf2sclone-
${{ runner.os }}-buildx-
- name: Print buildx and compose
Expand All @@ -71,17 +55,33 @@ 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 1 (prod)
if: matrix.testenv == 'prod'
run: |
set -eux
./test/test.sh prod1 1 1
- name: Integration test 2 (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 prod2 1 1
build:
strategy:
matrix:
variant:
- asp-nginx
- asp-php
- bf2sclone-nginx
- bf2sclone-php
- asp
- bf2sclone
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
2 changes: 0 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
"port": 9000,
"pathMappings": {
"/src": "${workspaceRoot}/src",
"/src/ASP/system/config/config.php": "${workspaceRoot}/config/ASP/config.php",
"/src/bf2sclone/config.inc.php": "${workspaceRoot}/config/bf2sclone/config.inc.php",
},
"xdebugSettings": {
"max_data": 10000,
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
"*.con": "ini",
"*.aspx": "php",
},
// "editor.trimAutoWhitespace": false
}
31 changes: 31 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
// 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 (prod1)",
"type": "shell",
"command": "./test/test.sh prod 1",
"group": "build"
},
{
"label": "Test (prod2)",
"type": "shell",
"command": "./test/test.sh prod 1",
"group": "build"
},
{
"label": "Test (dns)",
"type": "shell",
"command": "./test/test.sh dns",
"group": "build"
},
]
}
34 changes: 31 additions & 3 deletions Dockerfile.asp-php → Dockerfile.asp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ RUN chown -R www-data:www-data . \

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,34 @@ RUN set -eux; \
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.php /config.sample/config.php
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
ENV ADMIN_BACKUP_PATH=/src/ASP/system/database/backups
# Authorize all gameservers within private IP ranges
ENV GAME_HOSTS=127.0.0.1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
VOLUME /src/ASP/system/config
VOLUME /src/ASP/system/database/backups
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.asp-nginx

This file was deleted.

26 changes: 22 additions & 4 deletions Dockerfile.bf2sclone-php → Dockerfile.bf2sclone
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ RUN chown -R www-data:www-data . \

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 All @@ -19,7 +22,6 @@ RUN docker-php-ext-install pdo pdo_mysql
# mysqli
RUN docker-php-ext-install mysqli


# Xdebug: https://stackoverflow.com/questions/46825502/how-do-i-install-xdebug-on-dockers-official-php-fpm-alpine-image
# PHPIZE_DEPS: autoconf dpkg-dev dpkg file g++ gcc libc-dev make pkgconf re2c
RUN apk add --no-cache --virtual .build-dependencies $PHPIZE_DEPS \
Expand All @@ -41,9 +43,25 @@ RUN set -eux; \
php -i; \
php -m

# Add default configs
COPY ./config/bf2sclone/php/conf.d/php.ini /usr/local/etc/php/conf.d/php.ini
COPY ./config/bf2sclone/php-fpm.d/www.conf /usr/local/etc/php-fpm.d/www.conf
# Add configs
COPY ./config/bf2sclone/. /
COPY ./src/bf2sclone/config.inc.php /config.inc.sample.php
RUN set -eux; \
chmod +x /docker-entrypoint.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;

VOLUME /src/bf2sclone/cache
EXPOSE 80
EXPOSE 9000
WORKDIR /src/bf2sclone
ENTRYPOINT []
CMD ["/docker-entrypoint.sh"]

FROM dev AS prod

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

This file was deleted.

Loading

0 comments on commit fe94cf4

Please sign in to comment.