# .ONESHELL:
ifneq (,$(wildcard ./.env))
- include .env
- export
+ include .env
+ export
endif
.PHONY: _help
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)
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
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
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
ENV="${1:-dev}"
echo "Deploying for environment: $ENV"
+# Always show diff before installing
+show_diff "$ENV"
+
echo "Installing new configurations..."
# Cleanup disabled configurations