Skip to content

Commit

Permalink
Merge pull request #4 from startersclan/enhancement/ci-combine-nginx-…
Browse files Browse the repository at this point in the history
…and-php-into-a-single-web-container

Enhancement (ci): Combine `nginx` and `php` into a single `web` container
  • Loading branch information
leojonathanoh authored Oct 29, 2023
2 parents 0b8b9ac + 58752d8 commit 7feab10
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 119 deletions.
19 changes: 13 additions & 6 deletions .github/workflows/ci-master-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,21 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@v2

- name: Cache Docker layers
- name: Cache Docker layers (daemon)
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-test-${{ github.sha }}
path: /tmp/.buildx-cache-daemon
key: ${{ runner.os }}-buildx-daemon-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-daemon-
- name: Cache Docker layers (web)
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache-web
key: ${{ runner.os }}-buildx-web-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-test-
${{ runner.os }}-buildx-web-
- name: Print buildx and compose
run: |
Expand All @@ -45,9 +53,8 @@ jobs:
strategy:
matrix:
variant:
- web-nginx
- web-php
- daemon
- web
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
20 changes: 16 additions & 4 deletions Dockerfile.web-php → Dockerfile.web
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ ARG TARGETPLATFORM
ARG BUILDPLATFORM
RUN echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM"

# 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 @@ -56,6 +59,19 @@ RUN set -eux; \
php -i; \
php -m

# Add default configs
COPY ./config/web/supervisor.conf /supervisor.conf
COPY ./config/web/etc/nginx/nginx.conf /etc/nginx/nginx.conf
COPY ./config/web/usr/local/etc/php/conf.d/php.ini /usr/local/etc/php/conf.d/php.ini
COPY ./config/web/usr/local/etc/php-fpm.d/php-fpm.conf /usr/local/etc/php-fpm.d/php-fpm.conf
# 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;

CMD ["/usr/bin/supervisord", "-c", "/supervisor.conf", "--pidfile", "/run/supervisord.pid"]

FROM base AS prod

# Set permissions for 'www-data' user
Expand All @@ -71,7 +87,3 @@ RUN set -eux; \
chown -R www-data:www-data /heatmaps; \
find /heatmaps -type d -exec chmod 750 {} \; ; \
find /heatmaps -type f -exec chmod 640 {} \; ;

# Add default configs
COPY ./config/web/php/conf.d/php.ini /usr/local/etc/php/conf.d/php.ini
COPY ./config/web/php-fpm.d/www.conf /usr/local/etc/php-fpm.d/www.conf
18 changes: 0 additions & 18 deletions Dockerfile.web-nginx

This file was deleted.

24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

