Skip to content

Commit 15d2fd7

Browse files
authored
Ensure PostgreSQL is ready before table creation
Added a wait command to ensure PostgreSQL is ready before creating the table.
1 parent 84278bd commit 15d2fd7

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ jobs:
6464
- name: Wait for pods
6565
run: |
6666
kubectl wait --for=condition=ready pod -l app=postgres --timeout=120s
67+
68+
# Wait for postgres to actually accept connections
69+
kubectl exec $(kubectl get pod -l app=postgres -o jsonpath="{.items[0].metadata.name}") -- sh -c "until pg_isready -h 127.0.0.1 -U postgres; do echo 'waiting for postgres...'; sleep 2; done"
70+
71+
# Now create the table
6772
kubectl exec $(kubectl get pod -l app=postgres -o jsonpath="{.items[0].metadata.name}") -- psql -h 127.0.0.1 -U postgres -d todo_db -c "CREATE TABLE IF NOT EXISTS todo (todo_id SERIAL PRIMARY KEY, description VARCHAR(255));"
73+
6874
kubectl wait --for=condition=ready pod -l app=backend --timeout=120s
6975
kubectl wait --for=condition=ready pod -l app=frontend --timeout=120s
7076

0 commit comments

Comments
 (0)