2022-09-16 12:30:59 +02:00
|
|
|
WD=/var/lib/dags/acme_rsync
|
|
|
|
|
2022-09-16 15:28:46 +02:00
|
|
|
.PHONY: all refresh_pg sync_certs
|
2022-09-16 12:30:59 +02:00
|
|
|
|
|
|
|
NGINX_RELOAD=$(WD)/nginx_reload
|
|
|
|
PROSODY_RELOAD=$(WD)/prosody_reload
|
|
|
|
|
2022-09-16 15:28:46 +02:00
|
|
|
all: sync_certs $(NGINX_RELOAD) $(PROSODY_RELOAD) refresh_pg
|
2022-09-16 12:30:59 +02:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
2022-09-16 18:25:53 +02:00
|
|
|
ACME_DIR=/srv/certs/acme
|
2022-09-16 18:08:42 +02:00
|
|
|
DOMAIN=monotremata.xyz
|
2022-09-16 18:25:08 +02:00
|
|
|
CERT_PATH=$(ACME_DIR)/$(DOMAIN)
|
2022-09-16 18:08:42 +02:00
|
|
|
CERT=$(CERT_PATH)/fullchain.cer
|
|
|
|
KEY=$(CERT_PATH)/$(DOMAIN).key
|
2022-09-16 12:30:59 +02:00
|
|
|
|
|
|
|
###############################################################################
|
2022-09-16 15:28:46 +02:00
|
|
|
# Sync the certificates using rsync. Because `sync` is a phony
|
2022-09-16 12:30:59 +02:00
|
|
|
# target, it will be run each time, but the certificate files will only be
|
|
|
|
# updated if a renewal happens
|
|
|
|
|
2022-09-16 18:08:42 +02:00
|
|
|
$(CERT): sync_certs
|
|
|
|
$(KEY): sync_certs
|
2022-09-16 12:30:59 +02:00
|
|
|
|
2022-09-23 10:32:48 +02:00
|
|
|
RSYNCD_HOST=narwhal
|
|
|
|
RSYNCD_USER=user
|
|
|
|
|
|
|
|
GOPASS=doas -u gopass gopass
|
|
|
|
RSYNC_PASSWORD = $(shell $(GOPASS) $(RSYNCD_HOST)/rsyncd/$(RSYNCD_USER))
|
|
|
|
|
|
|
|
REMOTE_ACME_PATH=rsync://$(RSYNCD_USER)@$(RSYNCD_HOST)/acme
|
2022-09-16 12:30:59 +02:00
|
|
|
RSYNC_OPTS=--archive --delete --acls --xattrs --compress --verbose --human-readable
|
|
|
|
|
|
|
|
sync_certs:
|
2022-09-16 18:25:08 +02:00
|
|
|
mkdir -p $(ACME_DIR)
|
2022-09-23 10:32:48 +02:00
|
|
|
RSYNC_PASSWORD=$(RSYNC_PASSWORD); \
|
2022-09-16 12:30:59 +02:00
|
|
|
rsync \
|
|
|
|
$(RSYNC_OPTS) \
|
2022-09-16 15:28:46 +02:00
|
|
|
$(REMOTE_ACME_PATH) \
|
2022-09-16 18:25:08 +02:00
|
|
|
$(ACME_DIR)
|
2022-09-16 12:30:59 +02:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# Reload the nginx instance running on my reverse proxy docker-compose service
|
|
|
|
# so that it uses the new certificates.
|
|
|
|
# The target is just an empty sentinel target with no meaningful data other
|
|
|
|
# than its modification date.
|
|
|
|
# So far, the nginx instance running on the `monotremata` certificates, so it
|
|
|
|
# only needs to be reloaded that is updated
|
|
|
|
|
2022-09-16 15:28:46 +02:00
|
|
|
NGINX_COMPOSE_FILE=/srv/services/www/docker-compose.yml
|
2022-09-16 12:30:59 +02:00
|
|
|
|
|
|
|
$(NGINX_RELOAD): $(MONOTREMATA_CERT) $(MONOTREMATA_KEY)
|
|
|
|
mkdir -p $(@D)
|
|
|
|
docker-compose \
|
|
|
|
--file $(NGINX_COMPOSE_FILE) \
|
|
|
|
exec nginx \
|
|
|
|
nginx -s reload
|
|
|
|
touch $@
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
2022-09-16 15:28:46 +02:00
|
|
|
PROSODY_CERTS_PATH=/srv/volumes/xmpp/certs
|
2022-09-16 12:30:59 +02:00
|
|
|
|
2022-09-16 18:08:42 +02:00
|
|
|
PROSODY_CERT=$(PROSODY_CERTS_PATH)/monotremata.xyz.crt
|
|
|
|
PROSODY_KEY=$(PROSODY_CERTS_PATH)/monotremata.xyz.key
|
2022-09-16 15:28:46 +02:00
|
|
|
|
|
|
|
PROSODY_UID=101
|
|
|
|
PROSODY_GID=102
|
|
|
|
|
2022-09-16 18:08:42 +02:00
|
|
|
$(PROSODY_CERT): $(CERT)
|
|
|
|
install -o $(PROSODY_UID) -g $(PROSODY_GID) -m 644 $< $@
|
2022-09-16 15:28:46 +02:00
|
|
|
|
2022-09-16 18:08:42 +02:00
|
|
|
$(PROSODY_KEY): $(KEY)
|
|
|
|
install -o $(PROSODY_UID) -g $(PROSODY_GID) -m 600 $< $@
|
2022-09-16 15:28:46 +02:00
|
|
|
|
|
|
|
PROSODY_COMPOSE_FILE=/srv/services/xmpp/docker-compose.yml
|
|
|
|
|
2022-09-16 18:08:42 +02:00
|
|
|
$(PROSODY_RELOAD): $(PROSODY_CERT) $(PROSODY_KEY)
|
2022-09-16 12:30:59 +02:00
|
|
|
mkdir -p $(@D)
|
2022-09-16 15:28:46 +02:00
|
|
|
docker-compose --file $(PROSODY_COMPOSE_FILE) exec \
|
|
|
|
prosody prosodyctl reload
|
2022-09-16 12:30:59 +02:00
|
|
|
touch $@
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# Copy the certificate for the postgresql domain to the folder where postgre
|
|
|
|
# service expects it
|
|
|
|
|
|
|
|
PG_SSL_PATH=/srv/volumes/postgres/ssl
|
|
|
|
PG_CERT=$(PG_SSL_PATH)/server.crt
|
|
|
|
PG_KEY=$(PG_SSL_PATH)/server.key
|
|
|
|
|
2022-09-16 18:08:42 +02:00
|
|
|
$(PG_CERT): $(CERT)
|
2022-09-16 12:30:59 +02:00
|
|
|
mkdir -p $(@D)
|
|
|
|
rsync --copy-links $< $@
|
|
|
|
|
2022-09-16 18:08:42 +02:00
|
|
|
$(PG_KEY): $(KEY)
|
2022-09-16 12:30:59 +02:00
|
|
|
mkdir -p $(@D)
|
|
|
|
rsync --copy-links $< $@
|
|
|
|
|
|
|
|
refresh_pg: $(PG_CERT) $(PG_KEY)
|