mirror of
https://github.com/swissmakers/swiss-datashare.git
synced 2026-04-21 06:03:13 +02:00
Improve project setup with Docker
This commit is contained in:
35
entrypoint.sh
Normal file
35
entrypoint.sh
Normal file
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
# This script is used to inject env variables in Docker after the build.
|
||||
# Normally the env variables get injecten while the build. This means, you can't add env variables when you start the conatainer.
|
||||
# Source of the script: https://raphaelpralat.medium.com/system-environment-variables-in-next-js-with-docker-1f0754e04cde
|
||||
|
||||
set +x
|
||||
|
||||
envFilename='.env'
|
||||
nextFolder='./.next/'
|
||||
function apply_path {
|
||||
# read all config file
|
||||
while read line; do
|
||||
# no comment or not empty
|
||||
if [ "${line:0:1}" == "#" ] || [ "${line}" == "" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# split
|
||||
configName="$(cut -d'=' -f1 <<<"$line")"
|
||||
configValue="$(cut -d'=' -f2 <<<"$line")"
|
||||
# get system env
|
||||
envValue=$(env | grep "^$configName=" | grep -oe '[^=]*$');
|
||||
|
||||
# if config found
|
||||
if [ -n "$configValue" ] && [ -n "$envValue" ]; then
|
||||
# replace all
|
||||
echo "Replace: ${configValue} with: ${envValue}"
|
||||
find $nextFolder \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#$configValue#$envValue#g"
|
||||
fi
|
||||
done < $envFilename
|
||||
}
|
||||
|
||||
apply_path
|
||||
echo "Starting Nextjs"
|
||||
exec "$@"
|
||||
Reference in New Issue
Block a user