95 lines
2.3 KiB
Bash
95 lines
2.3 KiB
Bash
|
|
#!/bin/bash
|
||
|
|
|
||
|
|
set -e
|
||
|
|
|
||
|
|
# Install Docker and Docker Compose
|
||
|
|
echo "Installing Docker and Docker Compose..."
|
||
|
|
apt-get update
|
||
|
|
apt-get install -y ca-certificates curl gnupg lsb-release
|
||
|
|
|
||
|
|
# Add Docker's official GPG key
|
||
|
|
mkdir -p /etc/apt/keyrings
|
||
|
|
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||
|
|
|
||
|
|
# Add Docker repository
|
||
|
|
echo \
|
||
|
|
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
|
||
|
|
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||
|
|
|
||
|
|
# Update package index
|
||
|
|
apt-get update
|
||
|
|
|
||
|
|
# Install Docker Engine
|
||
|
|
apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
||
|
|
|
||
|
|
# Create directories for data persistence
|
||
|
|
echo "Creating data directories..."
|
||
|
|
mkdir -p /var/lib/n8n/data /var/lib/n8n/ssl
|
||
|
|
|
||
|
|
# Generate random passwords
|
||
|
|
echo "Generating random passwords..."
|
||
|
|
POSTGRES_PASSWORD=$(openssl rand -hex 16)
|
||
|
|
N8N_ENCRYPTION_KEY=$(openssl rand -hex 16)
|
||
|
|
|
||
|
|
# Create docker-compose.yml
|
||
|
|
echo "Creating docker-compose.yml..."
|
||
|
|
cat > /root/docker-compose.yml << EOF
|
||
|
|
version: '3.8'
|
||
|
|
services:
|
||
|
|
db:
|
||
|
|
image: ankane/pgvector:latest
|
||
|
|
container_name: n8n-db
|
||
|
|
environment:
|
||
|
|
POSTGRES_PASSWORD: $POSTGRES_PASSWORD
|
||
|
|
POSTGRES_DB: n8n
|
||
|
|
POSTGRES_USER: n8n
|
||
|
|
volumes:
|
||
|
|
- /var/lib/n8n/data/postgres:/var/lib/postgresql/data
|
||
|
|
networks:
|
||
|
|
- n8n-network
|
||
|
|
restart: unless-stopped
|
||
|
|
|
||
|
|
n8n:
|
||
|
|
image: docker.n8n.io/n8nio/n8n:latest
|
||
|
|
container_name: n8n-app
|
||
|
|
environment:
|
||
|
|
DB_TYPE: postgresdb
|
||
|
|
DB_POSTGRESDB_HOST: db
|
||
|
|
DB_POSTGRESDB_PORT: 5432
|
||
|
|
DB_POSTGRESDB_USER: n8n
|
||
|
|
DB_POSTGRESDB_PASSWORD: $POSTGRES_PASSWORD
|
||
|
|
DB_POSTGRESDB_DATABASE: n8n
|
||
|
|
N8N_ENCRYPTION_KEY: $N8N_ENCRYPTION_KEY
|
||
|
|
TIMEZONE: Europe/Berlin
|
||
|
|
volumes:
|
||
|
|
- /var/lib/n8n/data/n8n:/home/n8n/.n8n
|
||
|
|
networks:
|
||
|
|
- n8n-network
|
||
|
|
restart: unless-stopped
|
||
|
|
depends_on:
|
||
|
|
- db
|
||
|
|
|
||
|
|
networks:
|
||
|
|
n8n-network:
|
||
|
|
driver: bridge
|
||
|
|
EOF
|
||
|
|
|
||
|
|
# Start Docker stack
|
||
|
|
echo "Starting Docker stack..."
|
||
|
|
cd /root
|
||
|
|
docker compose up -d
|
||
|
|
|
||
|
|
# Wait for n8n to be ready
|
||
|
|
echo "Waiting for n8n to be ready..."
|
||
|
|
sleep 30
|
||
|
|
|
||
|
|
# Output credentials as JSON
|
||
|
|
echo "Outputting credentials..."
|
||
|
|
cat << EOF
|
||
|
|
{
|
||
|
|
"ctid": "$CTID",
|
||
|
|
"ip": "$IP",
|
||
|
|
"postgres_password": "$POSTGRES_PASSWORD",
|
||
|
|
"n8n_encryption_key": "$N8N_ENCRYPTION_KEY"
|
||
|
|
}
|
||
|
|
EOF
|