2
0

fix(docker): 🐛 Fix the whole docker deployment pipeline

I've been able to deploy the application on another machine (finally).
This commit is contained in:
Baptiste Arnaud
2022-03-29 08:45:20 +02:00
parent c64afb7073
commit 1f992c6779
9 changed files with 39 additions and 22 deletions

2
.gitignore vendored
View File

@ -2,7 +2,7 @@ node_modules
.next .next
.env .env
.env.local .env.local
.env.prod .env.production
workspace.code-workspace workspace.code-workspace
.DS_Store .DS_Store
.turbo .turbo

View File

@ -18,14 +18,12 @@ FROM base AS builder
COPY --from=installer /app/ . COPY --from=installer /app/ .
COPY --from=pruner /app/out/full/ . COPY --from=pruner /app/out/full/ .
RUN apt-get -qy update && apt-get -qy install openssl 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 RUN find . -name node_modules | xargs rm -rf
FROM base AS runner FROM base AS runner
WORKDIR /app WORKDIR /app
ENV NODE_ENV production ENV NODE_ENV production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY ./packages/db/prisma ./prisma COPY ./packages/db/prisma ./prisma
COPY --from=installer /app/node_modules ./node_modules COPY --from=installer /app/node_modules ./node_modules
COPY --from=builder /app/apps/${SCOPE}/next.config.js ./ 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}/package.json ./package.json
COPY --from=builder /app/apps/${SCOPE}/.next/standalone ./ COPY --from=builder /app/apps/${SCOPE}/.next/standalone ./
COPY --from=builder /app/apps/${SCOPE}/.next/static ./.next/static COPY --from=builder /app/apps/${SCOPE}/.next/static ./.next/static
RUN chown -Rf nextjs:nodejs /app RUN apt-get -qy update && apt-get -qy install openssl
USER nextjs
EXPOSE 3000 EXPOSE 3000
ENV PORT 3000 ENV PORT 3000
CMD ["node", "server.js"] CMD ["node", "server.js"]

View File

@ -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

View File

@ -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. | | 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 | | ADMIN_EMAIL | -- | The email that will get a "Pro" plan on user creation |
| NEXTAUTH_URL | http://localhost:3000 | The builder base URL | | 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 | | NEXT_PUBLIC_VIEWER_URL | http://localhost:3001 | The viewer base URL |
### SMTP (optional) ### SMTP (optional)

View File

@ -18,13 +18,19 @@ You need a server with Docker installed. If your server doesn't come with Docker
On your server: On your server:
1. Clone the forked repo: 1. Clone the repo:
```sh ```sh
git clone https://github.com/baptistearno/typebot.io.git 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: 3. Start the applications:

View File

@ -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

View File

@ -1,6 +1,6 @@
version: '3.9' version: '3.9'
services: services:
typebot_db: db:
image: postgres:13 image: postgres:13
restart: always restart: always
volumes: volumes:
@ -8,25 +8,29 @@ services:
environment: environment:
- POSTGRES_DB=typebot - POSTGRES_DB=typebot
- POSTGRES_PASSWORD=typebot - POSTGRES_PASSWORD=typebot
typebot_builder: builder:
depends_on: depends_on:
- typebot_db - db
build: build:
context: . context: .
args: args:
- SCOPE=builder - SCOPE=builder
ports: ports:
- '8080:3000' - '8080:3000'
extra_hosts:
- 'host.docker.internal:host-gateway'
env_file: env_file:
- typebot-config.env - './apps/builder/.env.production'
entrypoint: > entrypoint: >
/bin/sh -c " /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_modules/.bin/prisma migrate deploy;
node server.js;" node server.js;"
typebot_viewer: viewer:
depends_on: depends_on:
- typebot_db - db
restart: always restart: always
build: build:
context: . context: .
@ -35,7 +39,11 @@ services:
ports: ports:
- '8081:3000' - '8081:3000'
env_file: env_file:
- typebot-config.env - './apps/viewer/.env.production'
entrypoint: >
/bin/sh -c "
./node_modules/bin/prisma generate;
node server.js;"
volumes: volumes:
db_data: db_data:
s3_data: s3_data:

View File

@ -4,7 +4,7 @@ import path from 'path'
require('dotenv').config({ require('dotenv').config({
path: path.join( path: path.join(
__dirname, __dirname,
process.env.NODE_ENV === 'production' ? '.env.prod' : '.env.local' process.env.NODE_ENV === 'production' ? '.env.production' : '.env.local'
), ),
}) })

View File

@ -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