From 556c8770dab9e08c47e3fc7f7f355a2c78c014de Mon Sep 17 00:00:00 2001 From: Joao P Dubas Date: Mon, 7 Oct 2024 11:48:26 +0000 Subject: [PATCH 1/3] test: add docker compose profile to execute tests On this profile a new image is built that can handle tests locally. --- docker-compose.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 21b55ec..2ca1931 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,6 +19,7 @@ services: context: . args: BUILD_MIX_ENV: dev + pull_policy: never hostname: &app_host ex_trainer depends_on: - db @@ -53,6 +54,39 @@ services: scale: 3 entrypoint: ./priv/docker/service/docker-entrypoint.sh command: local-cookie + test: + image: 'joaodubas/ex_trainer:test' + build: + target: builder + context: . + args: + BUILD_MIX_ENV: test + pull_policy: never + profiles: + - test + hostname: ex_trainer_test + depends_on: + - db + init: true + volumes: + - './mix.exs:/opt/app/mix.exs:ro' + - './mix.lock:/opt/app/mix.lock:ro' + - './students.csv:/opt/app/students.csv:ro' + - './config:/opt/app/config' + - './cover:/opt/app/cover' + - './lib:/opt/app/lib' + - './priv:/opt/app/priv' + - './report:/opt/app/report' + - './test:/opt/app/test' + environment: + POSTGRES_HOST: *db_host + POSTGRES_USER: *db_user + POSTGRES_PASS: *db_pass + POSTGRES_NAME: wabanex_test + working_dir: /opt/app + restart: never + entrypoint: mix test + command: --trace --cover --slowest 10 volumes: db_data: {} -- 2.47.2 From 041e94edaf6ef15fdbc760375a292f28ca5d172d Mon Sep 17 00:00:00 2001 From: Joao P Dubas Date: Mon, 7 Oct 2024 11:51:06 +0000 Subject: [PATCH 2/3] test: add target to execute tests locally --- Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Makefile b/Makefile index 9e7f75f..220ebf4 100644 --- a/Makefile +++ b/Makefile @@ -55,6 +55,15 @@ compose_ps: ## status of containers compose_remote: ## connect to remote node @$(COMPOSE) exec app ./priv/docker/service/docker-remote.sh +.PHONY: compose_test +compose_test: ## execute test on docker environment + @$(COMPOSE) --profile test run --rm test + +.PHONY: compose_test_shell +compose_test_shell: ## enter test environment shell + @$(COMPOSE) --profile test run --rm --entrypoint bash test -c bash + .PHONY: help help: @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + -- 2.47.2 From 15b91c88b8271b6b244cd3cdc264aaecb12d7d45 Mon Sep 17 00:00:00 2001 From: Joao P Dubas Date: Mon, 7 Oct 2024 11:51:33 +0000 Subject: [PATCH 3/3] chore: reorder targets alphabetically --- Makefile | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 220ebf4..9034144 100644 --- a/Makefile +++ b/Makefile @@ -28,14 +28,6 @@ static_code_analysis: check_format credo dialyzer ## run static code analysis test: ## run tests @mix test --cover --trace --slowest 10 -.PHONY: compose_up -compose_up: ## start containers for this service - @$(COMPOSE) up -d - -.PHONY: compose_watch -compose_watch: ## start containers for this service watching for updates in filesystem - @$(COMPOSE) up -w - .PHONY: compose_database_create compose_database_create: @$(COMPOSE) run --rm --entrypoint mix app ecto.create @@ -63,7 +55,14 @@ compose_test: ## execute test on docker environment compose_test_shell: ## enter test environment shell @$(COMPOSE) --profile test run --rm --entrypoint bash test -c bash +.PHONY: compose_up +compose_up: ## start containers for this service + @$(COMPOSE) up -d + +.PHONY: compose_watch +compose_watch: ## start containers for this service watching for updates in filesystem + @$(COMPOSE) up -w + .PHONY: help help: @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' - -- 2.47.2