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, based on examples in `./docs/examples`

Closes #132
  • Loading branch information
leojonathanoh committed Nov 2, 2023
1 parent 3ff0dda commit a907703
Show file tree
Hide file tree
Showing 52 changed files with 894 additions and 1,318 deletions.
51 changes: 33 additions & 18 deletions .github/workflows/ci-master-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
matrix:
testenv:
- dev
- prod
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -25,40 +26,40 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@v2

- name: Cache Docker layers (asp-nginx)
- name: Cache Docker layers (asp)
uses: actions/cache@v3
with:
path: /tmp/.buildx-asp-cache-nginx
key: ${{ runner.os }}-buildx-asp-nginx-${{ github.sha }}
key: ${{ runner.os }}-buildx-asp-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-asp-nginx-
${{ runner.os }}-buildx-asp-
${{ runner.os }}-buildx-
- name: Cache Docker layers (asp-php)
- name: Cache Docker layers (asp)
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache-asp-php
key: ${{ runner.os }}-buildx-asp-php-${{ github.sha }}
path: /tmp/.buildx-cache-asp
key: ${{ runner.os }}-buildx-asp-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-asp-php-
${{ runner.os }}-buildx-asp-
${{ runner.os }}-buildx-
- name: Cache Docker layers (bf2sclone-nginx)
- name: Cache Docker layers (bf2sclone)
uses: actions/cache@v3
with:
path: /tmp/.buildx-bf2sclone-cache-nginx
key: ${{ runner.os }}-buildx-bf2sclone-nginx-${{ github.sha }}
key: ${{ runner.os }}-buildx-bf2sclone-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-bf2sclone-nginx-
${{ runner.os }}-buildx-bf2sclone-
${{ runner.os }}-buildx-
- name: Cache Docker layers (bf2sclone-php)
- name: Cache Docker layers (bf2sclone)
uses: actions/cache@v3
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 @@ -74,14 +75,28 @@ jobs:
docker compose -f docker-compose.yml -f docker-compose.build.yml up --build -d
docker compose -f docker-compose.test.yml up
- name: Integration test 1 (prod)
if: matrix.testenv == 'prod'
run: |
set -eux
cd docs/bf2hub-bf2stats-example
(cd docs/bf2hub-bf2stats-example && docker compose -f docker-compose.yml -f docker-compose.build.prod.yml up --build -d)
docker compose -f docker-compose.test.yml --profile prod up
- name: Integration test 2 (prod)
if: matrix.testenv == 'prod'
run: |
set -eux
cd docs/full-bf2-stack-example
(cd docs/full-bf2-stack-example && docker compose -f docker-compose.yml -f docker-compose.build.prod.yml up --build -d)
docker compose -f docker-compose.test.yml --profile prod up
build:
strategy:
matrix:
variant:
- asp-nginx
- asp-php
- bf2sclone-nginx
- bf2sclone-php
- asp
- bf2sclone
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/.*
!/.github
!/.vscode
/src/ASP/system/config/config.php
/src/ASP/system/config/config.php.bak
/src/python/bf2/logs/*.log
/src/python/bf2/logs/snapshots/sent/*.txt
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
28 changes: 25 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,28 @@ 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.php
RUN chmod +x /docker-entrypoint.sh;
# Disable the built-in php-fpm configs, since we're using our own config
RUN set -eux; \
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
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.

23 changes: 19 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,22 @@ 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 chmod +x /docker-entrypoint.sh;
# Disable the built-in php-fpm configs, since we're using our own config
RUN set -eux; \
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.

55 changes: 31 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@

[![github-actions](https://github.com/startersclan/bf2stats/workflows/ci-master-pr/badge.svg)](https://github.com/startersclan/bf2stats/actions)
[![github-release](https://img.shields.io/github/v/release/startersclan/bf2stats?style=flat-square)](https://github.com/startersclan/bf2stats/releases/)
[![docker-image-size](https://img.shields.io/docker/image-size/startersclan/bf2stats/master-asp-nginx?label=asp-nginx)](https://hub.docker.com/r/startersclan/asp)
[![docker-image-size](https://img.shields.io/docker/image-size/startersclan/bf2stats/master-asp-php?label=asp-php)](https://hub.docker.com/r/startersclan/asp)
[![docker-image-size](https://img.shields.io/docker/image-size/startersclan/bf2stats/master-bf2sclone-nginx?label=bf2sclone-nginx)](https://hub.docker.com/r/startersclan/asp)
[![docker-image-size](https://img.shields.io/docker/image-size/startersclan/bf2stats/master-bf2sclone-php?label=bf2sclone-php)](https://hub.docker.com/r/startersclan/asp)
[![docker-image-size](https://img.shields.io/docker/image-size/startersclan/bf2stats/master-asp?label=asp)](https://hub.docker.com/r/startersclan/asp)
[![docker-image-size](https://img.shields.io/docker/image-size/startersclan/bf2stats/master-bf2sclone?label=bf2sclone)](https://hub.docker.com/r/startersclan/asp)
[![docker-image-size](https://img.shields.io/docker/image-size/startersclan/bf2stats/master-bf2sclone?label=bf2sclone)](https://hub.docker.com/r/startersclan/asp)

BF2Statistics [`2.x.x`](https://code.google.com/archive/p/bf2stats/) with docker support.

Although BF2Statistics [`3.1.0`](https://github.com/BF2Statistics/ASP) has been released, it is not backward compatible with `<= 2.x.x`. Hence, this project is to help those who want to retain their `2.x.x` stats system, and to ease deployment of the stack since support is scarce. It runs on PHP 7.4 with nginx.

## Usage
## Usage (docker)

```sh
docker pull startersclan/bf2stats:2.5.1-asp-nginx
docker pull startersclan/bf2stats:2.5.1-asp-php
docker pull startersclan/bf2stats:2.5.1-bf2sclone-nginx
docker pull startersclan/bf2stats:2.5.1-bf2sclone-php
docker pull startersclan/bf2stats:2.5.1-asp
docker pull startersclan/bf2stats:2.5.1-bf2sclone
```

See [this](docs/full-bf2-stack-example) example showing how to deploy [Battlefield 2 1.5 server](https://github.com/startersclan/docker-bf2/), [PRMasterserver](https://github.com/startersclan/PRMasterServer) as the master server, and `bf2stats` as the stats web server, using `docker-compose`.

See [this](docs/bf2hub-bf2stats-example) example showing how to deploy [Battlefield 2 1.5 server](https://github.com/startersclan/docker-bf2/), with BF2Hub as the master server and `bf2stats` as the stats web server, using `docker-compose`.

### Upgrading to v2.6.0 from prior versions

See here for [quick instructions](docs/upgrades/upgrade-docker-images-to-2.6.md).

## Development

```sh
Expand Down Expand Up @@ -76,24 +77,29 @@ docker exec -it $( docker-compose ps -q bf2 ) bash -c 'cat python/bf2/logs/bf2ga
docker exec -it $( docker-compose ps -q bf2 ) bash -c 'ls -al python/bf2/logs/snapshots/sent'
docker exec -it $( docker-compose ps -q bf2 ) bash -c 'ls -al python/bf2/logs/snapshots/unsent'

# asp-php - Exec into container
docker exec -it $( docker-compose ps -q asp-php ) sh
# asp-php - Read logs
docker exec -it $( docker-compose ps -q asp-php ) cat /src/ASP/system/logs/stats_debug.log
docker exec -it $( docker-compose ps -q asp-php ) cat /src/ASP/system/logs/validate_awards.log
docker exec -it $( docker-compose ps -q asp-php ) cat /src/ASP/system/logs/validate_ranks.log
# asp-php - List snapshots
docker exec -it $( docker-compose ps -q asp-php ) ls -al /src/ASP/system/snapshots/processed
docker exec -it $( docker-compose ps -q asp-php ) ls -al /src/ASP/system/snapshots/temp
# asp - Exec into container
docker exec -it $( docker-compose ps -q asp ) sh
# asp - Read logs
docker exec -it $( docker-compose ps -q asp ) cat /src/ASP/system/logs/stats_debug.log
docker exec -it $( docker-compose ps -q asp ) cat /src/ASP/system/logs/validate_awards.log
docker exec -it $( docker-compose ps -q asp ) cat /src/ASP/system/logs/validate_ranks.log
# asp - List snapshots
docker exec -it $( docker-compose ps -q asp ) ls -al /src/ASP/system/snapshots/processed
docker exec -it $( docker-compose ps -q asp ) ls -al /src/ASP/system/snapshots/temp

# Test routes
docker-compose -f docker-compose.test.yml up

# Test production builds locally
docker build -t startersclan/bf2stats:asp-nginx -f Dockerfile.asp-nginx --target prod .
docker build -t startersclan/bf2stats:asp-php -f Dockerfile.asp-php --target prod .
docker build -t startersclan/bf2stats:bf2sclone-nginx -f Dockerfile.bf2sclone-nginx --target prod .
docker build -t startersclan/bf2stats:bf2sclone-php -f Dockerfile.bf2sclone-php --target prod .
(cd docs/bf2hub-bf2stats-example && docker compose -f docker-compose.yml -f docker-compose.build.prod.yml up --build)
docker compose -f docker-compose.test.yml --profile prod up
(cd docs/full-bf2-stack-example && docker compose -f docker-compose.yml -f docker-compose.build.prod.yml up --build)
docker compose -f docker-compose.test.yml --profile prod up

docker build -t startersclan/bf2stats:asp -f Dockerfile.asp --target prod .
docker build -t startersclan/bf2stats:asp -f Dockerfile.asp --target prod .
docker build -t startersclan/bf2stats:bf2sclone -f Dockerfile.bf2sclone --target prod .
docker build -t startersclan/bf2stats:bf2sclone -f Dockerfile.bf2sclone --target prod .

# Dump the DB
docker exec $( docker-compose ps -q db ) mysqldump -uroot -padmin bf2stats | gzip > bf2stats.sql.gz
Expand All @@ -108,6 +114,7 @@ docker-compose down
docker-compose down
docker volume rm bf2stats_prmasterserver-volume
docker volume rm bf2stats_backups-volume
docker volume rm bf2stats_config-volume
docker volume rm bf2stats_logs-volume
docker volume rm bf2stats_snapshots-volume
docker volume rm bf2stats_bf2sclone-cache-volume
Expand Down Expand Up @@ -136,7 +143,7 @@ Grant ASP `php`'s `www-data` user write permission for `config.php`.

```sh
chmod 666 ./config/ASP/config.php
docker-compose restart asp-php
docker-compose restart asp
```

### Q: `Warning: file_put_contents(/src/ASP/system/config/config.php): failed to open stream: Permission denied in /src/ASP/system/core/Config.php on line 165` appearing in ASP dashboard
Expand All @@ -145,7 +152,7 @@ A: Grant ASP `php`'s `www-data` user write permission for `config.php`.

```sh
chmod 666 ./config/ASP/config.php
docker-compose restart asp-php
docker-compose restart asp
```

### Q: `There was an error testing the system. Please refresh the page and try again.` when using `System > Test System` in ASP
Expand Down
40 changes: 0 additions & 40 deletions config/ASP/config.php

This file was deleted.

Loading

0 comments on commit a907703

Please sign in to comment.