-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_vectorized_postgres.sh
More file actions
executable file
·54 lines (45 loc) · 1.17 KB
/
Copy pathcreate_vectorized_postgres.sh
File metadata and controls
executable file
·54 lines (45 loc) · 1.17 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
#!/bin/sh
set -eu
is_valid_name() {
case "$1" in
""|*[!a-zA-Z0-9_.-]*)
return 1
;;
*)
return 0
;;
esac
}
if [ "${1-}" = "" ]; then
printf "Postgres name: "
read -r POSTGRES_NAME
else
POSTGRES_NAME="$1"
fi
if ! is_valid_name "$POSTGRES_NAME"; then
printf "Invalid postgres name. Use letters, numbers, dot, underscore, or dash.\n" >&2
exit 1
fi
if [ "${POSTGRES_PASSWORD-}" = "" ]; then
printf "Postgres password: "
read -r POSTGRES_PASSWORD
fi
if [ "$POSTGRES_PASSWORD" = "" ]; then
printf "Postgres password cannot be empty.\n" >&2
exit 1
fi
CONTAINER_NAME="${POSTGRES_NAME}-postgres"
IMAGE="${POSTGRES_IMAGE-pgvector/pgvector:pg18}"
printf "Container: %s\n" "$CONTAINER_NAME"
printf "Image: %s\n" "$IMAGE"
if docker ps -a --format '{{.Names}}' | grep -qx "$CONTAINER_NAME"; then
printf "Container '%s' already exists. Remove it first:\n" "$CONTAINER_NAME" >&2
printf "docker rm -f %s\n" "$CONTAINER_NAME" >&2
exit 1
fi
docker run \
--name "$CONTAINER_NAME" \
-p "5432:5432" \
-e "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" \
-e "POSTGRES_USER=postgres" \
-d "$IMAGE"