fix: prepare the existing HTTP site for SSH releases
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
6bd1940f5e
commit
f4dd351f87
|
|
@ -6,42 +6,33 @@ script, and activates the release through SSH. The sole deployment secret is
|
|||
|
||||
## One-time server setup
|
||||
|
||||
Obtain this branch's files on server1 using your existing repository access,
|
||||
or transfer the Nginx snippet from your workstation. From the repository directory,
|
||||
run the following as `mihir`.
|
||||
Server inspection on 19 November 2026 found an HTTP-only site at
|
||||
`/etc/nginx/sites-enabled/ManiCandles.midastix.com.conf`, with its old root at
|
||||
`/var/www/ManiCandles.midastix.com`. Certbot is installed. The setup script is
|
||||
specific to that configuration and refuses to overwrite a site with TLS settings.
|
||||
|
||||
Obtain this branch's files on server1 using your existing repository access.
|
||||
From the repository directory, run the following as `mihir`.
|
||||
|
||||
```sh
|
||||
sudo install -d -o mihir -g "$(id -gn mihir)" -m 0755 \
|
||||
/var/www/manicandles /var/www/manicandles/releases /var/www/manicandles/incoming
|
||||
sudo install -d -m 0755 /etc/nginx/snippets
|
||||
sudo install -m 0644 deploy/nginx-locations.conf /etc/nginx/snippets/manicandles.conf
|
||||
command -v flock
|
||||
command -v curl
|
||||
sudo sh scripts/setup-static-host.sh
|
||||
sudo certbot --nginx -d manicandles.midastix.com --redirect
|
||||
sudo nginx -t
|
||||
curl --fail --show-error https://manicandles.midastix.com/
|
||||
```
|
||||
|
||||
Identify the existing Nginx site file for `manicandles.midastix.com`.
|
||||
Alternatively, copy `scripts/setup-static-host.sh` and
|
||||
`deploy/nginx-locations.conf` together to `/tmp/` on server1, and run
|
||||
`sudo sh /tmp/setup-static-host.sh`, followed by the Certbot and verification
|
||||
commands above. The snippet must be beside the setup script for this layout.
|
||||
|
||||
```sh
|
||||
sudo nginx -T 2>&1 | grep -E '^# configuration file|server_name.*manicandles'
|
||||
```
|
||||
|
||||
Back up that site file before editing it. Inside its existing HTTPS `server`
|
||||
block for `manicandles.midastix.com`, replace the old `root`, `index`, and
|
||||
`location` directives with this include. Preserve its `listen`, `server_name`,
|
||||
certificate paths, TLS settings, and HTTP-to-HTTPS redirect. Resolve any duplicate
|
||||
security header definitions against the snippet.
|
||||
|
||||
```nginx
|
||||
include /etc/nginx/snippets/manicandles.conf;
|
||||
```
|
||||
|
||||
Validate and reload. If validation fails, restore the saved site file before
|
||||
continuing. Reload preserves existing connections. The frontend will begin
|
||||
serving when the first release supplies `/var/www/manicandles/current`.
|
||||
|
||||
```sh
|
||||
sudo nginx -t && sudo systemctl reload nginx
|
||||
```
|
||||
Setup backs up the original site under `/var/backups`, prepares writable release
|
||||
directories, installs the snippet, validates Nginx, and reloads it. Validation or
|
||||
reload failure restores the saved site file. If the old root contains an index,
|
||||
setup retains it as the initial `current` release and a rollback target. If no
|
||||
old index exists, the frontend awaits its first deployment. DNS must point to
|
||||
server1 and public port 80 must be reachable for certificate issuance. Complete
|
||||
Certbot's email and agreement prompts yourself. Verify HTTPS before merging.
|
||||
|
||||
Save the complete matching private key in Drone's `manicandles_deploy_key`
|
||||
secret. Its public key must be authorized for `mihir` on server1. Keep the
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ test "$(cat "$release/release.txt")" = "$release_id"
|
|||
|
||||
# A slow older pipeline must not replace a newer successful release.
|
||||
last_build=0
|
||||
if [ -L current ]; then
|
||||
if [ -L current ] && [ -f current/release.txt ]; then
|
||||
last_release=$(cat current/release.txt)
|
||||
last_build=${last_release%%-*}
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
#!/bin/sh
|
||||
set -eu
|
||||
test "$(id -u)" = 0 || { echo 'Run this setup script with sudo.' >&2; exit 1; }
|
||||
script_dir=$(CDPATH= cd "$(dirname "$0")" && pwd)
|
||||
snippet="$script_dir/../deploy/nginx-locations.conf"
|
||||
if [ ! -f "$snippet" ]; then snippet="$script_dir/nginx-locations.conf"; fi
|
||||
test -s "$snippet"
|
||||
site=$(readlink -f /etc/nginx/sites-enabled/ManiCandles.midastix.com.conf)
|
||||
test -f "$site"
|
||||
if grep -Eq 'listen[[:space:]].*443|ssl_certificate' "$site"; then
|
||||
echo 'This site already contains TLS settings. Review its configuration before running setup.' >&2
|
||||
exit 1
|
||||
fi
|
||||
nginx -t
|
||||
command -v curl
|
||||
command -v flock
|
||||
command -v certbot
|
||||
root=/var/www/manicandles
|
||||
install -d -o mihir -g "$(id -gn mihir)" -m 0755 "$root" "$root/releases" "$root/incoming"
|
||||
if [ ! -e "$root/current" ] && [ ! -L "$root/current" ] && [ -s /var/www/ManiCandles.midastix.com/index.html ]; then
|
||||
ln -s /var/www/ManiCandles.midastix.com "$root/current"
|
||||
chown -h mihir:"$(id -gn mihir)" "$root/current"
|
||||
fi
|
||||
install -d -m 0755 /etc/nginx/snippets /var/backups
|
||||
backup="/var/backups/manicandles-nginx-$(date +%Y%m%d%H%M%S)-$$.conf"
|
||||
cp -p "$site" "$backup"
|
||||
if [ -e /etc/nginx/snippets/manicandles.conf ] && ! cmp -s "$snippet" /etc/nginx/snippets/manicandles.conf; then
|
||||
echo 'A different deployment snippet exists. Review the existing setup before continuing.' >&2
|
||||
exit 1
|
||||
fi
|
||||
install -m 0644 "$snippet" /etc/nginx/snippets/manicandles.conf
|
||||
cat > "$site" <<'NGINX'
|
||||
server {
|
||||
listen 80;
|
||||
server_name manicandles.midastix.com;
|
||||
include /etc/nginx/snippets/manicandles.conf;
|
||||
}
|
||||
NGINX
|
||||
if ! nginx -t || ! systemctl reload nginx; then
|
||||
cp -p "$backup" "$site"
|
||||
nginx -t && systemctl reload nginx
|
||||
echo "Setup failed. Restored $backup" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "Site prepared. Original configuration saved at $backup"
|
||||
echo 'Next run: sudo certbot --nginx -d manicandles.midastix.com --redirect'
|
||||
|
|
@ -51,4 +51,15 @@ test "$(cat "$fixture/site/current/release.txt")" = 2-bbb
|
|||
rm "$fixture/site/wrong-marker"
|
||||
deploy 1-aaa
|
||||
test "$(cat "$fixture/site/current/release.txt")" = 2-bbb
|
||||
# The existing HTTP site has no release metadata and must remain a rollback target.
|
||||
rm "$fixture/site/current"
|
||||
mkdir -p "$fixture/site/legacy"
|
||||
echo legacy > "$fixture/site/legacy/index.html"
|
||||
ln -s "$fixture/site/legacy" "$fixture/site/current"
|
||||
touch "$fixture/site/fail-health"
|
||||
if deploy 3-ccc; then echo 'Expected rollback to legacy site' >&2; exit 1; fi
|
||||
test "$(cat "$fixture/site/current/index.html")" = legacy
|
||||
rm "$fixture/site/fail-health"
|
||||
deploy 3-ccc
|
||||
test "$(cat "$fixture/site/previous/index.html")" = legacy
|
||||
printf 'Deployment activation, rollback and stale-build checks passed.\n'
|
||||
|
|
|
|||
Loading…
Reference in New Issue