Skip to content

Commit

Permalink
fixed docker-entrypoint test, removed dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
gottfired committed May 5, 2023
1 parent 2b4123c commit 53dba88
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 38 deletions.
26 changes: 0 additions & 26 deletions Dockerfile

This file was deleted.

16 changes: 11 additions & 5 deletions template/docker-entrypoint.sh
Expand Up @@ -5,25 +5,31 @@

set -e

if [ "$1" == "test" ]; then
NGINX_BASE=./nginx
else
NGINX_BASE=/etc/nginx
fi

# Only update config with defined env variables if we are running an nginx process so we can still attach with debugging commands
# without accidentally modifying anything
if [ "$1" == "nginx" ] || [ "$1" == "test" ]; then
if [ ! -z "${REACT_APP_API_BASE_URL}" ]; then
sed -i "/ENV_API_BASE_URL/c\var ENV_API_BASE_URL = \"${REACT_APP_API_BASE_URL}\";" /etc/nginx/html/app/config.js
sed -i "/ENV_API_BASE_URL/c\var ENV_API_BASE_URL = \"${REACT_APP_API_BASE_URL}\";" $NGINX_BASE/html/app/config.js
fi

if [ ! -z "${REACT_APP_DEPLOYMENT_ENV}" ]; then
sed -i "/ENV_DEPLOYMENT_ENV/c\var ENV_DEPLOYMENT_ENV = \"${REACT_APP_DEPLOYMENT_ENV}\";" /etc/nginx/html/app/config.js
sed -i "/ENV_DEPLOYMENT_ENV/c\var ENV_DEPLOYMENT_ENV = \"${REACT_APP_DEPLOYMENT_ENV}\";" $NGINX_BASE/html/app/config.js
fi

if [ ! -z "${REACT_APP_BASE_NAME}" ]; then
sed -i "/ENV_BASE_NAME/c\var ENV_BASE_NAME = \"${REACT_APP_BASE_NAME}\";" /etc/nginx/html/app/config.js
sed -i "s#REACT_APP_BASE_NAME#$REACT_APP_BASE_NAME#g" /etc/nginx/conf.d/default.conf | sed "s#//#/#g"
sed -i "/ENV_BASE_NAME/c\var ENV_BASE_NAME = \"${REACT_APP_BASE_NAME}\";" $NGINX_BASE/html/app/config.js
sed -i "s#REACT_APP_BASE_NAME#$REACT_APP_BASE_NAME#g" $NGINX_BASE/conf.d/default.conf | sed "s#//#/#g"

# The <base href="/"> is already set to "/". If the REACT_APP_BASE_NAME is a "/", it will change the base href to "//" which is invalid.
# Therefore we only run the command if the REACT_APP_BASE_NAME is not "/".
if [ "$REACT_APP_BASE_NAME" != "/" ]; then
sed -i "s#<base href=\"/\">#<base href=\"$REACT_APP_BASE_NAME/\">#g" /etc/nginx/html/app/index.html | sed "s#<base href=\"//\">#<base href=\"/\">#g"
sed -i "s#<base href=\"/\">#<base href=\"$REACT_APP_BASE_NAME/\">#g" $NGINX_BASE/html/app/index.html | sed "s#<base href=\"//\">#<base href=\"/\">#g"
fi
fi
fi
Expand Down
17 changes: 10 additions & 7 deletions template/scripts/test-docker-entrypoint.sh
@@ -1,15 +1,18 @@
#!/bin/bash

NGINX_BASE=./nginx

# Create fake nginx folder structure to match production
mkdir -p /etc/nginx/html/app
mkdir -p /etc/nginx/conf.d
mkdir -p $NGINX_BASE/html/app
mkdir -p $NGINX_BASE/conf.d


NGINX_CONF=/etc/nginx/conf.d/default.conf
CONFIG_JS=/etc/nginx/html/app/config.js
INDEX_HTML=/etc/nginx/html/app/index.html
NGINX_CONF=$NGINX_BASE/conf.d/default.conf
CONFIG_JS=$NGINX_BASE/html/app/config.js
INDEX_HTML=$NGINX_BASE/html/app/index.html

# Copy build files
cp -r ./build/* /etc/nginx/html/app
cp -r ./build/* $NGINX_BASE/html/app

# Copy nginx config
cp ./nginx-default.conf $NGINX_CONF
Expand Down Expand Up @@ -50,6 +53,6 @@ if ! grep -q "<base href=\"$BASE/\">" "$INDEX_HTML"; then
fi

# Cleanup
rm -rf /etc/nginx
rm -rf $NGINX_BASE

echo "docker-entrypoint.sh test passed successfully"

0 comments on commit 53dba88

Please sign in to comment.