update makefile an deploy.sh
authorShane Jaroch <chown_tee@proton.me>
Wed, 21 Jan 2026 05:28:39 +0000 (00:28 -0500)
committerShane Jaroch <chown_tee@proton.me>
Wed, 21 Jan 2026 05:28:39 +0000 (00:28 -0500)
Makefile
scripts/deploy.sh

index 5403e34e1c4996cb126ba209b3576f01a1b1228a..eca9152df4161ef002051af1ef2f4ea7a27787bc 100644 (file)
--- 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
index 49ed8080222c58b75dc3685e3fca87d064c4af47..afedceb63d4dab4186ba5e8a530ea26986fc5e69 100755 (executable)
@@ -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