-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·211 lines (183 loc) · 5.33 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·211 lines (183 loc) · 5.33 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env bash
set -euo pipefail
echo "=== OpenClaw on Fly.io ==="
echo ""
# Check for flyctl
if ! command -v fly &> /dev/null; then
echo "Error: flyctl is not installed."
echo "Install it with: curl -L https://fly.io/install.sh | sh"
exit 1
fi
# Check auth
if ! fly auth whoami &> /dev/null; then
echo "Not logged in to Fly.io. Launching login..."
fly auth login
fi
# App name
DEFAULT_APP="openclaw-$(openssl rand -hex 4)"
read -rp "App name [${DEFAULT_APP}]: " APP_NAME
APP_NAME="${APP_NAME:-$DEFAULT_APP}"
# Region
read -rp "Region [iad]: " REGION
REGION="${REGION:-iad}"
# Setup password
while true; do
read -rsp "Setup password (protects /setup wizard): " SETUP_PASSWORD
echo ""
if [ -n "${SETUP_PASSWORD}" ]; then break; fi
echo "Required — this protects your setup wizard from the internet."
done
# --- LLM Provider ---
echo ""
echo "=== LLM Provider ==="
echo ""
echo " 1) Anthropic (API key)"
echo " 2) OpenAI (API key)"
echo " 3) Google Gemini (API key)"
echo " 4) OpenRouter (API key)"
echo " 5) Moonshot AI (API key)"
echo " 6) MiniMax (API key)"
echo ""
read -rp "Choose provider [1]: " PROVIDER_CHOICE
PROVIDER_CHOICE="${PROVIDER_CHOICE:-1}"
AUTH_CHOICE=""
API_KEY_FLAG=""
API_KEY=""
case "${PROVIDER_CHOICE}" in
1)
AUTH_CHOICE="apiKey"
API_KEY_FLAG="--anthropic-api-key"
read -rsp "Anthropic API key: " API_KEY
echo ""
;;
2)
AUTH_CHOICE="openai-api-key"
API_KEY_FLAG="--openai-api-key"
read -rsp "OpenAI API key: " API_KEY
echo ""
;;
3)
AUTH_CHOICE="gemini-api-key"
API_KEY_FLAG="--gemini-api-key"
read -rsp "Google Gemini API key: " API_KEY
echo ""
;;
4)
AUTH_CHOICE="openrouter-api-key"
API_KEY_FLAG="--openrouter-api-key"
read -rsp "OpenRouter API key: " API_KEY
echo ""
;;
5)
AUTH_CHOICE="moonshot-api-key"
API_KEY_FLAG="--moonshot-api-key"
read -rsp "Moonshot AI API key: " API_KEY
echo ""
;;
6)
AUTH_CHOICE="minimax-api"
API_KEY_FLAG="--minimax-api-key"
read -rsp "MiniMax API key: " API_KEY
echo ""
;;
*)
echo "Invalid choice, defaulting to Anthropic."
AUTH_CHOICE="apiKey"
API_KEY_FLAG="--anthropic-api-key"
read -rsp "Anthropic API key: " API_KEY
echo ""
;;
esac
if [ -z "${API_KEY}" ]; then
echo "Error: API key is required."
exit 1
fi
# --- Optional channels ---
echo ""
echo "=== Channels (optional, press Enter to skip) ==="
echo ""
read -rsp "Discord bot token: " DISCORD_TOKEN
echo ""
read -rsp "Telegram bot token: " TELEGRAM_TOKEN
echo ""
read -rsp "Slack bot token (xoxb-...): " SLACK_BOT_TOKEN
echo ""
if [ -n "${SLACK_BOT_TOKEN}" ]; then
read -rsp "Slack app token (xapp-...): " SLACK_APP_TOKEN
echo ""
else
SLACK_APP_TOKEN=""
fi
# --- Generate fly.toml ---
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cat > "$SCRIPT_DIR/fly.toml" <<TOML
# OpenClaw on Fly.io
# https://fly.io/docs/reference/configuration/
app = "${APP_NAME}"
primary_region = "${REGION}"
[build]
[env]
NODE_ENV = "production"
OPENCLAW_STATE_DIR = "/data"
[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = "stop"
auto_start_machines = true
min_machines_running = 0
[[http_service.checks]]
interval = "30s"
timeout = "5s"
grace_period = "30s"
method = "GET"
path = "/healthz"
[mounts]
source = "openclaw_data"
destination = "/data"
[[vm]]
size = "shared-cpu-2x"
memory = "4096mb"
TOML
# --- Create app + volume ---
echo ""
echo "Creating Fly app: ${APP_NAME} in ${REGION}..."
fly apps create "${APP_NAME}" || true
echo "Creating persistent volume..."
fly volumes create openclaw_data --size 1 --region "${REGION}" --app "${APP_NAME}" --yes || true
# --- Set secrets ---
echo "Setting secrets..."
GATEWAY_TOKEN=$(openssl rand -hex 32)
SECRETS=(
"SETUP_PASSWORD=${SETUP_PASSWORD}"
"OPENCLAW_GATEWAY_TOKEN=${GATEWAY_TOKEN}"
"OPENCLAW_AUTH_CHOICE=${AUTH_CHOICE}"
"OPENCLAW_API_KEY_FLAG=${API_KEY_FLAG}"
"OPENCLAW_API_KEY=${API_KEY}"
)
[ -n "${DISCORD_TOKEN}" ] && SECRETS+=("OPENCLAW_DISCORD_TOKEN=${DISCORD_TOKEN}")
[ -n "${TELEGRAM_TOKEN}" ] && SECRETS+=("OPENCLAW_TELEGRAM_TOKEN=${TELEGRAM_TOKEN}")
[ -n "${SLACK_BOT_TOKEN}" ] && SECRETS+=("OPENCLAW_SLACK_BOT_TOKEN=${SLACK_BOT_TOKEN}")
[ -n "${SLACK_APP_TOKEN}" ] && SECRETS+=("OPENCLAW_SLACK_APP_TOKEN=${SLACK_APP_TOKEN}")
fly secrets set "${SECRETS[@]}" --app "${APP_NAME}"
# --- Deploy ---
echo ""
echo "Deploying OpenClaw (this takes a few minutes for the first build)..."
fly deploy --app "${APP_NAME}"
echo ""
echo "=== Deployment Complete ==="
echo ""
echo "Your OpenClaw instance is running and configured!"
echo ""
echo " App URL: https://${APP_NAME}.fly.dev"
echo " Setup wizard: https://${APP_NAME}.fly.dev/setup"
echo " Gateway URL: wss://${APP_NAME}.fly.dev"
echo " Gateway token: ${GATEWAY_TOKEN}"
echo ""
echo "Connect your local CLI:"
echo " openclaw config set gateway.mode remote"
echo " openclaw config set gateway.remote.url wss://${APP_NAME}.fly.dev"
echo " openclaw config set gateway.remote.token ${GATEWAY_TOKEN}"
echo " openclaw health"
echo ""
echo "Manage later at https://${APP_NAME}.fly.dev/setup (change provider, add channels, edit config)"
echo ""