From f7d4a31b25df5d5a4e4c3799642c90f6bf3eafc5 Mon Sep 17 00:00:00 2001 From: Hugo Bollon Date: Thu, 18 Jul 2024 16:38:24 +0200 Subject: [PATCH] chore: add Makefile to simplify dev operations --- Makefile | 34 ++++++++++++++++++++++++++++++++++ docker-compose.yml | 13 +++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..9bc5105e --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +VERSION ?= $(shell git describe --always --tags) +DOCKER_TAG ?= latest + +export DOCKER_BUILDKIT=1 + +.PHONY: build +build: ## Build docker image + docker build --tag=camptocamp/geoshop-api:$(VERSION) \ + --build-arg=VERSION=$(VERSION) . + docker tag camptocamp/geoshop-api:$(VERSION) camptocamp/geoshop-api:$(DOCKER_TAG) + +.PHONY: test +test: ## Run tests + docker compose exec -T api python manage.py test -v 2 --force-color --noinput + +.PHONY: prepare_env +prepare_env: destroy_env build ## Prepare Docker environment + docker compose up -d + until [ "$$(docker inspect -f '{{.State.Health.Status}}' geoshop-back-api-1)" = "healthy" ]; do \ + echo "Waiting for api..."; \ + sleep 1; \ + done; + +.PHONY: destroy_env +destroy_env: ## Destroy Docker environment + docker compose down --remove-orphans + +.PHONY: help +help: ## Display this help + @echo "Usage: make " + @echo + @echo "Available targets:" + @grep --extended-regexp --no-filename '^[a-zA-Z_-]+:.*## ' $(MAKEFILE_LIST) | sort | \ + awk 'BEGIN {FS = ":.*?## "}; {printf " %-20s%s\n", $$1, $$2}' \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 236cbdde..f38caa59 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,7 +29,7 @@ services: retries: 5 migrate: - image: geoshop-api + image: camptocamp/geoshop-api build: context: . dockerfile: Dockerfile @@ -49,7 +49,7 @@ services: - geoshop api: - image: geoshop-api + image: camptocamp/geoshop-api depends_on: db: condition: service_healthy @@ -60,6 +60,15 @@ services: PGHOST: "db" command: "gunicorn wsgi -b :8000 --timeout 90" restart: unless-stopped + healthcheck: + test: + [ + "CMD-SHELL", + "curl -f http://127.0.0.1:8000/health/readiness || exit 1", + ] + interval: 10s + timeout: 5s + retries: 5 volumes: - "static-files:/app/geoshop_back/static:ro" ports: