diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ccfa5b46..9eb06d89 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -69,7 +69,7 @@ jobs: run: composer install - name: Setup the application - run: make setup + run: make db-setup env: DB_PORT: ${{ job.services.postgres.ports[5432] }} diff --git a/Makefile b/Makefile index d33c981c..938244f8 100644 --- a/Makefile +++ b/Makefile @@ -16,87 +16,110 @@ else CLI = ./docker/bin/cli endif -ifndef COVERAGE - COVERAGE = --coverage-html ./coverage -endif - -ifdef FILTER - PHPUNIT_FILTER = --filter=$(FILTER) -else - PHPUNIT_FILTER = -endif - -ifdef FILE - PHPUNIT_FILE = $(FILE) -else - PHPUNIT_FILE = ./tests -endif - .PHONY: docker-start -docker-start: .env ## Start a development server with Docker - @echo "Running webserver on http://localhost:8000" +docker-start: PORT ?= 8000 +docker-start: .env ## Start a development server (can take a PORT argument) + @echo "Running webserver on http://localhost:$(PORT)" $(DOCKER_COMPOSE) up -.PHONY: docker-clean -docker-clean: ## Stop and clean Docker server - $(DOCKER_COMPOSE) down - .PHONY: docker-build docker-build: ## Rebuild the Docker images - $(DOCKER_COMPOSE) build + $(DOCKER_COMPOSE) build --pull + +.PHONY: docker-pull +docker-pull: ## Pull the Docker images from the Docker Hub + $(DOCKER_COMPOSE) pull --ignore-buildable + +.PHONY: docker-clean +docker-clean: ## Clean the Docker stuff + $(DOCKER_COMPOSE) down -v .PHONY: install -install: ## Install the dependencies +install: INSTALLER ?= all +install: ## Install the dependencies (can take an INSTALLER argument) +ifeq ($(INSTALLER), $(filter $(INSTALLER), all composer)) $(COMPOSER) install +endif +ifeq ($(INSTALLER), $(filter $(INSTALLER), all npm)) $(NPM) install +endif -.PHONY: setup -setup: .env ## Setup the application system +.PHONY: db-setup +db-setup: .env ## Setup and migrate the application system $(CLI) migrations setup --seed -.PHONY: rollback -rollback: ## Reverse the last migration +.PHONY: db-rollback +db-rollback: ## Reverse the last migration (can take a STEPS argument) ifdef STEPS $(CLI) migrations rollback --steps=$(STEPS) else $(CLI) migrations rollback endif -.PHONY: reset -reset: ## Reset the database +.PHONY: db-reset +db-reset: ## Reset the database (take a FORCE argument) ifndef FORCE $(error Please run the operation with FORCE=true) endif +ifndef NO_DOCKER $(DOCKER_COMPOSE) stop job_worker +endif $(CLI) migrations reset --force --seed +ifndef NO_DOCKER $(DOCKER_COMPOSE) start job_worker +endif -.PHONY: icons-build -icons-build: ## Build the icons asset +.PHONY: icons +icons: ## Build the icons asset $(NPM) run build:icons .PHONY: test -test: ## Run the test suite +test: FILE ?= ./tests +ifdef FILTER +test: override FILTER := --filter=$(FILTER) +endif +test: COVERAGE ?= --coverage-html ./coverage +test: ## Run the test suite (can take FILE, FILTER and COVERAGE arguments) $(PHP) ./vendor/bin/phpunit \ -c .phpunit.xml \ $(COVERAGE) \ - $(PHPUNIT_FILTER) \ - $(PHPUNIT_FILE) + $(FILTER) \ + $(FILE) .PHONY: lint -lint: ## Run the linters on the PHP and JS files +lint: LINTER ?= all +lint: ## Execute the linters (can take a LINTER argument) +ifeq ($(LINTER), $(filter $(LINTER), all phpstan)) $(PHP) vendor/bin/phpstan analyse --memory-limit 1G -c .phpstan.neon +endif +ifeq ($(LINTER), $(filter $(LINTER), all rector)) $(PHP) vendor/bin/rector process --dry-run --config .rector.php +endif +ifeq ($(LINTER), $(filter $(LINTER), all phpcs)) $(PHP) vendor/bin/phpcs +endif +ifeq ($(LINTER), $(filter $(LINTER), all js)) $(NPM) run lint-js +endif +ifeq ($(LINTER), $(filter $(LINTER), all css)) $(NPM) run lint-css +endif .PHONY: lint-fix -lint-fix: ## Fix the errors detected by the linters +lint-fix: LINTER ?= all +lint-fix: ## Fix the errors detected by the linters (can take a LINTER argument) +ifeq ($(LINTER), $(filter $(LINTER), all rector)) $(PHP) vendor/bin/rector process --config .rector.php +endif +ifeq ($(LINTER), $(filter $(LINTER), all phpcs)) $(PHP) vendor/bin/phpcbf +endif +ifeq ($(LINTER), $(filter $(LINTER), all js)) $(NPM) run lint-js-fix +endif +ifeq ($(LINTER), $(filter $(LINTER), all css)) $(NPM) run lint-css-fix +endif .PHONY: release release: ## Release a new version (take a VERSION argument) diff --git a/docker/development/docker-compose.yml b/docker/development/docker-compose.yml index 6641f127..bbcdecf2 100644 --- a/docker/development/docker-compose.yml +++ b/docker/development/docker-compose.yml @@ -31,7 +31,7 @@ services: image: nginx:alpine restart: unless-stopped ports: - - "8000:8000" + - "${PORT:-8000}:8000" - "8001:8001" volumes: - ../..:/var/www/html:z diff --git a/docs/development.md b/docs/development.md index 0ac55d51..471f248d 100644 --- a/docs/development.md +++ b/docs/development.md @@ -34,6 +34,13 @@ Once this is done, you should start the services: $ make docker-start ``` +> [!TIP] +> You can change the port of the application by passing the `PORT` parameter: +> +> ```console +> $ make docker-start PORT=9000 +> ``` + This command calls `docker compose` with the file under the `docker/development` folder. The first time you call it, it will download the Docker images and build the `php` one with the information from the `docker/development/Dockerfile.php` file. @@ -41,7 +48,7 @@ The first time you call it, it will download the Docker images and build the The last step is to setup the environment with: ```console -$ make setup +$ make db-setup ``` It will copy the `env.sample` file to `.env` and call the Flus CLI to @@ -101,7 +108,7 @@ You should now install the dependencies and setup the database with: ```console $ export NO_DOCKER=true # tell the `make` commands to use native commands $ make install -$ make setup +$ make db-setup ``` You’re all good now, just start a PHP development server: diff --git a/docs/production.md b/docs/production.md index 782d96cd..997598b1 100644 --- a/docs/production.md +++ b/docs/production.md @@ -87,8 +87,6 @@ You must now load the SQL schema to your database. You can do it with: ```console flus# sudo -u www-data php cli migrations setup --seed -flus# # OR via make -flus# sudo -u www-data make setup NO_DOCKER=true ``` If the permissions are correct, you should have a message to tell you the diff --git a/docs/update.md b/docs/update.md index 8ca25b02..542c919c 100644 --- a/docs/update.md +++ b/docs/update.md @@ -34,7 +34,10 @@ flus# chown -R www-data:www-data . Then, apply the migrations and load seeds with: ```console -flus$ sudo -u www-data make setup NO_DOCKER=true +flus$ # In production +flus# sudo -u www-data php cli migrations setup --seed +flus$ # In development +flus$ make db-setup ``` Finally, you might need to restart PHP and the job worker so it detects @@ -59,7 +62,7 @@ If at any time something goes wrong and you need to reset the application to its previous state, you should start by reverse the migrations with: ```console -flus$ sudo -u www-data make rollback STEP=1 NO_DOCKER=true +flus$ sudo -u www-data php cli migrations rollback --steps=1 ``` You can increase `STEP` to rollback more migrations (its default value is `1` @@ -72,7 +75,7 @@ flus$ git checkout PREVIOUS_TAG If something goes really wrong with the database, you can use the joker command: ```console -flus$ sudo -u www-data make reset FORCE=true +flus$ make db-reset FORCE=true ``` It will reset the database and reload the schema. **Note this command doesn't