Skip to content

Instantly share code, notes, and snippets.

@koaps
Last active April 23, 2019 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koaps/73c71a0c00c3b633f0e5911cc5140536 to your computer and use it in GitHub Desktop.
Save koaps/73c71a0c00c3b633f0e5911cc5140536 to your computer and use it in GitHub Desktop.
Local Dev
ALL_ACTIONS := build up down clean
ALL_TARGETS := proxy
DO_A := $(filter $(ALL_ACTIONS),$(MAKECMDGOALS))
DO_T := $(filter $(ALL_TARGETS),$(MAKECMDGOALS))
.DEFAULT_GOAL := all
actions := $(strip $(if $(DO_A), $(DO_A), up))
targets := $(strip $(if $(DO_T), $(DO_T), $(ALL_TARGETS)))
define name-target
.$(strip $2)_$(strip $1)
endef
define add-target
$(1) += $(call name-target, $(1), $(2))
endef
define do-target
$(1): $(2)
endef
# make targets
$(foreach t,$(targets),$(foreach a,$(actions),$(eval $(call add-target, $(t), $(a)) )))
$(foreach t,$(targets),$(eval $(call do-target, $(t), $($t)) ))
# docker control
define .dc_clean
docker_cleanup && \
docker network prune -f && \
docker volume prune -f
endef
define .dc_down
cd $(1) && \
docker-compose down -v
endef
define .dc_build
cd $(1) && \
docker-compose build
endef
define .dc_pull
cd $(1) && \
docker-compose pull
endef
define .dc_up
cd $(1) && \
docker-compose up --force-recreate -d
endef
## all target
.PHONY: all
all: $(ALL_TARGETS)
## clean target
.PHONY: clean
clean:
$(call .dc_clean)
.down_proxy:
$(call .dc_down, dev_proxy)
.up_proxy:
$(call .dc_up, dev_proxy)
%:
@:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment