Reputation: 475
I built a docker image (based on official nginx image) to serve the build folder, result of yarn build. My problem is that I have a unique image to be used both on test and prod environments. I don't want to have different images for each environment, instead i'd like to leverage on containers startup configuration in order to run my container with test or prod configuration. That is, some kind of configuration decoupled from the build task which can be applied on top of a build
The reason is that there are no differences between the 2 environments, except for my backend endpoint which is used by my custom http client inside admin-on-rest app.
Is there a support for this kind of configuration or should I implement something like this ?
Thanks
Upvotes: 0
Views: 74
Reputation: 5076
You can get something like this by adding a new script to your image that updates the address used by nginx:
#!/bin/bash
if [[ ! -z "$PROD" && "PROD" != '0' ]] ; then
sed -i 's/address_in_file/test_env_address/g' /etc/nginx/conf.d/default.conf
else
sed -i 's/address_in_file/prod_env_address/g' /etc/nginx/conf.d/default.conf
fi
nginx -g daemon off
It's not a nice solution but it works.
address_in_file is the current backend address defined in your configuration file
test_env_address is the new address that the should appear if the script is started with the environment variable PROD = 0 (or no PROD at all)
prod_env_address is the production address
Upvotes: 1