78 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			Makefile
		
	
	
	
	
	
			
		
		
	
	
			78 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			Makefile
		
	
	
	
	
	
.PHONY: create_contexts deploy upload pull start stop restart
 | 
						|
 | 
						|
include config.mk
 | 
						|
 | 
						|
create_contexts:
 | 
						|
	@- $(foreach host,$(DEPLOY_HOSTS), \
 | 
						|
	    docker context create $(host) --description "$(host)" --docker "host=ssh://$(SSH_USER)@$(host)"; \
 | 
						|
	)
 | 
						|
	
 | 
						|
deploy: upload pre-deploy pull start post-deploy
 | 
						|
 | 
						|
pre-deploy:
 | 
						|
	@- $(foreach host,$(DEPLOY_HOSTS), \
 | 
						|
		cd $(DEPLOY_PATH)/$(DEPLOY_NAME); \
 | 
						|
		sh pre-deploy.sh; \
 | 
						|
	)
 | 
						|
	
 | 
						|
post-deploy:
 | 
						|
	@- $(foreach host,$(DEPLOY_HOSTS), \
 | 
						|
		cd $(DEPLOY_PATH)/$(DEPLOY_NAME); \
 | 
						|
		sh post-deploy.sh; \
 | 
						|
	)
 | 
						|
	
 | 
						|
upload:
 | 
						|
	@- echo "\n### uploading files"
 | 
						|
	@- $(foreach host,$(DEPLOY_HOSTS), \
 | 
						|
		rsync -rav --exclude '*~' . $(SSH_USER)@$(host):$(DEPLOY_PATH)/$(DEPLOY_NAME); \
 | 
						|
	)
 | 
						|
 | 
						|
pull:
 | 
						|
	@- echo "\n### pulling image(s)"
 | 
						|
	@- $(foreach ctx,$(DEPLOY_HOSTS), \
 | 
						|
		docker context use $(ctx); \
 | 
						|
		docker pull $(DOCKER_IMAGE); \
 | 
						|
	)
 | 
						|
	
 | 
						|
start: start-$(DEPLOY_TYPE)
 | 
						|
 | 
						|
stop: stop-$(DEPLOY_TYPE)
 | 
						|
 | 
						|
logs: logs-$(DEPLOY_TYPE)
 | 
						|
 | 
						|
start-compose:
 | 
						|
	@- echo "\n### starting service(s)"
 | 
						|
	@- $(foreach ctx,$(DEPLOY_HOSTS), \
 | 
						|
		docker context use $(ctx); \
 | 
						|
		docker-compose up -d; \
 | 
						|
	)
 | 
						|
 | 
						|
stop-compose:
 | 
						|
	@- echo "\n### stopping service(s)"
 | 
						|
	@- $(foreach ctx,$(DEPLOY_HOSTS), \
 | 
						|
		docker context use $(ctx); \
 | 
						|
		docker-compose down; \
 | 
						|
	)
 | 
						|
 | 
						|
logs-compose:
 | 
						|
	@- echo "\n### logs"
 | 
						|
	@- docker context use $(host)
 | 
						|
	@- docker-compose logs -f $(service)
 | 
						|
 | 
						|
start-swarm:
 | 
						|
 | 
						|
stop-swarm:
 | 
						|
 | 
						|
logs-swarm:
 | 
						|
 | 
						|
restart:
 | 
						|
	@- $(foreach ctx,$(DEPLOY_HOSTS), \
 | 
						|
		docker context use $(ctx); \
 | 
						|
		docker-compose restart; \
 | 
						|
	)
 | 
						|
 | 
						|
reload:
 | 
						|
	@- $(foreach host,$(DEPLOY_HOSTS), \
 | 
						|
		docker context use $(ctx); \
 | 
						|
		docker-compose restart; \
 | 
						|
	)	
 |