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,40 +12,46 @@ OBJECTSDIRECT = $(SOURCES:.sql=.direct)
# app custom config # app custom config
# comments prefixed with '#- ' will be copied to $(CFG).sample # 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 zone suffix
ACME_DOMAIN ?= ACME_DOMAIN ?=
#- This NS hostname for use in all SOA #- 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 -include $(CFG).bak
export export
-include $(CFG)
export
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# dcape v1 comparibility
start-hook: update ifneq ($(findstring $(MAKECMDGOALS),psql),)
USE_DB := yes
stop: 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 # Find and include DCAPE_ROOT/Makefile
#- dcape compose docker image
DCAPE_COMPOSE ?= dcape-compose DCAPE_COMPOSE ?= dcape-compose
DCAPE_ROOT ?= $(shell docker inspect -f "{{.Config.Labels.dcape_root}}" $(DCAPE_COMPOSE)) DCAPE_ROOT ?= $(shell docker inspect -f "{{.Config.Labels.dcape_root}}" $(DCAPE_COMPOSE))
@@ -56,19 +62,23 @@ else
endif endif
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
## DB operations
#:
.PHONY: update
update: $(OBJECTS) update: $(OBJECTS)
%.done: %.sql %.done: %.sql
@echo "*** $< ***" @echo "*** $< ***"
@csum=$$(md5sum $< | sed 's/ .*//') ; \ @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 ## Load updated zone files via psql connection
update-direct: $(CFG) $(OBJECTSDIRECT) update-direct: $(CFG) $(OBJECTSDIRECT)
%.direct: %.sql %.direct: %.sql
@echo "*** $< ***" @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 ## 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 ## Usage