-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: now using docker for dev with dedicated makefile (#107)
- Loading branch information
Showing
75 changed files
with
756 additions
and
662 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ __pycache__/ | |
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,94 @@ | ||
# Default target | ||
.DEFAULT_GOAL := help | ||
|
||
# Help message | ||
# Colors | ||
YELLOW := \033[1;33m | ||
GREEN := \033[1;32m | ||
CYAN := \033[1;36m | ||
RESET := \033[0m | ||
|
||
# Aliases | ||
DOCKER_RUN := docker compose run \ | ||
--volume ${PWD}/app:/code/app \ | ||
--volume ${PWD}/tests:/code/tests \ | ||
--volume ${PWD}/htmlcov:/code/htmlcov \ | ||
--volume ${PWD}/logs:/code/logs \ | ||
--publish 8000:8000 \ | ||
--rm \ | ||
app | ||
|
||
help: | ||
@echo "=============================================================================" | ||
@echo " OverFast API Makefile Help" | ||
@echo "=============================================================================" | ||
@echo "Available targets:" | ||
@echo "" | ||
@echo " make install" | ||
@echo " Install dependencies." | ||
@echo "" | ||
@echo " make run" | ||
@echo " Run OverFastAPI application." | ||
@echo "" | ||
@echo " make test [TARGET=path/to/tests] [COVERAGE=true]" | ||
@echo " Run tests with optional coverage calculation and target specification." | ||
@echo "Usage: make <command>" | ||
@echo "" | ||
@echo " make lint" | ||
@echo " Run linter." | ||
@echo "" | ||
@echo " make format" | ||
@echo " Run formatter." | ||
@echo "" | ||
@echo " make docker-up" | ||
@echo " Build and run the project using Docker Compose." | ||
@echo "" | ||
@echo " make clean" | ||
@echo " Remove generated files." | ||
@echo "=============================================================================" | ||
@echo "${CYAN}Commands:${RESET}" | ||
@printf " ${GREEN}%-10s${RESET} : ${YELLOW}%s${RESET}\n" "build" "Build project images (dev mode)." | ||
@printf " ${GREEN}%-10s${RESET} : ${YELLOW}%s${RESET}\n" "start" "Run OverFastAPI application (dev mode)." | ||
@printf " ${GREEN}%-10s${RESET} : ${YELLOW}%s${RESET}\n" "lint" "Run linter." | ||
@printf " ${GREEN}%-10s${RESET} : ${YELLOW}%s${RESET}\n" "format" "Run formatter." | ||
@printf " ${GREEN}%-10s${RESET} : ${YELLOW}%s${RESET}\n" "shell" "Access an interactive shell inside the app container" | ||
@printf " ${GREEN}%-10s${RESET} : ${YELLOW}%s${RESET}\n" "exec" "Execute a given COMMAND inside the app container" | ||
@printf " ${GREEN}%-10s${RESET} : ${YELLOW}%s${RESET}\n" "test" "Run tests. PYTEST_ARGS can be specified." | ||
@printf " ${GREEN}%-10s${RESET} : ${YELLOW}%s${RESET}\n" "up" "Build & run OverFastAPI application (production mode)." | ||
@printf " ${GREEN}%-10s${RESET} : ${YELLOW}%s${RESET}\n" "down" "Stop the app and remove containers." | ||
@printf " ${GREEN}%-10s${RESET} : ${YELLOW}%s${RESET}\n" "clean" "Clean up Docker environment" | ||
@printf " ${GREEN}%-10s${RESET} : ${YELLOW}%s${RESET}\n" "help" "Show this help message" | ||
|
||
# Install dependencies | ||
install: | ||
@echo "Installing dependencies..." | ||
poetry lock --no-update | ||
poetry install | ||
# Build project images | ||
build: | ||
@echo "Building OverFastAPI (dev mode)..." | ||
BUILD_TARGET="dev" docker compose build | ||
|
||
# Run OverFastAPI application | ||
run: | ||
@echo "Launching OverFastAPI..." | ||
uvicorn app.main:app --reload | ||
|
||
# Run tests with coverage (optional) | ||
test: | ||
ifdef COVERAGE | ||
@echo "Running tests with coverage..." | ||
python -m pytest --cov app --cov-report html -n auto $(TARGET) | ||
else | ||
@echo "Running tests..." | ||
python -m pytest -n auto $(TARGET) | ||
endif | ||
# Run OverFastAPI application (dev mode) | ||
start: | ||
@echo "Launching OverFastAPI (dev mode)..." | ||
$(DOCKER_RUN) uvicorn app.main:app --reload --host 0.0.0.0 | ||
|
||
# Run linter | ||
lint: | ||
@echo "Running linter..." | ||
ruff check --fix --exit-non-zero-on-fix | ||
$(DOCKER_RUN) ruff check --fix --exit-non-zero-on-fix | ||
|
||
# Run formatter | ||
format: | ||
@echo "Running formatter..." | ||
ruff format | ||
$(DOCKER_RUN) ruff format | ||
|
||
# Open a shell on the app container | ||
shell: | ||
@echo "Running shell on app container..." | ||
$(DOCKER_RUN) /bin/sh | ||
|
||
# Execute a command on the app container | ||
exec: | ||
@echo "Running shell on app container..." | ||
$(DOCKER_RUN) $(COMMAND) | ||
|
||
# Run tests (no coverage calculation if a target is specified) | ||
test: build | ||
ifdef PYTEST_ARGS | ||
@echo "Running tests on $(PYTEST_ARGS)..." | ||
$(DOCKER_RUN) python -m pytest $(PYTEST_ARGS) | ||
else | ||
@echo "Running all tests with coverage..." | ||
$(DOCKER_RUN) python -m pytest --cov app --cov-report html -n auto | ||
endif | ||
|
||
# Run OverFastAPI application (production mode) | ||
up: down | ||
@echo "Building OverFastAPI (production mode)..." | ||
docker compose build | ||
@echo "Launching OverFastAPI (production mode)..." | ||
docker compose up -d | ||
|
||
# Build and run the project using Docker Compose | ||
docker-up: | ||
@echo "Building and running the project using Docker Compose..." | ||
docker compose up --build -d | ||
# Remove containers | ||
down: | ||
@echo "Stopping OverFastAPI and cleaning containers..." | ||
docker compose down -v --remove-orphans | ||
|
||
# Clean up generated files | ||
clean: | ||
@echo "Cleaning up..." | ||
rm -rf __pycache__ .pytest_cache htmlcov | ||
# Clean Docker environment | ||
clean: down | ||
@echo "Cleaning Docker environment..." | ||
docker image prune -af | ||
docker network prune -f | ||
|
||
.PHONY: help install run test lint format docker-up clean | ||
.PHONY: help build start lint format shell exec test up down clean |
Oops, something went wrong.