initial commit
This commit is contained in:
66
run.sh
Normal file
66
run.sh
Normal file
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "🚀 Starting OneDev Deployment..."
|
||||
|
||||
# 1. Handle Environment Variables
|
||||
if [ ! -f .env ]; then
|
||||
echo "📄 .env file not found. Creating one from .env.example..."
|
||||
cp .env.example .env
|
||||
echo "⚠️ Please edit the .env file with your DOMAIN (and EMAIL for SSL), then run this script again."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Load environment variables
|
||||
source .env
|
||||
|
||||
# 2. Handle Reverse Proxy and SSL Configuration
|
||||
mkdir -p certs
|
||||
echo "🔒 Configuring Reverse Proxy..."
|
||||
|
||||
if [ -f "certs/cert.pem" ] && [ -f "certs/key.pem" ]; then
|
||||
echo "✅ Custom SSL certificates detected. Configuring Caddy to use custom TLS."
|
||||
cat <<EOF > Caddyfile
|
||||
{\$DOMAIN} {
|
||||
tls /certs/cert.pem /certs/key.pem
|
||||
reverse_proxy onedev:6610
|
||||
}
|
||||
EOF
|
||||
elif [ -n "$EMAIL" ]; then
|
||||
echo "🌐 No custom certs found, but EMAIL is set. Auto-provisioning Let's Encrypt SSL."
|
||||
cat <<EOF > Caddyfile
|
||||
{\$DOMAIN} {
|
||||
tls {\$EMAIL}
|
||||
reverse_proxy onedev:6610
|
||||
}
|
||||
EOF
|
||||
else
|
||||
echo "⚠️ No custom certs and no EMAIL provided. Configuring for plain HTTP."
|
||||
cat <<EOF > Caddyfile
|
||||
http://{\$DOMAIN} {
|
||||
reverse_proxy onedev:6610
|
||||
}
|
||||
EOF
|
||||
fi
|
||||
|
||||
# 3. Determine docker compose command
|
||||
if command -v docker-compose &> /dev/null; then
|
||||
COMPOSE_CMD="docker-compose"
|
||||
elif docker --help | grep -q "compose"; then
|
||||
COMPOSE_CMD="docker compose"
|
||||
else
|
||||
echo "❌ Error: Docker Compose not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 4. Deploy
|
||||
echo "🐳 Pulling images and starting containers..."
|
||||
$COMPOSE_CMD pull
|
||||
$COMPOSE_CMD up -d
|
||||
|
||||
echo "✅ Deployment complete!"
|
||||
if [ -n "$EMAIL" ] || ([ -f "certs/cert.pem" ] && [ -f "certs/key.pem" ]); then
|
||||
echo "🌐 Access your server securely at: https://${DOMAIN}"
|
||||
else
|
||||
echo "🌐 Access your server at: http://${DOMAIN}"
|
||||
fi
|
||||
Reference in New Issue
Block a user