VPS := $(VPS_USER)@$(VPS_HOST)
-# Detect Environment
-ifeq ($(VPS_HOST),$(VPS_HOST_DEV))
- ENV := dev
-else ifeq ($(VPS_HOST),$(VPS_HOST_PROD))
- ENV := prod
+# Logic:
+# 1. Default ENV to dev.
+# 2. Allow user to override ENV=prod.
+# 3. Set VPS_HOST based on ENV.
+
+ENV ?= dev
+
+ifeq ($(ENV),prod)
+ VPS_HOST := $(VPS_HOST_PROD)
else
- ENV := dev
+ VPS_HOST := $(VPS_HOST_DEV)
endif
+VPS := $(VPS_USER)@$(VPS_HOST)
+
.PHONY: stage/nginx
stage/nginx: ##H @Remote Stage files on the remote VPS
@echo "Staging files on $(VPS_HOST) (ENV=$(ENV))..."
.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"
+ ssh -t $(VPS) "bash ~/.nginx-staging/scripts/deploy.sh diff $(ENV)"
.PHONY: deploy/nginx
deploy/nginx: ##H @Remote Deploy staged files to remote
.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"
+ ssh -t $(VPS) "bash ~/.nginx-staging/scripts/deploy.sh test $(ENV)"
.PHONY: deploy/klaus
deploy/klaus: ##H @Remote Deploy Klaus (systemd + nginx) and install deps
diff/local: ##H @Local Show diff against system config
ifdef SUDO_USER
@echo "Checking diff locally as $(SUDO_USER)..."
- su -P $(SUDO_USER) -c "bash scripts/deploy.sh diff"
+ su -P $(SUDO_USER) -c "bash scripts/deploy.sh diff $(ENV)"
else
@echo "Checking diff locally..."
- bash scripts/deploy.sh diff
+ bash scripts/deploy.sh diff $(ENV)
endif
.PHONY: test/local
test/local: ##H @Local Test current configuration
@echo "Testing locally..."
- bash scripts/deploy.sh test
+ bash scripts/deploy.sh test $(ENV)
.PHONY: deploy/local
deploy/local: ##H Deploy Nginx and Gitweb configuration (local)
ifdef SUDO_USER
@echo "Deploying locally as $(SUDO_USER)..."
@# We need to run the entire script as the SUDO_USER to ensure they can sudo inside it
- su -P $(SUDO_USER) -c "bash scripts/deploy.sh"
+ su -P $(SUDO_USER) -c "bash scripts/deploy.sh $(ENV)"
else
@echo "Deploying locally..."
- bash scripts/deploy.sh
+ bash scripts/deploy.sh $(ENV)
endif
.PHONY: certbot/local
echo "Source: $REPO_ROOT"
if [ "$1" = "diff" ]; then
- echo "Detected changes (diff):"
+ ENV="${2:-dev}"
+ 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
for FILE in "$NGINX_CONF_SRC"/*.conf; do
echo "Skipping encrypted secrets.conf diff..."
continue
fi
- diff -u --color=always "$DEST_CONF_DIR/$BASENAME" "$FILE" || true
+
+ # Logic to check against default.conf
+ TARGET_FILE="$DEST_CONF_DIR/$BASENAME"
+ if [[ "$BASENAME" == "default.dev.conf" || "$BASENAME" == "default.prod.conf" || "$BASENAME" == "default.conf" ]]; then
+ if [ "$BASENAME" == "default.${ENV}.conf" ]; then
+ TARGET_FILE="$DEST_CONF_DIR/default.conf"
+ else
+ continue
+ fi
+ fi
+
+ diff -u --color=always "$TARGET_FILE" "$FILE" || true
done
# Diff gitweb.conf
fi
if [ "$1" = "test" ]; then
- echo "Running pre-flight validation..."
+ ENV="${2:-dev}"
+ echo "Running pre-flight validation for ENV=$ENV..."
TMP_WORK_DIR=$(mktemp -d)
TMP_NGINX_CONF="$TMP_WORK_DIR/nginx.conf"
TMP_CONF_D="$TMP_WORK_DIR/conf.d"
echo "Skipping encrypted secrets.conf for test..."
continue
fi
- cp "$FILE" "$TMP_CONF_D/"
+
+ # Handle default configuration switching
+ if [[ "$BASENAME" == "default.dev.conf" || "$BASENAME" == "default.prod.conf" || "$BASENAME" == "default.conf" ]]; then
+ if [ "$BASENAME" == "default.${ENV}.conf" ]; then
+ # Rename to default.conf
+ cp "$FILE" "$TMP_CONF_D/default.conf"
+ else
+ # Skip other environment configs
+ continue
+ fi
+ else
+ cp "$FILE" "$TMP_CONF_D/"
+ fi
done
# Generate test nginx.conf