From 3c61753bd3c942773d1eae347abd67cc21662689 Mon Sep 17 00:00:00 2001 From: Alexey Kovrizhkin Date: Tue, 19 Dec 2023 02:16:59 +0300 Subject: [PATCH] dcape v3 --- Makefile | 56 ++++++++++++++++++++++++++++++++----------------------- README.md | 5 ++++- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index b0451a6..5c47e19 100644 --- a/Makefile +++ b/Makefile @@ -12,40 +12,46 @@ OBJECTSDIRECT = $(SOURCES:.sql=.direct) # app custom config # comments prefixed with '#- ' will be copied to $(CFG).sample -#- Postgresql container name (access via docker) -PG_CONTAINER ?= dcape-db-1 - -#- PowerDNS DB user name -PGUSER ?= pdns - -#- PowerDNS DB name -PGDATABASE ?= pdns - -#- Used ONLY for direct DB access without docker (update-direct) -PGPASSWORD ?= - #- ACME zone suffix -ACME_DOMAIN ?= +ACME_DOMAIN ?= #- This NS hostname for use in all SOA -NSERVER ?= +NSERVER ?= + +#- db container +DB_CONTAINER ?= # + +#- PowerDNS DB user name +PGUSER ?= pdns + +#- PowerDNS DB name +PGDATABASE ?= pdns + +#- Used ONLY for direct DB access without docker (update-direct) +PGPASSWORD ?= +#- Used ONLY for direct DB access without docker (update-direct) +DB_PORT_LOCAL ?= + +USE_DCAPE_DC := no # ------------------------------------------------------------------------------ -include $(CFG).bak export --include $(CFG) -export - # ------------------------------------------------------------------------------ -# dcape v1 comparibility -start-hook: update - -stop: +ifneq ($(findstring $(MAKECMDGOALS),psql),) + USE_DB := yes +else ifneq ($(findstring $(MAKECMDGOALS),psql-local),) + USE_DB := yes + ifndef DB_PORT_LOCAL + $(error "DB_PORT_LOCAL must be set - $(MAKECMDGOALS)") + endif +endif # ------------------------------------------------------------------------------ # Find and include DCAPE_ROOT/Makefile +#- dcape compose docker image DCAPE_COMPOSE ?= dcape-compose DCAPE_ROOT ?= $(shell docker inspect -f "{{.Config.Labels.dcape_root}}" $(DCAPE_COMPOSE)) @@ -56,19 +62,23 @@ else endif # ------------------------------------------------------------------------------ +## DB operations +#: +.PHONY: update + update: $(OBJECTS) %.done: %.sql @echo "*** $< ***" @csum=$$(md5sum $< | sed 's/ .*//') ; \ - cat $< | docker exec -i $$PG_CONTAINER psql -U $$PGUSER -d $$PGDATABASE -vcsum=$$csum -vACME_DOMAIN=$(ACME_DOMAIN) -vNSERVER=$(NSERVER) > $@ + cat $< | docker exec -i $$DB_CONTAINER psql -U $$PGUSER -d $$PGDATABASE -vcsum=$$csum -vACME_DOMAIN=$(ACME_DOMAIN) -vNSERVER=$(NSERVER) > $@ ## Load updated zone files via psql connection update-direct: $(CFG) $(OBJECTSDIRECT) %.direct: %.sql @echo "*** $< ***" - @source $(CFG) && cat $< | PGPASSWORD=$$PGPASSWORD psql -h localhost -U $$PGUSER > $@ + @source $(CFG) && cat $< | PGPASSWORD=$${PGPASSWORD:?Must be set} psql -h localhost -U $$PGUSER -p $${DB_PORT_LOCAL:?Must be set} > $@ # ------------------------------------------------------------------------------ diff --git a/README.md b/README.md index 7302702..47dca0a 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,10 @@ This project contains Makefile and sample sql zone definition for loading zones ## Requirements -* [dcape](https://github.com/TenderPro/dcape) installed on remote host with pdns and gitea running +* linux 64bit (git, make, wget, gawk, openssl) +* [docker](http://docker.io) +* [dcape](https://github.com/dopos/dcape) +* Git service ([github](https://github.com), [gitea](https://gitea.io) or [gogs](https://gogs.io)) ## Usage