diff --git a/.github/workflows/ci-master-pr.yml b/.github/workflows/ci-master-pr.yml index 4d986bea..b2f86185 100644 --- a/.github/workflows/ci-master-pr.yml +++ b/.github/workflows/ci-master-pr.yml @@ -17,11 +17,38 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Test (integration) + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + + - name: Cache Docker layers (nginx) + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache-nginx + key: ${{ runner.os }}-buildx-nginx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx-nginx- + + - 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- + + - name: Print buildx and compose run: | set -eu - docker-compose up --build -d - docker-compose -f docker-compose.test.yml up + docker buildx ls + docker compose version + + - name: Integration test (dev) + 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 build: strategy: @@ -98,8 +125,9 @@ jobs: if: github.event_name == 'pull_request' uses: docker/build-push-action@v3 with: - file: Dockerfile.${{ matrix.variant }}.prod + file: Dockerfile.${{ matrix.variant }} context: '.' + target: prod platforms: linux/amd64 push: false tags: ${{ steps.meta.outputs.tags }} @@ -111,8 +139,9 @@ jobs: if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') uses: docker/build-push-action@v3 with: - file: Dockerfile.${{ matrix.variant }}.prod + file: Dockerfile.${{ matrix.variant }} 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 }} diff --git a/.vscode/launch.json b/.vscode/launch.json index cd549c2b..8d4f3b50 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,7 @@ "port": 9000, "pathMappings": { "/src": "${workspaceRoot}/src", + "/src/ASP/system/config/config.php": "${workspaceRoot}/config/ASP/config.php", }, "xdebugSettings": { "max_data": 10000, diff --git a/Dockerfile.nginx.prod b/Dockerfile.nginx similarity index 62% rename from Dockerfile.nginx.prod rename to Dockerfile.nginx index cdbbb0dd..5adae2ed 100644 --- a/Dockerfile.nginx.prod +++ b/Dockerfile.nginx @@ -1,7 +1,5 @@ -FROM nginx:1.21-alpine AS build -ARG TARGETPLATFORM -ARG BUILDPLATFORM -RUN echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM" +ARG IMAGE=nginx:1.21-alpine +FROM $IMAGE AS build # Set permissions for 'nginx' user COPY ./src /src @@ -10,8 +8,11 @@ RUN chown -R nginx:nginx . \ && find . -type d -exec chmod 750 {} \; \ && find . -type f -exec chmod 640 {} \; -FROM nginx:1.21-alpine AS final +FROM $IMAGE AS dev # Add default configs -COPY --from=build /src /src COPY config/ASP/nginx/nginx.conf /etc/nginx/nginx.conf + +FROM dev AS prod + +COPY --from=build /src /src diff --git a/Dockerfile.php.dev b/Dockerfile.php similarity index 54% rename from Dockerfile.php.dev rename to Dockerfile.php index 68337b5c..bc4071f1 100644 --- a/Dockerfile.php.dev +++ b/Dockerfile.php @@ -1,4 +1,14 @@ -FROM php:7.4-fpm-alpine +ARG IMAGE=php:7.4-fpm-alpine +FROM $IMAGE AS build + +# Set permissions for 'www-data' user +COPY ./src /src +WORKDIR /src +RUN chown -R www-data:www-data . \ + && find . -type d -exec chmod 750 {} \; \ + && find . -type f -exec chmod 640 {} \; + +FROM $IMAGE AS dev # opcache RUN docker-php-ext-install opcache @@ -9,7 +19,7 @@ # 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 \ - && pecl install xdebug-3.1.5 \ + && pecl install xdebug-3.1.6 \ && docker-php-ext-enable xdebug \ && docker-php-source delete \ && apk del .build-dependencies @@ -22,5 +32,20 @@ echo "xdebug.client_port=9000"; \ } > /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; -RUN php -i -RUN php -m +RUN set -eux; \ + echo; \ + 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 + +FROM dev AS prod + +# Disable xdebug +RUN set -eux; \ + rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \ + php -m; + +COPY --from=build /src /src diff --git a/Dockerfile.php.prod b/Dockerfile.php.prod deleted file mode 100644 index 2059a3e7..00000000 --- a/Dockerfile.php.prod +++ /dev/null @@ -1,27 +0,0 @@ -FROM php:7.4-fpm-alpine AS build -ARG TARGETPLATFORM -ARG BUILDPLATFORM -RUN echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM" - -# Set permissions for 'www-data' user -COPY ./src /src -WORKDIR /src -RUN chown -R www-data:www-data . \ - && find . -type d -exec chmod 750 {} \; \ - && find . -type f -exec chmod 640 {} \; - -FROM php:7.4-fpm-alpine AS final - -# opcache -RUN docker-php-ext-install opcache - -# mysql PDO -RUN docker-php-ext-install pdo pdo_mysql - -RUN php -i -RUN php -m - -# Add default configs -COPY --from=build /src /src -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 diff --git a/README.md b/README.md index fb140b31..8cac7315 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ [![github-actions](https://github.com/startersclan/asp/workflows/ci-master-pr/badge.svg)](https://github.com/startersclan/asp/actions) [![github-release](https://img.shields.io/github/v/release/startersclan/asp?style=flat-square)](https://github.com/startersclan/asp/releases/) -[![docker-image-size](https://img.shields.io/docker/image-size/startersclan/asp/nginx)](https://hub.docker.com/r/startersclan/asp) +[![docker-image-size](https://img.shields.io/docker/image-size/startersclan/asp/master-nginx?label=nginx)](https://hub.docker.com/r/startersclan/asp) +[![docker-image-size](https://img.shields.io/docker/image-size/startersclan/asp/master-php?label=php)](https://hub.docker.com/r/startersclan/asp) The new BF2Statistics 3.0 ASP, currently in public Beta. The GameSpy server to match is over at https://github.com/BF2Statistics/BattleSpy @@ -19,7 +20,7 @@ See [this](docs/full-bf2-stack-example) example showing how to deploy [Battlefie ```sh # Start -docker-compose up +docker-compose up --build # ASP available at http://localhost:8081/ASP. Username: admin, password admin. See ./config/ASP/config.php # phpmyadmin available at http://localhost:8083. Username: root, password: ascent. See ./config/ASP/config.php config file @@ -36,8 +37,8 @@ sudo iptables -A INPUT -i br+ -j ACCEPT docker-compose -f docker-compose.test.yml up # Test production builds locally -docker build -t startersclan/asp:nginx -f Dockerfile.nginx.prod . -docker build -t startersclan/asp:php -f Dockerfile.php.prod . +docker build -t startersclan/asp:nginx -f Dockerfile.nginx --target prod . +docker build -t startersclan/asp:php -f Dockerfile.php --target prod . # Dump the DB docker exec $( docker-compose ps | grep db | awk '{print $1}' ) mysqldump -uroot -pascent bf2stats | gzip > bf2stats.sql.gz diff --git a/docker-compose.build.yml b/docker-compose.build.yml new file mode 100644 index 00000000..7674decb --- /dev/null +++ b/docker-compose.build.yml @@ -0,0 +1,15 @@ +# This is a docker compose override file, for development builds with caching for CI environments +services: + asp-nginx: + build: + cache_from: + - type=local,src=/tmp/.buildx-cache-web + cache_to: + - type=local,dest=/tmp/.buildx-cache-web,mode=max + + asp-php: + build: + cache_from: + - type=local,src=/tmp/.buildx-cache-php + cache_to: + - type=local,dest=/tmp/.buildx-cache-php,mode=max diff --git a/docker-compose.yml b/docker-compose.yml index bb9d871f..eac55880 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -49,9 +49,12 @@ services: chown -R 999:999 /var/lib/mysql asp-nginx: - image: nginx:1.21-alpine + build: + dockerfile: Dockerfile.nginx + context: . + target: dev volumes: - - ./src:/src + - ./src:/src:ro - ./config/ASP/nginx/nginx.conf:/etc/nginx/nginx.conf:ro ports: - 8081:80 @@ -63,16 +66,17 @@ services: asp-php: build: - dockerfile: Dockerfile.php.dev + dockerfile: Dockerfile.php context: . + target: dev volumes: - ./src:/src - ./config/ASP/config.php:/src/ASP/system/config/config.php # Main config file. Must be writeable or else ASP will throw an exception. Customize as needed # - ./config/ASP/armyAbbreviationMap.php:/src/ASP/system/config/armyAbbreviationMap.php:ro # Optional: Customize as needed if using a custom mod # - ./config/ASP/backendAwards.php:/src/ASP/system/config/backendAwards.php:ro # Optional: Customize as needed if using a custom mod # - ./config/ASP/ranks.php:/src/ASP/system/config/ranks.php:ro # Optional: Customize as needed if using a custom mod - - ./config/ASP/php/conf.d/php.ini:/usr/local/etc/php/conf.d/php.ini:ro - - ./config/ASP/php-fpm.d/www.conf:/usr/local/etc/php-fpm.d/www.conf:ro + # - ./config/ASP/php/conf.d/php.ini:/usr/local/etc/php/conf.d/php.ini:ro + # - ./config/ASP/php-fpm.d/www.conf:/usr/local/etc/php-fpm.d/www.conf:ro - backups-volume:/src/ASP/system/backups # This volume is effectively unused since ASP doesn't allow DB backups for a remote DB, but mount it anyway to avoid errors. - cache-volume:/src/ASP/system/cache - logs-volume:/src/ASP/system/logs