Turgon37 / docker-smtp-relay

Docker image running a SMTP relay with postfix
MIT License
67 stars 33 forks source link

Sourcing environment variables #10

Open rhysxevans opened 5 years ago

rhysxevans commented 5 years ago

Hi

Firstly thanks for the project, it is appreciated.

I am having an issue when sourcing the environment variables from the system. IE source .env , does not work with spaces

eg RELAY_MYNETWORKS=127.0.0.0/8 172.29.0.0/24 is not valid.

my docker-compose file looks like - not complete file

  smtp-relay:
    image: turgon37/smtp-relay:$SMTP_RELAY_VERSION
    container_name: smtp-relay
    hostname: smtp-relay
    restart: unless-stopped
    environment:
      - "RELAY_POSTMASTER=${RELAY_POSTMASTER}"
      - "RELAY_MYHOSTNAME=${RELAY_MYHOSTNAME}"
      - "RELAY_MYDOMAIN=${RELAY_MYDOMAIN}"
      - "RELAY_MYNETWORKS=${RELAY_MYNETWORKS}"
      - "RELAY_HOST=${RELAY_HOST}"
      - "RELAY_MODE=${RELAY_MODE}"
      - "RELAY_LOGIN=${RELAY_LOGIN}"
      - "RELAY_PASSWORD=${RELAY_PASSWORD}"
      - "RELAY_USE_TLS=${RELAY_USE_TLS}"
      - "RELAY_TLS_CA=${RELAY_TLS_CA}"
      - 'RELAY_EXTRAS_SETTINGS=compatibility_level=2'
    networks: ['stack']
    expose:
      - "25"
    volumes:
      - data-smtp-relay-auth:/data
    healthcheck:
      test: nc -zv 127.0.0.1 25 || exit 1
      interval: 60s
      timeout: 10s
      retries: 5

I am able to enter the variables as RELAY_MYNETWORKS="127.0.0.0/8 172.29.0.0/24", however that doesn't reflect in the postfix configuration correctly., you end up with mynetworks = "127.0.0.0/8 172.29.0.0/24"

I can work around this by adding the following to the start.sh script (near the top)

# Set configuration according to ENV
RELAY_MYNETWORKS=`echo "$RELAY_MYNETWORKS" | tr -d '"'`

Any chance of getting "logic" this added to the image ?

Thanks

Turgon37 commented 5 years ago

@rhysxevans Hello, I did not reproduce the problem here

I'm using this env file

cat .env                                          
RELAY_MYNETWORKS="127.0.0.0/8 172.29.0.0/24"

and docker-compose file

version: '2'
services:
  smtp-relay:
    image: turgon37/smtp-relay
    container_name: smtp-relay
    hostname: smtp-relay
    restart: unless-stopped
    environment:
      - "RELAY_MYNETWORKS=${RELAY_MYNETWORKS}"

And run

source .env
docker-compose up -d

give me

docker-compose exec smtp-relay grep '^mynetworks' /etc/postfix/main.cf
mynetworks = 127.0.0.0/8 172.29.0.0/24

Are you using some other quote or escape character ?