From 1f992c6779258f51023d9aac6d4a744d06aa58e8 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Tue, 29 Mar 2022 08:45:20 +0200 Subject: [PATCH] =?UTF-8?q?fix(docker):=20=F0=9F=90=9B=20Fix=20the=20whole?= =?UTF-8?q?=20docker=20deployment=20pipeline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I've been able to deploy the application on another machine (finally). --- .gitignore | 2 +- Dockerfile | 7 ++---- apps/builder/.env.production.example | 6 +++++ apps/docs/docs/self-hosting/configuration.md | 1 + apps/docs/docs/self-hosting/docker.md | 10 ++++++-- apps/viewer/.env.production.example | 4 ++++ docker-compose.yml | 24 +++++++++++++------- packages/scripts/index.ts | 2 +- typebot-config.env | 5 ---- 9 files changed, 39 insertions(+), 22 deletions(-) create mode 100644 apps/builder/.env.production.example create mode 100644 apps/viewer/.env.production.example delete mode 100644 typebot-config.env diff --git a/.gitignore b/.gitignore index 9806a90d4..ab355bf90 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ node_modules .next .env .env.local -.env.prod +.env.production workspace.code-workspace .DS_Store .turbo diff --git a/Dockerfile b/Dockerfile index 081521a1b..a0cc6afaa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,14 +18,12 @@ FROM base AS builder COPY --from=installer /app/ . COPY --from=pruner /app/out/full/ . RUN apt-get -qy update && apt-get -qy install openssl -RUN yarn turbo run build --scope=${SCOPE} --include-dependencies --no-deps +RUN yarn turbo run build --scope=${SCOPE} --include-dependencies RUN find . -name node_modules | xargs rm -rf FROM base AS runner WORKDIR /app ENV NODE_ENV production -RUN addgroup --system --gid 1001 nodejs -RUN adduser --system --uid 1001 nextjs COPY ./packages/db/prisma ./prisma COPY --from=installer /app/node_modules ./node_modules COPY --from=builder /app/apps/${SCOPE}/next.config.js ./ @@ -33,8 +31,7 @@ COPY --from=builder /app/apps/${SCOPE}/public ./public COPY --from=builder /app/apps/${SCOPE}/package.json ./package.json COPY --from=builder /app/apps/${SCOPE}/.next/standalone ./ COPY --from=builder /app/apps/${SCOPE}/.next/static ./.next/static -RUN chown -Rf nextjs:nodejs /app -USER nextjs +RUN apt-get -qy update && apt-get -qy install openssl EXPOSE 3000 ENV PORT 3000 CMD ["node", "server.js"] \ No newline at end of file diff --git a/apps/builder/.env.production.example b/apps/builder/.env.production.example new file mode 100644 index 000000000..fe09cbd0d --- /dev/null +++ b/apps/builder/.env.production.example @@ -0,0 +1,6 @@ +DATABASE_URL=postgresql://postgres:typebot@postgres:5432/typebot +NEXT_PUBLIC_VIEWER_URL=http://localhost:8081 +ENCRYPTION_SECRET=SgVkYp2s5v8y/B?E(H+MbQeThWmZq4t6 +ADMIN_EMAIL=contact@baptiste-arnaud.fr +NEXTAUTH_URL=http://localhost:8080 +NEXTAUTH_URL_INTERNAL=http://host.docker.internal:8080 \ No newline at end of file diff --git a/apps/docs/docs/self-hosting/configuration.md b/apps/docs/docs/self-hosting/configuration.md index dd58b4a0a..0fcae6823 100644 --- a/apps/docs/docs/self-hosting/configuration.md +++ b/apps/docs/docs/self-hosting/configuration.md @@ -24,6 +24,7 @@ These variables are shared between builder and viewer. If you host them in a dif | ENCRYPTION_SECRET | SgVkYp2s5v8y/B?E(H+MbQeThWmZq4t6 | A 256-bit key used to encrypt sensitive data. It is strongly recommended to [generate](https://www.allkeysgenerator.com/Random/Security-Encryption-Key-Generator.aspx) a new one. | | ADMIN_EMAIL | -- | The email that will get a "Pro" plan on user creation | | NEXTAUTH_URL | http://localhost:3000 | The builder base URL | +| NEXTAUTH_URL_INTERNAL | -- | The internal builder base URL when `NEXTAUTH_URL` isn't publicly accessible (optionnal) | | NEXT_PUBLIC_VIEWER_URL | http://localhost:3001 | The viewer base URL | ### SMTP (optional) diff --git a/apps/docs/docs/self-hosting/docker.md b/apps/docs/docs/self-hosting/docker.md index 9fac1b91d..a9171dcc7 100644 --- a/apps/docs/docs/self-hosting/docker.md +++ b/apps/docs/docs/self-hosting/docker.md @@ -18,13 +18,19 @@ You need a server with Docker installed. If your server doesn't come with Docker On your server: -1. Clone the forked repo: +1. Clone the repo: ```sh git clone https://github.com/baptistearno/typebot.io.git ``` -2. Edit the `typebot-config.env` file. ([Check out the configuration guide](/self-hosting/configuration)) +2. Set up environment variables + + Copy `apps/builder/.env.production.example` to `apps/builder/.env.production` + + Copy `apps/viewer/.env.production.example` to `apps/viewer/.env.production` + + Check out the [Configuration guide](https://docs.typebot.io/self-hosting/configuration) to add your environment variables 3. Start the applications: diff --git a/apps/viewer/.env.production.example b/apps/viewer/.env.production.example new file mode 100644 index 000000000..2b26be5b2 --- /dev/null +++ b/apps/viewer/.env.production.example @@ -0,0 +1,4 @@ +DATABASE_URL=postgresql://postgres:typebot@postgres:5432/typebot +NEXT_PUBLIC_VIEWER_URL=http://localhost:8081 +ENCRYPTION_SECRET=SgVkYp2s5v8y/B?E(H+MbQeThWmZq4t6 +ADMIN_EMAIL=contact@baptiste-arnaud.fr \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 2686b38df..49f544f7f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ version: '3.9' services: - typebot_db: + db: image: postgres:13 restart: always volumes: @@ -8,25 +8,29 @@ services: environment: - POSTGRES_DB=typebot - POSTGRES_PASSWORD=typebot - typebot_builder: + builder: depends_on: - - typebot_db + - db build: context: . args: - SCOPE=builder ports: - '8080:3000' + extra_hosts: + - 'host.docker.internal:host-gateway' env_file: - - typebot-config.env + - './apps/builder/.env.production' entrypoint: > /bin/sh -c " - sleep 10; + ./node_modules/bin/prisma generate; + echo 'Waiting 5s for db to be ready...'; + sleep 5; ./node_modules/.bin/prisma migrate deploy; node server.js;" - typebot_viewer: + viewer: depends_on: - - typebot_db + - db restart: always build: context: . @@ -35,7 +39,11 @@ services: ports: - '8081:3000' env_file: - - typebot-config.env + - './apps/viewer/.env.production' + entrypoint: > + /bin/sh -c " + ./node_modules/bin/prisma generate; + node server.js;" volumes: db_data: s3_data: diff --git a/packages/scripts/index.ts b/packages/scripts/index.ts index d0ce1e0e2..58cdf2461 100644 --- a/packages/scripts/index.ts +++ b/packages/scripts/index.ts @@ -4,7 +4,7 @@ import path from 'path' require('dotenv').config({ path: path.join( __dirname, - process.env.NODE_ENV === 'production' ? '.env.prod' : '.env.local' + process.env.NODE_ENV === 'production' ? '.env.production' : '.env.local' ), }) diff --git a/typebot-config.env b/typebot-config.env deleted file mode 100644 index c9d9fadfe..000000000 --- a/typebot-config.env +++ /dev/null @@ -1,5 +0,0 @@ -DATABASE_URL=postgresql://typebot:typebot@postgres:5432/typebot -NEXT_PUBLIC_VIEWER_URL=http://localhost:8081 -ENCRYPTION_SECRET=SgVkYp2s5v8y/B?E(H+MbQeThWmZq4t6 -ADMIN_EMAIL=contact@baptiste-arnaud.fr -NEXTAUTH_URL=http://localhost:8080 \ No newline at end of file