From e1ffc64fe7d486225ec0b653e958de3c2e02cbda Mon Sep 17 00:00:00 2001 From: Max Chopart Date: Tue, 10 May 2022 16:04:40 +0200 Subject: [PATCH] [Upd] Update docker entrypoint configuration and environment variables are now set at runtime --- .docker/config.js.template | 7 ++++++ .../docker-entrypoint.sh | 0 .env.example | 4 ++++ .gitignore | 4 +++- Dockerfile | 24 ++++++++++++------- docker-compose.yml | 8 ------- 6 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 .docker/config.js.template rename create-env-file.sh => .docker/docker-entrypoint.sh (100%) create mode 100644 .env.example delete mode 100644 docker-compose.yml diff --git a/.docker/config.js.template b/.docker/config.js.template new file mode 100644 index 0000000..4ecaae7 --- /dev/null +++ b/.docker/config.js.template @@ -0,0 +1,7 @@ +// Dynamic configuration +window.__config__ = { + APP_DOMAIN: '${API_DOMAIN}', + APP_TITLE: '${APP_TITLE}', + LANGUAGE: '${LANGUAGE}', + NAVIGATOR_LANGUAGE: '${NAVIGATOR_LANGUAGE}' +} \ No newline at end of file diff --git a/create-env-file.sh b/.docker/docker-entrypoint.sh similarity index 100% rename from create-env-file.sh rename to .docker/docker-entrypoint.sh diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..fb1c19e --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +APP_TITLE=Plan Manager +APP_DOMAIN=https://localhost:3000/plan-manager/ +LANGUAGE: 'en', +NAVIGATOR_LANGUAGE: 'en' \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7d4754a..2a05e65 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,6 @@ npm-debug.log* yarn-debug.log* yarn-error.log* -.idea \ No newline at end of file +.idea + +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 97443ae..287be02 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,8 @@ # BASE STAGE # Prepare node, copy package.json FROM node:16-alpine AS base - -ARG REACT_APP_ENDPOINT - WORKDIR /usr/src/app COPY package.json package-lock.json ./ -COPY create-env-file.sh ./create-env-file.sh # DEPENDENCIES STAGE # Install production and dev dependencies @@ -15,8 +11,6 @@ FROM base AS dependencies #RUN npm set progress=false && npm config set depth 0 RUN npm install -RUN sh create-env-file.sh REACT_APP_ENDPOINT=$REACT_APP_ENDPOINT - # BUILD STAGE # run NPM build FROM dependencies as build @@ -28,5 +22,19 @@ RUN set -ex; \ # RELEASE STAGE # Only include the static files in the final image -FROM nginx -COPY --from=build /usr/src/app/build /usr/share/nginx/html \ No newline at end of file +FROM nginx:1.17.0-alpine + +# Copy the react build from Build Stage +COPY --from=build /usr/src/app/build /var/www + +# Copy our custom nginx config +COPY .docker/config.js.template /etc/nginx/config.js.template + +COPY --from=build /usr/src/app/build /usr/share/nginx/html + +# from the outside. +EXPOSE 80 + +COPY .docker/docker-entrypoint.sh / +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 4f099fd..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,8 +0,0 @@ -version: "3" -services: - plan-manager: - container_name: plan-manager - build: - context: . - args: - - REACT_APP_ENDPOINT=https://kbss.felk.cvut.cz/csat/plan-manager/ \ No newline at end of file