The alternatives suggested all have shortcomings in my view. A script which creates config_local.yaml on the fly and then starts Dancer2 app would otherwise work but it means that container won't be immutable. Immutable is one of the architectural best practices listed by Google. As it happens, this container is planned to run on Google Container Engine. You mentioned there are other ways to do this in Kubernetes. How? Using a tmpfs is also not an option because it would mean that container is dependent on the way it is being run (the runtime environment). Substituting variables in config.yaml is not overly complicated in my mind. Many platforms use environment variables to pass information to containers, docker or others, e.g. Java jar. I have used Openshift platform and it gave me a very good example of how env vars are governed in order to provide secrets to the container. By stating the env vars in the configuration, we make it clear to the programmer and to operations what is expected from the runtime environment. Besides this, it also makes local development easier if you "practice dotenv" - what The Twelve-Factor App recommends. I keep my environment in a .env file and I also use the same file when testing the container with local docker. See: * https://cloud.google.com/architecture/best-practices-for-operating-container... * https://docs.docker.com/storage/tmpfs/ * https://12factor.net/config On 27/07/2021 13:00, dancer-users-request@lists.preshweb.co.uk wrote:
Send dancer-users mailing list submissions to dancer-users@lists.preshweb.co.uk
To subscribe or unsubscribe via the World Wide Web, visit https://lists.preshweb.co.uk/mailman/listinfo/dancer-users or, via email, send a message with subject or body 'help' to dancer-users-request@lists.preshweb.co.uk
You can reach the person managing the list at dancer-users-owner@lists.preshweb.co.uk
When replying, please edit your Subject line so it is more specific than "Re: Contents of dancer-users digest..."
Today's Topics:
1. Re: Passing environment to dockerized Dancer2 (Adam Clarke) 2. Re: Passing environment to dockerized Dancer2 (Adam Clarke)
----------------------------------------------------------------------
Message: 1 Date: Mon, 19 Jul 2021 10:51:08 +1000 From: Adam Clarke <adamc@strategicdata.com.au> To: Perl Dancer users mailing list <dancer-users@lists.preshweb.co.uk> Subject: Re: [dancer-users] Passing environment to dockerized Dancer2 Message-ID: <FF6A5F5E-448C-4F0D-B829-1DA2BDAE3BAC@strategicdata.com.au> Content-Type: text/plain; charset=utf-8
On 19 Jul 2021, at 2:54 am, Mikko Johannes Koivunalho <mikko.koivunalho@iki.fi> wrote:
Problem: How do I pass the environment dependent parts of the configuration to the docker? I cannot use file `config_local.yaml` because then I would need to copy that file somehow into the container when it starts.
Possible solution: I would pass parts of the configuration as environment variables, e.g. /DB_HOST/ and/SITE_URL/, and then apply these over the values in config.yaml when I am creating the endpoints.
Suggestion: Change the command `/config/` (or the underlying file reader function) so that it can transpose environment variables into config strings, e.g. plugins->database->connections->main->host = '${DB_HOST}'.
I have built a solution to this. I have not yet submitted a Pull Request. I am using this solution in my build and web application. Please comment. Would this be a good pull request?
I?m not clear that this complexity is required give that the solution can be achieved using a startup script as per Racke?s previous reply. Also I?m assuming you?re not running your containers under Docker swarm or Kubernetes but if you are there are more advanced ways to achieve what I describe below.
In case Racke?s approach wasn?t clear, what you do is add an entry point script to your Docker image build using the ENTRYPOINT instruction. e.g. startup.sh. This script will always run at container start up.
The startup script would use the environment you had set to build an appropriate config_local.yaml inside your container before Dancer is invoked. There are lots of ways to do this, one simple and way from a shell script is to use envsubst. The last thing the startup script would do is start your Dancer app.
If you want or need your container to run in read only mode then you can combine this technique with a tempfs mount for config_local.yaml.
See: * https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#en... * https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.ht...
------------------------------
Message: 2 Date: Tue, 20 Jul 2021 17:52:48 +1000 From: Adam Clarke <adamc@strategicdata.com.au> To: Perl Dancer users mailing list <dancer-users@lists.preshweb.co.uk> Subject: Re: [dancer-users] Passing environment to dockerized Dancer2 Message-ID: <EF3743C7-C62A-477D-BD13-D82F0E7714DB@strategicdata.com.au> Content-Type: text/plain; charset=utf-8
On 19 Jul 2021, at 2:54 am, Mikko Johannes Koivunalho <mikko.koivunalho@iki.fi> wrote:
Problem: How do I pass the environment dependent parts of the configuration to the docker? I cannot use file `config_local.yaml` because then I would need to copy that file somehow into the container when it starts.
Possible solution: I would pass parts of the configuration as environment variables, e.g. /DB_HOST/ and/SITE_URL/, and then apply these over the values in config.yaml when I am creating the endpoints.
Suggestion: Change the command `/config/` (or the underlying file reader function) so that it can transpose environment variables into config strings, e.g. plugins->database->connections->main->host = '${DB_HOST}'.
I have built a solution to this. I have not yet submitted a Pull Request. I am using this solution in my build and web application. Please comment. Would this be a good pull request?
I?m not clear that this complexity is required give that the solution can be achieved using a startup script as per Racke?s previous reply. Also I?m assuming you?re not running your containers under Docker swarm or Kubernetes but if you are there are more advanced ways to achieve what I describe below.
In case Racke?s approach wasn?t clear, what you do is add an entry point script to your Docker image build using the ENTRYPOINT instruction. e.g. startup.sh. This script will always run at container start up.
The startup script would use the environment you had set to build an appropriate config_local.yaml inside your container before Dancer is invoked. There are lots of ways to do this, one simple and way from a shell script is to use envsubst. The last thing the startup script would do is start your Dancer app.
If you want or need your container to run in read only mode then you can combine this technique with a tempfs mount for config_local.yaml.
See: * https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#en... * https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.ht...
------------------------------
Subject: Digest Footer
_______________________________________________ dancer-users mailing list dancer-users@lists.preshweb.co.uk https://lists.preshweb.co.uk/mailman/listinfo/dancer-users
------------------------------
End of dancer-users Digest, Vol 124, Issue 4 ********************************************