From b0a295d8bbf7ad710695a14efbc0bd23b4dee771 Mon Sep 17 00:00:00 2001 From: Amruth Pillai Date: Mon, 7 Mar 2022 21:43:38 +0100 Subject: [PATCH] build(docker): minimize production docker image size by using ubuntu:focal --- .env.example | 12 ++++----- client/.eslintrc.json | 15 +++++++++--- client/.gitignore | 3 +++ client/Dockerfile | 2 -- client/modals/auth/LoginModal.tsx | 3 ++- client/next.config.js | 11 +++------ client/package.json | 9 ++++--- client/pages/_app.tsx | 4 ++- client/services/axios.ts | 5 ++-- package.json | 2 +- pnpm-lock.yaml | 39 +++++++++++++++++++++++++++--- server/Dockerfile | 10 +++++--- server/src/config/app.config.ts | 4 +-- server/src/config/config.module.ts | 14 ++++++----- server/src/config/google.config.ts | 2 +- 15 files changed, 91 insertions(+), 44 deletions(-) diff --git a/.env.example b/.env.example index 66abcba1..982b7a1e 100644 --- a/.env.example +++ b/.env.example @@ -1,10 +1,10 @@ -# Reactive Resume +# App TZ=UTC SECRET_KEY=change-me # URLs -APP_URL=http://localhost:3000 -SERVER_URL=http://localhost:3100 +PUBLIC_APP_URL=https://localhost:3000 +PUBLIC_SERVER_URL=https://localhost:3100 # Database POSTGRES_HOST=localhost @@ -25,9 +25,7 @@ MAIL_PORT= MAIL_USERNAME= MAIL_PASSWORD= -# Google OAuth -GOOGLE_CLIENT_ID=change-me +# Google +PUBLIC_GOOGLE_CLIENT_ID=change-me GOOGLE_CLIENT_SECRET=change-me - -# Google Web Fonts GOOGLE_API_KEY=change-me diff --git a/client/.eslintrc.json b/client/.eslintrc.json index 19a6f4df..eade8f0a 100644 --- a/client/.eslintrc.json +++ b/client/.eslintrc.json @@ -1,7 +1,14 @@ { - "extends": ["../.eslintrc.json", "next/core-web-vitals"], - "ignorePatterns": [".next"], + "extends": [ + "../.eslintrc.json", + "next/core-web-vitals" + ], + "ignorePatterns": [ + ".next", + "__ENV.js" + ], "rules": { - "@next/next/no-img-element": "off" + "@next/next/no-img-element": "off", + "@next/next/no-sync-scripts": "off" } -} +} \ No newline at end of file diff --git a/client/.gitignore b/client/.gitignore index 14b267cf..630c4200 100644 --- a/client/.gitignore +++ b/client/.gitignore @@ -34,3 +34,6 @@ yarn-error.log* # typescript *.tsbuildinfo + +# react-env +__ENV.js \ No newline at end of file diff --git a/client/Dockerfile b/client/Dockerfile index 11162a8e..c4e156d9 100644 --- a/client/Dockerfile +++ b/client/Dockerfile @@ -24,8 +24,6 @@ COPY --from=dependencies /app/node_modules ./node_modules COPY --from=dependencies /app/schema/node_modules ./schema/node_modules COPY --from=dependencies /app/client/node_modules ./client/node_modules -RUN [[ -e .env ]] && cp .env ./client/.env - RUN pnpm run build:schema RUN pnpm run build:client diff --git a/client/modals/auth/LoginModal.tsx b/client/modals/auth/LoginModal.tsx index 1e8aff0a..0ddf71a7 100644 --- a/client/modals/auth/LoginModal.tsx +++ b/client/modals/auth/LoginModal.tsx @@ -1,3 +1,4 @@ +import env from '@beam-australia/react-env'; import { joiResolver } from '@hookform/resolvers/joi'; import { Google, Login, Visibility, VisibilityOff } from '@mui/icons-material'; import { Button, IconButton, InputAdornment, TextField } from '@mui/material'; @@ -54,7 +55,7 @@ const LoginModal: React.FC = () => { ); const { signIn } = useGoogleLogin({ - clientId: process.env.googleClientId as string, + clientId: env('GOOGLE_CLIENT_ID'), onSuccess: async (response: GoogleLoginResponse | GoogleLoginResponseOffline) => { await loginWithGoogleMutation({ accessToken: (response as GoogleLoginResponse).accessToken }); diff --git a/client/next.config.js b/client/next.config.js index 1040820c..8d83cda3 100644 --- a/client/next.config.js +++ b/client/next.config.js @@ -7,15 +7,12 @@ const nextConfig = { i18n, - images: { - domains: ['www.gravatar.com'], - }, - env: { appVersion: version, - appUrl: process.env.APP_URL, - serverUrl: process.env.SERVER_URL, - googleClientId: process.env.GOOGLE_CLIENT_ID, + }, + + images: { + domains: ['www.gravatar.com'], }, // Hack to make Tailwind darkMode 'class' strategy with CSS Modules diff --git a/client/package.json b/client/package.json index 012d420e..6e00535a 100644 --- a/client/package.json +++ b/client/package.json @@ -1,12 +1,13 @@ { "name": "@reactive-resume/client", "scripts": { - "dev": "next dev", + "dev": "react-env --prefix PUBLIC -- next dev", "build": "next build", - "start": "next start", + "start": "react-env --prefix PUBLIC -- next start", "lint": "next lint --fix" }, "dependencies": { + "@beam-australia/react-env": "^3.1.1", "@emotion/css": "^11.7.1", "@emotion/react": "^11.8.1", "@emotion/styled": "^11.8.1", @@ -52,6 +53,7 @@ }, "devDependencies": { "@babel/core": "^7.17.5", + "@reactive-resume/schema": "workspace:*", "@types/downloadjs": "^1.4.3", "@types/lodash": "^4.14.179", "@types/node": "17.0.21", @@ -68,7 +70,6 @@ "prettier": "^2.5.1", "sass": "^1.49.9", "tailwindcss": "^3.0.23", - "typescript": "<4.6.0", - "@reactive-resume/schema": "workspace:*" + "typescript": "<4.6.0" } } diff --git a/client/pages/_app.tsx b/client/pages/_app.tsx index 16d6abe9..1154450f 100644 --- a/client/pages/_app.tsx +++ b/client/pages/_app.tsx @@ -21,13 +21,15 @@ const App: React.FC = ({ Component, pageProps }) => { <> Reactive Resume + - + +