-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path03-run-docker-container.sh
More file actions
executable file
·33 lines (29 loc) · 1.14 KB
/
Copy path03-run-docker-container.sh
File metadata and controls
executable file
·33 lines (29 loc) · 1.14 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
#!/bin/bash
# Variables
source ./00-variables.sh
# The database runs in-cluster (statefulset.yml). Reach it from the host by
# port-forwarding the primary (write) Service to localhost:$PG_LOCAL_PORT.
# Requires 05-deploy-app.sh (deploys the DB) and 06-create-test-data.sh
# (creates PlannerDB + testuser) to have run first.
echo "Port-forwarding svc/$PG_PRIMARY_SERVICE to localhost:$PG_LOCAL_PORT..."
kubectl port-forward -n "$NAMESPACE" "svc/$PG_PRIMARY_SERVICE" "$PG_LOCAL_PORT:5432" &
PF_PID=$!
trap 'kill "$PF_PID" 2>/dev/null' EXIT
# Wait for the forwarded port to accept connections.
echo "Waiting for PostgreSQL to accept connections on localhost:$PG_LOCAL_PORT..."
until pg_isready -h localhost -p "$PG_LOCAL_PORT" -U "$PG_USER_NAME" &>/dev/null; do
sleep 2
done
# --network=host so the container reaches the port-forward on the host's loopback.
docker run -it \
--rm \
--network=host \
-e PORT=$PORT \
-e PG_HOST="localhost" \
-e PG_PORT="$PG_LOCAL_PORT" \
-e PG_DATABASE="$PG_DATABASE_NAME" \
-e PG_USER="$PG_USER_NAME" \
-e PG_PASSWORD="$PG_USER_PASSWORD" \
-e LOGIN_NAME="$LOGIN_NAME" \
--name "$IMAGE_NAME" \
"$IMAGE_NAME:$IMAGE_TAG"