ufw rules

This commit is contained in:
Yann Autissier
2022-11-18 14:01:16 +00:00
parent 4206ffb5b7
commit 96567c54dc
10 changed files with 53 additions and 8 deletions
+6
View File
@@ -1,14 +1,20 @@
CMDARGS += ufw ufw-docker
UFW_UPDATE ?= $(or $(SERVICE),$(DOCKER_SERVICES))
ifeq ($(SETUP_UFW),true)
# function ufw: Exec command ufw with args 1
define ufw
$(call INFO,ufw,$(1)$(comma))
$(call app-bootstrap,ufw-docker)
$(call app-exec,,ufw $(1))
endef
# function ufw-docker: Exec command ufw-docker with args 1
define ufw-docker
$(call INFO,ufw-docker,$(1)$(comma))
$(call app-bootstrap,ufw-docker)
$(call app-exec,,ufw-docker $(1))
endef
endif
+32
View File
@@ -1,5 +1,37 @@
# target ufw: Call ufw ARGS
.PHONY: ufw
ufw:
$(call ufw,$(ARGS))
# target ufw-delete: Fire ufw-update UFW_DELETE=true
.PHONY: ufw-delete
ufw-delete: UFW_DELETE := true
ufw-delete: ufw-update
# target ufw-docker: Call ufw-docker ARGS
.PHONY: ufw-docker
ufw-docker:
$(call ufw-docker,$(ARGS))
# target ufw-docker: Call ufw and ufw-docker foreach service UFW_UPDATE
.PHONY: ufw-update
ufw-update:
$(foreach update,$(UFW_UPDATE), \
$(foreach port,$(UFW_DOCKER_$(DOCKER_COMPOSE_PROJECT_NAME)-$(update)), \
$(call ufw-docker,$(if $(UFW_DELETE),delete) allow $(DOCKER_COMPOSE_PROJECT_NAME)-$(update) $(port)) \
) \
$(foreach port,$(UFW_UPDATE_$(DOCKER_COMPOSE_PROJECT_NAME)-$(update)), \
$(call ufw,$(if $(UFW_DELETE),delete) allow $(port)) \
) \
)
## ex: ufw-node-up will update ufw rules for stack node
.PHONY: stack-%
ufw-%:
$(eval stack := $(subst -$(lastword $(subst -, ,$*)),,$*))
$(eval command := $(lastword $(subst -, ,$*)))
$(if $(findstring -,$*), \
$(if $(filter ufw-$(command),$(MAKE_TARGETS)), \
$(call make,ufw-$(command) STACK="$(stack)") \
) \
)