[![github-actions](https://github.com/startersclan/hlstatsx-community-edition/workflows/ci-master-pr/badge.svg)](https://github.com/startersclan/hlstatsx-community-edition/actions)
[![github-release](https://img.shields.io/github/v/release/startersclan/hlstatsx-community-edition?style=flat-square)](https://github.com/startersclan/hlstatsx-community-edition/releases/)
[![docker-image-size](https://img.shields.io/docker/image-size/startersclan/hlstatsx-community-edition/web)](https://hub.docker.com/r/startersclan/hlstatsx-community-edition)
[![docker-image-size](https://img.shields.io/docker/image-size/startersclan/hlstatsx-community-edition/daemon)](https://hub.docker.com/r/startersclan/hlstatsx-community-edition)
[![docker-image-size](https://img.shields.io/docker/image-size/startersclan/hlstatsx-community-edition/master-web?label=web)](https://hub.docker.com/r/startersclan/hlstatsx-community-edition)
[![docker-image-size](https://img.shields.io/docker/image-size/startersclan/hlstatsx-community-edition/master-daemon?label=daemon)](https://hub.docker.com/r/startersclan/hlstatsx-community-edition)

HLstatsX Community Edition is an open-source project licensed
under GNU General Public License v2 and is a real-time stats
Expand Down Expand Up @@ -32,11 +32,18 @@ a PHP frontend.

---

## Usage

```sh
docker run --rm -it -p 80:80 startersclan/hlstatsx-community-edition:v1.7.0-web
docker run --rm -it -p 27500:27500/udp startersclan/hlstatsx-community-edition:v1.7.0-daemon --help
```

## Development

```sh
# 1. Start Counter-strike 1.6 server, source-udp-forwarder, HLStatsX:CE stack
docker compose up
docker compose up --build
# HLStatsX:CE web frontend available at http://localhost:8081/. Admin Panel username: admin, password 123456
# phpmyadmin available at http://localhost:8083. Root username: root, root password: root. Username: hlstatsxce, password: hlstatsxce

Expand Down Expand Up @@ -76,10 +83,8 @@ docker attach $( docker compose ps -q cstrike )
# CS 1.6 server - Exec into container
docker exec -it $( docker compose ps -q cstrike) bash

# web-nginx - Exec into container
docker exec -it $( docker compose ps -q web-nginx ) sh
# web-php - Exec into container
docker exec -it $( docker compose ps -q web-php ) sh
# web - Exec into container
docker exec -it $( docker compose ps -q web ) sh
# Run awards
docker exec -it $( docker compose ps -q awards) sh -c /awards.sh
# Generate heatmaps
Expand All @@ -88,12 +93,11 @@ docker exec -it $( docker compose ps -q heatmaps) php /heatmaps/generate.php #--
docker exec -it $( docker compose ps -q db ) sh

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

# Test production builds locally
docker build -t startersclan/hlstatsx-community-edition:daemon -f Dockerfile.daemon .
docker build -t startersclan/hlstatsx-community-edition:web-nginx -f Dockerfile.web-nginx .
docker build -t startersclan/hlstatsx-community-edition:web-php -f Dockerfile.web-php .
docker build -t startersclan/hlstatsx-community-edition:web -f Dockerfile.web .

# Dump the DB
docker exec $( docker compose ps -q db ) mysqldump -uroot -proot hlstatsxce | gzip > hlstatsxce.sql.gz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ http {
location ~ /\.[^/]+$ {
return 401;
}
# Deny access to the certain folders
location ~ ^/(includes|pages|updater|system) {
# Deny access to the certain files / folders
location ~ ^/config.php {
return 401;
}
location ~ ^/(includes|pages|updater|system)/ {
return 401;
}

Expand All @@ -88,7 +91,7 @@ http {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass web-php:9000;
fastcgi_pass 127.0.0.1:9000;
}

location / {
Expand Down
10 changes: 0 additions & 10 deletions config/web/php-fpm.d/www.conf

This file was deleted.

31 changes: 31 additions & 0 deletions config/web/supervisor.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[supervisord]
nodaemon=true
user=root
logfile=/dev/null
logfile_maxbytes=0

[program:nginx]
command=nginx -c /etc/nginx/nginx.conf -g 'daemon off;'
process_name=%(program_name)s_%(process_num)02d
user=root
numprocs=1
autostart=true
autorestart=false
startsecs=0
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:php-fpm]
command=php-fpm -F
process_name=%(program_name)s_%(process_num)02d
user=root
numprocs=1
autostart=true
autorestart=false
startsecs=0
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
27 changes: 27 additions & 0 deletions config/web/usr/local/etc/php-fpm.d/php-fpm.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[global]
daemonize = no
error_log = /proc/self/fd/2
; https://github.com/docker-library/php/pull/725#issuecomment-443540114
log_limit = 8192
log_buffering = no

[default]
listen = 9000
user = www-data
listen.owner = www-data
listen.group = www-data
pm = dynamic
pm.max_children = 30
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.process_idle_timeout = 10s
pm.max_requests = 500
catch_workers_output = yes
decorate_workers_output = no
chdir = /
pm.status_path = /status
php_admin_value[log_errors] = On
php_admin_value[expose_php] = Off
php_admin_value[display_errors] = Off
php_admin_value[date.timezone] = UTC
File renamed without changes.
38 changes: 19 additions & 19 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ services:
image: alpine:latest
environment:
URLS: |
http://web-nginx/ 302
http://web-nginx/css/spinner.gif 200
http://web-nginx/hlstatsimg/ajax.gif 200
http://web-nginx/includes/ 401
http://web-nginx/pages/ 401
http://web-nginx/pages/.htaccess 401
http://web-nginx/styles/classic.css 200
http://web-nginx/updater/ 401
http://web-nginx/autocomplete.php 200
http://web-nginx/config.php 200
http://web-nginx/hlstats.php 200
http://web-nginx/index.php 302
http://web-nginx/ingame.php 200
http://web-nginx/show_graph.php 200
http://web-nginx/sig.php 200
http://web-nginx/status.php 200
http://web-nginx/trend_graph.php 200
http://web/ 302
http://web/css/spinner.gif 200
http://web/hlstatsimg/ajax.gif 200
http://web/includes/ 401
http://web/pages/ 401
http://web/pages/.htaccess 401
http://web/styles/classic.css 200
http://web/updater/ 401
http://web/autocomplete.php 200
http://web/config.php 401
http://web/hlstats.php 200
http://web/index.php 302
http://web/ingame.php 200
http://web/show_graph.php 200
http://web/sig.php 200
http://web/status.php 200
http://web/trend_graph.php 200
networks:
- default
entrypoint:
Expand All @@ -33,8 +33,8 @@ services:
echo "Waiting for stack to be ready"
s=0
while true; do
nc -vz -w 1 web-nginx 80 \
&& nc -vz -w 1 web-php 9000 \
nc -vz -w 1 web 80 \
&& nc -vz -w 1 web 9000 \
&& nc -vz -w 1 db 3306 \
&& break || true
s=$$(( $$s + 1 ))
Expand Down
12 changes: 0 additions & 12 deletions docker-compose.tmp.yml

This file was deleted.

Loading

0 comments on commit 7feab10

Please sign in to comment.