baptisteArno / typebot.io

💬 Typebot is a powerful chatbot builder that you can self-host.
https://typebot.io
Other
6.98k stars 1.91k forks source link

Docker swarm docker-compose.yml with viewer replication #1689

Open PowerBootWS opened 1 month ago

PowerBootWS commented 1 month ago

I'm not overly skilled at contributing on Github and don't want to make a mess of things, so I'll add this here.

I modified the default docker-compose.yml stack to facilitate deployment on docker swarm using 'docker stack deploy' with replication and rolling updates. It works beautifully when installed on both the docker CLI or Portainer stack. Feel free to add to the repo or share if desired.


# This version was deployed as a STACK in Portainer and therefore does not reference an external .env file.
# If deploying from the docker CLI, be sure to reference the .env file as noted. External ports have been commented out as 
# this version is deployed behind a Cloudflare Tunnel.  See comments.
# Using docker CLI, deploy with: docker stack deploy -c docker-compose.yml typebot

volumes:
  db-data:

services:
  typebot-db:
    image: postgres:14-alpine
    restart: always
    volumes:
      - db-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=typebot
      - POSTGRES_PASSWORD=typebot
    networks:
      - default

  typebot-builder:
    image: baptistearno/typebot-builder:latest
    restart: always
    depends_on:
      - typebot-db
    # Uncomment the ports section if exposing externally using a loadbalancer or ingress such as nginx, traefik, etc.
  #   ports:
  #     - '8080:3000'
    deploy:
      placement:
        constraints:
          - node.role == manager
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    # If using an external .env file (deploying from CLI), comment out the next section and uncomment the env_file reference after it.
    environment:
      ENCRYPTION_SECRET: ${ENCRYPTION_SECRET}
      DATABASE_URL: postgresql://postgres:typebot@typebot-db:5432/typebot
      NEXTAUTH_URL: ${NEXTAUTH_URL}
      NEXT_PUBLIC_VIEWER_URL: ${NEXT_PUBLIC_VIEWER_URL}
      ADMIN_EMAIL: ${ADMIN_EMAIL}
      DISABLE_SIGNUP: 'true'
      DEFAULT_WORKSPACE_PLAN: 'UNLIMITED'
      NEXT_PUBLIC_BOT_FILE_UPLOAD_MAX_SIZE: 5
      SMTP_USERNAME: ${SMTP_USERNAME}
      SMTP_PASSWORD: ${SMTP_PASSWORD}
      SMTP_HOST: ${SMTP_HOST}
      SMTP_PORT: ${SMTP_PORT}
      NEXT_PUBLIC_SMTP_FROM: ${NEXT_PUBLIC_SMTP_FROM}
    #   env_file: .env
    networks:
      - default
      # Remove the following if using a different loadbalancer or ingress method
      - cloudflaretunnel

  typebot-viewer:
    image: baptistearno/typebot-viewer:latest
    restart: always
    # Uncomment the ports section if exposing externally using a loadbalancer or ingress such as nginx, traefik, etc.
    #   ports:
    #     - '8081:3000'
    deploy:
      placement:
        constraints:
          - node.role == worker
      replicas: 3 # Set desired number of viewers (workers)
      resources:
        limits:
          cpus: '.1'
          memory: 100m
      update_config:
        parallelism: 1
        delay: 10s
        order: start-first
      restart_policy:
        condition: any
    # If using an external .env file (deploying from CLI), comment out the next section and uncomment the env_file reference after it.
    environment:
      ENCRYPTION_SECRET: ${ENCRYPTION_SECRET}
      DATABASE_URL: postgresql://postgres:typebot@typebot-db:5432/typebot
      NEXT_PUBLIC_VIEWER_URL: ${NEXT_PUBLIC_VIEWER_URL}
    # env_file: .env
    networks:
      - default
      # Remove the following if using a different loadbalancer or ingress method
      - cloudflaretunnel

networks:
  default:
  # Remove the following if using a different loadbalancer or ingress method
  cloudflaretunnel:
    external: true
PowerBootWS commented 1 month ago

Error occurred in db connection. Disregard. I will update when resolved.