2021-02-09 17:05:00 +01:00
##
# COMMON
.PHONY : bootstrap
2021-05-17 03:40:02 +02:00
bootstrap : bootstrap -git bootstrap -docker app -bootstrap ## Bootstrap application
2021-02-09 17:05:00 +01:00
.PHONY : boostrap -docker
bootstrap-docker : docker -network -create
$( call make,docker-compose-up)
.PHONY : bootstrap -git
2021-05-17 03:40:02 +02:00
bootstrap-git : bootstrap -git -$( APP_DIR )
.PHONY : bootstrap -git -%
bootstrap-git-% :
if ! git config remote.origin.url > /dev/null ; \
then git clone $( GIT_REPOSITORY) $* ; \
2021-02-09 17:05:00 +01:00
fi
.PHONY : config
config : docker -compose -config ## View docker compose file
.PHONY : connect
connect : docker -compose -connect ## Connect to docker $(SERVICE)
.PHONY : connect @%
connect@% : SERVICE ?= $( DOCKER_SERVICE )
connect@% : ## Connect to docker $(SERVICE) on first remote host
2021-05-17 03:40:02 +02:00
$( call make,ssh-connect,$( MYOS) ,APP SERVICE)
2021-02-09 17:05:00 +01:00
.PHONY : down
down : docker -compose -down ## Remove application dockers
.PHONY : exec
exec : ## Exec a command in docker $(SERVICE)
i f n e q ( , $( filter $ ( ENV ) ,$ ( ENV_DEPLOY ) ) )
$( call exec,$( ARGS) )
e l s e
$( call make,docker-compose-exec,,ARGS)
e n d i f
.PHONY : exec @%
exec@% : SERVICE ?= $( DOCKER_SERVICE )
exec@% : ## Exec a command in docker $(SERVICE) on all remote hosts
2021-05-17 03:40:02 +02:00
$( call make,ssh-exec,$( MYOS) ,APP ARGS SERVICE)
2021-02-09 17:05:00 +01:00
.PHONY : logs
logs : docker -compose -logs ## Display application dockers logs
.PHONY : ps
ps : docker -compose -ps ## List application dockers
.PHONY : recreate
2021-05-31 03:45:39 +02:00
recreate : docker -compose -recreate app -start ## Recreate application dockers
2021-02-09 17:05:00 +01:00
.PHONY : reinstall
reinstall : clean ## Reinstall application
$( call make,.env)
$( call make,install)
.PHONY : restart
2021-05-31 03:45:39 +02:00
restart : docker -compose -restart app -start ## Restart application
2021-02-09 17:05:00 +01:00
.PHONY : run
run : ## Run a command in a new docker
i f n e q ( , $( filter $ ( ENV ) ,$ ( ENV_DEPLOY ) ) )
$( call run,$( ARGS) )
e l s e
$( call make,docker-compose-run,,ARGS)
e n d i f
.PHONY : run @%
run@% : SERVICE ?= $( DOCKER_SERVICE )
run@% : ## Run a command on all remote hosts
2021-05-17 03:40:02 +02:00
$( call make,ssh-run,$( MYOS) ,APP ARGS)
2021-02-09 17:05:00 +01:00
.PHONY : scale
scale : docker -compose -scale ## Scale application to NUM dockers
.PHONY : ssh @%
ssh@% : ## Connect to first remote host
2021-05-17 03:40:02 +02:00
$( call make,ssh,$( MYOS) ,APP)
2021-02-09 17:05:00 +01:00
# target stack: Call docker-stack function with each value of $(STACK)
.PHONY : stack
stack :
$( foreach stackz,$( STACK) ,$( call docker-stack,$( stackz) ) )
# target stack-%: Call docker-compose-* command on a given stack
## ex: calling stack-base-up will fire the docker-compose-up target on the base stack
## it splits $* on dashes and extracts stack from the beginning of $* and command
## from the last part of $*
.PHONY : stack -%
stack-% :
$( eval stack := $( subst -$( lastword $( subst -, ,$* ) ) ,,$* ) )
$( eval command := $( lastword $( subst -, ,$* ) ) )
$( if $( findstring -,$* ) , \
2021-05-31 22:29:12 +02:00
$( if $( filter $( command ) ,$( filter-out %-%,$( patsubst docker-compose-%,%,$( filter docker-compose-%,$( MAKE_TARGETS) ) ) ) ) , \
2021-05-17 03:40:02 +02:00
$( call make,docker-compose-$( command ) STACK = " $( stack) " $( if $( filter node,$( stack) ) ,COMPOSE_PROJECT_NAME= $( COMPOSE_PROJECT_NAME_NODE) ) ,,ARGS COMPOSE_IGNORE_ORPHANS SERVICE) ) )
2021-02-09 17:05:00 +01:00
.PHONY : start
start : docker -compose -start ## Start application dockers
.PHONY : stop
stop : docker -compose -stop ## Stop application dockers
.PHONY : tests app -tests
tests : app -tests ## Test application
.PHONY : up
2021-05-31 03:45:39 +02:00
up : docker -compose -up app -start ## Create application dockers
2021-02-09 17:05:00 +01:00
.PHONY : update app -update
2021-06-01 00:52:21 +02:00
update : update -app app -update ## Update application
2021-02-09 17:05:00 +01:00
# target %: Always fired target
## this target is fired everytime make is runned to call the stack target and
## update COMPOSE_FILE variable with all .yml files of the current project stack
% : FORCE stack %-rule -exists ;
# target %-rule-exists: Print a warning message if $* target does not exists
%-rule-exists :
2021-05-31 22:29:12 +02:00
$( if $( filter $* ,$( MAKECMDGOALS) ) ,$( if $( filter-out $* ,$( MAKE_TARGETS) ) ,printf " ${ COLOR_BROWN } WARNING ${ COLOR_RESET } : ${ COLOR_GREEN } target ${ COLOR_RESET } $* ${ COLOR_GREEN } not available in app ${ COLOR_RESET } $( APP) .\n " >& 2) )