|
| 1 | +mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) |
| 2 | +current_dir := $(notdir $(patsubst %/,%,$(dir $(mkfile_path)))) |
| 3 | +envfile := ./.env |
| 4 | +clear_db_after_schema_change := database/last-cleared.dummy |
| 5 | +db_schema := database/init/* |
| 6 | + |
| 7 | +.PHONY: help start start-no-webhooks debug sql logs stop clear-db |
| 8 | + |
| 9 | +# help target adapted from https://gist.github.com/prwhite/8168133#gistcomment-2278355 |
| 10 | +TARGET_MAX_CHAR_NUM=20 |
| 11 | + |
| 12 | +## Show help |
| 13 | +help: |
| 14 | + @echo '' |
| 15 | + @echo 'Usage:' |
| 16 | + @echo ' make <target>' |
| 17 | + @echo '' |
| 18 | + @echo 'Targets:' |
| 19 | + @awk '/^[a-zA-Z\-\_0-9]+:/ { \ |
| 20 | + helpMessage = match(lastLine, /^## (.*)/); \ |
| 21 | + if (helpMessage) { \ |
| 22 | + helpCommand = substr($$1, 0, index($$1, ":")-1); \ |
| 23 | + helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \ |
| 24 | + printf " %-$(TARGET_MAX_CHAR_NUM)s %s\n", helpCommand, helpMessage; \ |
| 25 | + } \ |
| 26 | + } \ |
| 27 | + { lastLine = $$0 }' $(MAKEFILE_LIST) |
| 28 | + |
| 29 | +## Start the services |
| 30 | +start: $(envfile) $(clear_db_after_schema_change) |
| 31 | + @echo "Pulling images from Docker Hub (this may take a few minutes)" |
| 32 | + docker-compose pull |
| 33 | + @echo "Starting Docker services" |
| 34 | + docker-compose up --detach |
| 35 | + ./wait-for-client.sh |
| 36 | + |
| 37 | +## Start the services without webhooks |
| 38 | +start-no-webhooks: $(envfile) $(clear_db_after_schema_change) |
| 39 | + @echo "Pulling images from Docker Hub (this may take a few minutes)" |
| 40 | + docker-compose pull |
| 41 | + @echo "Starting Docker services" |
| 42 | + docker-compose up --detach client |
| 43 | + ./wait-for-client.sh |
| 44 | + |
| 45 | +## Start the services in debug mode |
| 46 | +debug: $(envfile) $(clear_db_after_schema_change) |
| 47 | + @echo "Starting services (this may take a few minutes if there are any changes)" |
| 48 | + docker-compose -f docker-compose.yml -f docker-compose.debug.yml up --build --detach |
| 49 | + ./wait-for-client.sh |
| 50 | + |
| 51 | +## Start an interactive psql session (services must running) |
| 52 | +sql: |
| 53 | + docker-compose exec db psql -U postgres |
| 54 | + |
| 55 | +## Show the service logs (services must be running) |
| 56 | +logs: |
| 57 | + docker-compose logs --follow |
| 58 | + |
| 59 | +## Stop the services |
| 60 | +stop: |
| 61 | + docker-compose down |
| 62 | + docker volume rm $(current_dir)_client_node_modules || true |
| 63 | + docker volume rm $(current_dir)_server_node_modules || true |
| 64 | + |
| 65 | +## Clear the sandbox and development databases |
| 66 | +clear-db: stop |
| 67 | + docker volume rm $(current_dir)_pg_sandbox_data || true |
| 68 | + docker volume rm $(current_dir)_pg_development_data || true |
| 69 | + |
| 70 | +$(envfile): |
| 71 | + @echo "Error: .env file does not exist! See the README for instructions." |
| 72 | + @exit 1 |
| 73 | + |
| 74 | +# Remove local DBs if the DB schema has changed |
| 75 | +$(clear_db_after_schema_change): $(db_schema) |
| 76 | + @$(MAKE) clear-db |
| 77 | + @touch $(clear_db_after_schema_change) |
0 commit comments