-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-instance.sh
More file actions
executable file
·65 lines (52 loc) · 1.93 KB
/
setup-instance.sh
File metadata and controls
executable file
·65 lines (52 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# This script configures the VM instance and deploys n8n.
# Exit on error
set -e
# --- Parameters ---
DOMAIN_NAME=$1
if [ -z "$DOMAIN_NAME" ]; then
echo "Usage: $0 <domain_name>"
exit 1
fi
# --- System Update ---
echo "Updating the system..."
sudo apt-get update
sudo apt-get upgrade -y
# --- Docker Installation ---
echo "Installing Docker..."
sudo apt-get install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=\"$(dpkg --print-architecture)\" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# --- Docker Permissions ---
echo "Configuring Docker permissions..."
sudo usermod -aG docker "$USER"
# --- Application Setup ---
APP_DIR="/opt/n8n"
echo "Creating application directory..."
sudo mkdir -p "$APP_DIR"
sudo chown "$USER":"$USER" "$APP_DIR"
echo "Moving template files to the application directory..."
# Move all files including hidden ones (like .env)
shopt -s dotglob
mv ./templates/* "$APP_DIR"
shopt -u dotglob
cd "$APP_DIR"
# --- Dynamic Configuration ---
echo "Configuring Caddyfile and .env file..."
sed -i "s/__DOMAIN_NAME__/$DOMAIN_NAME/g" Caddyfile
sed -i "s/__DOMAIN_NAME__/$DOMAIN_NAME/g" .env
sed -i "s/your-email@example.com/admin@$DOMAIN_NAME/g" Caddyfile
# --- Application Launch ---
echo "Starting n8n and Caddy..."
# Use sg to run docker compose with the docker group (since we just added the user to it)
sg docker -c "docker compose up -d"
# --- Status Confirmation ---
echo "Application containers started:"
sg docker -c "docker ps"