Reloads nginx after substituting environment variables
This commit is contained in:
parent
9918c872e0
commit
0728801a13
11
Dockerfile
11
Dockerfile
|
@ -14,7 +14,7 @@ RUN npm install && \
|
|||
npm run build:$build_config
|
||||
|
||||
### STAGE 2: Run ###
|
||||
FROM nginx:alpine as runtime
|
||||
FROM nginx:alpine
|
||||
RUN set -x && apk add --update --no-cache bash libintl gettext curl
|
||||
|
||||
COPY --from=builder /crc-bpmn/dist/* /etc/nginx/html/
|
||||
|
@ -24,11 +24,14 @@ COPY --from=builder /crc-bpmn/nginx.conf /etc/nginx/conf.d/default.conf
|
|||
COPY ./docker/substitute-env-variables.sh ./entrypoint.sh
|
||||
RUN chmod +x ./entrypoint.sh
|
||||
|
||||
# Substitute environment variables in nginx configuration and index.html
|
||||
# The entrypoint.sh script will run after the container finishes starting.
|
||||
# Substitutes environment variables in nginx configuration and index.html,
|
||||
# then reloads nginx.
|
||||
ENTRYPOINT ["./entrypoint.sh", \
|
||||
"/etc/nginx/html/index.html,/etc/nginx/conf.d/default.conf", \
|
||||
"PRODUCTION,API_URL,IRB_URL,HOME_ROUTE,BASE_HREF,PORT0", \
|
||||
"/etc/nginx/html"]
|
||||
"/etc/nginx/html", \
|
||||
"true"]
|
||||
|
||||
### STAGE 3: Profit! ###
|
||||
CMD ["nginx", "-s", "reload"]
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
|
|
|
@ -62,21 +62,21 @@ services:
|
|||
- "5000:5000"
|
||||
command: ./wait-for-it.sh pb:5001 -t 0 -- ./docker_run.sh
|
||||
|
||||
# # Uncomment for debugging
|
||||
# bpmn:
|
||||
# container_name: bpmn
|
||||
# depends_on:
|
||||
# - db
|
||||
# - pb
|
||||
# - ldap
|
||||
# - backend
|
||||
# image: sartography/cr-connect-bpmn:$E2E_TAG
|
||||
# environment:
|
||||
# - API_URL=http://localhost:5000/v1.0
|
||||
# - BASE_HREF=/bpmn
|
||||
# - HOME_ROUTE=home
|
||||
# - IRB_URL=http://localhost:5001/
|
||||
# - PORT0=5002
|
||||
# - PRODUCTION=false
|
||||
# ports:
|
||||
# - "5002:5002"
|
||||
# Uncomment for debugging
|
||||
bpmn:
|
||||
container_name: bpmn
|
||||
depends_on:
|
||||
- db
|
||||
- pb
|
||||
- ldap
|
||||
- backend
|
||||
image: sartography/cr-connect-bpmn:$E2E_TAG
|
||||
environment:
|
||||
- API_URL=http://localhost:5000/v1.0
|
||||
- BASE_HREF=/bpmn
|
||||
- HOME_ROUTE=home
|
||||
- IRB_URL=http://localhost:5001/
|
||||
- PORT0=5002
|
||||
- PRODUCTION=false
|
||||
ports:
|
||||
- "5002:5002"
|
||||
|
|
|
@ -6,26 +6,40 @@
|
|||
# $1: Comma-delimited list of file paths
|
||||
# $2: Comma-delimited list of environment variables
|
||||
# $3: Absolute path to nginx html directory (optional)
|
||||
# $4: Should restart nginx (optional)
|
||||
#####################################################################
|
||||
|
||||
echo 'Substituting environment variables...'
|
||||
num_args=0
|
||||
|
||||
# The first parameter is a comma-delimited list of paths to files which should be substituted
|
||||
if [[ -z $1 ]]; then
|
||||
echo 'ERROR: No target files given.'
|
||||
exit 1
|
||||
else
|
||||
num_args=1
|
||||
fi
|
||||
|
||||
# The second parameter is a comma-delimited list of environment variable names
|
||||
if [[ -z $2 ]]; then
|
||||
echo 'ERROR: No environment variables given.'
|
||||
exit 1
|
||||
else
|
||||
num_args=2
|
||||
fi
|
||||
|
||||
# The third parameter is the absolute path to the nginx html directory
|
||||
if [[ -z $2 ]]; then
|
||||
echo 'ERROR: No path to nginx html directory given.'
|
||||
exit 1
|
||||
if [[ -z $3 ]]; then
|
||||
echo '' # It's optional. Don't print anything.
|
||||
else
|
||||
num_args=3
|
||||
fi
|
||||
|
||||
# The fourth parameter, if 'true', is whether we should reload nginx
|
||||
if [[ -z $4 ]]; then
|
||||
echo '' # It's optional. Don't print anything.
|
||||
else
|
||||
num_args=4
|
||||
fi
|
||||
|
||||
# Add trailing slash to $BASE_HREF if needed
|
||||
|
@ -35,7 +49,7 @@ if [[ "$2" == *"BASE_HREF"* ]]; then
|
|||
[[ $last_char != "/" ]] && BASE_HREF="$BASE_HREF/"; :
|
||||
|
||||
# The third parameter is the absolute path to the nginx html directory
|
||||
if [[ $# -ge 3 ]]; then
|
||||
if [[ $num_args -ge 3 ]]; then
|
||||
# Replace all instances of __REPLACE_ME_WITH_BASE_HREF__ with $BASE_HREF
|
||||
find "$3" \( -type d -name .git -prune \) -o -type f -print0 | \
|
||||
xargs -0 sed -i 's@__REPLACE_ME_WITH_BASE_HREF__@'"$BASE_HREF"'@g'
|
||||
|
@ -71,11 +85,18 @@ do
|
|||
echo "$env_var = ${!env_var}"
|
||||
done
|
||||
|
||||
# Execute all other commands with parameters
|
||||
if [[ $# -gt 3 ]]; then
|
||||
exec "${@:4}"
|
||||
else
|
||||
if [[ $# -gt 2 ]]; then
|
||||
exec "${@:3}"
|
||||
# Reload nginx
|
||||
if [ $num_args -ge 4 ] && [ "$4" == "true" ]; then
|
||||
# Check to see if nginx command is available
|
||||
if hash nginx 2> /dev/null; then
|
||||
echo "Reloading nginx..."
|
||||
exec nginx -s reload
|
||||
echo "nginx reloaded."
|
||||
else
|
||||
echo "nginx command not found on this system."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Execute all other commands with parameters
|
||||
num_args=$((num_args + 1))
|
||||
exec "${@:num_args}"
|
||||
|
|
Loading…
Reference in New Issue