Am using flyway for DB migration in a NodeJS application. Building a docker image of the app through Travis CI, which gets pushed to Azure Container registry. From there, a web-hook picks up the image and spins up a container instance in the azure app service.
Am having difficulty in passing the env. specific DB connection configs to flyway migrate cli command.
Added the connection details as Application Settings in the app service, but that didn't get passed to docker run command. Although, it seems like the settings are available for the application once it started.
Couldn't use the Travis CI env. variables, as the connection details differs by environment.
Looking for help, if someone solved similar problem.
I found a way to resolve this one. Thought will post the solution as someone else might find it helpful.
First, I need to have env. specific DB connection details: For this I configured the parameters in the Azure App Service and retrieved it using CLI command in the TravisCI build script.
Second, I need to pass the DB configs to docker container as environment variables. As Azure app service doesn't allow us to alter the docker run
command, we can't pass explicit environment configs while starting up a docker container.
So to overcome this limitation,
I set up build arguments (See set build time variables) for docker build command to pass env. specific DB connection details to docker build.
Since build arguments are not persisted to final build image, I had to convert them to environment variables using the ENV
command. See setting docker environment variables.
Now the DB connection parameters are available as env. configs when the docker starts up. Hence, the flyway migrate
command on docker start up able to connect to DB without issues.