Skip to content

Commit cc8a0cf

Browse files
authored
Merge pull request #330 from OmentaElvis/fix/docker-compose
fix(docker): Update docker-compose.yml to fix broken postgress and MinIO initialization.
2 parents 092689d + ecd9ddd commit cc8a0cf

3 files changed

Lines changed: 49 additions & 35 deletions

File tree

docker-compose.yml

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,9 @@ services:
5555
depends_on:
5656
- minio
5757
restart: on-failure
58-
entrypoint: >
59-
/bin/sh -c '
60-
echo "Waiting for MinIO to start...";
61-
sleep 15;
62-
for i in 1 2 3 4 5; do
63-
echo "Attempt $i to connect to MinIO...";
64-
if /usr/bin/mc alias set myminio http://minio:9000 minioadmin minioadmin; then
65-
echo "Successfully connected to MinIO!";
66-
/usr/bin/mc mb --ignore-existing myminio/worklenz-bucket;
67-
/usr/bin/mc policy set public myminio/worklenz-bucket;
68-
exit 0;
69-
fi
70-
echo "Connection failed, retrying in 5 seconds...";
71-
sleep 5;
72-
done;
73-
echo "Failed to connect to MinIO after 5 attempts";
74-
exit 1;
75-
'
58+
entrypoint: ["/bin/sh", "/scripts/createbuckets-entrypoint.sh"]
59+
volumes:
60+
- ./docker/createbuckets-entrypoint.sh:/scripts/createbuckets-entrypoint.sh:ro
7661
networks:
7762
- worklenz
7863
db:
@@ -91,11 +76,13 @@ services:
9176
interval: 10s
9277
timeout: 5s
9378
retries: 5
79+
start_period: 30s
9480
restart: unless-stopped
9581
networks:
9682
- worklenz
9783
volumes:
9884
- worklenz_postgres_data:/var/lib/postgresql/data
85+
- ./docker/db-init-wrapper.sh:/usr/local/bin/db-init-wrapper.sh:ro
9986
- type: bind
10087
source: ./worklenz-backend/database/sql
10188
target: /docker-entrypoint-initdb.d/sql
@@ -111,23 +98,7 @@ services:
11198
- type: bind
11299
source: ./pg_backups
113100
target: /docker-entrypoint-initdb.d/pg_backups
114-
command: >
115-
bash -c '
116-
if command -v apt-get >/dev/null 2>&1; then
117-
apt-get update && apt-get install -y dos2unix
118-
elif command -v apk >/dev/null 2>&1; then
119-
apk add --no-cache dos2unix
120-
fi
121-
122-
find /docker-entrypoint-initdb.d -type f -name "*.sh" -exec sh -c '"'"'
123-
for f; do
124-
dos2unix "$f" 2>/dev/null || true
125-
chmod +x "$f"
126-
done
127-
'"'"' sh {} +
128-
129-
exec docker-entrypoint.sh postgres
130-
'
101+
command: ["/usr/local/bin/db-init-wrapper.sh"]
131102
db-backup:
132103
image: postgres:15
133104
container_name: worklenz_db_backup

docker/createbuckets-entrypoint.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
set -e
3+
4+
echo "Waiting for MinIO to start..."
5+
sleep 15
6+
7+
for i in 1 2 3 4 5; do
8+
echo "Attempt $i to connect to MinIO..."
9+
if /usr/bin/mc alias set myminio http://minio:9000 minioadmin minioadmin; then
10+
echo "Successfully connected to MinIO!"
11+
/usr/bin/mc mb --ignore-existing myminio/worklenz-bucket
12+
/usr/bin/mc policy set public myminio/worklenz-bucket
13+
exit 0
14+
fi
15+
16+
echo "Connection failed, retrying in 5 seconds..."
17+
sleep 5
18+
done
19+
20+
echo "Failed to connect to MinIO after 5 attempts"
21+
exit 1
22+

docker/db-init-wrapper.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Install dos2unix if possible
5+
if command -v apt-get >/dev/null 2>&1; then
6+
apt-get update && apt-get install -y dos2unix
7+
elif command -v apk >/dev/null 2>&1; then
8+
apk add --no-cache dos2unix
9+
fi
10+
11+
# Normalize and chmod all .sh files
12+
for f in /docker-entrypoint-initdb.d/*.sh; do
13+
if [ -f "$f" ]; then
14+
dos2unix "$f" 2>/dev/null || true
15+
chmod +x "$f"
16+
fi
17+
done
18+
19+
# hand control to the real entrypoint
20+
exec docker-entrypoint.sh postgres
21+

0 commit comments

Comments
 (0)