11
22DOCKER_COMPOSE_FILE ?= docker-compose.yml
3+ DOCKER_COMPOSE ?= docker compose
4+ UTILITY := utility
35
46# Well documented Makefiles
57DEFAULT_GOAL := help
68
79help :
8- @awk ' BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-40s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST )
10+ @echo " Available commands:"
11+ @echo " "
12+ @echo " === Setup ==="
13+ @echo " make config - Install default config to alpha-core"
14+ @echo " make setup-all - Run config, db-setup, and up"
15+ @echo " make external_db - Switch to external DB and disable local sql"
16+ @echo " make internal_db - Switch to local sql and enable localdb profile"
17+ @echo " "
18+ @echo " === Database ==="
19+ @echo " make db-user - Create DB user (if not root)"
20+ @echo " make db-create - Create databases"
21+ @echo " make db-drop - Drop databases"
22+ @echo " make db-populate - Populate databases (schema only)"
23+ @echo " make db-update - Apply database updates"
24+ @echo " make db-setup - Create, populate, then update databases"
25+ @echo " make db-backup - Backup databases (optional BACKUP=folder)"
26+ @echo " make db-restore - Restore databases (optional BACKUP=folder)"
27+ @echo " "
28+ @echo " === Docker ==="
29+ @echo " make up - Build and start all containers"
30+ @echo " make start - Start all containers"
31+ @echo " make stop - Stop all containers (not dev)"
32+ @echo " make restart - Restart all containers (not dev)"
33+ @echo " make down - Stop and remove containers (not dev)"
34+ @echo " make build-utility - Build utility image"
35+ @echo " make connect <name> - Connect to container"
36+ @echo " make list - List running containers"
37+ @echo " "
38+ @echo " === Logs ==="
39+ @echo " make log <name> - Show container log"
40+ @echo " make logs - Show all containers logs"
941
1042# #@ [Run Firsttime]
43+ .PHONY : config
1144config : # # Install default config to alpha-core
12- cp etc/config/config.yml.dist etc/config/config.yml
45+ @if [ -e etc/config/config.yml ] && [ ! -w etc/config/config.yml ]; then \
46+ echo " etc/config/config.yml is not writable; run: sudo chown $$ USER:$$ USER etc/config/config.yml" ; \
47+ exit 1; \
48+ fi
49+ @cp etc/config/config.yml.dist etc/config/config.yml
50+ @echo " Config installed to etc/config/config.yml"
51+
52+ setup-all : # # Run config, db-setup, and up
53+ $(MAKE ) config
54+ $(MAKE ) db-setup
55+ $(MAKE ) up
56+
57+ external_db : # # Switch to external DB and disable local sql
58+ @set -a; . ./.env; set +a; python3 etc/docker/external_db.py
59+
60+ internal_db : # # Switch to local sql and enable localdb profile
61+ @set -a; . ./.env; set +a; python3 etc/docker/internal_db.py
62+ # #@ [Database]
63+ db-create : build-utility db-start-local db-user # # Create databases
64+ $(DOCKER_COMPOSE ) run --rm $(UTILITY ) /bin/commands/create_databases.sh
65+
66+ db-drop : build-utility db-start-local # # Drop databases
67+ $(DOCKER_COMPOSE ) run --rm $(UTILITY ) /bin/commands/drop_databases.sh
68+
69+ db-populate : build-utility db-start-local # # Populate databases (schema only)
70+ $(DOCKER_COMPOSE ) run --rm $(UTILITY ) /bin/commands/populate_databases.sh
71+
72+ db-update : build-utility db-start-local # # Apply database updates
73+ $(DOCKER_COMPOSE ) run --rm $(UTILITY ) /bin/commands/update_databases.sh
74+
75+ db-setup : # # Create, populate, then update databases
76+ $(MAKE ) db-create
77+ $(MAKE ) db-populate
78+ $(MAKE ) db-update
79+
80+ db-backup : build-utility db-start-local # # Backup databases (optional BACKUP=folder)
81+ $(DOCKER_COMPOSE ) run --rm $(UTILITY ) /bin/commands/backup_db.sh
82+
83+ db-restore : build-utility db-start-local # # Restore databases (optional BACKUP=folder)
84+ $(DOCKER_COMPOSE ) run --rm $(UTILITY ) /bin/commands/restore_db.sh
1385
1486# #@ [Docker]
87+ build-utility : # # Build utility image
88+ $(DOCKER_COMPOSE ) build $(UTILITY )
89+
90+ db-user : build-utility db-start-local # # Create DB user (if not root)
91+ $(DOCKER_COMPOSE ) run --rm $(UTILITY ) /bin/commands/create_db_user.sh
92+
93+ db-start-local : # # Start local sql if MYSQL_HOST=sql
94+ @set -a; . ./.env; set +a; \
95+ if [ " $$ MYSQL_HOST" = " sql" ] || [ " $$ MYSQL_HOST" = " 127.0.0.1" ] || [ " $$ MYSQL_HOST" = " localhost" ]; then \
96+ $(DOCKER_COMPOSE ) up -d sql; \
97+ echo " Waiting for sql to be ready..." ; \
98+ host=" $$ MYSQL_HOST" ; \
99+ port=" $$ MYSQL_PORT" ; \
100+ if [ " $$ MYSQL_HOST" = " sql" ]; then \
101+ host=" 127.0.0.1" ; \
102+ port=" $$ MYSQL_HOST_PORT" ; \
103+ fi ; \
104+ i=0; \
105+ while [ $$ i -lt 30 ]; do \
106+ if bash -c " </dev/tcp/$$ host/$$ port" > /dev/null 2>&1 ; then \
107+ echo " sql is ready." ; \
108+ break ; \
109+ fi ; \
110+ i=$$((i+1 ) ); \
111+ sleep 2; \
112+ done ; \
113+ if [ $$ i -ge 30 ]; then \
114+ echo " Timed out waiting for sql." ; \
115+ exit 1; \
116+ fi ; \
117+ fi
118+
15119up : # # Build and start all containers
16- docker compose -f $( DOCKER_COMPOSE_FILE ) up -d
120+ $( DOCKER_COMPOSE ) up -d
17121
18122start : # # Start all containers
19- docker compose -f $( DOCKER_COMPOSE_FILE ) start
123+ $( DOCKER_COMPOSE ) start
20124
21125stop : # # Stop all containers (not dev)
22- docker compose -f $( DOCKER_COMPOSE_FILE ) stop
126+ $( DOCKER_COMPOSE ) stop
23127
24128restart : # # Restart all containers (not dev)
25- docker compose -f $( DOCKER_COMPOSE_FILE ) restart
129+ $( DOCKER_COMPOSE ) restart
26130
27131down : # # Stop and remove containers (not dev)
28- docker compose -f $(DOCKER_COMPOSE_FILE ) down
29-
30- build : # # Just build all docker images
31- docker compose -f $(DOCKER_COMPOSE_FILE ) build
132+ $(DOCKER_COMPOSE ) down
32133
33134connect : # # Connect to container. usage: make connect <container>
34135 docker exec -it $(filter-out $@ ,$(MAKECMDGOALS ) ) /bin/sh
@@ -37,22 +138,8 @@ list: ## List all runnning containers
37138 docker ps -a --format=" table {{.Names}}\t{{.Image}}\t{{.Status}}"
38139
39140# #@ [Logs]
40- log : # # show one contaienr log. usage: make log <container >
141+ log : # # show one contaienr log. usage: make log <contai ner >
41142 docker logs $(filter-out $@ ,$(MAKECMDGOALS ) ) -f
42143
43- all-logs : # # Show all containers logs
44- docker-compose logs -f
45-
46- # #@ [Profiles: dev]
47- up-dev : # # Build and start dev profile with PhpMyAdmin, Inotify (run it after make up)
48- docker compose -f $(DOCKER_COMPOSE_FILE ) --profile dev up -d
49-
50- start-dev : # # Start built containers in dev profile
51- docker start alpha-core-phpmyadmin-1 alpha-core-inotify-1
52-
53- stop-dev : # # Stop built containers in dev profile
54- docker stop alpha-core-phpmyadmin-1 alpha-core-inotify-1
55-
56- down-dev : # # Stop and remove dev profile containers
57- docker stop alpha-core-phpmyadmin-1 alpha-core-inotify-1
58- docker rm alpha-core-phpmyadmin-1 alpha-core-inotify-1
144+ logs : # # Show all containers logs
145+ $(DOCKER_COMPOSE ) logs -f
0 commit comments