From 64bb14beb9acddf0dd9709b064fe766e4b85e130 Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Wed, 21 Jan 2026 00:28:39 -0500 Subject: [PATCH] update makefile an deploy.sh --- Makefile | 31 ++++++++++++++----------------- scripts/deploy.sh | 20 +++++++++++++++++--- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 5403e34..eca9152 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,8 @@ # .ONESHELL: ifneq (,$(wildcard ./.env)) - include .env - export + include .env + export endif .PHONY: _help @@ -48,9 +48,9 @@ VPS := $(VPS_USER)@$(VPS_HOST) ENV ?= dev ifeq ($(ENV),prod) - VPS_HOST := $(VPS_HOST_PROD) + VPS_HOST := $(VPS_HOST_PROD) else - VPS_HOST := $(VPS_HOST_DEV) + VPS_HOST := $(VPS_HOST_DEV) endif VPS := $(VPS_USER)@$(VPS_HOST) @@ -67,23 +67,20 @@ stage/nginx: ##H @Remote Stage files on the remote VPS scripts/deploy.sh \ scripts/gen_services_map.py \ scripts/homepage.html | \ - ssh $(VPS) "rm -rf ~/.nginx-staging && mkdir -p ~/.nginx-staging && tar xz -C ~/.nginx-staging" + ssh $(VPS) "rm -rf ~/.nginx-staging \ + && mkdir -p ~/.nginx-staging \ + && tar xz -C ~/.nginx-staging" -.PHONY: diff/nginx -diff/nginx: ##H @Remote Show diff between local and remote - @echo "Checking diff against $(VPS_HOST)..." - ssh -t $(VPS) "bash ~/.nginx-staging/scripts/deploy.sh diff $(ENV)" .PHONY: deploy/nginx deploy/nginx: ##H @Remote Deploy staged files to remote -deploy/nginx: stage/nginx test/nginx diff/nginx - @echo "Deploying checked-in nginx config to $(VPS_HOST)..." - ssh -t $(VPS) "bash ~/.nginx-staging/scripts/deploy.sh $(ENV)" - -.PHONY: test/nginx -test/nginx: ##H @Remote Test staged configuration without deploying - @echo "Testing staged config on $(VPS_HOST)..." - ssh -t $(VPS) "bash ~/.nginx-staging/scripts/deploy.sh test $(ENV)" +deploy/nginx: stage/nginx + @echo "Connecting to $(VPS_HOST)..." + @# We chain test && diff && deploy in ONE SSH session. + @# This preserves the sudo timestamp so you only type your password once. + ssh -t $(VPS) "bash ~/.nginx-staging/scripts/deploy.sh test $(ENV) && \ + bash ~/.nginx-staging/scripts/deploy.sh $(ENV)" + .PHONY: deploy/klaus deploy/klaus: ##H @Remote Deploy Klaus (systemd + nginx) and install deps diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 49ed808..afedceb 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -14,8 +14,9 @@ is_text_file() { echo "Source: $REPO_ROOT" -if [ "$1" = "diff" ]; then - ENV="${2:-dev}" +# Function to show diff +show_diff() { + local ENV="$1" echo "Detected changes (diff) for ENV=$ENV:" # We can't use simple diff -r because we need to exclude secrets.conf if encrypted # So we loop through source files @@ -41,14 +42,24 @@ if [ "$1" = "diff" ]; then fi fi - diff -u --color=always "$TARGET_FILE" "$FILE" || true + if [ -f "$TARGET_FILE" ]; then + diff -u --color=always "$TARGET_FILE" "$FILE" || true + else + echo "New file: $BASENAME" + # Show content of new file as diff (dev null vs new) + diff -u --color=always /dev/null "$FILE" || true + fi done # Diff gitweb.conf if [ -f "$GITWEB_CONF_SRC" ]; then diff -u --color=always /etc/gitweb.conf "$GITWEB_CONF_SRC" || true fi +} +if [ "$1" = "diff" ]; then + ENV="${2:-dev}" + show_diff "$ENV" exit 0 fi @@ -115,6 +126,9 @@ fi ENV="${1:-dev}" echo "Deploying for environment: $ENV" +# Always show diff before installing +show_diff "$ENV" + echo "Installing new configurations..." # Cleanup disabled configurations -- 2.52.0