Skip to content

Commit

Permalink
feat(docker): add support for old docker-compose command
Browse files Browse the repository at this point in the history
  • Loading branch information
psyray committed Jul 24, 2024
1 parent 7ce72e3 commit 95f8894
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,53 @@ COMPOSE_DEV_ALL_FILES := -f docker-compose.dev.yml
SERVICES := db web proxy redis celery celery-beat
SERVICES_DEV := db web proxy redis celery celery-beat

# Check if 'docker compose' command is available, otherwise use 'docker-compose'
DOCKER_COMPOSE := $(shell if command -v docker > /dev/null && docker compose version > /dev/null 2>&1; then echo "docker compose"; else echo "docker-compose"; fi)
$(info Using: $(shell echo "$(DOCKER_COMPOSE)"))

# --------------------------

.PHONY: setup certs up build username pull down stop restart rm logs

certs: ## Generate certificates.
@${COMPOSE_PREFIX_CMD} docker compose -f docker-compose.setup.yml run --rm certs
@${COMPOSE_PREFIX_CMD} ${DOCKER_COMPOSE} -f docker-compose.setup.yml run --rm certs

setup: ## Generate certificates.
@make certs

up: ## Build and start all services.
${COMPOSE_PREFIX_CMD} docker compose ${COMPOSE_ALL_FILES} up -d --build ${SERVICES}
${COMPOSE_PREFIX_CMD} ${DOCKER_COMPOSE} ${COMPOSE_ALL_FILES} up -d --build ${SERVICES}

build: ## Build all services.
${COMPOSE_PREFIX_CMD} docker compose ${COMPOSE_ALL_FILES} build ${SERVICES}
${COMPOSE_PREFIX_CMD} ${DOCKER_COMPOSE} ${COMPOSE_ALL_FILES} build ${SERVICES}

username: ## Generate Username (Use only after make up).
${COMPOSE_PREFIX_CMD} docker compose ${COMPOSE_ALL_FILES} exec web python3 manage.py createsuperuser
${COMPOSE_PREFIX_CMD} ${DOCKER_COMPOSE} ${COMPOSE_ALL_FILES} exec web python3 manage.py createsuperuser

pull: ## Pull Docker images.
docker login docker.pkg.github.com
${COMPOSE_PREFIX_CMD} docker compose ${COMPOSE_ALL_FILES} pull
${COMPOSE_PREFIX_CMD} ${DOCKER_COMPOSE} ${COMPOSE_ALL_FILES} pull

down: ## Down all services.
${COMPOSE_PREFIX_CMD} docker compose ${COMPOSE_ALL_FILES} down
${COMPOSE_PREFIX_CMD} ${DOCKER_COMPOSE} ${COMPOSE_ALL_FILES} down

stop: ## Stop all services.
${COMPOSE_PREFIX_CMD} docker compose ${COMPOSE_ALL_FILES} stop ${SERVICES}
${COMPOSE_PREFIX_CMD} ${DOCKER_COMPOSE} ${COMPOSE_ALL_FILES} stop ${SERVICES}

restart: ## Restart all services.
${COMPOSE_PREFIX_CMD} docker compose ${COMPOSE_ALL_FILES} restart ${SERVICES}
${COMPOSE_PREFIX_CMD} ${DOCKER_COMPOSE} ${COMPOSE_ALL_FILES} restart ${SERVICES}

rm: ## Remove all services containers.
${COMPOSE_PREFIX_CMD} docker compose $(COMPOSE_ALL_FILES) rm -f ${SERVICES}
${COMPOSE_PREFIX_CMD} ${DOCKER_COMPOSE} $(COMPOSE_ALL_FILES) rm -f ${SERVICES}

test:
${COMPOSE_PREFIX_CMD} docker compose $(COMPOSE_ALL_FILES) exec celery python3 -m unittest tests/test_scan.py
${COMPOSE_PREFIX_CMD} ${DOCKER_COMPOSE} $(COMPOSE_ALL_FILES) exec celery python3 -m unittest tests/test_scan.py

logs: ## Tail all logs with -n 1000.
${COMPOSE_PREFIX_CMD} docker compose $(COMPOSE_ALL_FILES) logs --follow --tail=1000 ${SERVICES}
${COMPOSE_PREFIX_CMD} ${DOCKER_COMPOSE} $(COMPOSE_ALL_FILES) logs --follow --tail=1000 ${SERVICES}

images: ## Show all Docker images.
${COMPOSE_PREFIX_CMD} docker compose $(COMPOSE_ALL_FILES) images ${SERVICES}
${COMPOSE_PREFIX_CMD} ${DOCKER_COMPOSE} $(COMPOSE_ALL_FILES) images ${SERVICES}

prune: ## Remove containers and delete volume data.
@make stop && make rm && docker volume prune -f
Expand All @@ -62,13 +66,13 @@ help: ## Show this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m (default: help)\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-12s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)

dev_build: ## Build all services.
${COMPOSE_PREFIX_CMD} docker compose ${COMPOSE_DEV_ALL_FILES} build ${SERVICES_DEV}
${COMPOSE_PREFIX_CMD} ${DOCKER_COMPOSE} ${COMPOSE_DEV_ALL_FILES} build ${SERVICES_DEV}

dev_up: ## Build and start all services.
${COMPOSE_PREFIX_CMD} docker compose ${COMPOSE_DEV_ALL_FILES} up -d --build ${SERVICES_DEV}
${COMPOSE_PREFIX_CMD} ${DOCKER_COMPOSE} ${COMPOSE_DEV_ALL_FILES} up -d --build ${SERVICES_DEV}

dev_down: ## Down all services.
${COMPOSE_PREFIX_CMD} docker compose ${COMPOSE_DEV_ALL_FILES} down
${COMPOSE_PREFIX_CMD} ${DOCKER_COMPOSE} ${COMPOSE_DEV_ALL_FILES} down

dev_logs: ## Tail all logs with -n 1000.
${COMPOSE_PREFIX_CMD} docker compose $(COMPOSE_DEV_ALL_FILES) logs --follow --tail=1000 ${SERVICES_DEV}
${COMPOSE_PREFIX_CMD} ${DOCKER_COMPOSE} $(COMPOSE_DEV_ALL_FILES) logs --follow --tail=1000 ${SERVICES_DEV}

0 comments on commit 95f8894

Please sign in to comment.