-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-dev.sh
More file actions
executable file
·357 lines (317 loc) · 10.8 KB
/
setup-dev.sh
File metadata and controls
executable file
·357 lines (317 loc) · 10.8 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# =========================
# 1) One-time setup script
# =========================
# This creates:
# - a dedicated docker network
# - named volumes (so data persists across container restarts/recreates)
# - containers with fixed names: sqlserver, azurite, mongodb, postgres, clickhouse, metabase, mailhog, openobserve, redis, minio, sentry, victorialogs
#
# Save as: ~/bin/setup-dev.sh
# Run: chmod +x ~/bin/setup-dev.sh && ~/bin/setup-dev.sh
cat > ~/bin/setup-dev.sh <<'BASH'
#!/usr/bin/env bash
set -euo pipefail
# ---- config (edit if you want) ----
NET="devnet"
# Postgres (you asked for these defaults)
PG_USER="postgres"
PG_PASS="changeme"
PG_DB="postgres"
PG_PORT="5432"
# Mongo
MONGO_PORT="27017"
# ClickHouse
CH_HTTP_PORT="8123"
CH_TCP_PORT="9000"
# Metabase
MB_PORT="3000"
# Azurite
AZ_BLOB_PORT="10000"
AZ_QUEUE_PORT="10001"
AZ_TABLE_PORT="10002"
# SQL Server (you MUST set a strong SA password; SQL Server enforces complexity)
# If you already have one, export MSSQL_SA_PASSWORD before running the script.
: "${MSSQL_SA_PASSWORD:=ChangeMe_Strong!123}"
MSSQL_PORT="1433"
# OpenObserve
OO_HTTP_PORT="5080"
OO_GRPC_PORT="5081" # optional but nice to expose
# Redis
# MinIO S3
MINIO_PORT="9002"
MINIO_CONSOLE_PORT="9003"
# Access Key ID: minioadmin (default)
# Secret Access Key: minioadmin (default)
# Endpoint: http://localhost:9002
# Region: us-east-1 (default, can be changed)
# Default Bucket: user-uploads (created automatically on first start)
# Console UI: http://localhost:9003
# Sentry
SENTRY_PORT="9004"
# Web UI: http://localhost:9004
# Default admin user: sentry / sentry (change on first login)
# Uses existing postgres and redis containers
# DSN will be shown in start-dev output after first initialization
# VictoriaLogs
VICTORIALOGS_PORT="9428"
# Web UI: http://localhost:9428
# Log ingestion endpoint: http://localhost:9428/insert/loki/api/v1/push
# Query API: http://localhost:9428/select/logsql/query
# ---- volumes (named = persistent) ----
V_MSSQL="sqlserver_data"
V_AZURITE="azurite_data"
V_MONGO="mongodb_data"
V_PG="pg_data" # keeping your screenshot name
V_CH="clickhouse_data"
V_MB="metabase_data"
V_OO="openobserve_data"
V_REDIS="redis_data"
V_MINIO="minio_data"
V_SENTRY="sentry_data"
V_VICTORIALOGS="victorialogs_data"
# ---- helpers ----
ensure_network() {
if ! docker network inspect "$NET" >/dev/null 2>&1; then
docker network create "$NET" >/dev/null
fi
}
ensure_volume() {
local v="$1"
if ! docker volume inspect "$v" >/dev/null 2>&1; then
docker volume create "$v" >/dev/null
fi
}
ensure_image() {
local image="$1"
if ! docker image inspect "$image" >/dev/null 2>&1; then
echo "Pulling image: $image"
docker pull "$image" || {
echo "Warning: Failed to pull $image, docker run will attempt to pull it"
}
fi
}
ensure_container() {
local name="$1"
shift
# Extract image name (last argument that looks like an image name)
# This handles cases like: redis:7 redis-server --appendonly yes
# Image names typically: contain / or :, don't start with /, and aren't common command words
local image=""
local args=("$@")
local skip_words="yes|no|true|false"
for ((i=${#args[@]}-1; i>=0; i--)); do
local arg="${args[i]}"
# Skip flags and common command words
if [[ "$arg" =~ ^-- ]] || [[ "$arg" =~ ^($skip_words)$ ]]; then
continue
fi
# Image names typically contain / (registry/repo) or : (tag), or are simple names
# But exclude file paths (starting with /)
if [[ "$arg" =~ ^[a-zA-Z0-9._/-]+(:[a-zA-Z0-9._-]+)?$ ]] && [[ ! "$arg" =~ ^/ ]] && [[ "$arg" =~ (/|:) ]]; then
image="$arg"
break
fi
done
# If no image found with / or :, try the last non-flag argument (for simple names like "mongo:7")
if [[ -z "$image" ]]; then
for ((i=${#args[@]}-1; i>=0; i--)); do
local arg="${args[i]}"
if [[ ! "$arg" =~ ^-- ]] && [[ ! "$arg" =~ ^($skip_words)$ ]] && [[ ! "$arg" =~ ^/ ]]; then
# Check if it looks like an image name (alphanumeric with possible : and -)
if [[ "$arg" =~ ^[a-zA-Z0-9._/-]+(:[a-zA-Z0-9._-]+)?$ ]]; then
image="$arg"
break
fi
fi
done
fi
if [[ -z "$image" ]]; then
echo "Error: Could not determine image name for container $name" >&2
return 1
fi
# Ensure image is available
ensure_image "$image"
if ! docker container inspect "$name" >/dev/null 2>&1; then
# create container but don't necessarily start it yet
# Suppress stdout but show stderr for errors
if ! docker run -d --name "$name" "$@" >/dev/null; then
echo "Error: Failed to create container $name" >&2
return 1
fi
docker stop "$name" >/dev/null 2>&1
fi
}
main() {
ensure_network
# volumes (persist data even if you docker rm + recreate the container)
ensure_volume "$V_MSSQL"
ensure_volume "$V_AZURITE"
ensure_volume "$V_MONGO"
ensure_volume "$V_PG"
ensure_volume "$V_CH"
ensure_volume "$V_MB"
ensure_volume "$V_OO"
ensure_volume "$V_REDIS"
ensure_volume "$V_MINIO"
ensure_volume "$V_SENTRY"
ensure_volume "$V_VICTORIALOGS"
# ---- SQL Server ----
# Server=localhost,1433;Database=master;User Id=sa;Password=ChangeMe_Strong!123;TrustServerCertificate=True;
# Data dir: /var/opt/mssql
ensure_container sqlserver \
--restart unless-stopped \
--network "$NET" \
-p "${MSSQL_PORT}:1433" \
-e "ACCEPT_EULA=Y" \
-e "MSSQL_SA_PASSWORD=${MSSQL_SA_PASSWORD}" \
-v "${V_MSSQL}:/var/opt/mssql" \
mcr.microsoft.com/mssql/server:2022-latest
# ---- Azurite ----
# DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://localhost:10000/devstoreaccount1;QueueEndpoint=http://localhost:10001/devstoreaccount1;TableEndpoint=http://localhost:10002/devstoreaccount1;
# Data dir: /data
ensure_container azurite \
--restart unless-stopped \
--network "$NET" \
-p "${AZ_BLOB_PORT}:10000" \
-p "${AZ_QUEUE_PORT}:10001" \
-p "${AZ_TABLE_PORT}:10002" \
-v "${V_AZURITE}:/data" \
mcr.microsoft.com/azure-storage/azurite \
azurite --blobHost 0.0.0.0 --queueHost 0.0.0.0 --tableHost 0.0.0.0 --location /data --debug /data/debug.log
# ---- MongoDB ----
# mongodb://localhost:27017
# Data dir: /data/db
ensure_container mongodb \
--restart unless-stopped \
--network "$NET" \
-p "${MONGO_PORT}:27017" \
-v "${V_MONGO}:/data/db" \
mongo:7
# ---- Postgres ----
# postgresql://postgres:changeme@localhost:5432/postgres
# Data dir: /var/lib/postgresql/data
ensure_container postgres \
--restart unless-stopped \
--network "$NET" \
-p "${PG_PORT}:5432" \
-e "POSTGRES_USER=${PG_USER}" \
-e "POSTGRES_PASSWORD=${PG_PASS}" \
-e "POSTGRES_DB=${PG_DB}" \
-v "${V_PG}:/var/lib/postgresql/data" \
postgres:16
# ---- ClickHouse ----
# clickhouse://localhost:9000
# http://localhost:8123
# Data dir: /var/lib/clickhouse
ensure_container clickhouse \
--restart unless-stopped \
--network "$NET" \
-p "${CH_HTTP_PORT}:8123" \
-p "${CH_TCP_PORT}:9000" \
-v "${V_CH}:/var/lib/clickhouse" \
clickhouse/clickhouse-server:latest
# ---- Metabase ----
# Web UI: http://localhost:3000
# We'll persist its internal app DB to /metabase-data (H2 by default)
ensure_container metabase \
--restart unless-stopped \
--network "$NET" \
-p "${MB_PORT}:3000" \
-e "MB_DB_FILE=/metabase_data/metabase.db" \
-v "${V_MB}:/metabase_data" \
metabase/metabase:latest
# ---- MailHog ----
# SMTP: 1025, Web UI: 8025
ensure_container mailhog \
--restart unless-stopped \
--network "$NET" \
-p 1025:1025 \
-p 8025:8025 \
mailhog/mailhog
# ---- OpenObserve ----
# http://localhost:5080
ensure_container openobserve \
--restart unless-stopped \
--network "$NET" \
-p "${OO_HTTP_PORT}:5080" \
-p "${OO_GRPC_PORT}:5081" \
-e "ZO_ROOT_USER_EMAIL=root@example.com" \
-e "ZO_ROOT_USER_PASSWORD=Complexpass#123" \
-v "${V_OO}:/data" \
openobserve/openobserve:latest
# ---- Redis ----
# redis://localhost:6379
ensure_container redis \
--restart unless-stopped \
--network "$NET" \
-p 6379:6379 \
-v "${V_REDIS}:/data" \
redis:7 \
redis-server --appendonly yes
# ---- MinIO S3 ----
# S3-compatible object storage
# Access Key ID: minioadmin (default, can be changed via MINIO_ROOT_USER env var)
# Secret Access Key: minioadmin (default, can be changed via MINIO_ROOT_PASSWORD env var)
# Endpoint: http://localhost:9002
# Region: us-east-1 (default, can be changed)
# Default Bucket: user-uploads (created automatically on first start)
# Console UI: http://localhost:9003 (login with minioadmin/minioadmin)
ensure_container minio \
--restart unless-stopped \
--network "$NET" \
-p "${MINIO_PORT}:9000" \
-p "${MINIO_CONSOLE_PORT}:9001" \
-e "MINIO_ROOT_USER=minioadmin" \
-e "MINIO_ROOT_PASSWORD=minioadmin" \
-v "${V_MINIO}:/data" \
minio/minio:latest \
server /data --console-address ":9001"
# ---- Sentry ----
# Error tracking and monitoring
# Web UI: http://localhost:9004
# Default admin: sentry / sentry (change on first login)
# Uses existing postgres and redis containers
# DSN format: http://<key>@localhost:9004/<project-id>
# Note: First startup will initialize database - this may take a minute
ensure_container sentry \
--restart unless-stopped \
--network "$NET" \
-p "${SENTRY_PORT}:9000" \
-e "SENTRY_SECRET_KEY=dev-secret-key-change-in-production-please" \
-e "SENTRY_POSTGRES_HOST=postgres" \
-e "SENTRY_POSTGRES_PORT=5432" \
-e "SENTRY_DB_USER=${PG_USER}" \
-e "SENTRY_DB_PASSWORD=${PG_PASS}" \
-e "SENTRY_DB_NAME=sentry" \
-e "SENTRY_REDIS_HOST=redis" \
-e "SENTRY_REDIS_PORT=6379" \
-e "SENTRY_REDIS_DB=0" \
-e "SENTRY_USE_SSL=false" \
-e "SENTRY_URL_PREFIX=http://localhost:9004" \
-e "SENTRY_SINGLE_ORGANIZATION=true" \
-v "${V_SENTRY}:/var/lib/sentry/files" \
sentry:latest \
run web
# ---- VictoriaLogs ----
# Log management and querying system
# Web UI: http://localhost:9428
# Log ingestion endpoint: http://localhost:9428/insert/loki/api/v1/push (Loki-compatible)
# Query API: http://localhost:9428/select/logsql/query
# Compatible with Loki clients and Grafana
ensure_container victorialogs \
--restart unless-stopped \
--network "$NET" \
-p "${VICTORIALOGS_PORT}:9428" \
-v "${V_VICTORIALOGS}:/victoria-logs-data" \
victoriametrics/victoria-logs:latest \
-storageDataPath=/victoria-logs-data
echo "Setup complete."
echo "Run: start-dev (after installing it below) or: ~/bin/start-dev"
echo ""
echo "Postgres creds: user=${PG_USER} pass=${PG_PASS}"
}
main "$@"
BASH
chmod +x ~/bin/setup-dev.sh
echo "Wrote ~/bin/setup-dev.sh"
echo "Run it now with: ~/bin/setup-dev.sh"