From e03fe9f7d9e4a36e5b0d6e74670eb9c6c4b6657f Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Tue, 21 Jun 2022 10:36:41 +0200 Subject: [PATCH] =?UTF-8?q?fix(docker):=20=F0=9F=90=9B=20Runtime=20public?= =?UTF-8?q?=20environment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + Dockerfile | 4 +- apps/builder/.env.docker | 12 +- .../builder/components/share/ShareContent.tsx | 5 +- .../share/codeSnippets/Chat/EmbedCode.tsx | 8 +- .../codeSnippets/Container/EmbedCode.tsx | 8 +- .../share/codeSnippets/Iframe/EmbedCode.tsx | 8 +- .../share/codeSnippets/Popup/EmbedCode.tsx | 8 +- .../share/codeSnippets/ReactCode.tsx | 20 +-- .../share/customDomain/CustomDomainModal.tsx | 8 +- .../modals/GtmModal/GtmInstructions.tsx | 8 +- .../share/integrations/modals/NotionModal.tsx | 14 +- .../ShopifyModal/ShopifyInstructions.tsx | 8 +- .../integrations/modals/WordpressModal.tsx | 14 +- apps/builder/components/shared/CodeEditor.tsx | 4 +- .../SendEmailSettings/SendEmailSettings.tsx | 7 +- .../shared/ImageUploadContent/GiphySearch.tsx | 5 +- .../ImageUploadContent/ImageUploadContent.tsx | 11 +- .../components/shared/SearchableDropdown.tsx | 4 +- .../components/shared/SmartNumberInput.tsx | 4 +- .../components/shared/Textbox/TextBox.tsx | 4 +- .../components/shared/VariableSearchInput.tsx | 4 +- .../FontSelector/FontSelector.tsx | 12 +- .../TypebotContext/TypebotContext.tsx | 4 +- apps/builder/next.config.js | 5 - apps/builder/package.json | 2 +- apps/builder/pages/_document.tsx | 2 + apps/builder/pages/api/auth/[...nextauth].ts | 9 +- .../api/typebots/[typebotId]/invitations.ts | 4 +- apps/builder/playwright/tests/results.spec.ts | 3 +- .../builder/playwright/tests/settings.spec.ts | 4 +- apps/builder/services/api/dbRules.ts | 4 +- apps/builder/services/api/emails.ts | 3 +- apps/builder/services/folders.ts | 6 +- apps/builder/services/integrations.ts | 6 +- apps/builder/services/stripe.ts | 10 +- apps/builder/services/typebots/invitations.ts | 6 +- apps/builder/services/typebots/results.tsx | 6 +- apps/builder/services/typebots/typebots.ts | 6 +- apps/builder/services/user/apiTokens.ts | 6 +- apps/builder/services/workspace/member.ts | 4 +- apps/viewer/.env.docker | 2 +- apps/viewer/layouts/ErrorPage.tsx | 4 +- apps/viewer/package.json | 2 +- apps/viewer/pages/[[...publicId]].tsx | 6 +- apps/viewer/pages/_document.tsx | 31 ++++ apps/viewer/services/api/dbRules.ts | 4 +- builder-entrypoint.sh | 2 +- docker-compose.build.yml | 5 +- env.sh | 161 ++++++++++++++++++ package.json | 2 +- .../src/components/TypebotViewer.tsx | 4 +- packages/utils/src/utils.ts | 16 ++ viewer-entrypoint.sh | 2 +- 54 files changed, 349 insertions(+), 164 deletions(-) create mode 100644 apps/viewer/pages/_document.tsx create mode 100644 env.sh diff --git a/.gitignore b/.gitignore index f2c7410285..41786c94cc 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ firebaseServiceAccount.json tags dump.sql + +__env.js diff --git a/Dockerfile b/Dockerfile index 0f7d4e9064..91a152d7f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,10 +36,10 @@ COPY --from=builder /app/apps/${SCOPE}/.next/static ./.next/static COPY --from=builder /app/apps/${SCOPE}/.env.docker ./.env.production RUN apt-get -qy update && apt-get -qy install openssl -COPY entrypoint.sh ./ +COPY env.sh ./ COPY ${SCOPE}-entrypoint.sh ./ RUN chmod +x ./${SCOPE}-entrypoint.sh -RUN chmod +x ./entrypoint.sh +RUN chmod +x ./env.sh ENTRYPOINT ./${SCOPE}-entrypoint.sh EXPOSE 3000 diff --git a/apps/builder/.env.docker b/apps/builder/.env.docker index cc204ce976..343791d83f 100644 --- a/apps/builder/.env.docker +++ b/apps/builder/.env.docker @@ -1,7 +1,7 @@ # Don't edit this file -NEXT_PUBLIC_VIEWER_URL=DOCKER_NEXT_PUBLIC_VIEWER_URL -NEXT_PUBLIC_SMTP_FROM=DOCKER_NEXT_PUBLIC_SMTP_FROM -NEXT_PUBLIC_GOOGLE_API_KEY=DOCKER_NEXT_PUBLIC_GOOGLE_API_KEY -NEXT_PUBLIC_GIPHY_API_KEY=DOCKER_NEXT_PUBLIC_GIPHY_API_KEY -NEXT_PUBLIC_STRIPE_PUBLIC_KEY=DOCKER_NEXT_PUBLIC_STRIPE_PUBLIC_KEY -NEXT_PUBLIC_SENTRY_DSN=DOCKER_NEXT_PUBLIC_SENTRY_DSN +NEXT_PUBLIC_VIEWER_URL= +NEXT_PUBLIC_SMTP_FROM= +NEXT_PUBLIC_GOOGLE_API_KEY= +NEXT_PUBLIC_GIPHY_API_KEY= +NEXT_PUBLIC_STRIPE_PUBLIC_KEY= +NEXT_PUBLIC_SENTRY_DSN= diff --git a/apps/builder/components/share/ShareContent.tsx b/apps/builder/components/share/ShareContent.tsx index 9eeb261feb..709a6ac338 100644 --- a/apps/builder/components/share/ShareContent.tsx +++ b/apps/builder/components/share/ShareContent.tsx @@ -20,6 +20,7 @@ import { isDefined, isNotDefined } from 'utils' import { CustomDomainsDropdown } from './customDomain/CustomDomainsDropdown' import { EditableUrl } from './EditableUrl' import { integrationsList } from './integrations/EmbedButton' +import { env } from 'utils' export const ShareContent = () => { const { workspace } = useWorkspace() @@ -58,9 +59,7 @@ export const ShareContent = () => { {typebot && ( diff --git a/apps/builder/components/share/codeSnippets/Chat/EmbedCode.tsx b/apps/builder/components/share/codeSnippets/Chat/EmbedCode.tsx index c2974d9673..cca1852795 100644 --- a/apps/builder/components/share/codeSnippets/Chat/EmbedCode.tsx +++ b/apps/builder/components/share/codeSnippets/Chat/EmbedCode.tsx @@ -5,7 +5,7 @@ import { BubbleParams } from 'typebot-js' import { parseInitBubbleCode, typebotJsHtml } from '../params' import { useTypebot } from 'contexts/TypebotContext' import { CodeEditor } from 'components/shared/CodeEditor' -import { isEmpty } from 'utils' +import { env, isEmpty } from 'utils' type ChatEmbedCodeProps = { withStarterVariables?: boolean @@ -21,9 +21,9 @@ export const ChatEmbedCode = ({ const snippet = prettier.format( createSnippet({ url: `${ - isEmpty(process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL) - ? process.env.NEXT_PUBLIC_VIEWER_URL - : process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL + isEmpty(env('VIEWER_INTERNAL_URL')) + ? env('VIEWER_URL') + : env('VIEWER_INTERNAL_URL') }/${typebot?.publicId}`, button, proactiveMessage, diff --git a/apps/builder/components/share/codeSnippets/Container/EmbedCode.tsx b/apps/builder/components/share/codeSnippets/Container/EmbedCode.tsx index d2dd0e0945..16d13fb153 100644 --- a/apps/builder/components/share/codeSnippets/Container/EmbedCode.tsx +++ b/apps/builder/components/share/codeSnippets/Container/EmbedCode.tsx @@ -5,7 +5,7 @@ import { parseInitContainerCode, typebotJsHtml } from '../params' import { IframeParams } from 'typebot-js' import { useTypebot } from 'contexts/TypebotContext' import { CodeEditor } from 'components/shared/CodeEditor' -import { isEmpty } from 'utils' +import { env, isEmpty } from 'utils' type ContainerEmbedCodeProps = { widthLabel: string @@ -23,9 +23,9 @@ export const ContainerEmbedCode = ({ const snippet = prettier.format( parseSnippet({ url: `${ - isEmpty(process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL) - ? process.env.NEXT_PUBLIC_VIEWER_URL - : process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL + isEmpty(env('VIEWER_INTERNAL_URL')) + ? env('VIEWER_URL') + : env('VIEWER_INTERNAL_URL') }/${typebot?.publicId}`, heightLabel, widthLabel, diff --git a/apps/builder/components/share/codeSnippets/Iframe/EmbedCode.tsx b/apps/builder/components/share/codeSnippets/Iframe/EmbedCode.tsx index 8656aca812..f9c0f96205 100644 --- a/apps/builder/components/share/codeSnippets/Iframe/EmbedCode.tsx +++ b/apps/builder/components/share/codeSnippets/Iframe/EmbedCode.tsx @@ -1,7 +1,7 @@ import { FlexProps } from '@chakra-ui/react' import { CodeEditor } from 'components/shared/CodeEditor' import { useTypebot } from 'contexts/TypebotContext' -import { isEmpty } from 'utils' +import { env, isEmpty } from 'utils' type Props = { widthLabel: string @@ -14,9 +14,9 @@ export const IframeEmbedCode = ({ }: Props & FlexProps) => { const { typebot } = useTypebot() const src = `${ - isEmpty(process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL) - ? process.env.NEXT_PUBLIC_VIEWER_URL - : process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL + isEmpty(env('VIEWER_INTERNAL_URL')) + ? env('VIEWER_URL') + : env('VIEWER_INTERNAL_URL') }/${typebot?.publicId}` const code = `