From c3d1986c037234c9885e4b692ed2e05c9a7e86c0 Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Sat, 10 Jan 2026 14:30:45 -0500 Subject: [PATCH] update make target: deploy --- Makefile | 45 ++++++++++++++++++++++++++++++++++++++------- scripts/deploy.sh | 5 +++++ 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index e9f5083..a8ef640 100644 --- a/Makefile +++ b/Makefile @@ -3,22 +3,53 @@ -include .env +.PHONY: _help +_help: + @printf "\nUsage: make , valid commands:\n\n" + @awk 'BEGIN {FS = ":.*?##H "}; \ + /##H/ && !/@awk.*?##H/ { \ + target=$$1; doc=$$2; \ + category="General"; \ + if (doc ~ /^@/) { \ + category=substr(doc, 2, index(doc, " ")-2); \ + doc=substr(doc, index(doc, " ")+1); \ + } \ + if (length(target) > max) max = length(target); \ + targets[NR] = target; docs[NR] = doc; cats[NR] = category; \ + } \ + END { \ + last_cat = ""; \ + for (i = 1; i <= NR; i++) { \ + if (cats[i] != "") { \ + if (cats[i] != last_cat) { \ + printf "\n\033[1;36m%s Commands:\033[0m\n", cats[i]; \ + last_cat = cats[i]; \ + } \ + printf " \033[1;34m%-*s\033[0m %s\n", max, targets[i], docs[i]; \ + } \ + } \ + print ""; \ + }' $(MAKEFILE_LIST) + + + + VPS_HOST ?= dev.nutra.tk VPS_USER ?= gg VPS = $(VPS_USER)@$(VPS_HOST) .PHONY: stage/nginx -stage/nginx: +stage/nginx: ##H @Deploy Stage files for deployment @echo "Staging files on $(VPS_HOST)..." - tar --transform 's|.*/||' -czf - etc/nginx/conf.d/*.conf scripts/deploy.sh | \ - ssh $(VPS) "rm -rf ~/nginx-staging && mkdir -p ~/nginx-staging && tar -xzv -C ~/nginx-staging" + tar --transform 's|.*/||' --exclude='secrets.conf' -czf - etc/nginx/conf.d/*.conf scripts/deploy.sh | \ + ssh $(VPS) "rm -rf ~/.nginx-staging && mkdir -p ~/.nginx-staging && tar -xzv -C ~/.nginx-staging" .PHONY: diff/nginx -diff/nginx: +diff/nginx: ##H @Deploy See diff, test with nginx -t @echo "Checking diff against $(VPS_HOST)..." - ssh -t $(VPS) "bash ~/nginx-staging/deploy.sh diff" + ssh -t $(VPS) "bash ~/.nginx-staging/deploy.sh diff" .PHONY: deploy/nginx -deploy/nginx: +deploy/nginx: ##H @Deploy Copy into place and reload nginx @echo "Deploying checked-in nginx config to $(VPS_HOST)..." - ssh -t $(VPS) "bash ~/nginx-staging/deploy.sh" + ssh -t $(VPS) "bash ~/.nginx-staging/deploy.sh" diff --git a/scripts/deploy.sh b/scripts/deploy.sh index c587bee..9384e99 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -13,6 +13,11 @@ echo "" echo "Running pre-flight validation on staged config..." TMP_NGINX_CONF=$(mktemp) +# Create a temporary nginx.conf that points to STAGING_DIR instead of /etc/nginx/conf.d +# We assume the standard include is "/etc/nginx/conf.d/*.conf" +# We strictly replace that string with our staging path. +sed "s|/etc/nginx/conf.d/\*\.conf|$STAGING_DIR/*.conf|g" /etc/nginx/nginx.conf > "$TMP_NGINX_CONF" + if sudo nginx -t -c "$TMP_NGINX_CONF"; then echo "✓ Pre-flight validation passed." rm "$TMP_NGINX_CONF" -- 2.52.0