2021-01-11 18:44:43 +00:00
|
|
|
veekun_pokedex_repository = ../pokedex
|
|
|
|
local_config = --settings=config.local
|
|
|
|
docker_config = --settings=config.docker-compose
|
2021-03-19 18:09:59 +00:00
|
|
|
HASURA_GRAPHQL_ADMIN_SECRET=pokemon
|
2021-01-11 18:44:43 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
.PHONY: help
|
2021-08-30 16:24:56 +00:00
|
|
|
.SILENT:
|
2020-02-17 20:58:07 +00:00
|
|
|
|
|
|
|
help:
|
|
|
|
@grep -E '^[a-zA-Z_-]+:.*?# .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?# "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
|
|
|
|
|
|
|
install: # Install base requirements to run project
|
2016-03-05 08:29:26 +00:00
|
|
|
pip install -r requirements.txt
|
2014-12-04 11:11:46 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
dev-install: # Install developer requirements + base requirements
|
2016-03-05 09:27:25 +00:00
|
|
|
pip install -r test-requirements.txt
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
setup: # Set up the project database
|
2021-01-11 18:44:43 +00:00
|
|
|
python manage.py migrate ${local_config}
|
2014-12-04 11:11:46 +00:00
|
|
|
|
2023-02-06 11:10:08 +00:00
|
|
|
build-db: # Build database
|
|
|
|
echo "from data.v2.build import build_all; build_all()" | python manage.py shell ${local_config}
|
|
|
|
|
2021-01-11 18:44:43 +00:00
|
|
|
wipe-sqlite-db: # Delete's the project database
|
2014-12-04 11:11:46 +00:00
|
|
|
rm -rf db.sqlite3
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
serve: # Run the project locally
|
2021-01-11 18:44:43 +00:00
|
|
|
python manage.py runserver ${local_config}
|
2014-12-04 11:11:46 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
test: # Run tests
|
2021-01-11 18:44:43 +00:00
|
|
|
python manage.py test ${local_config}
|
2014-12-04 11:11:46 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
clean: # Remove any pyc files
|
2016-06-25 14:42:39 +00:00
|
|
|
find . -type f -name '*.pyc' -delete
|
2016-04-30 14:36:56 +00:00
|
|
|
|
2021-01-11 18:44:43 +00:00
|
|
|
migrate: # Run any outstanding migrations
|
|
|
|
python manage.py migrate ${local_config}
|
|
|
|
|
|
|
|
make-migrations: # Create migrations files if schema has changed
|
|
|
|
python manage.py makemigrations ${local_config}
|
2019-01-04 14:35:35 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
shell: # Load a shell
|
2021-01-11 18:44:43 +00:00
|
|
|
python manage.py shell ${local_config}
|
|
|
|
|
|
|
|
docker-up: # (Docker) Create services/volumes/networks
|
|
|
|
docker-compose up -d
|
|
|
|
|
|
|
|
docker-migrate: # (Docker) Run any pending migrations
|
|
|
|
docker-compose exec -T app python manage.py migrate ${docker_config}
|
|
|
|
|
|
|
|
docker-build-db: # (Docker) Build the database
|
|
|
|
docker-compose exec -T app sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell ${docker_config}'
|
|
|
|
|
|
|
|
docker-make-migrations: # (Docker) Create migrations files if schema has changed
|
|
|
|
docker-compose exec -T app sh -c 'python manage.py makemigrations ${docker_config}'
|
|
|
|
|
2021-02-13 18:27:58 +00:00
|
|
|
docker-flush-db: # (Docker) Removes all the data present in the database but preserves tables and migrations
|
|
|
|
docker-compose exec -T app sh -c 'python manage.py flush --no-input ${docker_config}'
|
|
|
|
|
|
|
|
docker-destroy-db: # (Docker) Removes the volume where the database is installed on, alongside to the container itself
|
|
|
|
docker rm -f pokeapi_db_1
|
|
|
|
docker volume rm pokeapi_pg_data
|
2021-01-11 18:44:43 +00:00
|
|
|
|
|
|
|
docker-shell: # (Docker) Launch an interative shell for the pokeapi container
|
|
|
|
docker-compose exec app sh -l
|
|
|
|
|
|
|
|
docker-stop: # (Docker) Stop containers
|
|
|
|
docker-compose stop
|
|
|
|
|
|
|
|
docker-down: # (Docker) Stop and removes containers and networks
|
|
|
|
docker-compose down
|
|
|
|
|
2023-11-25 12:21:14 +00:00
|
|
|
docker-test: # (Docker) Run tests
|
|
|
|
docker-compose exec -T app python manage.py test ${local_config}
|
|
|
|
|
2021-08-30 16:24:56 +00:00
|
|
|
docker-prod:
|
2023-01-09 15:11:23 +00:00
|
|
|
docker-compose -f docker-compose.yml -f docker-compose.override.yml -f Resources/compose/docker-compose-prod-graphql.yml up -d
|
2021-08-30 16:24:56 +00:00
|
|
|
|
2021-01-11 18:44:43 +00:00
|
|
|
docker-setup: docker-up docker-migrate docker-build-db # (Docker) Start services, prepare the latest DB schema, populate the DB
|
2020-02-17 20:58:07 +00:00
|
|
|
|
|
|
|
format: # Format the source code
|
|
|
|
black .
|
|
|
|
|
|
|
|
format-check: # Check the source code has been formatted
|
|
|
|
black . --check
|
2021-01-11 18:44:43 +00:00
|
|
|
|
|
|
|
pull:
|
|
|
|
git checkout master
|
|
|
|
git pull
|
|
|
|
|
|
|
|
pull-veekun:
|
|
|
|
git -C ${veekun_pokedex_repository} checkout master-pokeapi
|
|
|
|
git -C ${veekun_pokedex_repository} pull
|
|
|
|
|
2021-03-19 18:09:59 +00:00
|
|
|
sync-from-veekun: pull pull-veekun # Copy data from ../pokedex to this repository
|
2021-01-11 18:44:43 +00:00
|
|
|
cp -a ${veekun_pokedex_repository}/pokedex/data/csv/. ./data/v2/csv
|
|
|
|
|
2021-03-19 18:09:59 +00:00
|
|
|
sync-to-veekun: pull pull-veekun # Copy data from this repository to ../pokedex
|
2021-01-11 18:44:43 +00:00
|
|
|
cp -a ./data/v2/csv/. ${veekun_pokedex_repository}/pokedex/data/csv
|
2021-03-08 21:50:19 +00:00
|
|
|
|
2021-03-23 18:44:14 +00:00
|
|
|
# read-env-file: # Exports ./.env into shell environment variables
|
|
|
|
# export `egrep -v '^#' .env | xargs`
|
2021-03-19 18:09:59 +00:00
|
|
|
|
2024-01-09 22:17:57 +00:00
|
|
|
hasura-export: # Export Hasura configuration, be sure to have set HASURA_GRAPHQL_ADMIN_SECRET
|
|
|
|
hasura md export --project graphql
|
2021-03-08 21:50:19 +00:00
|
|
|
|
2024-01-09 22:17:57 +00:00
|
|
|
hasura-apply: # Apply local Hasura configuration, be sure to have set HASURA_GRAPHQL_ADMIN_SECRET
|
|
|
|
hasura md apply --project graphql
|
2021-03-19 18:09:59 +00:00
|
|
|
|
|
|
|
hasura-get-anon-schema: # Dumps GraphQL schema
|
2021-03-23 18:44:14 +00:00
|
|
|
gq http://localhost:8080/v1/graphql --introspect > graphql/schema.graphql
|
2021-05-27 17:25:40 +00:00
|
|
|
|
|
|
|
kustomize-apply: # (Kustomize) Run kubectl apply -k on the connected k8s cluster
|
2021-06-05 20:58:10 +00:00
|
|
|
kubectl apply -k Resources/k8s/kustomize/base/
|
|
|
|
|
|
|
|
kustomize-staging-apply: # (Kustomize) Run kubectl apply -k on the connected k8s cluster
|
|
|
|
kubectl apply -k Resources/k8s/kustomize/staging/
|
2021-05-27 17:25:40 +00:00
|
|
|
|
|
|
|
k8s-migrate: # (k8s) Run any pending migrations
|
2021-05-30 20:53:55 +00:00
|
|
|
kubectl exec --namespace pokeapi deployment/pokeapi -- python manage.py migrate --settings=config.docker-compose
|
2021-05-27 17:25:40 +00:00
|
|
|
|
|
|
|
k8s-build-db: # (k8s) Build the database
|
2021-05-30 20:53:55 +00:00
|
|
|
kubectl exec --namespace pokeapi deployment/pokeapi -- sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker-compose'
|
2021-05-27 17:25:40 +00:00
|
|
|
|
|
|
|
k8s-delete: # (k8s) Delete pokeapi namespace
|
2021-08-30 16:24:56 +00:00
|
|
|
kubectl delete namespace pokeapi
|
2022-05-13 20:17:43 +00:00
|
|
|
|
2023-01-30 15:07:34 +00:00
|
|
|
start-graphql-prod:
|
|
|
|
git pull origin master
|
|
|
|
git submodule update --init
|
2024-01-09 19:47:47 +00:00
|
|
|
docker compose -f docker-compose.yml -f Resources/compose/docker-compose-prod-graphql.yml up -d
|
|
|
|
docker compose stop app
|
|
|
|
|
|
|
|
down-graphql-prod:
|
|
|
|
docker container rm $(docker container ls -aq) -f
|
|
|
|
docker system prune --all --volumes --force
|
|
|
|
sync; echo 3 > /proc/sys/vm/drop_caches
|
2023-01-30 15:07:34 +00:00
|
|
|
|
|
|
|
update-graphql-data-prod:
|
2022-05-13 20:17:43 +00:00
|
|
|
git pull origin master
|
2022-07-21 10:01:06 +00:00
|
|
|
git submodule update --init
|
2024-01-09 19:47:47 +00:00
|
|
|
docker compose stop graphql-engine
|
2022-05-13 20:17:43 +00:00
|
|
|
sync; echo 3 > /proc/sys/vm/drop_caches
|
2024-01-09 19:47:47 +00:00
|
|
|
docker compose -f docker-compose.yml -f Resources/compose/docker-compose-prod-graphql.yml up -d app
|
2022-05-13 20:17:43 +00:00
|
|
|
make docker-migrate
|
|
|
|
make docker-build-db
|
2024-01-10 15:44:32 +00:00
|
|
|
docker compose stop app
|
2022-05-13 20:17:43 +00:00
|
|
|
sync; echo 3 > /proc/sys/vm/drop_caches
|
2024-01-09 19:47:47 +00:00
|
|
|
docker compose exec -T web sh -c 'rm -rf /tmp/cache/*'
|
|
|
|
docker compose start graphql-engine
|
2024-01-10 19:34:19 +00:00
|
|
|
sleep 30
|
|
|
|
make hasura-apply
|