Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
veteran29 committed Oct 21, 2023
2 parents a3e4c42 + 340df3c commit 0c2a22f
Show file tree
Hide file tree
Showing 375 changed files with 15,592 additions and 15,864 deletions.
88 changes: 35 additions & 53 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
# the different stages of this Dockerfile are meant to be built into separate images
# https://docs.docker.com/compose/compose-file/#target

ARG PHP_VERSION=8.0
ARG PHP_VERSION=8.2
ARG NGINX_VERSION=1.17

# Build assets in disposable node image
FROM node:11-alpine as armaforces_web_assets
FROM node:18-alpine as armaforces_web_assets

WORKDIR /tmp/app_build

COPY package.json package-lock.json webpack.config.js ./
COPY --link package.json package-lock.json webpack.config.js ./
RUN npm install

WORKDIR /tmp/app_build/assets/

COPY assets ./
COPY --link assets ./
RUN npm run build:ci


# Build PHP application image
FROM php:${PHP_VERSION}-fpm-alpine AS armaforces_web_php

# build for production
ENV APP_ENV=prod

WORKDIR /www/app

# php extensions installer: https://github.com/mlocati/docker-php-extension-installer
COPY --from=mlocati/php-extension-installer --link /usr/bin/install-php-extensions /usr/local/bin/

# persistent / runtime deps
RUN apk add --no-cache \
acl \
fcgi \
Expand All @@ -29,62 +38,33 @@ RUN apk add --no-cache \
git \
;

ARG APCU_VERSION=5.1.18
RUN set -eux; \
apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
icu-dev \
libzip-dev \
zlib-dev \
; \
\
docker-php-ext-configure zip; \
docker-php-ext-install -j$(nproc) \
install-php-extensions \
intl \
zip \
pdo_mysql \
; \
pecl install \
apcu-${APCU_VERSION} \
; \
pecl clear-cache; \
docker-php-ext-enable \
apcu \
opcache \
; \
\
runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)"; \
apk add --no-cache --virtual .api-phpexts-rundeps $runDeps; \
\
apk del .build-deps \
;

COPY --from=composer/composer:2-bin /composer /usr/bin/composer
RUN ln -s $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini
COPY .docker/php/conf.d/armaforces-web.ini $PHP_INI_DIR/conf.d/armaforces-web.ini
pdo_pgsql \
;

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
COPY --link .docker/php/conf.d/armaforces-web.ini $PHP_INI_DIR/conf.d/
COPY --link .docker/php/conf.d/armaforces-web.prod.ini $PHP_INI_DIR/conf.d/

# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV PATH="${PATH}:/root/.composer/vendor/bin"

WORKDIR /www/app

# build for production
ARG APP_ENV=prod
COPY --from=composer/composer:2-bin --link /composer /usr/bin/composer

# prevent the reinstallation of vendors at every changes in the source code
COPY composer.json composer.lock symfony.lock .env ./
RUN set -eux; \
composer install --prefer-dist --no-dev --no-scripts --no-progress --no-suggest; \
composer install --prefer-dist --no-dev --no-scripts --no-progress; \
composer clear-cache

# copy only specifically what we need
COPY bin bin/
COPY --link bin bin/
COPY config config/
COPY migrations migrations/
COPY public public/
Expand All @@ -97,12 +77,11 @@ RUN set -eux; \
composer dump-autoload --classmap-authoritative --no-dev; \
composer run-script --no-dev post-install-cmd; \
chmod +x bin/console; sync
VOLUME /www/app/var

# copy assets manifests
COPY --from=armaforces_web_assets /tmp/app_build/public/build/ public/build/

COPY .docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
COPY --link .docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint

# .env is copied again as COPY needs to copy at least one file
Expand All @@ -129,20 +108,23 @@ CMD ["nginx", "-g", "daemon off;"]

FROM armaforces_web_php AS armaforces_web_php_dev

ARG XDEBUG_VERSION=3.1.1
ENV APP_ENV=dev
#VOLUME /www/app/var/

RUN rm $PHP_INI_DIR/conf.d/app.prod.ini; \
mv "$PHP_INI_DIR/php.ini" "$PHP_INI_DIR/php.ini-production"; \
mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

RUN set -eux; \
apk add --no-cache --virtual .build-deps $PHPIZE_DEPS; \
pecl install xdebug-$XDEBUG_VERSION; \
docker-php-ext-enable xdebug; \
apk del .build-deps
install-php-extensions xdebug

RUN apk add --no-cache \
nodejs \
npm

ENV XDEBUG_INI_PATH=$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini
COPY .docker/php/conf.d/docker-php-ext-xdebug.ini $XDEBUG_INI_PATH
COPY --link .docker/php/conf.d/docker-php-ext-xdebug.ini $XDEBUG_INI_PATH

COPY .docker/php/scripts/xon.sh /usr/bin/xon
COPY .docker/php/scripts/xoff.sh /usr/bin/xoff
COPY --link .docker/php/scripts/xon.sh /usr/bin/xon
COPY --link .docker/php/scripts/xoff.sh /usr/bin/xoff
RUN chmod +x /usr/bin/xon /usr/bin/xoff
5 changes: 0 additions & 5 deletions .docker/mysql/vars.env

