From 7db71b7f74dc79f644efa084b162d78cf9f1e754 Mon Sep 17 00:00:00 2001 From: Nick Beaird Date: Sat, 3 Oct 2020 14:59:17 -0700 Subject: [PATCH 1/5] Add containers for prod like client instances --- backend/Dockerfile | 19 ++++++------------- client/Dockerfile | 36 +++++++++++++++--------------------- client/nginx/default.conf | 9 +++++++++ docker-compose.yml | 4 ++-- 4 files changed, 32 insertions(+), 36 deletions(-) create mode 100644 client/nginx/default.conf diff --git a/backend/Dockerfile b/backend/Dockerfile index a613c11c2..98827650f 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,23 +1,16 @@ -FROM node:14.11.0 AS development - +FROM node:14.11.0 AS api-development RUN mkdir /srv/backend && chown node:node /srv/backend - WORKDIR /srv/backend - USER node - COPY --chown=node:node package.json yarn.lock ./ - RUN yarn install --silent - RUN mkdir -p node_modules -FROM node:14.11.0-slim AS production - +FROM node:14.11.0-slim AS api-production +EXPOSE 4000 USER node - WORKDIR /srv/backend - -COPY --from=development --chown=root:root /srv/backend/node_modules ./node_modules - +COPY --from=api-development /srv/backend/node_modules ./node_modules COPY . . +CMD ["npm", "run", "dev"] + diff --git a/client/Dockerfile b/client/Dockerfile index 4f1d6ddd1..449215099 100644 --- a/client/Dockerfile +++ b/client/Dockerfile @@ -1,27 +1,21 @@ -FROM node:14.11.0 AS development - +FROM node:14.11.0 AS client-development RUN mkdir /srv/client && chown node:node /srv/client - WORKDIR /srv/client - USER node - +RUN mkdir -p node_modules COPY --chown=node:node package.json yarn.lock ./ - RUN yarn install --silent -RUN mkdir -p node_modules - -# # TODO: Fix production application. We are currently serving static frontend assets from the backend. -# FROM node:14.11.0-slim AS production - -# USER node - -# WORKDIR /srv/client - -# COPY --from=development --chown=root:root /srv/backend/.env /srv/backend -# COPY --from=development --chown=root:root /srv/client/.env /srv/backend - -# COPY . . - -# CMD ["node", "index.js"] +FROM node:14.11.0-slim AS client-builder +USER node +WORKDIR /srv/client +COPY --from=client-development /srv/client/node_modules node_modules +COPY . . +USER root +RUN npm run build + +FROM nginx as client-production +EXPOSE 3000 +COPY /nginx/default.conf /etc/nginx/conf.d/default.conf +COPY --from=client-builder /srv/client /usr/share/nginx/html/ +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/client/nginx/default.conf b/client/nginx/default.conf new file mode 100644 index 000000000..4ae4d829f --- /dev/null +++ b/client/nginx/default.conf @@ -0,0 +1,9 @@ +server { + + listen 3000; + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html; + } +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index b12581169..9af90da1e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ services: backend: build: context: ./backend - target: development + target: api-development command: yarn run dev volumes: - ./backend:/srv/backend @@ -22,7 +22,7 @@ services: client: build: context: ./client - target: development + target: client-development command: yarn run start volumes: - ./client:/srv/client From 8c5e874d39729be998f2a761f8dcd8b13b9613a7 Mon Sep 17 00:00:00 2001 From: Nick Beaird Date: Sat, 3 Oct 2020 15:00:05 -0700 Subject: [PATCH 2/5] Update packages for import issues --- client/package.json | 2 +- client/src/components/admin/reports/index.js | 2 +- client/yarn.lock | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client/package.json b/client/package.json index b24a63f3f..514e4c4cf 100644 --- a/client/package.json +++ b/client/package.json @@ -19,7 +19,7 @@ "moment-recur": "^1.0.7", "node-sass": "^4.14.1", "react": "^16.13.1", - "react-datepicker": "^3.1.3", + "react-datepicker": "^3.2.2", "react-dom": "^16.13.1", "react-router-dom": "^5.1.2", "react-scripts": "^3.4.1" diff --git a/client/src/components/admin/reports/index.js b/client/src/components/admin/reports/index.js index 7cc0c24a6..435a53f27 100644 --- a/client/src/components/admin/reports/index.js +++ b/client/src/components/admin/reports/index.js @@ -1,6 +1,6 @@ import React, {useState} from 'react'; -import Loading from '../donutChartLoading'; import DatePicker from 'react-datepicker'; +import Loading from '../donutChartLoading'; import 'react-datepicker/dist/react-datepicker.css'; import '../../../common/datepicker/index.scss'; import './index.scss'; diff --git a/client/yarn.lock b/client/yarn.lock index 3491682b3..1bb2bf091 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -10602,10 +10602,10 @@ react-app-polyfill@^1.0.6: regenerator-runtime "^0.13.3" whatwg-fetch "^3.0.0" -react-datepicker@^3.1.3: - version "3.1.3" - resolved "https://registry.yarnpkg.com/react-datepicker/-/react-datepicker-3.1.3.tgz#4bde7aae405deab72a6c102b95a6a0749b7df759" - integrity sha512-4KbdWWAxa/AZJIDhQZwiBpZE9hCYZ4/gTVstdo9WEpFCsfh69xHklB/FZrR95mgkIU7ecU36V2eCuGgIO+ci0A== +react-datepicker@^3.2.2: + version "3.2.2" + resolved "https://registry.yarnpkg.com/react-datepicker/-/react-datepicker-3.2.2.tgz#cd5351ab1bba0b34412dd11db3169801f8f8b2ef" + integrity sha512-/3D6hfhXcCNCbO8LICuQeoNDItWFyitGo+aLcsi0tAyJLtCInamYRwPIXhsEF+N6/qWim1yNyr71mqjj4YEBmg== dependencies: classnames "^2.2.6" date-fns "^2.0.1" From 6acd6a3b15557087932825551f24bcf9a1e98d4e Mon Sep 17 00:00:00 2001 From: Nick Beaird Date: Sat, 3 Oct 2020 16:24:47 -0700 Subject: [PATCH 3/5] Update docker filenames --- backend/{Dockerfile => Dockerfile.api} | 0 client/{Dockerfile => Dockerfile.client} | 2 +- docker-compose.yml | 2 ++ 3 files changed, 3 insertions(+), 1 deletion(-) rename backend/{Dockerfile => Dockerfile.api} (100%) rename client/{Dockerfile => Dockerfile.client} (88%) diff --git a/backend/Dockerfile b/backend/Dockerfile.api similarity index 100% rename from backend/Dockerfile rename to backend/Dockerfile.api diff --git a/client/Dockerfile b/client/Dockerfile.client similarity index 88% rename from client/Dockerfile rename to client/Dockerfile.client index 449215099..37d359cd9 100644 --- a/client/Dockerfile +++ b/client/Dockerfile.client @@ -17,5 +17,5 @@ RUN npm run build FROM nginx as client-production EXPOSE 3000 COPY /nginx/default.conf /etc/nginx/conf.d/default.conf -COPY --from=client-builder /srv/client /usr/share/nginx/html/ +COPY --from=client-builder /srv/client/build /usr/share/nginx/html/ CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 9af90da1e..5d7eb1077 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,6 +4,7 @@ services: backend: build: context: ./backend + dockerfile: Dockerfile.api target: api-development command: yarn run dev volumes: @@ -22,6 +23,7 @@ services: client: build: context: ./client + dockerfile: Dockerfile.client target: client-development command: yarn run start volumes: From 7f57a149d7e4878e78374dad0eb01cba74442d35 Mon Sep 17 00:00:00 2001 From: Nick Beaird Date: Sat, 3 Oct 2020 17:00:38 -0700 Subject: [PATCH 4/5] Revert "Update packages for import issues" This reverts commit 8c5e874d39729be998f2a761f8dcd8b13b9613a7. --- client/package.json | 2 +- client/src/components/admin/reports/index.js | 2 +- client/yarn.lock | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client/package.json b/client/package.json index 514e4c4cf..b24a63f3f 100644 --- a/client/package.json +++ b/client/package.json @@ -19,7 +19,7 @@ "moment-recur": "^1.0.7", "node-sass": "^4.14.1", "react": "^16.13.1", - "react-datepicker": "^3.2.2", + "react-datepicker": "^3.1.3", "react-dom": "^16.13.1", "react-router-dom": "^5.1.2", "react-scripts": "^3.4.1" diff --git a/client/src/components/admin/reports/index.js b/client/src/components/admin/reports/index.js index 435a53f27..7cc0c24a6 100644 --- a/client/src/components/admin/reports/index.js +++ b/client/src/components/admin/reports/index.js @@ -1,6 +1,6 @@ import React, {useState} from 'react'; -import DatePicker from 'react-datepicker'; import Loading from '../donutChartLoading'; +import DatePicker from 'react-datepicker'; import 'react-datepicker/dist/react-datepicker.css'; import '../../../common/datepicker/index.scss'; import './index.scss'; diff --git a/client/yarn.lock b/client/yarn.lock index 1bb2bf091..3491682b3 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -10602,10 +10602,10 @@ react-app-polyfill@^1.0.6: regenerator-runtime "^0.13.3" whatwg-fetch "^3.0.0" -react-datepicker@^3.2.2: - version "3.2.2" - resolved "https://registry.yarnpkg.com/react-datepicker/-/react-datepicker-3.2.2.tgz#cd5351ab1bba0b34412dd11db3169801f8f8b2ef" - integrity sha512-/3D6hfhXcCNCbO8LICuQeoNDItWFyitGo+aLcsi0tAyJLtCInamYRwPIXhsEF+N6/qWim1yNyr71mqjj4YEBmg== +react-datepicker@^3.1.3: + version "3.1.3" + resolved "https://registry.yarnpkg.com/react-datepicker/-/react-datepicker-3.1.3.tgz#4bde7aae405deab72a6c102b95a6a0749b7df759" + integrity sha512-4KbdWWAxa/AZJIDhQZwiBpZE9hCYZ4/gTVstdo9WEpFCsfh69xHklB/FZrR95mgkIU7ecU36V2eCuGgIO+ci0A== dependencies: classnames "^2.2.6" date-fns "^2.0.1" From 59c085cc71285e8fbcbfda09aaa92425ad825f91 Mon Sep 17 00:00:00 2001 From: Nick Beaird Date: Sat, 3 Oct 2020 17:01:50 -0700 Subject: [PATCH 5/5] Add in newlies on files --- client/Dockerfile.client | 2 +- client/nginx/default.conf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/Dockerfile.client b/client/Dockerfile.client index 37d359cd9..5efa15117 100644 --- a/client/Dockerfile.client +++ b/client/Dockerfile.client @@ -18,4 +18,4 @@ FROM nginx as client-production EXPOSE 3000 COPY /nginx/default.conf /etc/nginx/conf.d/default.conf COPY --from=client-builder /srv/client/build /usr/share/nginx/html/ -CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file +CMD ["nginx", "-g", "daemon off;"] diff --git a/client/nginx/default.conf b/client/nginx/default.conf index 4ae4d829f..7f78094f6 100644 --- a/client/nginx/default.conf +++ b/client/nginx/default.conf @@ -6,4 +6,4 @@ server { index index.html index.htm; try_files $uri $uri/ /index.html; } -} \ No newline at end of file +}