italia / Satosa-Saml2Spid

SATOSA SAML-to-SAML proxy with Spid compliances
Apache License 2.0
42 stars 23 forks source link

Homogeneous environment for dockerfile and .env #112

Closed MdreW closed 5 months ago

MdreW commented 5 months ago

docker-compose call some configuration from .env file and some other are called locally. This process require more time to find the configuration. If we want use .env file I propose to set all the configuration with an environment with a default. Example

environment:
  MONGO_INITDB_DATABASE: ${MONGO_DB:-oidcop}
  MONGO_INITDB_ROOT_USERNAME: "${MONGO_DBUSER:-satosa}"
  MONGO_INITDB_ROOT_PASSWORD: "${MONGO_DBPASSWORD:-password}"
salvatorelaiso commented 5 months ago

The mixed approach was probably a solution to reference an already defined variable in the docker-compose.yaml file, e.g.:

https://github.com/italia/Satosa-Saml2Spid/blob/22d05ba1372ac4fb7efdbe218f6d966fb882260d/Docker-compose/docker-compose.yml#L68-L71

This is a workaround since docker compose files can't use an environment variable defined in itself (see https://stackoverflow.com/a/63443704).

The possible solution is to use the suggested approach with a default value in the environment section of the docker compose file and let the user override them in the .env file.

MdreW commented 5 months ago

A little add:

version: '3'
services:
  satosa-nginx:
    environments:
      NGINX_HOSTNAME: "${HOSTNAME:-localhost}"

  satosa-mongo:
    environments:
      MONGODB_PASSWORD: "${MONGO_DBPASSWORD:-12345678}"
      MONGODB_USERNAME: "${MONGO_DBUSER:-satosa}"

  satosa-saml2spid:
    environment: 
      SATOSA_HOSTNAME: "${HOSTNAME:-localhost}"
      SATOSA_BASE: "https://$SATOSA_HOSTNAME"
      SATOSA_BASE_STATIC: https://$SATOSA_HOSTNAME/static 
      SATOSA_DISCO_SRV: https://$SATOSA_HOSTNAME/static/disco.html 
      SATOSA_UNKNOW_ERROR_REDIRECT_PAGE: https://$SATOSA_HOSTNAME/static/error_page.html
      MONGODB_PASSWORD: "${MONGO_DBPASSWORD:-12345678}"
      MONGODB_USERNAME: "${MONGO_DBUSER:-satosa}"