From a3b2cfb01ccf15699a08ae9e2fbeea25e15f10e1 Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Wed, 12 Oct 2022 10:48:04 -0400 Subject: [PATCH 1/5] rearrange docker files so that entrypoint and cmd from base image are not overwritten --- Dockerfile | 4 ---- .../docker-entrypoint.d/97-copy-to-public-path.sh | 2 ++ .../98-replace_env_var_place_holders.sh | 2 ++ docker/docker-entrypoint.d/99-update-config.sh | 2 ++ docker/docker-entrypoint.d/envvar.sh | 10 ++++++++++ docker/entrypoint.sh | 13 ------------- 6 files changed, 16 insertions(+), 17 deletions(-) create mode 100644 docker/docker-entrypoint.d/envvar.sh delete mode 100755 docker/entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 7e195d6..b32c39b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,9 +15,5 @@ RUN apt-get update && apt-get install -y jq WORKDIR /app COPY --from=build /app/dist dist COPY --from=build /app/dist/public_path_placeholder/monacoeditorwork dist/monacoeditorwork -COPY docker/entrypoint.sh . COPY docker/docker-entrypoint.d/* /docker-entrypoint.d/ COPY docker/nginx-default.conf.template /etc/nginx/templates/default.conf.template - -ENTRYPOINT ["./entrypoint.sh"] -CMD ["nginx", "-g", "daemon off;"] diff --git a/docker/docker-entrypoint.d/97-copy-to-public-path.sh b/docker/docker-entrypoint.d/97-copy-to-public-path.sh index 6bf7daa..e11e35c 100755 --- a/docker/docker-entrypoint.d/97-copy-to-public-path.sh +++ b/docker/docker-entrypoint.d/97-copy-to-public-path.sh @@ -1,6 +1,8 @@ #!/bin/bash # Copy the Vue files to the Vue publicPath +source $(dirname -- "$0")/envvar.sh; + PUBLIC_PATH=${PUBLIC_PATH:?"undefined"} DIST_DIR="/app/dist" diff --git a/docker/docker-entrypoint.d/98-replace_env_var_place_holders.sh b/docker/docker-entrypoint.d/98-replace_env_var_place_holders.sh index 8c32389..99661c5 100755 --- a/docker/docker-entrypoint.d/98-replace_env_var_place_holders.sh +++ b/docker/docker-entrypoint.d/98-replace_env_var_place_holders.sh @@ -1,6 +1,8 @@ #!/bin/bash # Replace place holders with env vars in Vue files +source $(dirname -- "$0")/envvar.sh; + PUBLIC_PATH=${PUBLIC_PATH:?"undefined"} SITE_DIR_ROOT="/app/site" diff --git a/docker/docker-entrypoint.d/99-update-config.sh b/docker/docker-entrypoint.d/99-update-config.sh index 6ae215d..4e9895a 100755 --- a/docker/docker-entrypoint.d/99-update-config.sh +++ b/docker/docker-entrypoint.d/99-update-config.sh @@ -1,6 +1,8 @@ #!/bin/bash # Update config.json +source $(dirname -- "$0")/envvar.sh; + PUBLIC_PATH=${PUBLIC_PATH:?"undefined"} API_NAME=${API_NAME:?"undefined"} API_HTTP=${API_HTTP:?"undefined"} diff --git a/docker/docker-entrypoint.d/envvar.sh b/docker/docker-entrypoint.d/envvar.sh new file mode 100644 index 0000000..c6edc77 --- /dev/null +++ b/docker/docker-entrypoint.d/envvar.sh @@ -0,0 +1,10 @@ +#!/bin/echo to be sourced +# This file is source by other files in this directory. + +PUBLIC_PATH="${PUBLIC_PATH:-/}" +API_HTTP="${API_HTTP:-http://localhost:8000}" +API_NAME="${API_NAME:-localhost}" + +echo + "PUBLIC_PATH=${PUBLIC_PATH}" +echo + "API_HTTP=${API_HTTP}" +echo + "API_NAME=${API_NAME}" diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh deleted file mode 100755 index 95ec2e8..0000000 --- a/docker/entrypoint.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -# Source docker-entrypoint.sh from Nginx image after setting environment -# variables with default values if not set - -export PUBLIC_PATH="${PUBLIC_PATH:-/}" -export API_HTTP="${API_HTTP:-http://localhost:8000}" -export API_NAME="${API_NAME:-localhost}" - -echo + "PUBLIC_PATH=${PUBLIC_PATH}" -echo + "API_HTTP=${API_HTTP}" -echo + "API_NAME=${API_NAME}" - -source /docker-entrypoint.sh From 52f85c4e5f8a9e8b3072941c6003bf802ba77122 Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Wed, 12 Oct 2022 10:54:14 -0400 Subject: [PATCH 2/5] rename files --- .../{97-copy-to-public-path.sh => 91-copy-to-public-path.sh} | 0 ...v_var_place_holders.sh => 92-replace_env_var_place_holders.sh} | 0 .../{99-update-config.sh => 93-update-config.sh} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename docker/docker-entrypoint.d/{97-copy-to-public-path.sh => 91-copy-to-public-path.sh} (100%) rename docker/docker-entrypoint.d/{98-replace_env_var_place_holders.sh => 92-replace_env_var_place_holders.sh} (100%) rename docker/docker-entrypoint.d/{99-update-config.sh => 93-update-config.sh} (100%) diff --git a/docker/docker-entrypoint.d/97-copy-to-public-path.sh b/docker/docker-entrypoint.d/91-copy-to-public-path.sh similarity index 100% rename from docker/docker-entrypoint.d/97-copy-to-public-path.sh rename to docker/docker-entrypoint.d/91-copy-to-public-path.sh diff --git a/docker/docker-entrypoint.d/98-replace_env_var_place_holders.sh b/docker/docker-entrypoint.d/92-replace_env_var_place_holders.sh similarity index 100% rename from docker/docker-entrypoint.d/98-replace_env_var_place_holders.sh rename to docker/docker-entrypoint.d/92-replace_env_var_place_holders.sh diff --git a/docker/docker-entrypoint.d/99-update-config.sh b/docker/docker-entrypoint.d/93-update-config.sh similarity index 100% rename from docker/docker-entrypoint.d/99-update-config.sh rename to docker/docker-entrypoint.d/93-update-config.sh From 88f9329f56929d47f2c8a94c4363bb68126e80f5 Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Wed, 12 Oct 2022 11:38:47 -0400 Subject: [PATCH 3/5] move code to envvar.sh --- docker/docker-entrypoint.d/91-copy-to-public-path.sh | 9 --------- .../92-replace_env_var_place_holders.sh | 11 ----------- docker/docker-entrypoint.d/93-update-config.sh | 8 -------- docker/docker-entrypoint.d/envvar.sh | 10 ++++++++++ 4 files changed, 10 insertions(+), 28 deletions(-) diff --git a/docker/docker-entrypoint.d/91-copy-to-public-path.sh b/docker/docker-entrypoint.d/91-copy-to-public-path.sh index e11e35c..48cd584 100755 --- a/docker/docker-entrypoint.d/91-copy-to-public-path.sh +++ b/docker/docker-entrypoint.d/91-copy-to-public-path.sh @@ -3,15 +3,6 @@ source $(dirname -- "$0")/envvar.sh; -PUBLIC_PATH=${PUBLIC_PATH:?"undefined"} - -DIST_DIR="/app/dist" -SITE_DIR_ROOT="/app/site" - -SITE_DIR=$(echo $SITE_DIR_ROOT/$PUBLIC_PATH | tr -s /) -SITE_DIR=${SITE_DIR%/} # e.g., /app/site/vue - - if [[ ! -d ${DIST_DIR} ]] then echo "Error: ${DIST_DIR} doesn't exit!" diff --git a/docker/docker-entrypoint.d/92-replace_env_var_place_holders.sh b/docker/docker-entrypoint.d/92-replace_env_var_place_holders.sh index 99661c5..077813e 100755 --- a/docker/docker-entrypoint.d/92-replace_env_var_place_holders.sh +++ b/docker/docker-entrypoint.d/92-replace_env_var_place_holders.sh @@ -3,17 +3,6 @@ source $(dirname -- "$0")/envvar.sh; -PUBLIC_PATH=${PUBLIC_PATH:?"undefined"} - -SITE_DIR_ROOT="/app/site" - -SITE_DIR=$(echo $SITE_DIR_ROOT/$PUBLIC_PATH | tr -s /) -SITE_DIR=${SITE_DIR%/} # e.g., /app/site/vue - -PUBLIC_PATH_PLACEHOLDER="/public_path_placeholder/" - -PUBLIC_PATH="${PUBLIC_PATH%/}/" - if [[ ! -d ${SITE_DIR} ]]; then echo "Error: ${SITE_DIR} doesn't exit!" exit 1 diff --git a/docker/docker-entrypoint.d/93-update-config.sh b/docker/docker-entrypoint.d/93-update-config.sh index 4e9895a..419e255 100755 --- a/docker/docker-entrypoint.d/93-update-config.sh +++ b/docker/docker-entrypoint.d/93-update-config.sh @@ -3,16 +3,8 @@ source $(dirname -- "$0")/envvar.sh; -PUBLIC_PATH=${PUBLIC_PATH:?"undefined"} -API_NAME=${API_NAME:?"undefined"} -API_HTTP=${API_HTTP:?"undefined"} - -SITE_DIR_ROOT="/app/site" CONFIG_JSON="config.json" -SITE_DIR=$(echo $SITE_DIR_ROOT/$PUBLIC_PATH | tr -s /) -SITE_DIR=${SITE_DIR%/} # e.g., /app/site/vue - if [[ ! -d ${SITE_DIR} ]]; then echo "Error: ${SITE_DIR} doesn't exit!" exit 1 diff --git a/docker/docker-entrypoint.d/envvar.sh b/docker/docker-entrypoint.d/envvar.sh index c6edc77..56c4b22 100644 --- a/docker/docker-entrypoint.d/envvar.sh +++ b/docker/docker-entrypoint.d/envvar.sh @@ -5,6 +5,16 @@ PUBLIC_PATH="${PUBLIC_PATH:-/}" API_HTTP="${API_HTTP:-http://localhost:8000}" API_NAME="${API_NAME:-localhost}" +PUBLIC_PATH="${PUBLIC_PATH%/}/" # ensure trailing slash + echo + "PUBLIC_PATH=${PUBLIC_PATH}" echo + "API_HTTP=${API_HTTP}" echo + "API_NAME=${API_NAME}" + +DIST_DIR="/app/dist" +SITE_DIR_ROOT="/app/site" + +SITE_DIR=$(echo $SITE_DIR_ROOT/$PUBLIC_PATH | tr -s /) +SITE_DIR=${SITE_DIR%/} # e.g., /app/site/vue + +PUBLIC_PATH_PLACEHOLDER="/public_path_placeholder/" From a009d5e366f40bf133f9fe334c313ccd748bcc54 Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Wed, 12 Oct 2022 12:24:26 -0400 Subject: [PATCH 4/5] move monacoeditorwork in a setup script instead of in Dockerfile --- Dockerfile | 1 - .../94-move-monaco-editor-workers.sh | 33 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100755 docker/docker-entrypoint.d/94-move-monaco-editor-workers.sh diff --git a/Dockerfile b/Dockerfile index b32c39b..6f6e7c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,6 +14,5 @@ RUN apt-get update && apt-get install -y jq WORKDIR /app COPY --from=build /app/dist dist -COPY --from=build /app/dist/public_path_placeholder/monacoeditorwork dist/monacoeditorwork COPY docker/docker-entrypoint.d/* /docker-entrypoint.d/ COPY docker/nginx-default.conf.template /etc/nginx/templates/default.conf.template diff --git a/docker/docker-entrypoint.d/94-move-monaco-editor-workers.sh b/docker/docker-entrypoint.d/94-move-monaco-editor-workers.sh new file mode 100755 index 0000000..d2a17da --- /dev/null +++ b/docker/docker-entrypoint.d/94-move-monaco-editor-workers.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# Copy the Vue files to the Vue publicPath + +set -e + +source $(dirname -- "$0")/envvar.sh; + +FILE=$(basename $0) + +BASE_NAME=monacoeditorwork + +SOURCE=$(echo ${SITE_DIR}/${PUBLIC_PATH_PLACEHOLDER}/${BASE_NAME} | tr -s /) +DEST=$(echo ${SITE_DIR}/${BASE_NAME} | tr -s /) + +if [[ ! -d ${SOURCE} ]] +then + echo "$FILE: the source dir doesn't exist: $SOURCE" + exit 0 +fi + +if [[ $SOURCE == $DEST ]] +then + echo "$FILE: the source and destination are the same: $SOURCE" + exit 0 +fi + +command="rm -rf $DEST" +echo + $command +eval $command + +command="mv $SOURCE $DEST" +echo + $command +eval $command From d3489684eb7ffeca3e579b9bcb97980741149566 Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Wed, 12 Oct 2022 12:32:15 -0400 Subject: [PATCH 5/5] update nginx version for docker --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6f6e7c7..4f3e0cf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN yarn build # -FROM nginx:1.21 +FROM nginx:1.22.0 RUN apt-get update && apt-get install -y jq