We have a website with multiple divisions. We want to reuse the same docker image for all the divisions.
First approach was to load the configuration dynamically from a server (depending on the ENV
variables in the image). This would mean that every client will have to send the request and that the configuration server's uptime is crucial.
We are now using variables in the environment.ts
file, eg:
export const environment = {
...
url: 'https://__DOMAIN__',
...
}
We then have an entrypoint.sh
script for the docker which can be called with arguments and replaces the strings in the application.
#!/bin/bash
DOMAIN="$1"
for filename in dist/**/*.js; do
if [[ $filename =~ "main" ]]; then
sed -i -e 's/__DOMAIN__/'$DOMAIN'/g' $filename
fi
done
...
pm2-runtime start pm2.json --web
The image is used in a Kubernetes deployment:
...
spec:
containers:
- image: <image-repo>
args: ["www.ecologic.ch"]
...
envsubst
would also be a possibility. You would then use ENV
variables in the environment
files and use envsubst
in the entrypoint
script. In the kubernetes deployment you would then add env
vars instead of args
.
Need more details?
Please let us know if you are interested in more details!
Top comments (0)