Files
worklenz/docker-compose.yml
kithmina1999 f142046dcc fix(docker): correct bash syntax in postgres backup command
The command was using incorrect quote escaping which could cause issues with variable expansion and file deletion. Fixed by using single quotes for the outer string and proper escaping for date command substitution.
2025-06-06 16:32:11 +05:30

158 lines
4.3 KiB
YAML

services:
frontend:
build:
context: ./worklenz-frontend
dockerfile: Dockerfile
container_name: worklenz_frontend
ports:
- "5000:5000"
depends_on:
backend:
condition: service_started
env_file:
- ./worklenz-frontend/.env.production
networks:
- worklenz
backend:
build:
context: ./worklenz-backend
dockerfile: Dockerfile
container_name: worklenz_backend
ports:
- "3000:3000"
depends_on:
db:
condition: service_healthy
minio:
condition: service_started
env_file:
- ./worklenz-backend/.env
networks:
- worklenz
minio:
image: minio/minio:latest
container_name: worklenz_minio
ports:
- "9000:9000"
- "9001:9001"
environment:
MINIO_ROOT_USER: ${S3_ACCESS_KEY_ID:-minioadmin}
MINIO_ROOT_PASSWORD: ${S3_SECRET_ACCESS_KEY:-minioadmin}
volumes:
- worklenz_minio_data:/data
command: server /data --console-address ":9001"
networks:
- worklenz
# MinIO setup helper - creates default bucket on startup
createbuckets:
image: minio/mc
container_name: worklenz_createbuckets
depends_on:
- minio
entrypoint: >
/bin/sh -c '
echo "Waiting for MinIO to start...";
sleep 15;
for i in 1 2 3 4 5; do
echo "Attempt $i to connect to MinIO...";
if /usr/bin/mc config host add myminio http://minio:9000 minioadmin minioadmin; then
echo "Successfully connected to MinIO!";
/usr/bin/mc mb --ignore-existing myminio/worklenz-bucket;
/usr/bin/mc policy set public myminio/worklenz-bucket;
exit 0;
fi
echo "Connection failed, retrying in 5 seconds...";
sleep 5;
done;
echo "Failed to connect to MinIO after 5 attempts";
exit 1;
'
networks:
- worklenz
db:
image: postgres:15
container_name: worklenz_db
environment:
POSTGRES_USER: ${DB_USER:-postgres}
POSTGRES_DB: ${DB_NAME:-worklenz_db}
POSTGRES_PASSWORD: ${DB_PASSWORD:-password}
healthcheck:
test:
[
"CMD-SHELL",
"pg_isready -d ${DB_NAME:-worklenz_db} -U ${DB_USER:-postgres}",
]
interval: 10s
timeout: 5s
retries: 5
networks:
- worklenz
volumes:
- worklenz_postgres_data:/var/lib/postgresql/data
- type: bind
source: ./worklenz-backend/database/sql
target: /docker-entrypoint-initdb.d/sql
consistency: cached
- type: bind
source: ./worklenz-backend/database/migrations
target: /docker-entrypoint-initdb.d/migrations
consistency: cached
- type: bind
source: ./worklenz-backend/database/00_init.sh
target: /docker-entrypoint-initdb.d/00_init.sh
consistency: cached
- type: bind
source: ./pg_backups
target: /docker-entrypoint-initdb.d/pg_backups
command: >
bash -c '
if command -v apt-get >/dev/null 2>&1; then
apt-get update && apt-get install -y dos2unix
elif command -v apk >/dev/null 2>&1; then
apk add --no-cache dos2unix
fi
find /docker-entrypoint-initdb.d -type f -name "*.sh" -exec sh -c '"'"'
for f; do
dos2unix "$f" 2>/dev/null || true
chmod +x "$f"
done
'"'"' sh {} +
exec docker-entrypoint.sh postgres
'
db-backup:
image: postgres:15
container_name: worklenz_db_backup
environment:
POSTGRES_USER: ${DB_USER:-postgres}
POSTGRES_DB: ${DB_NAME:-worklenz_db}
POSTGRES_PASSWORD: ${DB_PASSWORD:-password}
depends_on:
db:
condition: service_healthy
volumes:
- ./pg_backups:/pg_backups #host dir for backups files
#setup bassh loop to backup data evey 24h
command: >
bash -c 'while true; do
sleep 86400;
PGPASSWORD=$$POSTGRES_PASSWORD pg_dump -h worklenz_db -U $$POSTGRES_USER -d $$POSTGRES_DB \
> /pg_backups/worklenz_db_$$(date +%Y-%m-%d_%H-%M-%S).sql;
find /pg_backups -type f -name "*.sql" -mtime +30 -delete;
done'
restart: unless-stopped
networks:
- worklenz
volumes:
worklenz_postgres_data:
worklenz_minio_data:
pgdata:
networks:
worklenz: