-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- remove setup.cfg and use a pyproject.toml - refactor the docker files structure and process
- Loading branch information
1 parent
719fb9e
commit ad30d29
Showing
26 changed files
with
266 additions
and
319 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
tags: | ||
- 'v*' | ||
|
||
name: Build Docker image | ||
|
||
jobs: | ||
|
||
build-backend-amd64: | ||
name: backend/amd64 | ||
uses: code4romania/.github/.github/workflows/build-push-image.yml@main | ||
with: | ||
images: ghcr.io/code4romania/seismic-risc-backend | ||
context: ./ | ||
dockerfile: ./docker/dockerfiles/Dockerfile.backend | ||
registry: ghcr.io | ||
secrets: | ||
username: ${{ github.actor }} | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
build-frontend-amd64: | ||
name: frontend/amd64 | ||
uses: code4romania/.github/.github/workflows/build-push-image.yml@main | ||
with: | ||
images: ghcr.io/code4romania/seismic-risc-frontend | ||
context: ./client | ||
dockerfile: ./docker/dockerfiles/Dockerfile.frontend | ||
registry: ghcr.io | ||
secrets: | ||
username: ${{ github.actor }} | ||
token: ${{ secrets.GITHUB_TOKEN }} |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,96 +1,144 @@ | ||
help: ## Display a help message detailing commands and their purpose | ||
@echo "Commands:" | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | ||
@grep -E '^([a-zA-Z_-]+:.*?## .*|#+ (.*))$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | ||
@echo "" | ||
|
||
build-dev: ## builds the container with the development flag | ||
docker compose build | ||
docker compose up -d | ||
|
||
build-prod: ## builds the container with the production flag | ||
## [Managing the project] | ||
### Stopping the containers and dropping the databases | ||
stop-dev: ## stops the dev project | ||
docker compose down -t 60 | ||
|
||
drop-dev: ## stops the dev project | ||
docker compose down -v -t 60 | ||
|
||
stop-prod: ## stops the dev project | ||
docker compose -f docker-compose.prod.yml down -t 60 | ||
|
||
drop-prod: ## stops the dev project | ||
docker compose -f docker-compose.prod.yml down -v -t 60 | ||
|
||
### Building & starting the containers | ||
up-dev: ## run the project | ||
docker compose up --build | ||
|
||
upd-dev: ## run the project in detached mode | ||
docker compose up -d --build | ||
|
||
build-prod: | ||
docker compose -f docker-compose.prod.yml build \ | ||
--build-arg $$(cat .env.prod | grep ENVIRONMENT) \ | ||
--build-arg $$(cat .env.prod | grep REACT_APP_CAPTCHA_API_KEY) \ | ||
--build-arg $$(cat .env.prod | grep REACT_APP_HERE_MAPS_API_KEY) \ | ||
--build-arg $$(cat .env.prod | grep REACT_APP_DJANGO_SITE_URL) \ | ||
--build-arg $$(cat .env.prod | grep REACT_APP_DJANGO_PORT) \ | ||
--build-arg $$(cat .env.prod | grep REACT_APP_DJANGO_API_ENDPOINT) | ||
|
||
|
||
up-prod: ## run the project | ||
docker compose -f docker-compose.prod.yml up | ||
|
||
upd-prod: ## builds the container with the production flag | ||
docker compose -f docker-compose.prod.yml up -d | ||
|
||
### Using the dev setup | ||
run-dev: up-dev ## run the project | ||
rund-dev: upd-dev ## run the project in detached mode | ||
redo-dev: drop-dev up-dev ## delete the db and rerun the project | ||
redod-dev: drop-dev upd-dev ## delete the db and rerun the project in detached mode | ||
|
||
build: build-dev ## shorthand for the build-dev command | ||
### With an image built for production | ||
run-prod: build-prod up-prod ## run the project with production settings | ||
rund-prod: build-prod upd-prod ## run the project with production settings in detached mode | ||
redo-prod: drop-prod build-prod up-prod ## delete the db and rerun the project | ||
redod-prod: drop-prod build-prod upd-prod ## delete the db and rerun the project in detached mode | ||
|
||
superuser: ## creates a superuser for the API | ||
docker compose exec api ./manage.py createsuperuser | ||
### Other run options | ||
run: run-dev ## set the default run command to dev | ||
redo: redo-dev ## set the default redo command to dev | ||
rund: rund-dev ## set the default run command to dev | ||
redod: redod-dev ## set the default redo command to dev | ||
|
||
init-db: superuser ## sets up the database and fixtures | ||
docker compose exec api ./manage.py loaddata statistics | ||
docker compose exec api ./manage.py loaddata proximal_utilities | ||
docker compose exec api ./manage.py loaddata work_performed | ||
docker compose exec api ./manage.py loaddata buildings | ||
stop: stop-dev stop-prod ## stop all running projects | ||
|
||
drop-db-dev: ## drops the containers and removes the database for the development environment | ||
docker compose down -v -t 60 | ||
drop: drop-dev drop-prod ## drop all databases | ||
|
||
drop-db-prod: ## drops the containers and removes the database for the production environment | ||
docker compose -f docker-compose.prod.yml down -v -t 60 | ||
|
||
drop-db: drop-db-dev drop-db-prod ## drops the containers and removes the database for both environments | ||
## [Monitoring the containers] | ||
logs-dev: ## show the logs of the containers | ||
docker compose logs -f api | ||
|
||
redo-db: drop-db init-db ## drops the database, then sets up the database and fixtures | ||
logs: logs-dev ## set the default logs command to dev | ||
|
||
## [UTILS] | ||
requirements-build: ## run pip compile and add requirements from the *.in files | ||
docker compose run --rm --no-deps --entrypoint "bash -c" api "cd /code && pip-compile --resolver=backtracking -o requirements.txt requirements.in && pip-compile --resolver=backtracking -o requirements-dev.txt requirements-dev.in" | ||
logs-prod: ## show the logs of the containers | ||
docker compose -f docker-compose.prod.yml logs -f api | ||
|
||
requirements-update: ## run pip compile and rebuild the requirements files | ||
docker compose run --rm --no-deps --entrypoint "bash -c" api "cd /code && pip-compile --resolver=backtracking -r -U -o requirements.txt requirements.in && pip-compile --resolver=backtracking -r -U -o requirements-dev.txt requirements-dev.in && chmod a+r requirements.txt && chmod a+r requirements-dev.txt" | ||
|
||
migrations: ## generate migrations in a clean container | ||
docker compose exec api ./manage.py makemigrations | ||
## [Django operations] | ||
makemigrations: ## generate migrations in a clean container | ||
docker compose exec api sh -c "python3 -Wd ./manage.py makemigrations $(apps)" | ||
|
||
migrate: ## apply migrations in a clean container | ||
docker compose exec api ./manage.py migrate | ||
docker compose exec api sh -c "python3 -Wd ./manage.py migrate $(apps)" | ||
|
||
migrations: makemigrations migrate ## generate and apply migrations | ||
|
||
|
||
makemessages: ## generate the strings marked for translation | ||
docker compose exec api ./manage.py makemessages -a | ||
docker compose exec api sh -c "python3 -Wd ./manage.py makemessages -a" | ||
|
||
compilemessages: ## compile the translations | ||
docker compose exec api ./manage.py compilemessages | ||
docker compose exec api sh -c "python3 -Wd ./manage.py compilemessages" | ||
|
||
messages: makemessages compilemessages ## generate and compile the translations | ||
|
||
messages: makemessages compilemessages | ||
|
||
collectstatic: | ||
docker compose exec api ./manage.py collectstatic --no-input | ||
collectstatic: ## collect the static files | ||
docker compose exec api sh -c "python3 -Wd ./manage.py collectstatic --no-input" | ||
|
||
format: ## format the code with black & ruff | ||
docker compose exec api sh -c "black ./api && ruff check --fix ./api" | ||
|
||
pyshell: ## start a django shell | ||
docker compose exec api ./manage.py shell | ||
docker compose exec -it api sh -c "python3 -Wd ./manage.py shell" | ||
|
||
black: ## run the Black formatter on the Python code | ||
black --line-length 120 --target-version py311 --exclude migrations ./api | ||
sh: ## start a sh shell | ||
docker compose exec -it api sh -c "sh" | ||
|
||
## [TEST] | ||
test: ## run all tests | ||
docker compose run --rm api "pytest" | ||
bash: ## start a bash shell | ||
docker compose exec -it api sh -c "bash" | ||
|
||
test-pdb: ## run tests and enter debugger on failed assert or error | ||
docker compose run --rm api "pytest --pdb" | ||
|
||
test-lf: ## rerun tests that failed last time | ||
docker compose run --rm api "pytest --lf" | ||
## [Requirements management] | ||
requirements-build: ## run pip compile and add requirements from the *.in files | ||
docker compose exec api sh -c " \ | ||
pip-compile --strip-extras --resolver=backtracking -o requirements.txt requirements.in && \ | ||
pip-compile --strip-extras --resolver=backtracking -o requirements-dev.txt requirements-dev.in \ | ||
" | ||
|
||
requirements-update: ## run pip compile and rebuild the requirements files | ||
docker compose exec api sh -c " \ | ||
pip-compile --strip-extras --resolver=backtracking -r -U -o requirements.txt requirements.in && \ | ||
pip-compile --strip-extras --resolver=backtracking -r -U -o requirements-dev.txt requirements-dev.in && \ | ||
chmod a+r requirements.txt && \ | ||
chmod a+r requirements-dev.txt \ | ||
" | ||
|
||
## [CLEAN] | ||
clean: clean-docker clean-py ## remove all build, test, coverage and Python artifacts | ||
|
||
## [Clean-up] | ||
clean-docker: ## stop docker containers and remove orphaned images and volumes | ||
docker compose down -t 60 | ||
docker compose down -v -t 60 | ||
docker compose -f docker-compose.prod.yml down -v -t 60 | ||
docker system prune -f | ||
|
||
clean-py: ## remove Python test, coverage, file artifacts, and compiled message files | ||
find ./api -name '.coverage' -delete | ||
find ./api -name '.pytest_cache' -delete | ||
find ./api -name '__pycache__' -delete | ||
find ./api -name 'htmlcov' -delete | ||
find ./api -name '*.pyc' -delete | ||
find ./api -name '*.pyo' -delete | ||
find ./api -name '*.mo' -delete | ||
find ./backend -name '*.mo' -delete | ||
find ./backend -name '*.pyc' -delete | ||
find ./backend -name '*.pyo' -delete | ||
find ./backend -name '.coverage' -delete | ||
find ./backend -name '.pytest_cache' -delete | ||
find ./backend -name '.ruff_cache' -delete | ||
find ./backend -name '__pycache__' -delete | ||
find ./backend -name 'htmlcov' -delete | ||
|
||
clean: clean-docker clean-py ## remove all build, test, coverage and Python artifacts |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.