This commit is contained in:
Alexey Kovrizhkin
2023-12-19 02:16:59 +03:00
parent 8862bb2bc8
commit 3c61753bd3
2 changed files with 37 additions and 24 deletions

View File

@@ -12,8 +12,14 @@ 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
#- ACME zone suffix
ACME_DOMAIN ?=
#- This NS hostname for use in all SOA
NSERVER ?=
#- db container
DB_CONTAINER ?= #
#- PowerDNS DB user name
PGUSER ?= pdns
@@ -23,29 +29,29 @@ 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 ?=
#- ACME zone suffix
ACME_DOMAIN ?=
#- This NS hostname for use in all SOA
NSERVER ?=
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} > $@
# ------------------------------------------------------------------------------

View File

@@ -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