refactor(docker): improve command formatting and fix shell script issues

- Fix shell script syntax in db service command by using proper quoting and loop structure
- Clean up indentation and formatting in both db and db-backup services
- Ensure consistent command structure while maintaining the same functionality
This commit is contained in:
kithmina1999
2025-06-06 15:34:18 +05:30
parent dc22d1e6cb
commit 0987fb14b2

View File

@@ -107,19 +107,24 @@ services:
- type: bind - type: bind
source: ./pg_backups source: ./pg_backups
target: /docker-entrypoint-initdb.d/pg_backups target: /docker-entrypoint-initdb.d/pg_backups
command: > command: |
bash -c ' bash -c "
if command -v apt-get >/dev/null 2>&1; then if command -v apt-get >/dev/null 2>&1; then
apt-get update && apt-get install -y dos2unix apt-get update && apt-get install -y dos2unix
elif command -v apk >/dev/null 2>&1; then elif command -v apk >/dev/null 2>&1; then
apk add --no-cache dos2unix apk add --no-cache dos2unix
fi fi
find /docker-entrypoint-initdb.d -type f -name "*.sh" -exec sh -c '\''
dos2unix "{}" 2>/dev/null || true find /docker-entrypoint-initdb.d -type f -name '*.sh' -exec sh -c '
chmod +x "{}" for file; do
'\'' \; dos2unix \"$file\" 2>/dev/null || true
exec docker-entrypoint.sh postgres chmod +x \"$file\"
' done
' sh {} +
exec docker-entrypoint.sh postgres
"
db-backup: db-backup:
image: postgres:15 image: postgres:15
@@ -135,12 +140,12 @@ services:
- ./pg_backups:/pg_backups #host dir for backups files - ./pg_backups:/pg_backups #host dir for backups files
#setup bassh loop to backup data evey 24h #setup bassh loop to backup data evey 24h
command: > command: >
bash -c "while true; do bash -c "while true; do
sleep 86400; sleep 86400;
PGPASSWORD=$$POSTGRES_PASSWORD pg_dump -h worklenz_db -U $$POSTGRES_USER -d $$POSTGRES_DB \ 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; > /pg_backups/worklenz_db_\$(date +%Y-%m-%d_%H-%M-%S).sql;
find /pg_backups -type f -name '*.sql' -mtime +30 -delete; find /pg_backups -type f -name '*.sql' -mtime +30 -delete;
done" done"
restart: unless-stopped restart: unless-stopped
networks: networks:
- worklenz - worklenz