From 3f6a4c51b94ed66dead8ca478ddfa90f86dc5ae4 Mon Sep 17 00:00:00 2001 From: nataliaweni Date: Mon, 18 Dec 2023 09:56:09 -0300 Subject: [PATCH 1/7] Fix dockerfile to new patterns --- Dockerfile | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 902415c6..b4cf606f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,15 @@ FROM node:14-alpine as builder -ENV WORKDIR /home/app -WORKDIR $WORKDIR +WORKDIR /home/app -RUN apk update && apk add git yarn +RUN apk --no-cache update && \ + apk --no-cache add git yarn && \ + yarn global add @vue/cli -COPY package.json . -COPY yarn.lock . +COPY package.json yarn.lock ./ -RUN yarn install --network-timeout 1000000 +RUN --mount=type=cache,target=/root/.yarn \ + YARN_CACHE_FOLDER=/root/.yarn yarn install COPY . . @@ -54,17 +55,28 @@ ENV MP9_AB_MAPPING_TOKEN "${MP9_AB_MAPPING_TOKEN}" RUN yarn build -FROM nginx +FROM nginx:1.24-alpine + +ENV APP_USER=app \ + APP_GROUP=app \ + USER_ID=1999 \ + GROUP_ID=1999 + +RUN addgroup --system --gid ${GROUP_ID} ${APP_GROUP} \ + && adduser --system --disabled-password --home /home/${APP_USER} \ + --uid ${USER_ID} --ingroup ${APP_GROUP} ${APP_USER} COPY nginx.conf /etc/nginx/nginx.conf -COPY --from=builder /home/app/dist /usr/share/nginx/html/connect +COPY --from=builder --chown=${APP_USER}:${APP_GROUP} /home/app/dist /usr/share/nginx/html/connect COPY docker-entrypoint.sh /usr/share/nginx/ -RUN chmod +x /usr/share/nginx/docker-entrypoint.sh +WORKDIR /home/app + +USER ${APP_USER}:${APP_GROUP} +EXPOSE 8080 ENTRYPOINT ["/usr/share/nginx/docker-entrypoint.sh"] CMD ["nginx", "-g", "daemon off;"] -# COPY config.js.tmpl /usr/share/nginx/html/connect/ From 6d7ae4f1981f404e1f6fe85e8bb63a6a9efba169 Mon Sep 17 00:00:00 2001 From: nataliaweni Date: Fri, 22 Dec 2023 17:44:38 -0300 Subject: [PATCH 2/7] Update nginx configurations --- nginx.conf | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/nginx.conf b/nginx.conf index 6e1045c2..406b668a 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,8 +1,8 @@ user nginx; worker_processes 1; -error_log /var/log/nginx/error.log warn; -pid /var/run/nginx.pid; +error_log /dev/stdout info; +pid /tmp/nginx.pid; events { worker_connections 1024; @@ -16,10 +16,16 @@ http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; - access_log /var/log/nginx/access.log main; + client_body_temp_path /tmp/client_temp; + proxy_temp_path /tmp/proxy_temp_path; + fastcgi_temp_path /tmp/fastcgi_temp; + uwsgi_temp_path /tmp/uwsgi_temp; + scgi_temp_path /tmp/scgi_temp; + access_log /dev/stdout; + server { - listen 80; + listen 8080; server_name localhost; client_max_body_size 32m; @@ -29,6 +35,7 @@ http { root /usr/share/nginx/html/connect; index index.html; + server_tokens off; location / { expires 1s; @@ -36,12 +43,14 @@ http { } location ~ ^/static { - expires 365d; + expires 365d; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/lib/nginx/html; } + + } } From 60364de9050a4f67bb645e735b6734b8d732fbd3 Mon Sep 17 00:00:00 2001 From: nataliaweni Date: Wed, 27 Dec 2023 15:24:39 -0300 Subject: [PATCH 3/7] Add .dockerignore and refatoring dockerfile --- .dockerignore | 34 ++++++++++++++++++ Dockerfile | 82 +++++++++----------------------------------- docker-entrypoint.sh | 2 +- 3 files changed, 51 insertions(+), 67 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..4e085f44 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,34 @@ + +node_modules/ +/dist/ +.idea/ +.vscode/ +.git/ +.github/ + +npm-debug.log* +yarn-debug.log* +yarn-error.log* +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? +.DS_Store + +.editorconfig +.eslintrc.js +.gitignore +.prettierrc.js +.babel.config.js +.jest.config.js +.postcss.config.js +.vetur.config.js +.vue.config.js +.env +.env.local +.env.*.local + +/tests/ + +Dockerfile diff --git a/Dockerfile b/Dockerfile index b4cf606f..103c4b17 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,82 +1,32 @@ -FROM node:14-alpine as builder +# syntax = docker/dockerfile:1 + +ARG NODE_VERSION="14.17.4" +ARG BASE_VERSION="alpine3.14" + +FROM node:${NODE_VERSION}-${BASE_VERSION} as builder WORKDIR /home/app -RUN apk --no-cache update && \ - apk --no-cache add git yarn && \ - yarn global add @vue/cli +RUN apk --no-cache add git COPY package.json yarn.lock ./ RUN --mount=type=cache,target=/root/.yarn \ YARN_CACHE_FOLDER=/root/.yarn yarn install -COPY . . - -ARG VUE_APP_ROOT_API -ARG KEYCLOAK_ISSUER -ARG KEYCLOAK_AUTHORIZATION_ENDPOINT -ARG KEYCLOAK_USERINFO_ENDPOINT -ARG KEYCLOAK_END_SESSION_ENDPOINT -ARG KEYCLOAK_JWKS_URI -ARG KEYCLOAK_TOKEN_ENDPOINT -ARG KEYCLOAK_CHECK_SESSION_IFRAME -ARG KEYCLOAK_CLIENT_ID -ARG KEYCLOAK_REALM -ARG VUE_APP_HOTJAR_PROJECT_KEY -ARG VUE_APP_BOT_URL -ARG VUE_APP_SENTRY_DSN_ENDPOINT -ARG VUE_APP_HELPHERO -ARG VUE_APP_STRIPE_API -ARG LOGROCKET_ID -ARG LOGROCKET_CHILD_DOMAINS -ARG VUE_APP_URL_ACADEMY -ARG MP9_AB_MAPPING_TOKEN - -ENV VUE_APP_ROOT_API "${VUE_APP_ROOT_API}" -ENV KEYCLOAK_ISSUER "${KEYCLOAK_ISSUER}" -ENV KEYCLOAK_AUTHORIZATION_ENDPOINT "${KEYCLOAK_AUTHORIZATION_ENDPOINT}" -ENV KEYCLOAK_USERINFO_ENDPOINT "${KEYCLOAK_USERINFO_ENDPOINT}" -ENV KEYCLOAK_END_SESSION_ENDPOINT "${KEYCLOAK_END_SESSION_ENDPOINT}" -ENV KEYCLOAK_JWKS_URI "${KEYCLOAK_JWKS_URI}" -ENV KEYCLOAK_TOKEN_ENDPOINT "${KEYCLOAK_TOKEN_ENDPOINT}" -ENV KEYCLOAK_CHECK_SESSION_IFRAME "${KEYCLOAK_CHECK_SESSION_IFRAME}" -ENV KEYCLOAK_CLIENT_ID "${KEYCLOAK_CLIENT_ID}" -ENV KEYCLOAK_REALM "${KEYCLOAK_REALM}" -ENV VUE_APP_HOTJAR_PROJECT_KEY "${VUE_APP_HOTJAR_PROJECT_KEY}" -ENV VUE_APP_BOT_URL "${VUE_APP_BOT_URL}" -ENV VUE_APP_SENTRY_DSN_ENDPOINT "${VUE_APP_SENTRY_DSN_ENDPOINT}" -ENV VUE_APP_HELPHERO "${VUE_APP_HELPHERO}" -ENV VUE_APP_STRIPE_API "${VUE_APP_STRIPE_API}" -ENV LOGROCKET_ID "${LOGROCKET_ID}" -ENV LOGROCKET_CHILD_DOMAINS "${LOGROCKET_CHILD_DOMAINS}" -ENV VUE_APP_URL_ACADEMY "${VUE_APP_URL_ACADEMY}" -ENV MP9_AB_MAPPING_TOKEN "${MP9_AB_MAPPING_TOKEN}" +COPY . ./ RUN yarn build -FROM nginx:1.24-alpine - -ENV APP_USER=app \ - APP_GROUP=app \ - USER_ID=1999 \ - GROUP_ID=1999 - -RUN addgroup --system --gid ${GROUP_ID} ${APP_GROUP} \ - && adduser --system --disabled-password --home /home/${APP_USER} \ - --uid ${USER_ID} --ingroup ${APP_GROUP} ${APP_USER} +FROM nginxinc/nginx-unprivileged:1.25-alpine -COPY nginx.conf /etc/nginx/nginx.conf -COPY --from=builder --chown=${APP_USER}:${APP_GROUP} /home/app/dist /usr/share/nginx/html/connect - -COPY docker-entrypoint.sh /usr/share/nginx/ - -WORKDIR /home/app - -USER ${APP_USER}:${APP_GROUP} +COPY --chown=nginx:nginx nginx.conf /etc/nginx/nginx.conf +COPY --from=builder --chown=nginx:nginx /home/app/dist /usr/share/nginx/html/connect/ +COPY docker-entrypoint.sh / +RUN mv /usr/share/nginx/html/connect/index.html /usr/share/nginx/html/connect/index.html.tmpl \ + && cd /usr/share/nginx/html/connect/ \ + && ln -s /tmp/index.html EXPOSE 8080 -ENTRYPOINT ["/usr/share/nginx/docker-entrypoint.sh"] - +ENTRYPOINT ["bash","/docker-entrypoint.sh"] CMD ["nginx", "-g", "daemon off;"] - diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index b4d1127a..b3f574e2 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -14,6 +14,6 @@ export JSON_STRING='window.configs = { \ "FLOWS_GENERIC_TOKEN":"'${FLOWS_GENERIC_TOKEN}'", \ "MODULES_YAML":"'${MODULES_YAML}'", \ }' -sed -i "s|\/\/CONFIGURATIONS_PLACEHOLDER|${JSON_STRING}|" /usr/share/nginx/html/connect/index.html +sed "s|\/\/CONFIGURATIONS_PLACEHOLDER|${JSON_STRING}|" /usr/share/nginx/html/connect/index.html.tmpl > /tmp/index.html exec "$@" From 97237d004cd23ab1ee69471f0b80c7128af8bc0a Mon Sep 17 00:00:00 2001 From: nataliaweni Date: Thu, 28 Dec 2023 16:07:59 -0300 Subject: [PATCH 4/7] Add port 8080 to docker-compose --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index d9b428c1..ba3ac875 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,4 +25,4 @@ services: - VUE_APP_URL_ACADEMY=${VUE_APP_URL_ACADEMY} - MP9_AB_MAPPING_TOKEN=${MP9_AB_MAPPING_TOKEN} ports: - - 80:80 + - 8080:8080 From d6eaf19779aa775081ec0be0f28bd5a127d7737f Mon Sep 17 00:00:00 2001 From: nataliaweni Date: Thu, 28 Dec 2023 16:29:36 -0300 Subject: [PATCH 5/7] Update entrypoint command in the dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 103c4b17..f961f7a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,5 +28,5 @@ RUN mv /usr/share/nginx/html/connect/index.html /usr/share/nginx/html/connect/in && ln -s /tmp/index.html EXPOSE 8080 -ENTRYPOINT ["bash","/docker-entrypoint.sh"] +ENTRYPOINT ["bash","./docker-entrypoint.sh"] CMD ["nginx", "-g", "daemon off;"] From c4814c5a0ef6b91bbe86a025baca898ede2116c9 Mon Sep 17 00:00:00 2001 From: nataliaweni Date: Thu, 28 Dec 2023 16:37:24 -0300 Subject: [PATCH 6/7] Update entrypoint command --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f961f7a7..63085906 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,5 +28,5 @@ RUN mv /usr/share/nginx/html/connect/index.html /usr/share/nginx/html/connect/in && ln -s /tmp/index.html EXPOSE 8080 -ENTRYPOINT ["bash","./docker-entrypoint.sh"] +ENTRYPOINT ["bash","docker-entrypoint.sh"] CMD ["nginx", "-g", "daemon off;"] From 08297d60d6c8adcf0083476f1d6367714abdac8f Mon Sep 17 00:00:00 2001 From: nataliaweni Date: Thu, 28 Dec 2023 16:46:19 -0300 Subject: [PATCH 7/7] Update entrypoint command --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 63085906..50e4873b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,5 +28,5 @@ RUN mv /usr/share/nginx/html/connect/index.html /usr/share/nginx/html/connect/in && ln -s /tmp/index.html EXPOSE 8080 -ENTRYPOINT ["bash","docker-entrypoint.sh"] +ENTRYPOINT ["/docker-entrypoint.sh"] CMD ["nginx", "-g", "daemon off;"]