diff --git a/.env.docker b/.env.docker deleted file mode 100644 index ba19223174..0000000000 --- a/.env.docker +++ /dev/null @@ -1,107 +0,0 @@ -######################################################################## -# ------------ MANDATORY (CHANGE ACCORDING TO YOUR SETUP) ------------# -######################################################################## - - -############ -# BASICS # -############ - -WEBAPP_URL=http://localhost:3000 - -############## -# DATABASE # -############## - -DATABASE_URL='postgresql://postgres:postgres@postgres:5432/formbricks?schema=public' - -# Uncomment to enable a dedicated connection pool for Prisma using Prisma Data Proxy -# Cold boots will be faster and you'll be able to scale your DB independently of your app. -# @see https://www.prisma.io/docs/data-platform/data-proxy/use-data-proxy -# PRISMA_GENERATE_DATAPROXY=true -PRISMA_GENERATE_DATAPROXY= - -############### -# NEXT AUTH # -############### - -# @see: https://next-auth.js.org/configuration/options#nextauth_secret -# You can use: `openssl rand -base64 32` to generate one -NEXTAUTH_SECRET=RANDOM_STRING - -# Set this to your public-facing URL, e.g., https://example.com -# You do not need the NEXTAUTH_URL environment variable in Vercel. -NEXTAUTH_URL=http://localhost:3000 - -# If you encounter NEXT_AUTH URL problems this should always be localhost:3000 (or whatever port your app is running on) -# NEXTAUTH_URL_INTERNAL=http://localhost:3000 - -################ -# MAIL SETUP # -################ - -# Necessary if email verification and password reset are enabled. -# See optional configurations below if you want to disable these features. - -# MAIL_FROM=noreply@example.com -# SMTP_HOST=localhost -# SMTP_PORT=1025 -# Enable SMTP_SECURE_ENABLED for TLS (port 465) -# SMTP_SECURE_ENABLED=0 -# SMTP_USER=smtpUser -# SMTP_PASSWORD=smtpPassword - - -######################################################################## -# ------------------------------ OPTIONAL -----------------------------# -######################################################################## - -# Uncomment the variables you would like to use and customize the values. - -##################### -# Disable Features # -##################### - -# Email Verification. If you enable Email Verification you have to setup SMTP-Settings, too. -EMAIL_VERIFICATION_DISABLED=1 - -# Password Reset. If you enable Password Reset functionality you have to setup SMTP-Settings, too. -PASSWORD_RESET_DISABLED=1 - -# Signup. Disable the ability for new users to create an account. -# SIGNUP_DISABLED=1 - -# Team Invite. Disable the ability for invited users to create an account. -# INVITE_DISABLED=1 - -########## -# Other # -########## - -# Display privacy policy, imprint and terms of service links in the footer of signup & public pages. -PRIVACY_URL= -TERMS_URL= -IMPRINT_URL= - -# Disable Sentry warning -SENTRY_IGNORE_API_RESOLUTION_ERROR=1 - -# Enable Sentry Error Tracking -NEXT_PUBLIC_SENTRY_DSN= - -# Configure Github Login -GITHUB_AUTH_ENABLED=0 -GITHUB_ID= -GITHUB_SECRET= - -# Configure Google Login -GOOGLE_AUTH_ENABLED=0 -GOOGLE_CLIENT_ID= -GOOGLE_CLIENT_SECRET= - -# Cron Secret -CRON_SECRET= - -# Encryption key -# You can use: `openssl rand -base64 16` to generate one -FORMBRICKS_ENCRYPTION_KEY= \ No newline at end of file diff --git a/.env.example b/.env.example index b90eb507c6..808deb2939 100644 --- a/.env.example +++ b/.env.example @@ -10,7 +10,10 @@ WEBAPP_URL=http://localhost:3000 -SHORT_SURVEY_BASE_URL=http://localhost:3000/i +SURVEY_BASE_URL=http://localhost:3000/i + +# Set this if you want to have a shorter link for surveys +SHORT_SURVEY_BASE_URL= ############## # DATABASE # @@ -18,13 +21,6 @@ SHORT_SURVEY_BASE_URL=http://localhost:3000/i DATABASE_URL='postgresql://postgres:postgres@localhost:5432/formbricks?schema=public' -# Uncomment to enable a dedicated connection pool for Prisma using Prisma Data Proxy -# Cold boots will be faster and you'll be able to scale your DB independently of your app. -# @see https://www.prisma.io/docs/data-platform/data-proxy/use-data-proxy -# PRISMA_GENERATE_DATAPROXY=true -# i dont think we use it so ask Matti and remove it -PRISMA_GENERATE_DATAPROXY= - ############### # NEXT AUTH # ############### @@ -94,6 +90,15 @@ GOOGLE_AUTH_ENABLED=0 GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET= +# Cron Secret +CRON_SECRET= + +# Encryption key +# You can use: `openssl rand -base64 16` to generate one +FORMBRICKS_ENCRYPTION_KEY= + +# Configure this when you want to ship JS & CSS files from a complete URL instead of the current domain +# ASSET_PREFIX_URL= # Stripe Billing Variables STRIPE_SECRET_KEY= @@ -104,12 +109,4 @@ NEXT_PUBLIC_FORMBRICKS_API_HOST= NEXT_PUBLIC_FORMBRICKS_ENVIRONMENT_ID= NEXT_PUBLIC_FORMBRICKS_ONBOARDING_SURVEY_ID= -# Cron Secret -CRON_SECRET= - -# Encryption key -# You can use: `openssl rand -base64 16` to generate one -FORMBRICKS_ENCRYPTION_KEY= - -SHORT_SURVEY_BASE_URL= -*/ +*/ diff --git a/apps/formbricks-com/app/docs/self-hosting/docker/page.mdx b/apps/formbricks-com/app/docs/self-hosting/docker/page.mdx index 0ec213a9f3..8c51e7f3ee 100644 --- a/apps/formbricks-com/app/docs/self-hosting/docker/page.mdx +++ b/apps/formbricks-com/app/docs/self-hosting/docker/page.mdx @@ -61,10 +61,12 @@ Ensure `docker` & `docker compose` are installed on your server/system. Both are You're now ready to start the Formbricks Docker setup. The following command will start Formbricks together with a postgreSQL database using Docker Compose: + We pass the `--env-file /dev/null` flag to docker-compose to prevent it from reading the .env file. This is because we're using environment variables directly in the docker-compose.yml file as the env file is currently in a format not well recognised by docker systems. + ```bash - docker compose up -d + docker compose --env-file /dev/null up -d ``` @@ -103,7 +105,7 @@ Ensure `docker` & `docker compose` are installed on your server/system. Both are ```bash - docker compose up -d + docker compose --env-file /dev/null up -d ``` diff --git a/apps/formbricks-com/app/docs/self-hosting/from-source/page.mdx b/apps/formbricks-com/app/docs/self-hosting/from-source/page.mdx index f6209619e7..c306c28d31 100644 --- a/apps/formbricks-com/app/docs/self-hosting/from-source/page.mdx +++ b/apps/formbricks-com/app/docs/self-hosting/from-source/page.mdx @@ -29,7 +29,7 @@ Ensure `docker` & `docker compose` are installed on your server/system. Both are -2. **Modify the `.env.docker` file as required by your setup.**
This file comes with a basic setup and Formbricks works without making any changes to the file. To enable email sending functionality you need to configure the SMTP settings. If you configured your email credentials, you can also comment the following lines to enable email verification (`# EMAIL_VERIFICATION_DISABLED=1`) and password reset (`# PASSWORD_RESET_DISABLED=1`) +2. **Modify the environment variables in your `docker-compose.yml` file as required by your setup.**
This file comes with a basic setup and Formbricks works without making any changes to the file. To enable email sending functionality you need to configure the SMTP settings. If you configured your email credentials, you can also comment the following lines to enable email verification (`# NEXT_PUBLIC_EMAIL_VERIFICATION_DISABLED=1`) and password reset (`# NEXT_PUBLIC_PASSWORD_RESET_DISABLED=1`) ## Editing a NEXT_PUBLIC_* variable? @@ -38,12 +38,26 @@ Ensure `docker` & `docker compose` are installed on your server/system. Both are to take effect. -3. **Start the docker compose process.**
Finally start the docker compose process to build and spin up the Formbricks container as well as the PostgreSQL database.
_Use docker-compose if you are on an older docker version_ +3. **Generate NextAuth Secret** + + Next, you need to generate a NextAuth secret. This will be used for session signing and encryption. The `sed` command below generates a random string using `openssl`, then replaces the `NEXTAUTH_SECRET:` placeholder in the `docker-compose.yml` file with this generated secret: + + + + ```bash + sed -i "/x-nextauth-secret: &nextauth_secret/s/RANDOM_STRING/$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | head -c 32)/" docker-compose.yml + ``` + + + +4. **Start the docker compose process.**
Finally start the docker compose process to build and spin up the Formbricks container as well as the PostgreSQL database.
_Use docker-compose if you are on an older docker version_ + + We pass the `--env-file /dev/null` flag to docker-compose to prevent it from reading the .env file. This is because we're using environment variables directly in the docker-compose.yml file as the env file is currently in a format not well recognised by docker systems. ```bash - docker compose up -d + docker compose --env-file /dev/null up ``` @@ -59,7 +73,6 @@ These variables must also be provided at runtime. | WEBAPP_URL | Base URL of the site. | required | `http://localhost:3000` | | SURVEY_BASE_URL | Base URL of the link surveys. | required | `http://localhost:3000/s/` | | DATABASE_URL | Database URL with credentials. | required | `postgresql://postgres:postgres@postgres:5432/formbricks?schema=public` | -| PRISMA_GENERATE_DATAPROXY | Enables a dedicated connection pool for Prisma using Prisma Data Proxy. Uncomment to enable. | optional | | | NEXTAUTH_SECRET | Secret for NextAuth, used for session signing and encryption. | required | (Generated by the user) | | NEXTAUTH_URL | Location of the auth server. By default, this is the Formbricks docker instance itself. | required | `http://localhost:3000` | | PRIVACY_URL | URL for privacy policy. | optional | | diff --git a/apps/formbricks-com/app/docs/self-hosting/migrating-to-1.1/page.mdx b/apps/formbricks-com/app/docs/self-hosting/migrating-to-1.1/page.mdx index 7d3ab4f1b2..d17cbca6e8 100644 --- a/apps/formbricks-com/app/docs/self-hosting/migrating-to-1.1/page.mdx +++ b/apps/formbricks-com/app/docs/self-hosting/migrating-to-1.1/page.mdx @@ -75,12 +75,6 @@ x-environment: &environment # PostgreSQL DB for Formbricks to connect to DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/formbricks?schema=public" - # Uncomment to enable a dedicated connection pool for Prisma using Prisma Data Proxy - # Cold boots will be faster and you'll be able to scale your DB independently of your app. - # @see https://www.prisma.io/docs/data-platform/data-proxy/use-data-proxy - # PRISMA_GENERATE_DATAPROXY=true - PRISMA_GENERATE_DATAPROXY: - # NextJS Auth # @see: https://next-auth.js.org/configuration/options#nextauth_secret # You can use: `openssl rand -base64 32` to generate one diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile index 131bfe5631..95bd1168d1 100644 --- a/apps/web/Dockerfile +++ b/apps/web/Dockerfile @@ -1,11 +1,17 @@ FROM node:18-alpine AS installer RUN corepack enable && corepack prepare pnpm@latest --activate +ARG DATABASE_URL +ENV DATABASE_URL=$DATABASE_URL + +ARG NEXTAUTH_SECRET +ENV NEXTAUTH_SECRET=$NEXTAUTH_SECRET + WORKDIR /app COPY . . -# Copy .env file because Docker don't follow symlinks -COPY .env.docker /app/apps/web/.env +RUN touch /app/apps/web/.env + RUN pnpm install @@ -34,13 +40,13 @@ COPY --from=installer --chown=nextjs:nodejs /app/apps/web/public ./apps/web/publ COPY --from=installer --chown=nextjs:nodejs /app/packages/database/schema.prisma ./packages/database/schema.prisma COPY --from=installer --chown=nextjs:nodejs /app/packages/database/migrations ./packages/database/migrations -ENV NEXTAUTH_SECRET=$NEXTAUTH_SECRET - EXPOSE 3000 +ENV HOSTNAME "0.0.0.0" + CMD if [ "$NEXTAUTH_SECRET" != "RANDOM_STRING" ]; then \ pnpm dlx prisma migrate deploy && node apps/web/server.js; \ else \ - echo "ERROR: Please set a value for NEXTAUTH_SECRET in .env.docker!"; \ + echo "ERROR: Please set a value for NEXTAUTH_SECRET in your docker compose variables!"; \ exit 1; \ fi diff --git a/apps/web/env.mjs b/apps/web/env.mjs index 6ff26d2c87..bed57c7429 100644 --- a/apps/web/env.mjs +++ b/apps/web/env.mjs @@ -9,7 +9,6 @@ export const env = createEnv({ server: { WEBAPP_URL: z.string().url().optional(), DATABASE_URL: z.string().url(), - PRISMA_GENERATE_DATAPROXY: z.enum(["true", ""]).optional(), NEXTAUTH_SECRET: z.string().min(1), NEXTAUTH_URL: z.string().url().optional(), MAIL_FROM: z.string().email().optional(), @@ -82,7 +81,6 @@ export const env = createEnv({ runtimeEnv: { WEBAPP_URL: process.env.WEBAPP_URL, DATABASE_URL: process.env.DATABASE_URL, - PRISMA_GENERATE_DATAPROXY: process.env.PRISMA_GENERATE_DATAPROXY, NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET, NEXTAUTH_URL: process.env.NEXTAUTH_URL, MAIL_FROM: process.env.MAIL_FROM, diff --git a/docker-compose.yml b/docker-compose.yml index 7136ede5ce..b15febe476 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,83 @@ version: "3.3" + +# If you already have a local .env then please run this using +# docker compose --env-file /dev/null up + +# This should be the same as below if you are running via docker compose up +x-webapp-url: &webapp_url http://localhost:3000 + +# PostgreSQL DB for Formbricks to connect to +x-database-url: &database_url postgresql://postgres:postgres@postgres:5432/formbricks?schema=public + +# NextJS Auth +# @see: https://next-auth.js.org/configuration/options#nextauth_secret +# You can use: `openssl rand -base64 32` to generate one +x-nextauth-secret: &nextauth_secret luJthrnoDpVgGakjVYlccsZ1FdlwxIWogWIsrxzoQ6E= + +# Set this to your public-facing URL, e.g., https://example.com +# You do not need the NEXTAUTH_URL environment variable in Vercel. +x-nextauth-url: &nextauth_url http://localhost:3000 + +# Encryption key +# You can use: `openssl rand -base64 16` to generate one +x-formbricks-encryption-key: &formbricks_encryption_key + +# Necessary if email verification and password reset are enabled. +# See further below if you want to disable these features. +x-mail-from: &mail_from +x-smtp-host: &smtp_host +x-smtp-port: &smtp_port +# Enable SMTP_SECURE_ENABLED for TLS (port 465) +x-smtp-secure-enabled: &smtp_secure_enabled +x-smtp-user: &smtp_user +x-smtp-password: &smtp_password + +# Set the below value to your public-facing URL, e.g., https://example.com +x-survey-base-url: &survey_base_url http://localhost:3000/s + +# Set the below value if you have and want to share a shorter base URL than the x-survey-base-url +x-short-survey-base-url: &short_survey_base_url + +# Email Verification. If you enable Email Verification you have to setup SMTP-Settings, too. +x-email-verification-disabled: &email_verification_disabled 1 + +# Password Reset. If you enable Password Reset functionality you have to setup SMTP-Settings, too. +x-password-reset-disabled: &password_reset_disabled 1 + +# Signup. Disable the ability for new users to create an account. +x-signup-disabled: &signup_disabled 0 + +# Team Invite. Disable the ability for invited users to create an account. +x-invite-disabled: &invite_disabled 0 + +# Set the below values to display privacy policy, imprint and terms of service links in the footer of signup & public pages. +x-privacy-url: &privacy_url +x-terms-url: &terms_url +x-imprint-url: &imprint_url + + +# Configure Github Login +x-github-auth-enabled: &github_auth_enabled 0 +x-github-id: &github_id +x-github-secret: &github_secret + +# Configure Google Login +x-google-auth-enabled: &google_auth_enabled 0 +x-google-client-id: &google_client_id +x-google-client-secret: &google_client_secret + +# Disable Sentry warning +x-sentry-ignore-api-resolution-error: &sentry_ignore_api_resolution_error + +# Enable Sentry Error Tracking +x-next-public-sentry-dsn: &next_public_sentry_dsn + +# Cron Secret +x-cron-secret: &cron_secret + +# Configure ASSET_PREFIX_URL when you want to ship JS & CSS files from a complete URL instead of the current domain +x-asset-prefix-url: &asset_prefix_url + services: postgres: restart: always @@ -13,13 +92,47 @@ services: build: context: . dockerfile: ./apps/web/Dockerfile + args: + DATABASE_URL: *database_url + NEXTAUTH_SECRET: *nextauth_secret + depends_on: - postgres - env_file: - - .env.docker ports: - 3000:3000 + environment: + WEBAPP_URL: *webapp_url + DATABASE_URL: *database_url + NEXTAUTH_SECRET: *nextauth_secret + NEXTAUTH_URL: *nextauth_url + MAIL_FROM: *mail_from + SMTP_HOST: *smtp_host + SMTP_PORT: *smtp_port + SMTP_SECURE_ENABLED: *smtp_secure_enabled + SMTP_USER: *smtp_user + SMTP_PASSWORD: *smtp_password + FORMBRICKS_ENCRYPTION_KEY: *formbricks_encryption_key + SURVEY_BASE_URL: *survey_base_url + SHORT_SURVEY_BASE_URL: *short_survey_base_url + PRIVACY_URL: *privacy_url + TERMS_URL: *terms_url + IMPRINT_URL: *imprint_url + EMAIL_VERIFICATION_DISABLED: *email_verification_disabled + PASSWORD_RESET_DISABLED: *password_reset_disabled + SIGNUP_DISABLED: *signup_disabled + INVITE_DISABLED: *invite_disabled + SENTRY_IGNORE_API_RESOLUTION_ERROR: *sentry_ignore_api_resolution_error + NEXT_PUBLIC_SENTRY_DSN: *next_public_sentry_dsn + GITHUB_AUTH_ENABLED: *github_auth_enabled + GITHUB_ID: *github_id + GITHUB_SECRET: *github_secret + GOOGLE_AUTH_ENABLED: *google_auth_enabled + GOOGLE_CLIENT_ID: *google_client_id + GOOGLE_CLIENT_SECRET: *google_client_secret + CRON_SECRET: *cron_secret + ASSET_PREFIX_URL: *asset_prefix_url + volumes: postgres: driver: local diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index f71b963e33..ffd26180b4 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -7,12 +7,6 @@ x-environment: &environment # PostgreSQL DB for Formbricks to connect to DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/formbricks?schema=public" - # Uncomment to enable a dedicated connection pool for Prisma using Prisma Data Proxy - # Cold boots will be faster and you'll be able to scale your DB independently of your app. - # @see https://www.prisma.io/docs/data-platform/data-proxy/use-data-proxy - # PRISMA_GENERATE_DATAPROXY=true - PRISMA_GENERATE_DATAPROXY: - # NextJS Auth # @see: https://next-auth.js.org/configuration/options#nextauth_secret # You can use: `openssl rand -base64 32` to generate one diff --git a/docker/production.sh b/docker/production.sh index 4b4ff0e604..9387b34f22 100644 --- a/docker/production.sh +++ b/docker/production.sh @@ -161,12 +161,6 @@ x-environment: &environment # PostgreSQL DB for Formbricks to connect to DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/formbricks?schema=public" - # Uncomment to enable a dedicated connection pool for Prisma using Prisma Data Proxy - # Cold boots will be faster and you'll be able to scale your DB independently of your app. - # @see https://www.prisma.io/docs/data-platform/data-proxy/use-data-proxy - # PRISMA_GENERATE_DATAPROXY: true - PRISMA_GENERATE_DATAPROXY: - # NextJS Auth # @see: https://next-auth.js.org/configuration/options#nextauth_secret # You can use: $(openssl rand -base64 32) to generate one @@ -182,6 +176,47 @@ x-environment: &environment # Email configuration $email_config + # Set the below value if you want to have another base URL apart from your Domain Name + # SURVEY_BASE_URL: + + # Set the below value if you have and want to use a custom URL for the links created by the Link Shortener + # SHORT_SURVEY_BASE_URL: + + # Uncomment the below and set it to 1 to disable Email Verification for new signups + # EMAIL_VERIFICATION_DISABLED: + + # Uncomment the below and set it to 1 to disable Password Reset + # PASSWORD_RESET_DISABLED: + + # Uncomment the below and set it to 1 to disable Signups + # SIGNUP_DISABLED: + + # Uncomment the below and set it to 1 to disable Invites + # INVITE_DISABLED: + + # Uncomment the below and set a value to have your own Privacy Page URL on the signup & login page + # PRIVACY_URL: + + # Uncomment the below and set a value to have your own Terms Page URL on the auth and the surveys page + # TERMS_URL: + + # Uncomment the below and set a value to have your own Imprint Page URL on the auth and the surveys page + # IMPRINT_URL: + + # Uncomment the below and set to 1 if you want to enable GitHub OAuth + # GITHUB_AUTH_ENABLED: + # GITHUB_ID: + # GITHUB_SECRET: + + # Uncomment the below and set to 1 if you want to enable Google OAuth + # GOOGLE_AUTH_ENABLED: + # GOOGLE_CLIENT_ID: + # GOOGLE_CLIENT_SECRET: + + # Configure ASSET_PREFIX_URL when you want to ship JS & CSS files from a complete URL instead of the current domain + # ASSET_PREFIX_URL: *asset_prefix_url + + services: postgres: restart: always @@ -228,7 +263,9 @@ echo "🚗 NEXTAUTH_SECRET updated successfully!" newgrp docker <