Skip to content

Commit c46d346

Browse files
Replace postgres wait loop with Docker healthcheck (#12339)
Co-authored-by: RayBB <RayBB@users.noreply.github.com>
1 parent 459b33a commit c46d346

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

compose.override.yaml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ services:
2424
- LOCAL_DEV=true
2525
- OL_EXPOSE_SOLR_INTERNALS_PARAMS=true
2626
depends_on:
27-
- db
28-
- infobase
27+
db:
28+
condition: service_healthy
29+
infobase:
30+
condition: service_started
2931

3032
fast_web:
3133
build:
@@ -56,7 +58,7 @@ services:
5658
healthcheck:
5759
test: ["CMD", "curl", "-f", "http://localhost:8983/solr/openlibrary/admin/ping"]
5860
interval: 30s
59-
start_interval: 2s
61+
start_interval: 1s
6062
start_period: 20s
6163
timeout: 1s
6264
retries: 24
@@ -95,6 +97,13 @@ services:
9597
# if the db is empty (ie during first run).
9698
- ./docker/ol-db-init.sh:/docker-entrypoint-initdb.d/ol-db-init.sh
9799
- ol-postgres:/var/lib/postgresql
100+
healthcheck:
101+
test: ["CMD-SHELL", "pg_isready -U postgres"]
102+
interval: 30s
103+
start_interval: 1s
104+
start_period: 20s
105+
timeout: 1s
106+
retries: 24
98107

99108
covers:
100109
build:
@@ -121,7 +130,8 @@ services:
121130
- ol-vendor:/openlibrary/vendor
122131
- ${OL_MOUNT_DIR:-.}:/openlibrary
123132
depends_on:
124-
- db
133+
db:
134+
condition: service_healthy
125135

126136
home:
127137
image: "${OLIMAGE:-oldev:latest}"
@@ -149,6 +159,8 @@ services:
149159
depends_on:
150160
solr:
151161
condition: service_healthy
162+
db:
163+
condition: service_healthy
152164

153165
volumes:
154166
ol-vendor:

docker/ol-home-start.sh

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
11
#!/bin/bash
22

3-
# quick method to start all ol services from one script
4-
# inside an container, bypass all upstart/services
5-
6-
python --version
7-
8-
echo "Waiting for postgres..."
9-
until pg_isready --host db; do sleep 5; done
10-
11-
123
make reindex-solr

docker/ol-local-solr-start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ if [ -f "$OL_SCHEMA_FILE" ] && [ -f "$SOLR_SCHEMA_FILE" ]; then
3535
solr start -p $TMP_SOLR_PORT
3636
# Wait for solr core to be ready for searching
3737
until curl -s -o /dev/null -w "%{http_code}" "http://localhost:${TMP_SOLR_PORT}/solr/${CORE_NAME}/select?q=*:*&rows=0&wt=json" | grep -q "200"; do
38-
sleep 5;
38+
sleep 1;
3939
done
4040

4141
TOTAL_SOLR_DOCS=$(curl -s "http://localhost:${TMP_SOLR_PORT}/solr/${CORE_NAME}/select?q=*:*&rows=0&wt=json" | grep -oE '"numFound":[0-9]+' | grep -oE '[0-9]+')

0 commit comments

Comments
 (0)