Created
September 2, 2022 16:22
-
-
Save chasemc/179999864ea912c3c5e12edf292f976e to your computer and use it in GitHub Desktop.
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
include common_parameters.env | |
export | |
SHELL = /bin/bash | |
CURRENT_UID := $(shell id -u) | |
CURRENT_GID := $(shell id -g) | |
export CURRENT_UID | |
export CURRENT_GID | |
## help : Print help info | |
help : Makefile | |
@sed -n 's/^##//p' $< | |
## clean : Clean temporary files, INCLUDES DELETING THE NEXTFLOW TEMPORY WORK DIRECTORY | |
clean: | |
@echo "Cleaning up temporary Python files..." | |
find ./sgpy -type f -name "*.py[co]" -exec rm -r {} + | |
find ./sgpy -type d -name "__pycache__" -exec rm -r {} + | |
find ./sgpy -type d -name "htmlcov" -exec rm -r {} + | |
find ./sgpy -type d -name "Autometa.egg-info" -exec rm -r {} + | |
find ./sgpy -type d -name "dist" -exec rm -r {} + | |
find ./sgpy -type d -name "build" -exec rm -r {} + | |
find ./sgpy -type d -name ".eggs" -exec rm -r {} + | |
find ./sgpy -type d -name "*.egg-info" -exec rm -r {} + | |
find ./sgpy -type d -name ".pytest_cache" -exec rm -r {} + | |
find ./sgpy -type d -name ".tox" -exec rm -r {} + | |
find ./sgpy -type d -name ".coverage" -exec rm -r {} + | |
find ./django -type d -name "data2/local_postgres_data" -exec rm -r {} + | |
find ./django -type d -name "data2/local_postgres_data_backups" -exec rm -r {} + | |
find ./django -type d -name "data2/redis-data" -exec rm -r {} + | |
find . -name ".nextflow.log.*" -exec rm -r {} + | |
find . -type d -name ".nextflow" -exec rm -r {} + | |
find . -name ".nextflow.log" -exec rm {} + | |
find . -type d -name "work" -exec rm -r {} + | |
find . -type d -name ".pytest_cache" -exec rm -r {} + | |
find . -type d -name "__pycache__" -exec rm -r {} + | |
find . -type d -name "site" -exec rm -r {} + | |
## | |
## DJANGO SPECIFIC TASKS | |
## | |
## | |
# https://github.com/pydanny/cookiecutter-django/pull/1879#issuecomment-516251029 | |
PROJECT_NAME=socialgeneweb | |
export COMPOSE_FILE=local.yml | |
.PHONY: up down stop prune ps shell logs | |
default: up | |
# necessary so docker won't create these as root | |
make_django_dirs: | |
mkdir -p data2/local_postgres_data | |
mkdir -p data2/local_postgres_data_backups | |
mkdir -p data2/redis-data | |
django_build: | |
@echo "Building containers for for ${PROJECT_NAME}..." | |
CURRENT_UID=$(shell id -u):$(shell id -g) docker compose -f ${COMPOSE_FILE} --env-file common_parameters.env build --parallel | |
## django_up : Start up containers. | |
django_up: make_django_dirs django_build | |
@echo "Starting up containers for for ${PROJECT_NAME}..." | |
# @see:https://github.com/docker/compose/issues/6464 | |
#docker compose pull | |
CURRENT_UID=$(shell id -u):$(shell id -g) docker compose -f ${COMPOSE_FILE} --env-file common_parameters.env up --remove-orphans | |
upq: make_django_dirs | |
CURRENT_UID=$(shell id -u):$(shell id -g) docker compose -f ${COMPOSE_FILE} --env-file common_parameters.env up --remove-orphans | |
## build : Build python image. | |
build: | |
@echo "Building python image for for ${PROJECT_NAME}..." | |
docker compose build | |
## down : Stop containers. | |
down: stop | |
## start : Start containers without updating. | |
start: make_django_dirs | |
@echo "Starting containers for $(PROJECT_NAME) from where you left off..." | |
@docker compose start | |
## stop : Stop containers. | |
stop: | |
@echo "Stopping containers for $(PROJECT_NAME)..." | |
CURRENT_UID=$(shell id -u):$(shell id -g) docker compose -f ${COMPOSE_FILE} down | |
## prune : Remove containers and their volumes. | |
## You can optionally pass an argument with the service name to prune single container | |
## prune mariadb : Prune `mariadb` container and remove its volumes. | |
## prune mariadb solr : Prune `mariadb` and `solr` containers and remove their volumes. | |
prune: | |
@echo "Removing containers for $(PROJECT_NAME)..." | |
@docker compose down -v $(filter-out $@,$(MAKECMDGOALS)) | |
## ps : List running containers. | |
ps: | |
@docker ps --filter name='$(PROJECT_NAME)*' | |
## manage : Executes `manage.py` command. | |
## To use "--flag" arguments include them in quotation marks. | |
## For example: make manage "makemessages --locale=pl" | |
.PHONY: manage | |
manage: make_django_dirs | |
CURRENT_UID=$(shell id -u):$(shell id -g) docker compose -f $(COMPOSE_FILE) run --rm django python manage.py $(filter-out $@,$(MAKECMDGOALS)) $(subst \,,$(MAKEFLAGS)) | |
manage2: | |
CURRENT_UID=$(shell id -u):$(shell id -g) docker compose -f $(COMPOSE_FILE) run --rm django python manage.py list_model_info | |
migrate: | |
CURRENT_UID=$(shell id -u):$(shell id -g) docker compose -f $(COMPOSE_FILE) run --rm django python manage.py migrate | |
makemigrations: | |
docker compose -f local.yml run --rm django python3 manage.py makemigrations | |
show_urls: | |
CURRENT_UID=$(shell id -u):$(shell id -g) docker compose -f local.yml run --rm django python manage.py show_urls | |
createsuperuser: make_django_dirs | |
CURRENT_UID=$(shell id -u):$(shell id -g) docker compose -f $(COMPOSE_FILE) run --rm django python manage.py createsuperuser | |
## django_logs: print the django docker compose logs | |
django_logs: | |
@docker compose logs -f $(filter-out $@,$(MAKECMDGOALS)) | |
## | |
## NEO4J SPECIFIC TASKS | |
## | |
## memrec: Get an estimate of the Neo4j memory settings your machine is capable of | |
memrec: | |
docker run \ | |
--user="$(id -u)":"$(id -g)" \ | |
--env NEO4J_AUTH=neo4j/test \ | |
--interactive \ | |
--tty \ | |
neo4j:4.3.7 \ | |
neo4j-admin \ | |
memrec \ | |
--memory=60G \ | |
--verbose \ | |
--docker | |
## | |
## DEVELOPMENT TASKS | |
## | |
## django_test : Run pytest for the Django code | |
django_test: | |
CURRENT_UID=$(shell id -u):$(shell id -g) docker compose -f $(COMPOSE_FILE) run --rm django pytest | |
# https://stackoverflow.com/a/6273809/1826109 | |
%: | |
@: | |
########################################################################################################### | |
########################################################################################################### | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment