From 7f8efc86f092648edd31f383e0859debddca1be5 Mon Sep 17 00:00:00 2001 From: Chika Date: Mon, 28 Nov 2022 00:10:00 +0300 Subject: [PATCH] docker: pass env variables to web app --- .env | 5 ++++- apps/web/Dockerfile | 5 +++-- apps/web/components/Form.jsx | 6 ++++-- apps/web/config/constants.js | 2 -- apps/web/next.config.js | 9 ++++++++- apps/web/pages/_app.tsx | 4 +--- apps/web/pages/_document.tsx | 6 ++++-- apps/web/pages/index.jsx | 8 +++++--- docker-compose.yml | 11 ++++++++--- 9 files changed, 37 insertions(+), 19 deletions(-) delete mode 100644 apps/web/config/constants.js diff --git a/.env b/.env index 6c598c9..eee2926 100644 --- a/.env +++ b/.env @@ -1,5 +1,8 @@ NETWORK_NAME= -BASE_PATH= + +WEB_BASE_PATH= +WEB_APP_TITLE= +WEB_APP_DESCRIPTION= LDAP_BIND_DN= LDAP_BIND_CREDENTIALS= diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile index ea88762..43c45b0 100644 --- a/apps/web/Dockerfile +++ b/apps/web/Dockerfile @@ -16,6 +16,7 @@ FROM node:16-alpine AS installer RUN apk add --no-cache libc6-compat RUN apk update WORKDIR /app + ENV NEXT_TELEMETRY_DISABLED 1 # First install the dependencies (as they change less often) @@ -24,11 +25,10 @@ COPY --from=builder /app/out/json/ . COPY --from=builder /app/out/yarn.lock ./yarn.lock RUN yarn install -ARG NEXT_PUBLIC_COLOR_PRIMARY - # Build the project COPY --from=builder /app/out/full/ . COPY turbo.json turbo.json + RUN yarn turbo run build --filter=web... FROM node:16-alpine AS runner @@ -42,6 +42,7 @@ RUN adduser --system --uid 1001 nextjs USER nextjs COPY --from=installer /app/apps/web/next.config.js . +COPY --from=installer /app/apps/web/public ./public COPY --from=installer /app/apps/web/package.json . # Automatically leverage output traces to reduce image size diff --git a/apps/web/components/Form.jsx b/apps/web/components/Form.jsx index 0b950d7..43e07f9 100644 --- a/apps/web/components/Form.jsx +++ b/apps/web/components/Form.jsx @@ -2,9 +2,11 @@ import Input from 'elements/Input'; import Button from 'elements/Button'; import styles from './Form.module.scss'; import { H3 } from 'elements/H'; -import { title } from 'config/constants'; import { useRouter } from 'next/router'; import Error from 'elements/Error'; +import getConfig from 'next/config'; + +const { publicRuntimeConfig: config } = getConfig(); export default function Form() { const router = useRouter(); @@ -13,7 +15,7 @@ export default function Form() { return (
-

{title}

+

{config.appTitle}

{error} diff --git a/apps/web/config/constants.js b/apps/web/config/constants.js deleted file mode 100644 index 5021756..0000000 --- a/apps/web/config/constants.js +++ /dev/null @@ -1,2 +0,0 @@ -export const title = process.env.NEXT_PUBLIC_APP_NAME; -export const description = [process.env.NEXT_PUBLIC_APP_NAME, 'Эволюция'].join(' | '); diff --git a/apps/web/next.config.js b/apps/web/next.config.js index da80bb6..1697637 100644 --- a/apps/web/next.config.js +++ b/apps/web/next.config.js @@ -1,14 +1,21 @@ const path = require('path'); +const runtimeConfig = { + appTitle: process.env.APP_TITLE, + description: process.env.APP_DESCRIPTION, +}; + /** @type {import('next').NextConfig} */ const nextConfig = { - basePath: process.env.NEXT_PUBLIC_BASE_PATH, + basePath: process.env.BASE_PATH, output: 'standalone', reactStrictMode: true, swcMinify: true, eslint: { ignoreDuringBuilds: true, }, + serverRuntimeConfig: runtimeConfig, + publicRuntimeConfig: runtimeConfig, experimental: { outputFileTracingRoot: path.join(__dirname, '../../'), }, diff --git a/apps/web/pages/_app.tsx b/apps/web/pages/_app.tsx index 892ce62..1cd013d 100644 --- a/apps/web/pages/_app.tsx +++ b/apps/web/pages/_app.tsx @@ -16,9 +16,7 @@ export default function App({ Component, pageProps }: AppProps) {