partkeepr / PartKeepr

Open Source Inventory Management
http://www.partkeepr.org
GNU General Public License v3.0
1.38k stars 401 forks source link

Allow settings via environment variables #838

Closed mhubig closed 4 years ago

mhubig commented 7 years ago

I'm trying to build a Dockerfile to ease and speed up the deployment of Partkeepr. One particular problem I found is the use of the parameters.php file. In order to be able to build a stateless and reusable Docker image, I need to be able to set the values of the parameters file via some environment variables.

My goal is to be able to deploy partkeepr with a docker-compose.yml file like this:

version: "3"
services:

  partkeepr:
    image: mhubig/partkeepr
    environment:
      - PARTKEEPR_DATABASE_HOST=database
      - PARTKEEPR_DATABASE_NAME=partkeepr
      - PARTKEEPR_DATABASE_USER=partkeepr
      - PARTKEEPR_DATABASE_PASS=partkeepr
    ports:
      - "80:80"
    volumes:
      - partkeepr-data:/var/www/html/data
    depends_on:
      - database

  database:
    image: mariadb
    environment:
      - MYSQL_RANDOM_ROOT_PASSWORD=yes
      - MYSQL_DATABASE=partkeepr
      - MYSQL_USER=partkeepr
      - MYSQL_PASSWORD=partkeepr
    volumes:
      - mysql-data:/var/lib/mysql

volumes:
  partkeepr-data:
  mysql-data:

I tried using getenv but it didn't work out:

$container->setParameter('database_host', getenv('PARTKEEPR_DATABASE_HOST'));
$container->setParameter('database_name', getenv('PARTKEEPR_DATABASE_NAME'));
$container->setParameter('database_port', getenv('PARTKEEPR_DATABASE_PORT'));
$container->setParameter('database_user', getenv('PARTKEEPR_DATABASE_USER'));
$container->setParameter('database_password', getenv('PARTKEEPR_DATABASE_PASS'));

So my only choice for now would be an entrypoint script which takes the environment parameters and generates a working parameters.php file ... but this is not a very clean approach!

Drachenkaetzchen commented 7 years ago

I agree, this is problematic, but I'm afraid there's no other way - Symfony actually creates cache files out of the parameter.php values. You can try environment variables as documented here: http://symfony.com/doc/current/configuration/external_parameters.html but I'm really not sure if that works out

christianlupus commented 4 years ago

@mhubig I assume you managed your way around the problem by using the entrypoint function. Thus, I am closing this issue here. If you want to keep it up, please simply give a comment.