@@ -26,119 +26,46 @@ jobs:
2626 key : ${{ secrets.DEPLOY_KEY }}
2727 known_hosts : ${{ secrets.KNOWN_HOSTS }}
2828
29- - name : Build & Deploy (rotate site_live; no sed )
29+ - name : Remote Deploy via SSH (delete site_live then promote new build )
3030 run : |
3131 set -Eeuo pipefail
32- ssh "$SSH_USER@$SSH_HOST" bash -s <<EOF
32+ ssh "$SSH_USER@$SSH_HOST" bash -s -- "$PROJECT_DIR" <<'REMOTE'
3333 set -Eeuo pipefail
34-
35- TS=\$(date +%Y%m%d-%H%M%S)
36- PROJ="${PROJECT_DIR}"
37- DOM="${DOMAIN}"
34+ PROJ="$1"
3835
3936 echo "📂 cd \$PROJ"
40- cd "\$PROJ"
37+ cd "$PROJ"
38+
39+ echo "🔄 Git pull"
40+ git stash -u || true
41+ git pull --rebase || git pull
4142
42- echo "🐍 venv + deps"
43- apt-get update -y
44- apt-get install -y python3-venv python3-pip
43+ echo "🐍 venv & deps"
4544 python3 -m venv .venv
4645 . .venv/bin/activate
47- python -m pip install --upgrade pip
46+ python -m pip install -U pip
4847 pip install -r requirements.txt
4948
50- echo "🏗 mkdocs build (non-strict) "
49+ echo "🏗 mkdocs build"
5150 rm -rf site
5251 mkdocs build
5352
54- echo "🔁 prepare site_next"
55- rm -rf site_next
56- cp -a site site_next
57-
58- echo "🔁 rotate existing site_live (if any)"
59- if [ -e site_live ] || [ -L site_live ]; then
60- OLD="site_old_\$TS"
61- mv site_live "\$OLD"
62- echo "↪️ moved prior site to: \$OLD"
53+ echo "🧹 remove old live dir"
54+ if [ -d site_live ] || [ -L site_live ]; then
55+ rm -rf site_live
6356 fi
6457
65- echo "🔁 promote site_next -> site_live"
66- mv site_next site_live
67- # Make sure nginx (www-data) can read
68- if id -u www-data >/dev/null 2>&1; then
69- chown -R www-data:www-data site_live || true
70- fi
58+ echo "🚀 promote new build"
59+ mv site site_live
60+
61+ # make sure nginx can read it; no failure if user/group absent
62+ chown -R www-data:www-data site_live || true
7163 find site_live -type d -exec chmod 755 {} \; || true
7264 find site_live -type f -exec chmod 644 {} \; || true
73- touch site_live/.deployed-at
74-
75- echo "🚦 Nginx vhost housekeeping (no edits, just enable/disable files)"
76- mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled /etc/nginx/sites-disabled
77-
78- # 1) Create a clean STATIC vhost for docs (HTTP->HTTPS + HTTPS root)
79- STATIC_AVAIL="/etc/nginx/sites-available/ergo-docs-static.conf"
80- cat > "\$STATIC_AVAIL" <<'NGINX'
81- server {
82- listen 80;
83- listen [::]:80;
84- server_name docs.ergoplatform.com;
85- return 301 https://$host$request_uri;
86- }
87-
88- server {
89- listen 443 ssl;
90- listen [::]:443 ssl;
91- server_name docs.ergoplatform.com;
92-
93- ssl_certificate /etc/ssl/certs/docs.ergoplatform.com.pem;
94- ssl_certificate_key /etc/ssl/private/docs.ergoplatform.com.key;
95-
96- root /var/www/ergodocs/site_live;
97- index index.html;
98-
99- add_header Strict-Transport-Security "max-age=31536000" always;
100-
101- location / {
102- try_files $uri $uri/ =404;
103- }
104-
105- # Long cache for assets
106- location ~* \.(css|js|png|jpg|jpeg|gif|svg|woff2?|ttf|eot)$ {
107- expires 30d;
108- access_log off;
109- try_files $uri =404;
110- }
111- }
112- NGINX
113-
114- # Symlink it into sites-enabled (idempotent)
115- if [ ! -e /etc/nginx/sites-enabled/ergo-docs-static.conf ]; then
116- ln -s "\$STATIC_AVAIL" /etc/nginx/sites-enabled/ergo-docs-static.conf
117- fi
11865
119- # 2) Disable any enabled vhost files that also claim the same server_name (proxy leftovers)
120- for f in /etc/nginx/sites-enabled/*; do
121- [ -e "\$f" ] || continue
122- base=\$(basename "\$f")
123- # Keep the static one we just wrote
124- if [ "\$base" = "ergo-docs-static.conf" ]; then
125- continue
126- fi
127- if grep -qE "server_name[[:space:]]+${DOMAIN};" "\$f"; then
128- mv "\$f" "/etc/nginx/sites-disabled/\${base}.\$TS"
129- echo "➡️ disabled conflicting vhost: \${base}"
130- fi
131- done
132-
133- echo "🧪 nginx -t && reload"
134- nginx -t
135- systemctl reload nginx
136-
137- echo "🧪 origin check via SNI to 127.0.0.1 (Cloudflare origin cert -> -k)"
138- curl -fsS -k --resolve "\${DOM}:443:127.0.0.1" "https://\${DOM}/" > /tmp/home.html
139- grep -q "</html>" /tmp/home.html || { echo "❌ origin HTML incomplete"; exit 1; }
140- echo "✅ origin OK"
141- EOF
66+ echo "✅ done"
67+
68+
14269
14370 - name : List latest deployed files
14471 run : |
0 commit comments