pg_dump icon indicating copy to clipboard operation
pg_dump copied to clipboard

POSTGRES_PASSWORD_FILE doesn't work

Open nazmang opened this issue 2 years ago • 2 comments

Hi,

It seems entrypoint.sh not recognizing POSTGRES_PASSWORD_FILE variable. Seeing output below in container logs

Starting pg_dump
/run/secrets/POSTGRES_PASSWORD: line 1: 7@: command not found
/run/secrets/POSTGRES_PASSWORD: line 1: XXXXXXXX: command not found
PGUSER='/run/secrets/POSTGRES_USER'
POSTGRES_DB='zabbix'
PGHOST='postgres-zabbix'
PGPORT='5432'
PGDUMP='/dump'
RETAIN_COUNT=3
S3_HOSTNAME='s3.amazonaws.com'
S3_HOST_BUCKET='%(bucket)s.s3.amazonaws.com'
S3_SSL_OPTION='--ssl'
0 3 * * * /dump.sh >> /dump/dump-log 2>&1 

I'm using 14.7 version of the image, there is a part of my docker-compose.yml

 postgres-backup:
    image: martlark/pg_dump:14.7
    deploy:
      placement:
        constraints:
          - node.platform.arch==x86_64
          - node.role == worker
    networks:
      - zabbix-net  
    depends_on:
      - postgres-zabbix
    env_file:
      - start.env  
    environment:
      PGUSER: /run/secrets/POSTGRES_USER
      POSTGRES_PASSWORD_FILE: /run/secrets/POSTGRES_PASSWORD
      PGHOST: postgres-zabbix
      PGPORT: 5432
      CRON_SCHEDULE: 0 3 * * * # Every day at 3am
      RETAIN_COUNT: 3 # Keep this number of backups
    secrets:
      - POSTGRES_USER
      - POSTGRES_PASSWORD 
 
secrets:      
  POSTGRES_USER:
    file: ./.POSTGRES_USER
    name: POSTGRES_USER_v${CONF_VERSION}
  POSTGRES_PASSWORD:
    file: ./.POSTGRES_PASSWORD
    name: POSTGRES_PASSWORD_v${CONF_VERSION}      

It looks like source construction doesn't work

if [[ -f "${POSTGRES_PASSWORD_FILE}" ]];
then
   source "${POSTGRES_PASSWORD_FILE}"

Can you help with that? Thanks!

nazmang avatar Dec 10 '23 19:12 nazmang

Thanks for this. I'll work on it and see what the issue is.

Martlark avatar Dec 11 '23 20:12 Martlark

The problem was that the builtin source command is not available in sh

Martlark avatar Nov 09 '25 07:11 Martlark