Skip to content

Commit 50fac03

Browse files
authored
Restore Docker Script (#445)
1 parent f1cff83 commit 50fac03

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import os
2+
import subprocess
3+
import sys
4+
import time
5+
6+
# Default PostgreSQL port
7+
port = "5432"
8+
9+
# Set the host PostgreSQL port with the -p/--port flag
10+
for i, arg in enumerate(sys.argv):
11+
if arg in ["-p", "--port"]:
12+
if i + 1 < len(sys.argv):
13+
port = sys.argv[i + 1]
14+
15+
if "PGPASSWORD" not in os.environ:
16+
print("Error: PGPASSWORD is not set.")
17+
sys.exit(1)
18+
19+
try:
20+
subprocess.run(
21+
[
22+
"docker",
23+
"run",
24+
"--rm",
25+
"--name=dbos-db",
26+
f'--env=POSTGRES_PASSWORD={os.environ["PGPASSWORD"]}',
27+
"--env=PGDATA=/var/lib/postgresql/data",
28+
"--volume=/var/lib/postgresql/data",
29+
"-p",
30+
f"{port}:5432",
31+
"-d",
32+
"pgvector/pgvector:pg16",
33+
],
34+
check=True,
35+
)
36+
37+
print("Waiting for PostgreSQL to start...")
38+
attempts = 30
39+
40+
while attempts > 0:
41+
try:
42+
subprocess.run(
43+
[
44+
"docker",
45+
"exec",
46+
"dbos-db",
47+
"psql",
48+
"-U",
49+
"postgres",
50+
"-c",
51+
"SELECT 1;",
52+
],
53+
check=True,
54+
capture_output=True,
55+
)
56+
print("PostgreSQL started!")
57+
print("Database started successfully!")
58+
break
59+
except subprocess.CalledProcessError:
60+
attempts -= 1
61+
time.sleep(1)
62+
63+
if attempts == 0:
64+
print("Failed to start PostgreSQL.")
65+
66+
except subprocess.CalledProcessError as error:
67+
print(f"Error starting PostgreSQL in Docker: {error}")

0 commit comments

Comments
 (0)