# SSH deployment to server1 Drone validates the application and Nginx snippet, uploads `dist` and the release script, and activates the release through SSH. The sole deployment secret is `manicandles_deploy_key`. SSH uses `mihir@server1.midastix.com:22`. ## 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`. ```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 ``` Identify the existing Nginx site file for `manicandles.midastix.com`. ```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 ``` 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 private key outside the repository and logs. ## Release and acceptance After server setup, merge the change into main. Main-branch push builds perform an SSH access check before the quality gates. Feature branches validate the configuration, test rollback, and build the frontend without publishing a release. Uploads first enter `incoming/BUILD-COMMIT`. A completed build moves to `releases/BUILD-COMMIT/dist` under the deployment lock. Retried uploads cannot overwrite a published release. A file lock serializes activation. An older build cannot replace a newer active build. The `current` symlink changes atomically. HTTPS checks use the real hostname resolved to loopback and verify the certificate, release marker, homepage, `/workspace`, `/cart`, and `/api/v1/health/ready`. Failure restores the previous current symlink, or removes the first activation if no release existed before it. The last successful release is also retained at `previous`. Its assets can serve requests from browser tabs opened before the update. Failed first deployments leave the site awaiting a successful release. After the main build succeeds, test externally from a trusted terminal. ```sh curl --fail --show-error https://manicandles.midastix.com/release.txt curl --fail --show-error https://manicandles.midastix.com/api/v1/health/ready ``` Then exercise authenticated UAT journeys. The frontend release does not provision an organization or user accounts. ## Manual rollback As `mihir` on server1, restore the preceding successful release under the same lock used by CI. Verify the marker and API after switching. Coordinate this with active pipelines because a later successful deployment can activate a new release. ```sh ( set -eu cd /var/www/manicandles flock -x 9 test -s previous/index.html ln -s "$(readlink previous)" .rollback-current mv -Tf .rollback-current current ) 9>/var/www/manicandles/.deploy.lock curl --fail --show-error https://manicandles.midastix.com/release.txt curl --fail --show-error https://manicandles.midastix.com/api/v1/health/ready ``` Retain release directories until rollback has been verified. Disk retention is manual in this initial deployment flow.