One-Click Deployment Scripts for Developers

*Photo by Daniil Komov on Pexels*
Manual deployment is error-prone and time-consuming. A well-written deployment script eliminates human error, ensures consistency across environments, and lets you ship updates with a single command. Here are deployment scripts tested in production environments.
## Static Site Deployer
Deploy any static site to a remote server via SSH with rsync. Includes rollback support.
“`bash
#!/bin/bash
SERVER=”[email protected]”
REMOTE_PATH=”/var/www/site”
BACKUP_PATH=”/var/www/backups/$(date +%Y%m%d_%H%M%S)”
echo “Building project…”
npm run build
echo “Backing up current version…”
ssh $SERVER “cp -r $REMOTE_PATH $BACKUP_PATH”
echo “Deploying new version…”
rsync -avz –delete ./dist/ $SERVER:$REMOTE_PATH/
echo “Verifying deployment…”
ssh $SERVER “curl -s -o /dev/null -w ‘%{http_code}’ http://localhost/health”
echo “Deployment complete. Rollback: ssh $SERVER ‘rm -rf $REMOTE_PATH && cp -r $BACKUP_PATH $REMOTE_PATH'”
“`
## Docker Deployment Script
Deploy multi-container applications with zero downtime using rolling updates.
“`bash
#!/bin/bash
STACK=”myapp”
COMPOSE_FILE=”docker-compose.prod.yml”
echo “Pulling latest images…”
docker-compose -f $COMPOSE_FILE pull
echo “Deploying with zero downtime…”
docker stack deploy -c $COMPOSE_FILE $STACK –with-registry-auth
echo “Monitoring deployment…”
sleep 10
docker stack services $STACK
echo “Checking health endpoints…”
for service in $(docker stack services -q $STACK); do
docker service ps $service –no-trunc | head -5
done
“`
## Database Migration Script
Run and rollback database migrations safely with transaction wrapping.
“`bash
#!/bin/bash
DB_HOST=${DB_HOST:-localhost}
DB_NAME=${DB_NAME:-myapp}
MIGRATIONS_DIR=”./migrations”
run_migration() {
echo “Running: $1”
PGPASSWORD=$DB_PASS psql -h $DB_HOST -U $DB_USER -d $DB_NAME \
-v ON_ERROR_STOP=1 \
–single-transaction \
-f “$MIGRATIONS_DIR/$1”
}
echo “Current migration status:”
PGPASSWORD=$DB_PASS psql -h $DB_HOST -U $DB_USER -d $DB_NAME \
-c “SELECT * FROM migrations ORDER BY id DESC LIMIT 5;”
for file in $(ls $MIGRATIONS_DIR/*.sql | sort); do
basename=$(basename $file)
run_migration $basename && echo “OK: $basename” || echo “FAILED: $basename”
done
“`

*Photo by Brett Sayles on Pexels*
## CI/CD Pipeline Script
A self-hosted CI/CD pipeline using GitHub webhooks.
“`python
from flask import Flask, request
import subprocess, hmac, hashlib
app = Flask(__name__)
SECRET = b’your-webhook-secret’
@app.route(‘/deploy’, methods=[‘POST’])
def deploy():
signature = hmac.new(SECRET, request.data, hashlib.sha256).hexdigest()
if not hmac.compare_digest(
f’sha256={signature}’,
request.headers.get(‘X-Hub-Signature-256’, ”)
):
return ‘Invalid signature’, 403
subprocess.run([‘./deploy.sh’], cwd=’/var/www/app’)
return ‘Deployed’, 200
if __name__ == ‘__main__’:
app.run(port=9000)
“`
## SSL Auto-Renewal Script
Automate Let’s Encrypt renewal and deploy certificates.
“`bash
#!/bin/bash
DOMAINS=(“example.com” “app.example.com”)
WEBROOT=”/var/www/html”
for domain in “${DOMAINS[@]}”; do
certbot certonly –webroot -w $WEBROOT -d $domain –non-interactive
if [ $? -eq 0 ]; then
nginx -t && systemctl reload nginx
echo “Renewed: $domain”
else
echo “Failed: $domain”
fi
done
“`
## Post-Deployment Health Check
Verify your deployment is healthy after each release.
“`bash
#!/bin/bash
URL=”https://example.com/health”
EXPECTED=200
RETRIES=5
for i in $(seq 1 $RETRIES); do
STATUS=$(curl -s -o /dev/null -w ‘%{http_code}’ $URL)
if [ “$STATUS” = “$EXPECTED” ]; then
echo “Health check passed (attempt $i)”
exit 0
fi
echo “Attempt $i: got $STATUS, retrying…”
sleep 5
done
echo “Health check failed after $RETRIES attempts”
exit 1
“`
## Quick Start
“`bash
# Clone the scripts
git clone https://github.com/freefile/deploy-scripts
cd deploy-scripts
# Make executable
chmod +x *.sh
# Edit config variables at the top of each script
# Then deploy:
./deploy-static.sh
“`
All scripts are production-tested on Ubuntu 24.04 with Nginx and Docker. They include error handling, logging, and notifications. Download the complete collection at freefile.store.
*For more developer scripts, tools, and resources, visit freefile.store.*