feat: Add deployment to a staging environment
This commit is contained in:
parent
d2a29e8dec
commit
54988257e6
4 changed files with 161 additions and 13 deletions
99
deploy.sh
99
deploy.sh
|
|
@ -1,15 +1,92 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
sudo cp -rt /srv/www/binning.net \
|
||||
blog \
|
||||
includes \
|
||||
index.html \
|
||||
blog.html \
|
||||
resume.html \
|
||||
style.css \
|
||||
404.html
|
||||
set -e
|
||||
|
||||
sudo chown -R nginx:nginx /srv/www/binning.net/
|
||||
# Usage information
|
||||
usage() {
|
||||
printf "Usage: %s [staging|prod]\n\n staging - Deploy to local staging environment (/srv/www/stage.binning.net)\n prod - Deploy to production server via SSH (www.binning.net)\n\nExample:\n %s staging\n %s prod\n" "$0" "$0" "$0"
|
||||
exit 1
|
||||
}
|
||||
|
||||
sudo cp -t /etc/nixos/ \
|
||||
nginx.nix
|
||||
# Check if argument provided
|
||||
if [ $# -eq 0 ]; then
|
||||
printf "Error: No environment specified\n"
|
||||
usage
|
||||
fi
|
||||
|
||||
ENV=$1
|
||||
|
||||
case $ENV in
|
||||
staging)
|
||||
printf "Deploying to STAGING environment...\n"
|
||||
|
||||
STAGING_PATH="/srv/www/stage.binning.net"
|
||||
|
||||
# Create staging directory if it doesn't exist
|
||||
sudo mkdir -p ${STAGING_PATH}
|
||||
|
||||
# Deploy website files via rsync
|
||||
printf "Deploying website files...\n"
|
||||
sudo rsync -av --delete \
|
||||
blog \
|
||||
includes \
|
||||
index.html \
|
||||
blog.html \
|
||||
resume.html \
|
||||
style.css \
|
||||
404.html \
|
||||
${STAGING_PATH}/
|
||||
|
||||
# Set proper ownership
|
||||
sudo chown -R nginx:nginx ${STAGING_PATH}/
|
||||
|
||||
# Copy nginx config
|
||||
sudo cp -t /etc/nixos/ staging.nginx.nix
|
||||
|
||||
printf "✓ Staging deployment complete!\n Files deployed to: %s\n Nginx config: /etc/nixos/staging.nginx.nix\n\nTo activate, update your NixOS configuration to import staging.nginx.nix\nand run: sudo nixos-rebuild switch\n" "${STAGING_PATH}"
|
||||
;;
|
||||
|
||||
prod)
|
||||
printf "Deploying to PRODUCTION environment...\n"
|
||||
|
||||
# SSH details
|
||||
REMOTE_HOST="binning.net"
|
||||
REMOTE_USER="matthew.binning"
|
||||
REMOTE_PATH="/srv/www/binning.net"
|
||||
REMOTE_NIXOS="/etc/nixos/"
|
||||
|
||||
# Check if SSH key is set up
|
||||
if ! ssh -o BatchMode=yes -o ConnectTimeout=5 ${REMOTE_USER}@${REMOTE_HOST} exit 2>/dev/null; then
|
||||
printf "Warning: SSH connection test failed. Ensure SSH keys are configured.\nYou may be prompted for a password.\n"
|
||||
fi
|
||||
|
||||
# Deploy website files via rsync over SSH
|
||||
printf "Deploying website files...\n"
|
||||
rsync -avz --delete \
|
||||
-e ssh \
|
||||
blog \
|
||||
includes \
|
||||
index.html \
|
||||
blog.html \
|
||||
resume.html \
|
||||
style.css \
|
||||
404.html \
|
||||
${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_PATH}/
|
||||
|
||||
# Deploy nginx configuration
|
||||
printf "Deploying nginx configuration...\n"
|
||||
scp prod.nginx.nix ${REMOTE_USER}@${REMOTE_HOST}:/tmp/nginx.nix
|
||||
|
||||
# Set proper permissions and move config on remote server
|
||||
ssh ${REMOTE_USER}@${REMOTE_HOST} "sudo mv /tmp/nginx.nix ${REMOTE_NIXOS}nginx.nix && \
|
||||
sudo chown -R nginx:nginx ${REMOTE_PATH}/ && \
|
||||
printf 'Configuration deployed. Run sudo nixos-rebuild switch to activate.\n'"
|
||||
|
||||
printf "✓ Production deployment complete!\n\nSSH into %s and run: sudo nixos-rebuild switch\n" "${REMOTE_HOST}"
|
||||
;;
|
||||
|
||||
*)
|
||||
printf "Error: Invalid environment '%s'\n" "$ENV"
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue