2024-09-23 19:22:35 +00:00
|
|
|
# Makefile
|
|
|
|
FOLDER := ./docker
|
2024-09-10 09:50:11 +00:00
|
|
|
|
2024-09-23 19:22:35 +00:00
|
|
|
# The services that can be toggled
|
|
|
|
SERVICES := nginx nlu smtp4dev
|
|
|
|
|
|
|
|
# Function to dynamically add Docker Compose files based on enabled services
|
|
|
|
define compose_files
|
|
|
|
$(foreach service,$(SERVICES),$(if $($(shell echo $(service) | tr a-z A-Z)), -f $(FOLDER)/docker-compose.$(service).yml))
|
2024-09-10 09:50:11 +00:00
|
|
|
endef
|
|
|
|
|
2024-09-23 19:22:35 +00:00
|
|
|
# Function to dynamically add Docker Compose dev files based on enabled services and file existence
|
|
|
|
define compose_dev_files
|
|
|
|
$(foreach service,$(SERVICES), \
|
|
|
|
$(if $($(shell echo $(service) | tr a-z A-Z)), \
|
|
|
|
$(if $(shell [ -f $(FOLDER)/docker-compose.$(service).dev.yml ] && echo yes), -f $(FOLDER)/docker-compose.$(service).dev.yml)))
|
|
|
|
endef
|
2024-09-10 09:50:11 +00:00
|
|
|
|
2024-09-23 19:22:35 +00:00
|
|
|
# Function to dynamically add Docker Compose dev files based on enabled services and file existence
|
|
|
|
define compose_prod_files
|
|
|
|
$(foreach service,$(SERVICES), \
|
|
|
|
$(if $($(shell echo $(service) | tr a-z A-Z)), \
|
|
|
|
$(if $(shell [ -f $(FOLDER)/docker-compose.$(service).prod.yml ] && echo yes), -f $(FOLDER)/docker-compose.$(service).dev.yml)))
|
2024-09-20 17:28:55 +00:00
|
|
|
endef
|
2024-09-18 16:33:12 +00:00
|
|
|
|
2024-09-10 09:50:11 +00:00
|
|
|
# Ensure .env file exists and matches .env.example
|
|
|
|
check-env:
|
2024-09-23 19:22:35 +00:00
|
|
|
@if [ ! -f "$(FOLDER)/.env" ]; then \
|
2024-09-10 09:50:11 +00:00
|
|
|
echo "Error: .env file does not exist. Creating one now from .env.example ..."; \
|
2024-09-23 19:22:35 +00:00
|
|
|
cp $(FOLDER)/.env.example $(FOLDER)/.env; \
|
2024-09-10 09:50:11 +00:00
|
|
|
fi
|
|
|
|
@echo "Checking .env file for missing variables..."
|
2024-09-23 19:22:35 +00:00
|
|
|
@awk -F '=' 'NR==FNR {a[$$1]; next} !($$1 in a) {print "Missing env var: " $$1}' $(FOLDER)/.env $(FOLDER)/.env.example
|
2024-09-10 09:50:11 +00:00
|
|
|
|
|
|
|
init:
|
2024-09-23 19:22:35 +00:00
|
|
|
cp $(FOLDER)/.env.example $(FOLDER)/.env
|
2024-09-10 09:50:11 +00:00
|
|
|
|
2024-09-23 19:22:35 +00:00
|
|
|
# Start command: runs docker-compose with the main file and any additional service files
|
|
|
|
start: check-env
|
|
|
|
@docker compose -f $(FOLDER)/docker-compose.yml $(call compose_files) up -d
|
|
|
|
|
|
|
|
# Dev command: runs docker-compose with the main file, dev file, and any additional service dev files (if they exist)
|
2024-09-10 09:50:11 +00:00
|
|
|
dev: check-env
|
2024-09-23 19:22:35 +00:00
|
|
|
@docker compose -f $(FOLDER)/docker-compose.yml -f $(FOLDER)/docker-compose.dev.yml $(call compose_files) $(call compose_dev_files) up -d
|
2024-09-10 09:50:11 +00:00
|
|
|
|
2024-09-23 19:22:35 +00:00
|
|
|
# Start command: runs docker-compose with the main file and any additional service files
|
|
|
|
start-prod: check-env
|
|
|
|
@docker compose -f $(FOLDER)/docker-compose.yml -f $(FOLDER)/docker-compose.prod.yml $(call compose_files) $(call compose_prod_files) up -d
|
2024-09-10 09:50:11 +00:00
|
|
|
|
2024-09-23 19:22:35 +00:00
|
|
|
# Stop command: stops the running containers
|
|
|
|
stop:
|
|
|
|
@docker compose -f $(FOLDER)/docker-compose.yml -f $(FOLDER)/docker-compose.dev.yml $(call compose_files) $(call compose_dev_files) $(call compose_prod_files) down
|
2024-09-10 09:50:11 +00:00
|
|
|
|
2024-09-23 19:22:35 +00:00
|
|
|
# Destroy command: stops the running containers and removes the volumes
|
|
|
|
destroy:
|
|
|
|
@docker compose -f $(FOLDER)/docker-compose.yml -f $(FOLDER)/docker-compose.dev.yml $(call compose_files) $(call compose_dev_files) $(call compose_prod_files) down -v
|
2024-09-10 09:50:11 +00:00
|
|
|
|
2024-09-23 19:22:35 +00:00
|
|
|
# Migrate command:
|
2024-09-10 09:50:11 +00:00
|
|
|
migrate-up:
|
2024-09-23 19:22:35 +00:00
|
|
|
@docker compose -f $(FOLDER)/docker-compose.yml -f $(FOLDER)/docker-compose.dev.yml $(call compose_files) $(call compose_dev_files) up --no-deps -d database-init
|