This file was deleted.

3 changes: 3 additions & 0 deletions .docker/pgsql/vars.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POSTGRES_DB=af_website
POSTGRES_USER=user
POSTGRES_PASSWORD=password
17 changes: 9 additions & 8 deletions .docker/php/conf.d/armaforces-web.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Borrowed from https://github.com/api-platform/api-platform/blob/master/api/docker/php/conf.d/api-platform.ini

apc.enable_cli = 1
# Borrowed from https://github.com/api-platform/api-platform/blob/6ddd494ccec4dc5d0329c1ded75101e58b8747e4/api/docker/php/conf.d/app.ini
expose_php = 0
date.timezone = Europe/Warsaw
session.auto_start = Off
short_open_tag = Off
apc.enable_cli = 1
session.use_strict_mode = 1
zend.detect_unicode = 0

# http://symfony.com/doc/current/performance.html
; https://symfony.com/doc/current/performance.html
realpath_cache_size = 4096K
realpath_cache_ttl = 600
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 20000
opcache.memory_consumption = 256
realpath_cache_size = 4096K
realpath_cache_ttl = 600
opcache.enable_file_override = 1
2 changes: 2 additions & 0 deletions .docker/php/conf.d/armaforces-web.prod.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
;opcache.preload_user = www-data
;opcache.preload = /www/app/config/preload.php
12 changes: 5 additions & 7 deletions .docker/php/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ if [ "${1#-}" != "$1" ]; then
fi

if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
PHP_INI_RECOMMENDED="$PHP_INI_DIR/php.ini-production"
if [ "$APP_ENV" != 'prod' ]; then
PHP_INI_RECOMMENDED="$PHP_INI_DIR/php.ini-development"
fi
ln -sf "$PHP_INI_RECOMMENDED" "$PHP_INI_DIR/php.ini"

mkdir -p var/cache var/log
setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var || true
setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var || true

if [ "$APP_ENV" = 'dev' ]; then
composer install --prefer-dist --no-progress --no-interaction || true
fi

if [ "$APP_ENV" = 'prod' ]; then
php bin/console doctrine:migrations:migrate --allow-no-migration --no-interaction
fi

fi

exec docker-php-entrypoint "$@"
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
# https://symfony.com/doc/current/configuration/secrets.html
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
Expand Down Expand Up @@ -40,7 +41,7 @@ APP_SECRET=3c0e1589d36f2c28609e4ec5af60f545
###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
DATABASE_URL=mysql://root@mysql:3306/af_website?serverVersion=5.7
DATABASE_URL="postgresql://user:password@pgsql:5432/af_website?serverVersion=16&charset=utf8"
###< doctrine/doctrine-bundle ###

###> symfony/mailer ###
Expand Down
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots

APP_SECURITY_OAUTH_DISCORD_SERVER_ID=1
APP_SECURITY_OAUTH_DISCORD_SERVER_ID=

APP_SECURITY_API_ALLOWED_KEYS=test_key

Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,28 @@ jobs:
- name: Start stack
run: |
docker-compose -f docker-compose.test.yml up -d
docker-compose exec -T php composer install
docker compose -f docker-compose.test.yml up --wait
docker compose exec -T php composer install
- name: Setup database
run: |
make db env=test
- name: Run lint
run: |
docker-compose exec -T php bin/console cache:warmup --env=dev
docker compose exec -T php bin/console cache:warmup --env=dev
make cs env=test ci=true
- name: Run tests
run: |
make test-ci
- name: Failure logs
if: failure()
run: |
docker compose logs php
docker compose logs mysql
docker_release:
name: Docker release
runs-on: ubuntu-latest
Expand Down
15 changes: 8 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/.idea
/VERSION
# IDEs
.idea

/VERSION
fos_js_routes.js
public/img/background

Expand All @@ -14,16 +15,16 @@ public/img/background
/vendor/
###< symfony/framework-bundle ###

###> symfony/phpunit-bridge ###
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###

###> phpunit/phpunit ###
/phpunit.xml
.phpunit.result.cache
###< phpunit/phpunit ###

###> symfony/phpunit-bridge ###
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###

###> symfony/webpack-encore-bundle ###
/node_modules/
/public/build/
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cs:
docker-compose exec -T php php vendor/bin/php-cs-fixer fix ${dryrun}
docker-compose exec -T php php vendor/bin/phpstan analyse --memory-limit 512M

docker-compose exec -T php php tests/tests_namespace_checker.php
docker-compose exec -T php php bin/console lint:twig templates/
docker-compose exec -T php php bin/console lint:yaml --parse-tags config/
docker-compose exec -T php php bin/console doctrine:schema:validate --env=${env}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<img src="https://img.shields.io/badge/License-GPLv3-red.svg" alt="ArmaForces Website">
</a>
<a href="https://github.com/ArmaForces/Website/actions">
<img src="https://github.com/ArmaForces/Website/workflows/Tests/badge.svg">
<img src="https://github.com/ArmaForces/Website/actions/workflows/application.yml/badge.svg?branch=dev">
</a>
</p>

Expand Down
Loading

0 comments on commit 0c2a22f

Please sign in to comment.