diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..8fce60300 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +data/ diff --git a/.env.dist b/.env.dist index 810072f9a..ccbb0bfdd 100644 --- a/.env.dist +++ b/.env.dist @@ -1,7 +1,3 @@ -## Options to pass to `docker compose up` command -#DOCKER_UP_OPTIONS= -d # -d will launch container in detached mode -#ENABLE_XDEBUG=true # enable the PHP xDebug extension - ## App configuration DATABASE_HOST=db DATABASE_PORT=3306 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d6dce7af..9eee9c169 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,7 +62,7 @@ jobs: composer-options: "--no-scripts" - name: PHPStan - run: make phpstan + run: ./bin/phpstan --memory-limit=-1 functional: name: "Functional tests" @@ -77,16 +77,23 @@ jobs: key: | docker-${{ runner.os }}-${{ hashFiles( 'compose.yml', - 'docker/dockerfiles/apachephp/Dockerfile', - 'docker/dockerfiles/mysql/Dockerfile', - 'docker/dockerfiles/mysqltest/Dockerfile' + 'docker/apachephp/Dockerfile', + 'docker/mysql/dev/Dockerfile', + 'docker/mysql/test/Dockerfile' ) }} - - name: Delete symfony cache - run: rm -rf var/cache/test - - name: Tests - Functional - run: make test-functional + run: | + make init-file + make init-folder + docker compose up -d + docker compose exec --user localUser apachephp composer install --no-scripts + docker compose run --rm node bash -c "npm install --legacy-peer-deps && npm run build" + cat ./.docker/mysql/reset-db.sql | docker compose run -T --rm db /opt/mysql_no_db + docker compose exec --user localUser apachephptest php bin/phinx migrate + docker compose exec --user localUser apachephptest php bin/phinx seed:run + docker compose exec --user localUser apachephptest ./bin/behat + cat var/logs/test.deprecations.log | cut -d "]" -f 2 | awk '{$$1=$$1};1' | sort | uniq -c | sort -nr > var/logs/test.deprecations_grouped.log - uses: actions/upload-artifact@v4 with: @@ -111,16 +118,15 @@ jobs: key: | docker-${{ runner.os }}-${{ hashFiles( 'compose.yml', - 'docker/dockerfiles/apachephp/Dockerfile', - 'docker/dockerfiles/mysql/Dockerfile', - 'docker/dockerfiles/mysqltest/Dockerfile' + 'docker/apachephp/Dockerfile', + 'docker/mysql/dev/Dockerfile', + 'docker/mysql/test/Dockerfile' ) }} - - name: Delete symfony cache - run: rm -rf var/cache/test - - name: Tests - Integration - run: make test-integration-ci + run: | + make init-file + make test-integration-ci rector: name: "Rector" @@ -139,4 +145,4 @@ jobs: composer-options: "--no-scripts" - name: Rector - run: make rector + run: ./bin/rector --dry-run diff --git a/.gitignore b/.gitignore index 396d7e6e2..b11691c14 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,10 @@ +###> env file ### .env +###> docker file ### +docker.env.local +docker/data/history + deps.lock .idea # OS X @@ -26,6 +31,8 @@ node_modules /htdocs/assets /htdocs/templates/site/css/styles.css +# File generated by tests +/htdocs/pages/administration/avatar1.png js_dist # uploads /htdocs/uploads diff --git a/Makefile b/Makefile index e2a4492c1..6b78711d9 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,6 @@ --include .env default: help # Variables -CURRENT_UID ?= $(shell id -u) -DOCKER_UP_OPTIONS ?= DOCKER_COMPOSE_BIN ?= docker compose # Colors @@ -12,188 +9,149 @@ COLOR_TARGET = \033[32m COLOR_TITLE = \033[33m TEXT_BOLD = \033[1m -.PHONY: help -.SILENT: help -help: - printf "\n${COLOR_TITLE}Usage:${COLOR_RESET}\n" - printf " ${COLOR_TARGET}make${COLOR_RESET} [target]\n" - printf "\n" - awk '/^[\w\.@%-]+:/i { \ - helpMessage = match(lastLine, /^### (.*)/); \ - if (helpMessage) { \ - helpCommand = substr($$1, 0, index($$1, ":") - 1); \ - helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \ - printf " ${COLOR_TARGET}%-30s${COLOR_RESET} %s\n", helpCommand, helpMessage; \ - } \ - } \ - /^##@.+/ { \ - printf "\n${TEXT_BOLD}${COLOR_TITLE}%s${COLOR_RESET}\n", substr($$0, 5); \ - } \ - { lastLine = $$0 }' $(MAKEFILE_LIST) +##@ Setup 📜 +### Installer le projet from scratch +install: init-file init-folder + cp -n ./docker/data/history.dist ./docker/data/history && cp -n compose.override.yml-dist compose.override.yml -.PHONY: install docker-up docker-stop docker-down test hooks vendors db-seed db-migrations reset-db init console phpstan + $(DOCKER_COMPOSE_BIN) up -d --build -##@ Setup + $(DOCKER_COMPOSE_BIN) exec --user localUser apachephp composer install --no-scripts -### Installer les dépendences (composer, npm) -install: vendors + # Build les assets du projet + $(MAKE) --no-print-directory install-assets + $(MAKE) --no-print-directory build-assets -### Initialisation générale (config, bdd) -init: htdocs/uploads - make config - make init-db + # Reset la base de donnée + cat ./docker/mysql/reset-db.sql | $(DOCKER_COMPOSE_BIN) run -T --rm db /opt/mysql_no_db -##@ Docker + $(DOCKER_COMPOSE_BIN) exec --user localUser apachephp php bin/phinx migrate + $(DOCKER_COMPOSE_BIN) exec --user localUser apachephp php bin/phinx seed:run -### Démarrer les containers -docker-up: .env var/logs/.docker-build data compose.override.yml - CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) up $(DOCKER_UP_OPTIONS) +### Supprime les volumes docker, les fichiers et les dossier généré par le projet +reset: + $(DOCKER_COMPOSE_BIN) down --remove-orphans -v + rm -f ./.env -f ./docker.env.local -f ./docker/data/history -f compose.override.yml + sudo rm -rf ./var/cache/dev ./var/cache/prod ./var/cache/test ./var/logs/*.log ./vendor ./node_modules ./htdocs/bundles ./htdocs/docs ./htdocs/uploads ./htdocs/assets ./tmp -### Stopper les containers -docker-stop: - CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) stop +### Reinstalle le projet from scratch +reinstall: reset install -### Supprimer les containers -docker-down: - CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) down +##@ Front 💅 +### Install les assets +install-assets: + $(DOCKER_COMPOSE_BIN) run --rm node npm install --legacy-peer-deps -### Démarrer un bash dans le container PHP -console: - CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) exec -u localUser -it apachephp bash +### Build les assets +build-assets: + $(DOCKER_COMPOSE_BIN) run --rm node npm run build + +### Permet de build and watch les assets +watch-assets: + $(DOCKER_COMPOSE_BIN) run --rm node npm run watch -##@ Quality +##@ Quality ✨ +### Lance toute la suite de tests +tests: cs-lint unit-test test-integration behat -### (Dans Docker) Tests unitaires -test: - ./bin/phpunit --testsuite unit - ./bin/php-cs-fixer fix --dry-run -vv +### Lance les tests unitaire +unit-test: + $(DOCKER_COMPOSE_BIN) exec --user localUser apachephp ./bin/phpunit --testsuite unit -### (Dans Docker) Tests d'intégration -test-integration: - ./bin/phpunit --testsuite integration +### Tests d'intégration +test-integration: # not work + $(DOCKER_COMPOSE_BIN) exec --user localUser apachephp ./bin/phpunit --testsuite integration -### (Dans Docker) Tests fonctionnels +### Tests fonctionnels behat: - ./bin/behat + $(DOCKER_COMPOSE_BIN) exec --user localUser apachephp ./bin/behat -### (Dans Docker) PHP CS Fixer (dry run) +### PHP CS Fixer (dry run) cs-lint: - ./bin/php-cs-fixer fix --dry-run -vv + $(DOCKER_COMPOSE_BIN) exec --user localUser apachephp ./bin/php-cs-fixer fix --dry-run -vv -### (Dans Docker) PHP CS Fixer (fix) +### PHP CS Fixer (fix) cs-fix: - ./bin/php-cs-fixer fix -vv + $(DOCKER_COMPOSE_BIN) exec --user localUser apachephp ./bin/php-cs-fixer fix -vv -### (Dans Docker) Rector (dry run) +### Rector (dry run) rector: var/cache/dev/AppKernelDevDebugContainer.xml - ./bin/rector --dry-run + $(DOCKER_COMPOSE_BIN) exec --user localUser apachephp ./bin/rector --dry-run -### (Dans Docker) Rector (fix) +### Rector (fix) rector-fix: var/cache/dev/AppKernelDevDebugContainer.xml - ./bin/rector + $(DOCKER_COMPOSE_BIN) exec --user localUser apachephp ./bin/rector ### Tests fonctionnels -test-functional: data config htdocs/uploads tmp - CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) stop dbtest apachephptest mailcatcher - CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) up -d dbtest apachephptest mailcatcher - make clean-test-deprecated-log - CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) run --no-deps --rm -u localUser apachephp ./bin/behat - make var/logs/test.deprecations_grouped.log - CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) stop dbtest apachephptest mailcatcher +test-functional: + $(DOCKER_COMPOSE_BIN) stop dbtest apachephptest mailcatcher + $(DOCKER_COMPOSE_BIN) up -d dbtest apachephptest mailcatcher + $(DOCKER_COMPOSE_BIN) exec -u localUser apachephptest bash -c "rm -f /var/www/html/var/logs/test.deprecations.log" + $(DOCKER_COMPOSE_BIN) exec -u localUser apachephp ./bin/behat + cat var/logs/test.deprecations.log | cut -d "]" -f 2 | awk '{$$1=$$1};1' | sort | uniq -c | sort -nr > var/logs/test.deprecations_grouped.log + $(DOCKER_COMPOSE_BIN) stop dbtest apachephptest mailcatcher ### Tests d'intégration avec start/stop des images docker test-integration-ci: - CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) stop dbtest apachephptest - CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) up -d dbtest apachephptest - CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) run --no-deps --rm -u localUser apachephp make vendor - CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) run --no-deps --rm -u localUser apachephp ./bin/phpunit --testsuite integration - CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) stop dbtest apachephptest + $(DOCKER_COMPOSE_BIN) stop dbtest apachephptest + $(DOCKER_COMPOSE_BIN) up -d dbtest apachephptest apachephp + $(DOCKER_COMPOSE_BIN) exec -u localUser apachephp composer install --no-scripts + $(DOCKER_COMPOSE_BIN) exec -u localUser apachephp ./bin/phpunit --testsuite integration + $(DOCKER_COMPOSE_BIN) stop dbtest apachephptest -### (Dans Docker) Analyse PHPStan +### Analyse PHPStan phpstan: - ./bin/phpstan --memory-limit=-1 + $(DOCKER_COMPOSE_BIN) exec -u localUser apachephp ./bin/phpstan --memory-limit=-1 -##@ Frontend +##@ Docker 🐳 +### Démarrer un bash dans le container PHP +console: + $(DOCKER_COMPOSE_BIN) exec -u localUser apachephp bash -### Compiler les assets pour la production -.PHONY: assets -assets: - ./node_modules/.bin/webpack -p +##@ Git (En dehors du docker) 🔀 +### Mise en place de git hooks +hooks: pre-commit post-checkout -### Lancer le watcher pour les assets -watch: - ./node_modules/.bin/webpack --progress --colors --watch +help: + printf "\n${COLOR_TITLE}Usage:${COLOR_RESET}\n" + printf " ${COLOR_TARGET}make${COLOR_RESET} [target]\n" + printf "\n" + awk '/^[\w\.@%-]+:/i { \ + helpMessage = match(lastLine, /^### (.*)/); \ + if (helpMessage) { \ + helpCommand = substr($$1, 0, index($$1, ":") - 1); \ + helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \ + printf " ${COLOR_TARGET}%-30s${COLOR_RESET} %s\n", helpCommand, helpMessage; \ + } \ + } \ + /^##@.+/ { \ + printf "\n${TEXT_BOLD}${COLOR_TITLE}%s${COLOR_RESET}\n", substr($$0, 5); \ + } \ + { lastLine = $$0 }' $(MAKEFILE_LIST) -##@ Git +.PHONY: install tests hooks console phpstan help +.SILENT: help -### Mise en place de hooks -hooks: .git/hooks/pre-commit .git/hooks/post-checkout +## Target only used by other make command +# Used by "rector" target +var/cache/dev/AppKernelDevDebugContainer.xml: + $(DOCKER_COMPOSE_BIN) exec --user localUser apachephp bin/console cache:warmup --env=dev -.git/hooks/pre-commit: Makefile +# Used by "hooks" target +pre-commit: echo "#!/bin/sh" > .git/hooks/pre-commit echo "docker compose run --rm -u localUser apachephp make test" >> .git/hooks/pre-commit chmod +x .git/hooks/pre-commit -.git/hooks/post-checkout: Makefile +post-checkout: echo "#!/bin/sh" > .git/hooks/post-checkout - echo "docker compose run --rm -u localUser apachephp make vendor" >> .git/hooks/post-checkout + echo "docker compose run --rm -u localUser apachephp composer install --no-scripts" >> .git/hooks/post-checkout chmod +x .git/hooks/post-checkout +# Used by CI and "install" target +init-file: + cp -n .env.dist .env && cp -n docker.env docker.env.local -## Targets cachés - -var/logs/.docker-build: compose.yml compose.override.yml $(shell find docker -type f) - CURRENT_UID=$(CURRENT_UID) ENABLE_XDEBUG=$(ENABLE_XDEBUG) $(DOCKER_COMPOSE_BIN) build - touch var/logs/.docker-build - -.env: - cp .env.dist .env - -compose.override.yml: - cp compose.override.yml-dist compose.override.yml - -vendors: vendor node_modules - -vendor: composer.lock - composer install --no-scripts - -node_modules: - npm install --legacy-peer-deps - -init-db: - make reset-db - CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) run --rm -u localUser apachephp make db-migrations - CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) run --rm -u localUser apachephp make db-seed - -config: - CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) run --no-deps --rm -u localUser apachephp make vendors - CURRENT_UID=$(CURRENT_UID) $(DOCKER_COMPOSE_BIN) run --no-deps --rm -u localUser apachephp make assets - -data: - mkdir data - mkdir data/composer - -htdocs/uploads: - mkdir htdocs/uploads - -tmp: - mkdir -p tmp - -reset-db: - echo 'DROP DATABASE IF EXISTS web' | $(DOCKER_COMPOSE_BIN) run -T --rm db /opt/mysql_no_db - echo 'CREATE DATABASE web' | $(DOCKER_COMPOSE_BIN) run -T --rm db /opt/mysql_no_db - -db-migrations: - php bin/phinx migrate - -db-seed: - php bin/phinx seed:run - -clean-test-deprecated-log: - rm -f var/logs/test.deprecations.log - -var/logs/test.deprecations_grouped.log: - cat var/logs/test.deprecations.log | cut -d "]" -f 2 | awk '{$$1=$$1};1' | sort | uniq -c | sort -nr > var/logs/test.deprecations_grouped.log - -var/cache/dev/AppKernelDevDebugContainer.xml: - php bin/console cache:warmup --env=dev +# Used by CI and "install" target +init-folder: + mkdir -p ./htdocs/uploads -p ./tmp diff --git a/compose.override.yml-dist b/compose.override.yml-dist index 9729907ed..063bb9b86 100644 --- a/compose.override.yml-dist +++ b/compose.override.yml-dist @@ -5,8 +5,6 @@ services: apachephp: ports: - "9205:80" - # environment: - # XDEBUG_CONFIG: "remote_connect_back=1 profiler_enable=1 remote_autostart=0 remote_enable=1" mailcatcher: ports: - "1181:1080" diff --git a/compose.yml b/compose.yml index 3b0990e04..d9ef3085c 100644 --- a/compose.yml +++ b/compose.yml @@ -1,7 +1,28 @@ -# version 1.1 services: + apachephp: + build: + context: ./docker/apachephp + target: afup_web_dev + container_name: afup-web-apachephp + environment: + SYMFONY_ENV: "dev" + env_file: + - docker.env + - docker.env.local + - .env + volumes: + - ./:/var/www/html + # Permet d'avoir un bash history ainsi que des alias bash quand on est dans le container + - ./docker/config/bashrc:/home/localUser/.bashrc + - ./docker/config/bash_aliases:/home/localUser/.bash_aliases + - ./docker/data/history:/home/localUser/.bash_history + depends_on: + - db + - mailcatcher + db: - build: ./docker/dockerfiles/mysql + build: ./docker/mysql/dev + container_name: afup-web-db environment: MYSQL_ROOT_PASSWORD: root MYSQL_USER: afup @@ -10,8 +31,21 @@ services: volumes: - ./data/mysql:/var/lib/mysql + mailcatcher: + image: dockage/mailcatcher:0.9.0 + container_name: afup-web-mailcatcher + + node: + image: node:22.15-bookworm + container_name: afup-web-node + working_dir: /var/www/html + volumes: + - ./:/var/www/html + profiles: [front] # Avec ce paramètre node n'est pas lancé quand on docker compose up + dbtest: - build: ./docker/dockerfiles/mysqltest + build: ./docker/mysql/test + container_name: afup-web-db-test environment: MYSQL_ROOT_PASSWORD: root MYSQL_USER: afup @@ -24,42 +58,25 @@ services: timeout: 20s retries: 10 - apachephp: - build: - context: ./docker/dockerfiles/apachephp - args: - uid: ${CURRENT_UID:-1001} - gid: "1001" - ENABLE_XDEBUG: ${ENABLE_XDEBUG:-false} - environment: - SYMFONY_ENV: "dev" - HOST_PWD: ${PWD} - SYMFONY_IDE: "%env(IDE_USED)%://open?url=file://%%f&line=%%l&/var/www/html/>%env(HOST_PWD)%/" - env_file: - .env - volumes: - - ./:/var/www/html - links: - - db - - mailcatcher - apachephptest: build: - context: ./docker/dockerfiles/apachephp - args: - uid: ${CURRENT_UID:-1001} - gid: "1001" - ENABLE_XDEBUG: ${ENABLE_XDEBUG:-false} + context: ./docker/apachephp + target: afup_web_dev + container_name: afup-web-apachephp-test environment: SYMFONY_ENV: "test" HOST_PWD: ${PWD} SYMFONY_IDE: "%env(IDE_USED)%://open?url=file://%%f&line=%%l&/var/www/html/>%env(HOST_PWD)%/" env_file: - .env + - docker.env + - docker.env.local + - .env volumes: - ./:/var/www/html - links: - - statictestresources + # Permet d'avoir un bash history ainsi que des alias bash quand on est dans le container + - ./docker/config/bashrc:/localUser/.bashrc + - ./docker/config/bash_aliases:/localUser/.bash_aliases + - ./docker/data/history:/localUser/.bash_history healthcheck: test: [ "CMD", "curl", "-f", "https://apachephptest:80" ] interval: 30s @@ -68,11 +85,11 @@ services: depends_on: dbtest: condition: service_healthy - - mailcatcher: - image: dockage/mailcatcher:0.9.0 + statictestresources: + condition: service_started statictestresources: image: nginx:1.25.4 + container_name: afup-web-static volumes: - - ./docker/dockerfiles/statictestresources:/usr/share/nginx/html:ro + - ./docker/data/test/static-resources:/usr/share/nginx/html:ro diff --git a/doc/dev-setup.md b/doc/dev-setup.md index 82b449a81..24dcffd03 100644 --- a/doc/dev-setup.md +++ b/doc/dev-setup.md @@ -36,8 +36,7 @@ Ce document contient des instructions sur la mise en place d'une instance de dé git clone https://github.com/my-account/afup-web.git ``` -3. Lancer `make docker-up` pour lancer le projet -4. Lancer `make init` pour le setup initial (config, dépendances, base de données) +3. Lancer `make install` pour lancer le projet Le site devrait maintenant être accessible en local : @@ -52,7 +51,7 @@ La base de test inclus un utilisateur administration avec les identifiants suiva Plusieurs possibilités de configuration des containers sont disponibles, via l'utilisation de variables d'environnement. -Pour faciliter leur configuration, un fichier `.env` est créé à la racine du projet à la première exécution de la commande `make docker-up`. +Pour faciliter leur configuration, un fichier `.env` est créé à la racine du projet à la première exécution de la commande `make install`. Ce fichier contient la liste des options disponibles. ### Options Docker @@ -61,8 +60,6 @@ Le fichier `compose.override.yml` est créé automatiquement à l'installation d Par exemple, les ports utilisés pour le site et mailcatcher peuvent être modifiés dans ce fichier. -La variable d'environnement `DOCKER_UP_OPTIONS` permet de passer des options à la commande `docker compose up` (via `make docker-up`). - ### Processeurs ARM Pour faire fonctionner les images des bases de données (site et tests) sur un processeur ARM (par exemple sur Mac) il @@ -102,6 +99,12 @@ Il faut se connecter au container via `make console` puis : ./bin/behat ``` +ou + +```bash +make behat +``` + > [!TIP] > Il est possible de spécifier un test dans la ligne de commande : > ```bash @@ -121,23 +124,16 @@ Si par la suite, vous souhaitez lancer un test, il faut bien penser à les allum Les tests unitaires sont écrits via PHPUnit. -Il faut se connecter au container via `make console` puis : - ```bash -./bin/phpunit --testsuite unit +make unit-test ``` -Une alternative est d'utiliser `make test` dans le container, attention cette commande -exécute également [PHP-Cs-Fixer](#php-cs-fixer). - ### Tests d'intégration Ces tests sont écrits via PHPUnit et utilisent le kernel de Symfony : https://symfony.com/doc/current/testing.html#integration-tests -Pour les lancer, il faut se connecter au container via `make console` puis : - ```bash -./bin/phpunit --testsuite integration +make test-integration ``` Une alternative est d'utiliser la commande `make test-integration`, attention cette commande arrête les containeurs de @@ -151,8 +147,6 @@ Si par la suite, vous souhaitez lancer un test, il faut bien penser à les allum Cet outil sert à s'assurer de la mise en forme du PHP. -Il faut se connecter au container via `make console` puis, - Pour afficher les erreurs : ``` make cs-lint diff --git a/doc/xdebug/img/add-config.png b/doc/xdebug/img/add-config.png new file mode 100755 index 000000000..29b11a06a Binary files /dev/null and b/doc/xdebug/img/add-config.png differ diff --git a/doc/xdebug/img/add-server.png b/doc/xdebug/img/add-server.png new file mode 100755 index 000000000..f57fc6c1a Binary files /dev/null and b/doc/xdebug/img/add-server.png differ diff --git a/doc/xdebug/img/debug-config-panel.png b/doc/xdebug/img/debug-config-panel.png new file mode 100755 index 000000000..eb096d4a3 Binary files /dev/null and b/doc/xdebug/img/debug-config-panel.png differ diff --git a/doc/xdebug/img/debug-started-bottom-panel.png b/doc/xdebug/img/debug-started-bottom-panel.png new file mode 100755 index 000000000..282f55e62 Binary files /dev/null and b/doc/xdebug/img/debug-started-bottom-panel.png differ diff --git a/doc/xdebug/img/debug-started-top.png b/doc/xdebug/img/debug-started-top.png new file mode 100755 index 000000000..26daba636 Binary files /dev/null and b/doc/xdebug/img/debug-started-top.png differ diff --git a/doc/xdebug/img/final-debug-config.png b/doc/xdebug/img/final-debug-config.png new file mode 100755 index 000000000..b1514f505 Binary files /dev/null and b/doc/xdebug/img/final-debug-config.png differ diff --git a/doc/xdebug/img/final-server-config-macos.png b/doc/xdebug/img/final-server-config-macos.png new file mode 100755 index 000000000..57207f54e Binary files /dev/null and b/doc/xdebug/img/final-server-config-macos.png differ diff --git a/doc/xdebug/img/final-server-config.png b/doc/xdebug/img/final-server-config.png new file mode 100755 index 000000000..2135cbc86 Binary files /dev/null and b/doc/xdebug/img/final-server-config.png differ diff --git a/doc/xdebug/img/setup-remote-debug-config.png b/doc/xdebug/img/setup-remote-debug-config.png new file mode 100755 index 000000000..7db96f8eb Binary files /dev/null and b/doc/xdebug/img/setup-remote-debug-config.png differ diff --git a/doc/xdebug/img/test-debug-config.png b/doc/xdebug/img/test-debug-config.png new file mode 100755 index 000000000..6d85efb79 Binary files /dev/null and b/doc/xdebug/img/test-debug-config.png differ diff --git a/doc/xdebug/xdebug.md b/doc/xdebug/xdebug.md new file mode 100755 index 000000000..b3bc08159 --- /dev/null +++ b/doc/xdebug/xdebug.md @@ -0,0 +1,68 @@ +# XDEBUG + +* [Linux](#linux) +* [MacOS](#macos) + +Here, will explain how install xdebug on Phpstorm. + +## Linux + +1. Open config panel `Run > Edit Configurations` + +![Blank Panel](img/debug-config-panel.png) + +2. Add new `PHP Remote Debug` + +![New PHP Remote Debug](img/add-config.png) + +3. Set up the new remote debug by change : + +![Setup Remote Debug](img/setup-remote-debug-config.png) + +(1) Config name, chose what you want (e.g., AFUP Web Debug) + +(2) Check `Filter debug connection by IDE Key` + +(3) Fill `IDE key (session id)` with the environment variable `XDEBUG_IDEKEY` in `docker.env.local` file (e.g `PHPSTORM`) + +(4) Create server by clicking on `...` + +4. Add new one (1) and set up with : + +(2) Server name, the value is a part of environment variable `PHP_IDE_CONFIG`. For the env value `serverName=afup-web` use `afup-web` as server name. + +(3) Use value of environment variable `LOCAL_IP` as host and `XDEBUG_PORT` as port + +![Setup Server](img/add-server.png) + +5. Check `Use path mappings` and add `/var/www/html` (The project folder in docker container) in front of project file. At the end, you need to have something like this : + +![Final Server Config](img/final-server-config.png) + +And for remote debug config, something like this : + +![Final Remote Debug](img/final-debug-config.png) + +6. To check if the configuration works in menu `Run`, `Start Listening` (1) and `Break at first line` (2) + +Don't forget to change the value of `XDEBUG_MODE` from `Off` to `debug,develop` before testing + +![Test Debug Config](img/test-debug-config.png) + +8. Then, go to a project page in your browser, and you will see the page load without end. At this moment you will see on your phpstorm you have 2 clues to know xdebug work. (fig 1, 2) + +*Fig 1* +![Debug Started Bottom Panel](img/debug-started-bottom-panel.png) + +*Fig 2* +![Debug Started Top](img/debug-started-top.png) + +:rotating_light: On your `docker.env.local` when you change a value you need to restart your docker. + +## MacOS + +1. Before follow the linux tuto, you need to replace in `docker.env.local`, the value of `LOCAL_IP` by `host.docker.internal`. +2. At the fourth step in linux tuto you need to use `PHP_IDE_CONFIG` serverName value as `Host` + +*Final server config on MacOS* +![Final Server Config MacOS](img/final-server-config-macos.png) diff --git a/docker.env b/docker.env new file mode 100644 index 000000000..9b9a625bc --- /dev/null +++ b/docker.env @@ -0,0 +1,11 @@ +# Ce fichier de variable, permet de séparer les variables utilisés sur l'app (.env) +# des variables utilisés pour le docker (docker.env(.local)) +###< docker/xdebug ### +# If you want activate xdebug need replace by "off" by "debug,develop" +XDEBUG_MODE=debug,develop +XDEBUG_PORT=9003 +XDEBUG_IDEKEY=PHPSTORM +LOCAL_IP=172.17.0.1 +SSH_AUTH_SOCK=/tmp/agent.sock +PHP_IDE_CONFIG=serverName=afup-web +### docker/xdebug >### diff --git a/docker/apachephp/Dockerfile b/docker/apachephp/Dockerfile new file mode 100644 index 000000000..49ade8992 --- /dev/null +++ b/docker/apachephp/Dockerfile @@ -0,0 +1,55 @@ +FROM php:8.2-apache AS afup_web_base + +ARG UID=1008 +ARG GID=1008 + +WORKDIR /var/www/html + +# Update package list and install system dependencies +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + acl \ + git \ + file \ + gettext \ + gosu; \ + rm -rf /var/lib/apt/lists/*; \ + # verify that the binary works + gosu nobody true; + +RUN groupadd -g ${GID} localUser && \ + useradd -l -u ${UID} -g ${GID} -m -s /bin/bash localUser && \ + usermod -a -G www-data localUser + +ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + +RUN set -eux; \ + install-php-extensions @composer-2.2.25 zip intl pdo_mysql mysqli gd opcache pcntl \ + ; + +COPY --link php/conf.d/10-app.ini $PHP_INI_DIR/conf.d/ + +COPY --link --chmod=755 php/docker-healthcheck.sh /usr/local/bin/docker-healthcheck +HEALTHCHECK --start-period=1m CMD docker-healthcheck + +COPY --link --chmod=755 php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint + +ENTRYPOINT ["docker-entrypoint"] +CMD ["apache2-foreground"] + +FROM afup_web_base AS afup_web_dev + +COPY --link php/conf.d/20-app.dev.ini $PHP_INI_DIR/conf.d/ + +RUN set -eux; \ + install-php-extensions xdebug \ + ; + +COPY --link apache/apache.conf /etc/apache2/sites-available/000-default.conf +COPY --link apache/cert/apache.crt /etc/apache2/ssl/apache.crt +COPY --link apache/cert/apache.key /etc/apache2/ssl/apache.key + +RUN sed --in-place "s/User \${APACHE_RUN_USER}/User localUser/" /etc/apache2/apache2.conf && \ + sed --in-place "s/Group \${APACHE_RUN_GROUP}/Group localUser/" /etc/apache2/apache2.conf && \ + a2ensite 000-default && \ + a2enmod rewrite ssl diff --git a/docker/dockerfiles/apachephp/apache.conf b/docker/apachephp/apache/apache.conf similarity index 100% rename from docker/dockerfiles/apachephp/apache.conf rename to docker/apachephp/apache/apache.conf diff --git a/docker/dockerfiles/apachephp/apache.crt b/docker/apachephp/apache/cert/apache.crt similarity index 100% rename from docker/dockerfiles/apachephp/apache.crt rename to docker/apachephp/apache/cert/apache.crt diff --git a/docker/dockerfiles/apachephp/apache.key b/docker/apachephp/apache/cert/apache.key similarity index 100% rename from docker/dockerfiles/apachephp/apache.key rename to docker/apachephp/apache/cert/apache.key diff --git a/docker/apachephp/php/conf.d/10-app.ini b/docker/apachephp/php/conf.d/10-app.ini new file mode 100644 index 000000000..b5c47bd47 --- /dev/null +++ b/docker/apachephp/php/conf.d/10-app.ini @@ -0,0 +1,15 @@ +apc.enable_cli = 1 +date.timezone = Europe/Paris +session.auto_start = Off +short_open_tag = Off +expose_php = 0 +upload_max_filesize = 512M +memory_limit = 128M + +# https://symfony.com/doc/current/performance.html +opcache.interned_strings_buffer = 16 +opcache.max_accelerated_files = 20000 +opcache.memory_consumption = 256 +opcache.enable_file_override = 1 +realpath_cache_size = 4096K +realpath_cache_ttl = 600 diff --git a/docker/apachephp/php/conf.d/20-app.dev.ini b/docker/apachephp/php/conf.d/20-app.dev.ini new file mode 100644 index 000000000..8ac162813 --- /dev/null +++ b/docker/apachephp/php/conf.d/20-app.dev.ini @@ -0,0 +1,9 @@ +# Env variable load via docker.env and docker.env.local +xdebug.mode="${XDEBUG_MODE}" +xdebug.max_nesting_level=256 +xdebug.discover_client_host=false +xdebug.idekey="${XDEBUG_IDEKEY}" +xdebug.start_with_request=yes +xdebug.client_port="${XDEBUG_PORT}" +xdebug.client_host="${LOCAL_IP}" +xdebug.log_level=0 diff --git a/docker/apachephp/php/docker-entrypoint.sh b/docker/apachephp/php/docker-entrypoint.sh new file mode 100644 index 000000000..8f2950dda --- /dev/null +++ b/docker/apachephp/php/docker-entrypoint.sh @@ -0,0 +1,34 @@ +#!/bin/sh +set -e + +uid=$(stat -c %u /var/www/html) +gid=$(stat -c %g /var/www/html) + +sed -i -r "s/localUser:x:[0-9]+:[0-9]+:/localUser:x:$uid:$gid:/g" /etc/passwd +sed -i -r "s/localUser:x:[0-9]+:/localUser:x:$gid:/g" /etc/group +user=$(grep ":x:$uid:" /etc/passwd | cut -d: -f1) + +# first arg is `-f` or `--some-option` +if [ "${1#-}" != "$1" ]; then + set -- apache2-foreground "$@" +fi + +if [ "$1" = 'apache2-foreground' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then + + if [ "$APP_ENV" != 'prod' ]; then + if [ -d .git ]; then + git config --global --add safe.directory /var/www/html + fi + + mkdir -p var/cache var/logs var/sessions; + fi + + setfacl -R -m u:www-data:rwX -m u:localUser:rwX var + setfacl -dR -m u:www-data:rwX -m u:localUser:rwX var +fi + +if [ "$1" = 'bash' ] || [ "$1" = 'composer' ]; then + exec gosu ${user} docker-php-entrypoint "$@" +else + exec docker-php-entrypoint "$@" +fi diff --git a/docker/apachephp/php/docker-healthcheck.sh b/docker/apachephp/php/docker-healthcheck.sh new file mode 100644 index 000000000..a8c2fa13b --- /dev/null +++ b/docker/apachephp/php/docker-healthcheck.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -e + +if [[ -z "IGNORE_HEALTHCHECK_FCGI_PING" ]]; then + if env -i REQUEST_METHOD=GET SCRIPT_NAME=/ping SCRIPT_FILENAME=/ping cgi-fcgi -bind -connect 127.0.0.1:9000; then + exit 0 + else + echo "PHP-FPM is not pingable" + + exit 1 + fi +fi + +exit 0 diff --git a/docker/config/bash_aliases b/docker/config/bash_aliases new file mode 100644 index 000000000..b6e239ec8 --- /dev/null +++ b/docker/config/bash_aliases @@ -0,0 +1,7 @@ +# Global +alias ll='ls -alh --color' +alias clean-test-deprecated-log='rm -f /var/www/html/var/logs/test.deprecations.log' +alias group-deprecation-log="touch /var/www/html/var/logs/test.deprecations_grouped.log && cat /var/www/html/var/logs/test.deprecations.log | cut -d \"]\" -f 2 | awk '{\$1=\$1};1' | sort | uniq -c | sort -nr > /var/www/html/var/logs/test.deprecations_grouped.log" + +# Symfony +alias console='php bin/console' diff --git a/docker/config/bashrc b/docker/config/bashrc new file mode 100644 index 000000000..d60e51c74 --- /dev/null +++ b/docker/config/bashrc @@ -0,0 +1,22 @@ +# If not running interactively, don't do anything +case $- in + *i*) ;; + *) return;; +esac + +# don't put duplicate lines or lines starting with space in the history. +# See bash(1) for more options +HISTCONTROL=ignoreboth + +# append to the history file, don't overwrite it +shopt -s histappend + +# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) +HISTSIZE=1000 +HISTFILESIZE=2000 + +PS1="\u@\h:\w \[\e[37m\]\\$\[\e[m\] " + +if [ -f ~/.bash_aliases ]; then + . ~/.bash_aliases +fi diff --git a/docker/data/history.dist b/docker/data/history.dist new file mode 100644 index 000000000..feb2b6c09 --- /dev/null +++ b/docker/data/history.dist @@ -0,0 +1 @@ +# Keep the command history used in container diff --git a/docker/dockerfiles/statictestresources/feed.xml b/docker/data/test/static-resources/feed.xml similarity index 100% rename from docker/dockerfiles/statictestresources/feed.xml rename to docker/data/test/static-resources/feed.xml diff --git a/docker/dockerfiles/apachephp/Dockerfile b/docker/dockerfiles/apachephp/Dockerfile deleted file mode 100644 index 1a861a74a..000000000 --- a/docker/dockerfiles/apachephp/Dockerfile +++ /dev/null @@ -1,58 +0,0 @@ -FROM php:8.2-apache - -ARG ENABLE_XDEBUG=false -ARG uid=1008 -ARG gid=1008 - -## Update system -RUN apt-get update && \ - apt-get upgrade -y && \ - apt-get autoremove --purge -y && \ - rm -rf /var/lib/apt/lists/* && \ - # Create user for Apache - groupadd -g ${gid} localUser && \ - useradd -l -u ${uid} -g ${gid} -m -s /bin/bash localUser && \ - usermod -a -G www-data localUser - -RUN if [ "$ENABLE_XDEBUG" = "true" ]; then echo ************ XDEBUG ENABLED **********; \ -else echo ------------ XDEBUG DISABLED ==========; fi - -RUN curl -sL https://deb.nodesource.com/setup_22.x | bash - - -# Install required PHP extensions for AFUP website and other management package -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - libfreetype6-dev \ - libjpeg62-turbo-dev \ - libpng-dev \ - libzip-dev \ - libmcrypt4 \ - libicu-dev \ - nodejs \ - && \ - docker-php-ext-configure gd --with-freetype --with-jpeg \ - && \ - docker-php-ext-install \ - pdo_mysql \ - mysqli \ - zip \ - gd \ - intl \ - pcntl \ - && \ - if [ "$ENABLE_XDEBUG" = "true" ]; then pecl install xdebug-3.4.2 && docker-php-ext-enable xdebug; fi && \ - apt-get autoremove --purge -y && \ - rm -rf /var/lib/apt/lists/* - -# Configuration of Apache and PHP -COPY apache.conf /etc/apache2/sites-available/000-default.conf -COPY apache.crt /etc/apache2/ssl/apache.crt -COPY apache.key /etc/apache2/ssl/apache.key -RUN sed --in-place "s/User \${APACHE_RUN_USER}/User localUser/" /etc/apache2/apache2.conf && \ - sed --in-place "s/Group \${APACHE_RUN_GROUP}/Group localUser/" /etc/apache2/apache2.conf && \ - a2ensite 000-default && \ - a2enmod rewrite ssl && \ - echo "date.timezone=Europe/Paris" >> "/usr/local/etc/php/php.ini" - -# Installing Composer -COPY --from=composer:2 /usr/bin/composer /usr/bin/composer diff --git a/docker/dockerfiles/mysql/Dockerfile b/docker/mysql/dev/Dockerfile similarity index 100% rename from docker/dockerfiles/mysql/Dockerfile rename to docker/mysql/dev/Dockerfile diff --git a/docker/dockerfiles/mysql/my.cnf b/docker/mysql/dev/my.cnf similarity index 100% rename from docker/dockerfiles/mysql/my.cnf rename to docker/mysql/dev/my.cnf diff --git a/docker/dockerfiles/mysql/mysql b/docker/mysql/dev/mysql similarity index 100% rename from docker/dockerfiles/mysql/mysql rename to docker/mysql/dev/mysql diff --git a/docker/dockerfiles/mysql/mysql_no_db b/docker/mysql/dev/mysql_no_db similarity index 100% rename from docker/dockerfiles/mysql/mysql_no_db rename to docker/mysql/dev/mysql_no_db diff --git a/docker/mysql/reset-db.sql b/docker/mysql/reset-db.sql new file mode 100644 index 000000000..1705957c9 --- /dev/null +++ b/docker/mysql/reset-db.sql @@ -0,0 +1,2 @@ +DROP DATABASE IF EXISTS web; +CREATE DATABASE web; diff --git a/docker/dockerfiles/mysqltest/Dockerfile b/docker/mysql/test/Dockerfile similarity index 100% rename from docker/dockerfiles/mysqltest/Dockerfile rename to docker/mysql/test/Dockerfile diff --git a/docker/dockerfiles/mysqltest/my.cnf b/docker/mysql/test/my.cnf similarity index 100% rename from docker/dockerfiles/mysqltest/my.cnf rename to docker/mysql/test/my.cnf diff --git a/docker/dockerfiles/mysqltest/mysql b/docker/mysql/test/mysql similarity index 100% rename from docker/dockerfiles/mysqltest/mysql rename to docker/mysql/test/mysql diff --git a/docker/dockerfiles/mysqltest/mysql_no_db b/docker/mysql/test/mysql_no_db similarity index 100% rename from docker/dockerfiles/mysqltest/mysql_no_db rename to docker/mysql/test/mysql_no_db diff --git a/docker/dockerfiles/mysqltest/reset_db b/docker/mysql/test/reset_db similarity index 100% rename from docker/dockerfiles/mysqltest/reset_db rename to docker/mysql/test/reset_db diff --git a/package.json b/package.json index e2dfe68bf..88ff93d14 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "webpack": "^3.6" }, "scripts": { - "build": "./node_modules/.bin/webpack -p" + "build": "./node_modules/.bin/webpack -p", + "watch": "./node_modules/.bin/webpack --progress --colors --watch" }, "repository": { "type": "git",