-
Notifications
You must be signed in to change notification settings - Fork 63
compose refactor and project dependencies bump #220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,71 +1,104 @@ | ||
| # Set the default goal to "help" so that running "make" without arguments will display the help message. | ||
| .DEFAULT_GOAL := help | ||
|
|
||
| # ==================================================================================== | ||
| # HELP | ||
| # ==================================================================================== | ||
| # This target uses a combination of egrep, sort, and awk to parse the Makefile itself | ||
| # and generate a formatted help message. It looks for lines containing '##' and | ||
| # uses the text that follows as the help description for the target. | ||
| .PHONY: help | ||
| help: ## Show this help | ||
| @egrep -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' | ||
|
|
||
| # ==================================================================================== | ||
| # DOCKER COMPOSE MANAGEMENT | ||
| # ==================================================================================== | ||
| .PHONY: docker-build | ||
| docker-build: ## Build project with compose | ||
| docker-build: ## Build project Docker images using compose | ||
| docker compose build | ||
|
|
||
| .PHONY: docker-up | ||
| docker-up: ## Run project with compose | ||
| docker compose up --remove-orphans | ||
|
|
||
| .PHONY: docker-clean | ||
| docker-clean: ## Clean Reset project containers and volumes with compose | ||
| docker-clean: ## Clean and reset project containers and volumes | ||
| docker compose down -v --remove-orphans | true | ||
| docker compose rm -f | true | ||
| docker volume rm fastapi_postgres_data | true | ||
| docker volume rm panettone_postgres_data | true | ||
|
|
||
| # ==================================================================================== | ||
| # DATABASE MIGRATIONS | ||
| # ==================================================================================== | ||
| .PHONY: docker-apply-db-migrations | ||
| docker-apply-db-migrations: ## apply alembic migrations to database/schema | ||
| docker compose run --rm app alembic upgrade head | ||
| docker-apply-db-migrations: ## Apply alembic migrations to the database schema | ||
| docker compose run --rm api1 alembic upgrade head | ||
|
|
||
| .PHONY: docker-create-db-migration | ||
| docker-create-db-migration: ## Create new alembic database migration aka database revision. Example: make docker-create-db-migration msg="add users table" | ||
| docker compose up -d db | true | ||
| docker compose run --no-deps app alembic revision --autogenerate -m "$(msg)" | ||
| docker-create-db-migration: ## Create a new alembic database migration. Example: make docker-create-db-migration msg="add users table" | ||
| docker compose up -d postgres | true | ||
| docker compose run --no-deps api1 alembic revision --autogenerate -m "$(msg)" | ||
|
|
||
| # ==================================================================================== | ||
| # TESTING | ||
| # ==================================================================================== | ||
| .PHONY: docker-test | ||
| docker-test: ## Run project tests | ||
| docker compose -f compose.yml -f test-compose.yml run --rm app pytest tests --durations=0 -vv | ||
| docker compose -f compose.yml -f test-compose.yml run --rm api1 pytest tests --durations=0 -vv | ||
|
|
||
| .PHONY: docker-test-snapshot | ||
| docker-test-snapshot: ## Run project tests with inline snapshot | ||
| docker compose -f compose.yml -f test-compose.yml run --rm app pytest tests --inline-snapshot=fix | ||
| docker-test-snapshot: ## Run project tests and update snapshots | ||
| docker compose -f compose.yml -f test-compose.yml run --rm api1 pytest tests --inline-snapshot=fix | ||
|
|
||
| # ==================================================================================== | ||
| # CODE QUALITY & LINTING | ||
| # ==================================================================================== | ||
| .PHONY: safety | ||
| safety: ## Check project and dependencies with safety https://github.com/pyupio/safety | ||
| docker compose run --rm app safety check | ||
| safety: ## Check for insecure dependencies | ||
| docker compose run --rm api1 safety check | ||
|
|
||
| .PHONY: py-upgrade | ||
| py-upgrade: ## Upgrade project py files with pyupgrade library for python version 3.10 | ||
| pyupgrade --py313-plus `find app -name "*.py"` | ||
| py-upgrade: ## Upgrade Python syntax to a newer version | ||
| pyupgrade --py313-plus `find api1 -name "*.py"` | ||
|
|
||
| .PHONY: lint | ||
| lint: ## Lint project code. | ||
| lint: ## Lint and format project code | ||
| uv run ruff check --fix . | ||
|
|
||
| # ==================================================================================== | ||
| # DOCKER IMAGE BUILDING | ||
| # ==================================================================================== | ||
| .PHONY: slim-build | ||
| slim-build: ## with power of docker-slim build smaller and safer images | ||
| docker-slim build --compose-file docker-compose.yml --target-compose-svc app --dep-include-target-compose-svc-deps true --http-probe-exec app fastapi-sqlalchemy-asyncpg_app:latest | ||
| slim-build: ## Build smaller and more secure Docker images with docker-slim | ||
| docker-slim build --compose-file docker-compose.yml --target-compose-svc api1 --dep-include-target-compose-svc-deps true --http-probe-exec api1 fastapi-sqlalchemy-asyncpg_api1:latest | ||
|
|
||
| # ==================================================================================== | ||
| # DATABASE SEEDING | ||
| # ==================================================================================== | ||
| .PHONY: docker-feed-database | ||
| docker-feed-database: ## create database objects and insert data | ||
| docker compose exec db psql devdb devdb -f /home/gx/code/shakespeare_work.sql | true | ||
| docker compose exec db psql devdb devdb -f /home/gx/code/shakespeare_chapter.sql | true | ||
| docker compose exec db psql devdb devdb -f /home/gx/code/shakespeare_wordform.sql | true | ||
| docker compose exec db psql devdb devdb -f /home/gx/code/shakespeare_character.sql | true | ||
| docker compose exec db psql devdb devdb -f /home/gx/code/shakespeare_paragraph.sql | true | ||
| docker compose exec db psql devdb devdb -f /home/gx/code/shakespeare_character_work.sql | ||
| docker-feed-database: ## Create database objects and insert seed data | ||
| docker compose exec postgres psql devdb devdb -f /home/gx/code/shakespeare_work.sql | true | ||
| docker compose exec postgres psql devdb devdb -f /home/gx/code/shakespeare_chapter.sql | true | ||
| docker compose exec postgres psql devdb devdb -f /home/gx/code/shakespeare_wordform.sql | true | ||
| docker compose exec postgres psql devdb devdb -f /home/gx/code/shakespeare_character.sql | true | ||
| docker compose exec postgres psql devdb devdb -f /home/gx/code/shakespeare_paragraph.sql | true | ||
| docker compose exec postgres psql devdb devdb -f /home/gx/code/shakespeare_character_work.sql | ||
|
|
||
| # ==================================================================================== | ||
| # MODEL GENERATION | ||
| # ==================================================================================== | ||
| .PHONY: model-generate | ||
| model-generate: ## generate sqlalchemy models from database | ||
| model-generate: ## Generate SQLAlchemy models from the database schema | ||
| poetry run sqlacodegen --generator declarative postgresql://devdb:secret@0.0.0.0/devdb --outfile models.py --schemas shakespeare --options nobidi | ||
|
|
||
| # ==================================================================================== | ||
| # ALTERNATIVE RUNTIMES | ||
| # ==================================================================================== | ||
| .PHONY: docker-up-granian | ||
| docker-up-granian: ## Run project with compose and granian | ||
| docker-up-granian: ## Run project with compose and the Granian web server | ||
| docker compose -f granian-compose.yml up --remove-orphans | ||
|
|
||
| .PHONY: docker-up-valkey | ||
| docker-up-valkey: ## Run project with compose and valkey | ||
| docker-up-valkey: ## Run project with compose and Valkey | ||
| docker compose -f valkey-compose.yml up --remove-orphans | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,9 +1,9 @@ | ||
| services: | ||
| app: | ||
| api1: | ||
| environment: | ||
| - POSTGRES_DB=testdb | ||
|
|
||
| db: | ||
| postgres: | ||
| environment: | ||
| - POSTGRES_USER=${POSTGRES_USER} | ||
| - POSTGRES_DB=testdb |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.