1+ # List of binaries devent needs to function properly
12COMMANDS := sudo tar zstd getent stress
23$(foreach bin,$(COMMANDS),\
34 $(if $(shell command -v $(bin) 2> /dev/null),$(info),$(error Missing required dependency: `$(bin)`)))
4-
55TARGET := $(firstword $(MAKECMDGOALS ) )
66PARAMS := $(filter-out $(TARGET ) ,$(MAKECMDGOALS ) )
7+ # Hardcode the chainstate dir if we're booting from genesis
78ifeq ($(TARGET ) ,up-genesis)
89 export CHAINSTATE_DIR := $(PWD)/docker/chainstate/genesis
910endif
1011ifeq ($(TARGET ) ,genesis)
1112 export CHAINSTATE_DIR := $(PWD)/docker/chainstate/genesis
1213endif
1314
14-
15- # # UID and GID are not currently used, but will be in the near future
15+ # UID and GID are not currently used, but may be later to ensure consistent file permissions
1616export UID := $(shell getent passwd $$(whoami ) | cut -d":" -f 3)
1717export GID := $(shell getent passwd $$(whoami ) | cut -d":" -f 4)
1818EPOCH := $(shell date +% s)
@@ -23,6 +23,7 @@ CHAINSTATE_ARCHIVE ?= $(PWD)/docker/chainstate.tar.zstd
2323export CHAINSTATE_DIR ?= $(PWD ) /docker/chainstate/$(EPOCH )
2424export DOCKER_NETWORK ?= stacks
2525SERVICES := $(shell CHAINSTATE_DIR="" docker compose -f docker/docker-compose.yml --profile=default config --services)
26+ # Pauses the bitcoin miner script. Default is set to nearly 1 trillion blocks
2627PAUSE_HEIGHT ?= 999999999999
2728# Used for the stress testing target. modifies how much cpu to consume for how long
2829STRESS_CORES ?= $(shell cat /proc/cpuinfo | grep processor | wc -l)
@@ -43,15 +44,56 @@ $(CHAINSTATE_DIR): /usr/bin/tar /usr/bin/zstd
4344 fi
4445 fi
4546
46- # Boot the network from the local chainstate archive
47+
48+ # Build the images with a cache if present
49+ build : check-not-running
50+ COMPOSE_BAKE=true PWD=$(PWD ) docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT ) build
51+
52+ # Build the images without a cache (default uses cache)
53+ build-no-cache : check-not-running
54+ COMPOSE_BAKE=true PWD=$(PWD ) docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT ) build --no-cache
55+
56+ # Set env var of what the statically defined chainstate dir is
57+ current-chainstate-dir : | check-running
58+ $(eval ACTIVE_CHAINSTATE_DIR=$(shell cat .current-chainstate-dir) )
59+
60+ # If the network is already running, we need to exit (ex: trying to start the network when it's already running)
61+ check-not-running :
62+ @if test ` docker compose ls --filter name=$( PROJECT) -q` ; then \
63+ echo " " ; \
64+ echo " WARNING: Network appears to be running or was not properly shut down." ; \
65+ echo " Current chainstate directory: $$ (cat .current-chainstate-dir)" ; \
66+ echo " " ; \
67+ echo " To backup logs first: make backup-logs" ; \
68+ echo " To shut down: make down" ; \
69+ echo " " ; \
70+ exit 1; \
71+ fi
72+
73+ # If the network is not running, we need to exit (ex: trying to restart a container)
74+ check-running :
75+ @if test ! ` docker compose ls --filter name=$( PROJECT) -q` ; then \
76+ echo " Network not running. exiting" ; \
77+ exit 1; \
78+ fi
79+
80+ # For targets that need an arg, check that *something* is provided. it not, exit
81+ check-params : | check-running
82+ @if [ ! " $( PARAMS) " ]; then \
83+ echo " No service defined. Exiting" ; \
84+ exit 1; \
85+ fi
86+
87+ # Boot the network from a local chainstate archive
4788up : check-not-running | build $(CHAINSTATE_DIR )
4889 @echo " Starting $( PROJECT) network from chainstate archive"
4990 @echo " Chainstate Dir: $( CHAINSTATE_DIR) "
5091 @echo " Chainstate Archive: $( CHAINSTATE_ARCHIVE) "
5192 echo " $( CHAINSTATE_DIR) " > .current-chainstate-dir
5293 docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT ) up -d
5394
54- # Run the network from genesis
95+
96+ # Boot the network from genesis
5597genesis : check-not-running | build $(CHAINSTATE_DIR ) /usr/bin/sudo
5698 @echo " Starting $( PROJECT) network from genesis"
5799 @if [ -d " $( CHAINSTATE_DIR) " ]; then \
@@ -63,10 +105,8 @@ genesis: check-not-running | build $(CHAINSTATE_DIR) /usr/bin/sudo
63105 echo " $( CHAINSTATE_DIR) " > .current-chainstate-dir
64106 docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT ) up -d
65107
66- # secondary name to run genesis network
108+ # Secondary name to boot the genesis network
67109up-genesis : genesis
68- # secondary name to bring down genesis network
69- down-genesis : down
70110
71111# Shut down the network (chainstate and logs will be preserved, but not logs)
72112down : backup-logs current-chainstate-dir
@@ -76,31 +116,30 @@ down: backup-logs current-chainstate-dir
76116 rm -f .current-chainstate-dir
77117 fi
78118
79- # if the network is in a weird state - this target will force kill (bypassing error checks)
119+
120+ # Secondary name to bring down the genesis network
121+ down-genesis : down
122+
123+ # If the network is in an unexpected state - this target will force kill (bypassing error checks)
80124down-force :
81125 @echo " Force Shutting down $( PROJECT) network"
82126 docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT ) down
83127 @if [ -f .current-chainstate-dir ]; then \
84128 rm -f .current-chainstate-dir
85129 fi
86130
87- # Build the images with a cache if present
88- build : check-not-running
89- COMPOSE_BAKE=true PWD=$(PWD ) docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT ) build
90-
91- # Build the images without a cache (default uses cache)
92- build-no-cache : check-not-running
93- COMPOSE_BAKE=true PWD=$(PWD ) docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT ) build --no-cache
94131
95132# Stream specified service logs to STDOUT. does not validate if PARAMS is supplied
96133log : current-chainstate-dir
97134 @echo " Logs for service $( PARAMS) "
98135 docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT ) logs -t --no-log-prefix $(PARAMS ) -f
99136
137+
100138# Stream all services logs to STDOUT
101139log-all : current-chainstate-dir
102140 docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT ) logs -t -f
103141
142+
104143# Backup all service logs to $ACTIVE_CHAINSTATE_DIR/logs/<service-name>.log
105144backup-logs : current-chainstate-dir /usr/bin/sudo
106145 @if [ -f .current-chainstate-dir ]; then \
@@ -118,11 +157,8 @@ backup-logs: current-chainstate-dir /usr/bin/sudo
118157 done ; \
119158 fi
120159
121- # set env var of what the statically defined chainstate dir is
122- current-chainstate-dir : | check-running
123- $(eval ACTIVE_CHAINSTATE_DIR=$(shell cat .current-chainstate-dir) )
124160
125- # replace the existing chainstate archive. will be used with target `up`
161+ # Replace the existing chainstate archive. will be used with target `up`
126162snapshot : current-chainstate-dir down
127163 @echo " Creating $( PROJECT) chainstate snapshot from $( ACTIVE_CHAINSTATE_DIR) "
128164 @if [ -d " $( ACTIVE_CHAINSTATE_DIR) /logs" ]; then \
@@ -132,85 +168,67 @@ snapshot: current-chainstate-dir down
132168 @echo " cd $( ACTIVE_CHAINSTATE_DIR) ; sudo tar --zstd -cf $( CHAINSTATE_ARCHIVE) *; cd $( PWD) "
133169 cd $(ACTIVE_CHAINSTATE_DIR ) ; sudo tar --zstd -cf $(CHAINSTATE_ARCHIVE ) * ; cd $(PWD )
134170
135- # pause all services in the network (netork is down, but recoverably with target 'unpause')
171+
172+ # Pause all services in the network (netork is down, but recoverably with target 'unpause')
136173pause :
137174 @echo " Pausing all services"
138175 docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT ) pause $(SERVICES )
139176
140- # unpause all services in the network (only used after first using target 'pause')
177+
178+ # Unpause all services in the network (only used after first using target 'pause')
141179unpause :
142180 @echo " Unpausing all services"
143181 docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT ) unpause $(SERVICES )
144182
145- # stop an individual service
183+
184+ # Stop an individual service
146185stop : check-params current-chainstate-dir | check-running
147186 @echo " Killing service $( PARAMS) "
148187 @echo " Chainstate Dir: $( ACTIVE_CHAINSTATE_DIR) "
149188 @echo " Target: $( TARGET) "
150189 @echo " Params: $( PARAMS) "
151190 CHAINSTATE_DIR=$(ACTIVE_CHAINSTATE_DIR ) docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT ) down $(PARAMS )
152191
153- # start an individual service
192+
193+ # Start an individual service
154194start : check-params current-chainstate-dir | check-running
155195 @echo " Resuming service $( PARAMS) "
156196 @echo " Chainstate Dir: $( ACTIVE_CHAINSTATE_DIR) "
157197 @echo " Target: $( TARGET) "
158198 @echo " Params: $( PARAMS) "
159199 CHAINSTATE_DIR=$(ACTIVE_CHAINSTATE_DIR ) docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT ) up -d $(PARAMS )
160200
161- # restart a service with a defined servicename/duration. called script will validate PARAMS
162- # if no duration is provided, default of 30s shall be used
201+
202+ # Restart a service with a defined servicename/duration - Script will validate PARAMS
203+ # If no duration is provided, a default of 30s shall be used
163204restart : check-params | check-running
164205 @echo " Restarting service"
165206 @echo " Params: $( PARAMS) "
166207 ./docker/tests/restart-container.sh $(PARAMS )
167208
168- # use 'stress' binary to consume defined cpu over a specified time
209+
210+ # Use 'stress' binary to consume defined cpu over a specified time
169211stress :
170212 @echo " Stressing system CPU $( PARAMS) "
171213 @echo " Cores: $( STRESS_CORES) "
172214 @echo " Timeout: $( STRESS_TIMEOUT) "
173215 stress --cpu $(STRESS_CORES ) --timeout $(STRESS_TIMEOUT )
174216
175- # run the test script to verify the services are all load and operating as expected
217+
218+ # Run the liveness script to verify the services are all loaded and operating as expected
176219test :
177220 ./docker/tests/devnet-liveness.sh
178221
179- # run the chain monitor script (loops and curls /v2/info, parsing the output to show current heights of miners)
222+
223+ # Run the chain monitor script (loops and curls /v2/info, parsing the output to show current heights of miners)
180224monitor :
181225 ./docker/tests/chain-monitor.sh
182226
183- # if the network is already running, we need to exit (ex: trying to start the network when it's already running)
184- check-not-running :
185- @if test ` docker compose ls --filter name=$( PROJECT) -q` ; then \
186- echo " " ; \
187- echo " WARNING: Network appears to be running or was not properly shut down." ; \
188- echo " Current chainstate directory: $$ (cat .current-chainstate-dir)" ; \
189- echo " " ; \
190- echo " To backup logs first: make backup-logs" ; \
191- echo " To shut down: make down" ; \
192- echo " " ; \
193- exit 1; \
194- fi
195-
196- # if the network is not running, we need to exit (ex: trying to restart a container)
197- check-running :
198- @if test ! ` docker compose ls --filter name=$( PROJECT) -q` ; then \
199- echo " Network not running. exiting" ; \
200- exit 1; \
201- fi
202-
203- # for targets that need an arg, check that *something* is provided. it not, exit
204- check-params : | check-running
205- @if [ ! " $( PARAMS) " ]; then \
206- echo " No service defined. Exiting" ; \
207- exit 1; \
208- fi
209227
210- # force stop and remove any existing chainstates (leaving all docker images/layers)
228+ # Force stop and remove any existing chainstates (leaving all docker images/layers)
211229clean : down-force
212230 sudo rm -rf ./docker/chainstate/*
213231
214232
215- .PHONY : up genesis up-genesis down-genesis down down -force build build-no-cache log log-all backup-logs current-chainstate-dir snapshot pause unpause stop start restart stress test monitor check-not-running check-running check-params clean
233+ .PHONY : build build-no-cache current-chainstate-dir check-not-running check-running check-params up genesis up-genesis down down -genesis down-force log log-all backup-logs snapshot pause unpause stop start restart stress test monitor clean
216234.ONESHELL : all-in-one-shell
0 commit comments