Skip to content

Commit 13afba7

Browse files
feat: move env vars from build-time to run-time to better support self-hosting environments (formbricks#789)
* feat: privacy, imprint, and terms URL env vars now do not need rebuilding * feat: disable_singup env var now do not need rebuilding * feat: password_reset_disabled env var now do not need rebuilding * feat: email_verification_disabled env var now do not need rebuilding * feat: github_oauth & google_oauth env var now do not need rebuilding * feat: move logic of env vars to serverside and send boolean client-side * feat: invite_disabled env var now do not need rebuilding * feat: rename vars logically * feat: migration guide * feat: update docker-compose as per v1.1 * deprecate: unused NEXT_PUBLIC_VERCEL_URL & VERCEL_URL * deprecate: unused RAILWAY_STATIC_URL * deprecate: unused RENDER_EXTERNAL_URL * deprecate: unused HEROKU_APP_NAME * fix: define WEBAPP_URL & replace NEXT_WEBAPP_URL with it * migrate: NEXT_PUBLIC_IS_FORMBRICKS_CLOUD to IS_FORMBRICKS_CLOUD * chore: move all env parsing to a constants.ts from page files * feat: migrate client side envs to server side * redo: isFormbricksCloud to navbar serverside page * fix: constants is now a server only file * fix: removal of use swr underway * fix: move 1 tag away from swr to service * feat: move away from tags swr * feat: move away from surveys swr * feat: move away from eventClass swr * feat: move away from event swr * fix: make constants server-only * remove comments from .env.example, use constants in MetaInformation * clean up services * rename tag function * fix build error * fix smaller bugs, fix Response % not working in summary --------- Co-authored-by: Matthias Nannt <[email protected]>
1 parent 3c20874 commit 13afba7

File tree

137 files changed

+1764
-1727
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+1764
-1727
lines changed

.env.docker

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# BASICS #
88
############
99

10-
NEXT_PUBLIC_WEBAPP_URL=http://localhost:3000
10+
WEBAPP_URL=http://localhost:3000
1111

1212
##############
1313
# DATABASE #
@@ -63,25 +63,25 @@ NEXTAUTH_URL=http://localhost:3000
6363
#####################
6464

6565
# Email Verification. If you enable Email Verification you have to setup SMTP-Settings, too.
66-
NEXT_PUBLIC_EMAIL_VERIFICATION_DISABLED=1
66+
EMAIL_VERIFICATION_DISABLED=1
6767

6868
# Password Reset. If you enable Password Reset functionality you have to setup SMTP-Settings, too.
69-
NEXT_PUBLIC_PASSWORD_RESET_DISABLED=1
69+
PASSWORD_RESET_DISABLED=1
7070

7171
# Signup. Disable the ability for new users to create an account.
72-
# NEXT_PUBLIC_SIGNUP_DISABLED=1
72+
# SIGNUP_DISABLED=1
7373

7474
# Team Invite. Disable the ability for invited users to create an account.
75-
# NEXT_PUBLIC_INVITE_DISABLED=1
75+
# INVITE_DISABLED=1
7676

7777
##########
7878
# Other #
7979
##########
8080

8181
# Display privacy policy, imprint and terms of service links in the footer of signup & public pages.
82-
NEXT_PUBLIC_PRIVACY_URL=
83-
NEXT_PUBLIC_TERMS_URL=
84-
NEXT_PUBLIC_IMPRINT_URL=
82+
PRIVACY_URL=
83+
TERMS_URL=
84+
IMPRINT_URL=
8585

8686
# Disable Sentry warning
8787
SENTRY_IGNORE_API_RESOLUTION_ERROR=1
@@ -90,12 +90,12 @@ SENTRY_IGNORE_API_RESOLUTION_ERROR=1
9090
NEXT_PUBLIC_SENTRY_DSN=
9191

9292
# Configure Github Login
93-
NEXT_PUBLIC_GITHUB_AUTH_ENABLED=0
93+
GITHUB_AUTH_ENABLED=0
9494
GITHUB_ID=
9595
GITHUB_SECRET=
9696

9797
# Configure Google Login
98-
NEXT_PUBLIC_GOOGLE_AUTH_ENABLED=0
98+
GOOGLE_AUTH_ENABLED=0
9999
GOOGLE_CLIENT_ID=
100100
GOOGLE_CLIENT_SECRET=
101101

.env.example

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# BASICS #
99
############
1010

11-
NEXT_PUBLIC_WEBAPP_URL=http://localhost:3000
11+
WEBAPP_URL=http://localhost:3000
1212

1313
##############
1414
# DATABASE #
@@ -20,6 +20,7 @@ DATABASE_URL='postgresql://postgres:postgres@localhost:5432/formbricks?schema=pu
2020
# Cold boots will be faster and you'll be able to scale your DB independently of your app.
2121
# @see https://www.prisma.io/docs/data-platform/data-proxy/use-data-proxy
2222
# PRISMA_GENERATE_DATAPROXY=true
23+
# i dont think we use it so ask Matti and remove it
2324
PRISMA_GENERATE_DATAPROXY=
2425

2526
###############
@@ -34,9 +35,6 @@ NEXTAUTH_SECRET=RANDOM_STRING
3435
# You do not need the NEXTAUTH_URL environment variable in Vercel.
3536
NEXTAUTH_URL=http://localhost:3000
3637

37-
# If you encounter NEXT_AUTH URL problems this should always be localhost:3000 (or whatever port your app is running on)
38-
# NEXTAUTH_URL_INTERNAL=http://localhost:3000
39-
4038
################
4139
# MAIL SETUP #
4240
################
@@ -64,33 +62,33 @@ SMTP_PASSWORD=smtpPassword
6462
#####################
6563

6664
# Email Verification. If you enable Email Verification you have to setup SMTP-Settings, too.
67-
# NEXT_PUBLIC_EMAIL_VERIFICATION_DISABLED=1
65+
# EMAIL_VERIFICATION_DISABLED=1
6866

6967
# Password Reset. If you enable Password Reset functionality you have to setup SMTP-Settings, too.
70-
# NEXT_PUBLIC_PASSWORD_RESET_DISABLED=1
68+
# PASSWORD_RESET_DISABLED=1
7169

7270
# Signup. Disable the ability for new users to create an account.
73-
# NEXT_PUBLIC_SIGNUP_DISABLED=1
71+
# SIGNUP_DISABLED=1
7472

7573
# Team Invite. Disable the ability for invited users to create an account.
76-
# NEXT_PUBLIC_INVITE_DISABLED=1
74+
# INVITE_DISABLED=1
7775

7876
##########
7977
# Other #
8078
##########
8179

8280
# Display privacy policy, imprint and terms of service links in the footer of signup & public pages.
83-
NEXT_PUBLIC_PRIVACY_URL=
84-
NEXT_PUBLIC_TERMS_URL=
85-
NEXT_PUBLIC_IMPRINT_URL=
81+
PRIVACY_URL=
82+
TERMS_URL=
83+
IMPRINT_URL=
8684

8785
# Configure Github Login
88-
NEXT_PUBLIC_GITHUB_AUTH_ENABLED=0
86+
GITHUB_AUTH_ENABLED=0
8987
GITHUB_ID=
9088
GITHUB_SECRET=
9189

9290
# Configure Google Login
93-
NEXT_PUBLIC_GOOGLE_AUTH_ENABLED=0
91+
GOOGLE_AUTH_ENABLED=0
9492
GOOGLE_CLIENT_ID=
9593
GOOGLE_CLIENT_SECRET=
9694

.gitpod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ tasks:
3232
command: |
3333
gp sync-await init &&
3434
cp .env.example .env &&
35-
sed -i -r "s#^(NEXT_PUBLIC_WEBAPP_URL=).*#\1 $(gp url 3000)#" .env &&
35+
sed -i -r "s#^(WEBAPP_URL=).*#\1 $(gp url 3000)#" .env &&
3636
sed -i -r "s#^(NEXTAUTH_URL=).*#\1 $(gp url 3000)#" .env &&
3737
turbo --filter "@formbricks/web" go
3838

apps/formbricks-com/app/docs/self-hosting/from-source/page.mdx

Lines changed: 53 additions & 56 deletions
Large diffs are not rendered by default.
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
export const meta = {
2+
title: "Migrating Formbricks to v1.1",
3+
description:
4+
"Formbricks v1.1 comes with an amazing set of features including the ability to define most environment variables at runtime itself! No need to build the image again! This guide will help you migrate your existing Formbricks instance to v1.1",
5+
};
6+
7+
#### Self-Hosting
8+
9+
# Migrating to v1.1
10+
11+
Formbricks v1.1 includes a lot of new features and improvements. However, it also comes with a few breaking changes specifically with the environment variables. This guide will help you migrate your existing Formbricks instance to v1.1 without losing any data.
12+
13+
## Changes in .env
14+
15+
### Renamed Environment Variables
16+
This was introduced because we got a lot of requests from our users for the ability to define some common environment variables at runtime itself i.e. without having to rebuild the image for the changes to take effect.
17+
This is now possible with v1.1. However, due to Next.JS best practices, we had to deprecate the prefix **NEXT_PUBLIC_** in the following environment variables:
18+
19+
| till v1.0 | v1.1 |
20+
| ------------------------------------------- | --------------------------- |
21+
| **NEXT_PUBLIC_**EMAIL_VERIFICATION_DISABLED | EMAIL_VERIFICATION_DISABLED |
22+
| **NEXT_PUBLIC_**PASSWORD_RESET_DISABLED | PASSWORD_RESET_DISABLED |
23+
| **NEXT_PUBLIC_**SIGNUP_DISABLED | SIGNUP_DISABLED |
24+
| **NEXT_PUBLIC_**INVITE_DISABLED | INVITE_DISABLED |
25+
| **NEXT_PUBLIC_**PRIVACY_URL | PRIVACY_URL |
26+
| **NEXT_PUBLIC_**TERMS_URL | TERMS_URL |
27+
| **NEXT_PUBLIC_**IMPRINT_URL | IMPRINT_URL |
28+
| **NEXT_PUBLIC_**GITHUB_AUTH_ENABLED | GITHUB_AUTH_ENABLED |
29+
| **NEXT_PUBLIC_**GOOGLE_AUTH_ENABLED | GOOGLE_AUTH_ENABLED |
30+
| **NEXT_PUBLIC_**WEBAPP_URL | WEBAPP_URL |
31+
| **NEXT_PUBLIC_**IS_FORMBRICKS_CLOUD | IS_FORMBRICKS_CLOUD |
32+
| **NEXT_PUBLIC_**SURVEY_BASE_URL | SURVEY_BASE_URL |
33+
34+
<Note>
35+
Please note that their values and the logic remains exactly the same. Only the prefix has been deprecated. The other environment variables remain the same as well.
36+
</Note>
37+
38+
### Deprecated Environment Variables
39+
40+
- **NEXT_PUBLIC_VERCEL_URL**: Was used as Vercel URL (used instead of WEBAPP_URL), but from v1.1, you can just set the WEBAPP_URL environment variable to your Vercel URL.
41+
- **RAILWAY_STATIC_URL**: Was used as Railway Static URL (used instead of WEBAPP_URL), but from v1.1, you can just set the WEBAPP_URL environment variable.
42+
- **RENDER_EXTERNAL_URL**: Was used as an external URL to Render (used instead of WEBAPP_URL), but from v1.1, you can just set the WEBAPP_URL environment variable.
43+
- **HEROKU_APP_NAME**: Was used to build the App name on a Heroku hosted webapp, but from v1.1, you can just set the WEBAPP_URL environment variable.
44+
- **NEXT_PUBLIC_WEBAPP_URL**: Was used for the same purpose as WEBAPP_URL, but from v1.1, you can just set the WEBAPP_URL environment variable.
45+
- **PRISMA_GENERATE_DATAPROXY**: Was used to tell Prisma that it should generate the runtime for Dataproxy usage. But its officially deprecated now.
46+
47+
## Helper Shell Script
48+
For a seamless migration, below is a shell script for your self-hosted instance that will automatically update your environment variables to be compliant with the new naming conventions.
49+
50+
### Building From Source
51+
The below script will:
52+
1. Create a backup of your existing .env file as `.env.old`
53+
2. Update the .env file to be compliant with the new naming conventions
54+
55+
<CodeGroup title="Run the below in your terminal in the directory of your .env">
56+
```shell {{ title: '.env file' }}
57+
for var in NEXT_PUBLIC_EMAIL_VERIFICATION_DISABLED NEXT_PUBLIC_PASSWORD_RESET_DISABLED NEXT_PUBLIC_SIGNUP_DISABLED NEXT_PUBLIC_INVITE_DISABLED NEXT_PUBLIC_PRIVACY_URL NEXT_PUBLIC_TERMS_URL NEXT_PUBLIC_IMPRINT_URL NEXT_PUBLIC_GITHUB_AUTH_ENABLED NEXT_PUBLIC_GOOGLE_AUTH_ENABLED NEXT_PUBLIC_WEBAPP_URL NEXT_PUBLIC_IS_FORMBRICKS_CLOUD NEXT_PUBLIC_SURVEY_BASE_URL; do sed -i.old "s/^$var=/$(echo $var | sed 's/NEXT_PUBLIC_//')=/" .env; done; echo "Formbricks environment variables have been migrated as per v1.1! You are good to go."
58+
```
59+
</CodeGroup>
60+
61+
62+
### Docker & Single Script Setup
63+
64+
Now that these variables can be defined at runtime, you can append them inside your `x-environment` in the `docker-compose.yml` itself.
65+
For a more detailed guide on these environment variables, please refer to the [Important Runtime Variables](/docs/self-hosting/from-source#important-run-time-variables) section.
66+
67+
<CodeGroup title="docker-compose.yml">
68+
```yaml {{ title: 'docker-compose.yml' }}
69+
version: "3.3"
70+
x-environment: &environment
71+
environment:
72+
# The url of your Formbricks instance used in the admin panel
73+
WEBAPP_URL:
74+
75+
# PostgreSQL DB for Formbricks to connect to
76+
DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/formbricks?schema=public"
77+
78+
# Uncomment to enable a dedicated connection pool for Prisma using Prisma Data Proxy
79+
# Cold boots will be faster and you'll be able to scale your DB independently of your app.
80+
# @see https://www.prisma.io/docs/data-platform/data-proxy/use-data-proxy
81+
# PRISMA_GENERATE_DATAPROXY=true
82+
PRISMA_GENERATE_DATAPROXY:
83+
84+
# NextJS Auth
85+
# @see: https://next-auth.js.org/configuration/options#nextauth_secret
86+
# You can use: `openssl rand -base64 32` to generate one
87+
NEXTAUTH_SECRET:
88+
89+
# Set this to your public-facing URL, e.g., https://example.com
90+
# You do not need the NEXTAUTH_URL environment variable in Vercel.
91+
NEXTAUTH_URL: http://localhost:3000
92+
93+
# PostgreSQL password
94+
POSTGRES_PASSWORD: postgres
95+
96+
# Email Configuration
97+
MAIL_FROM:
98+
SMTP_HOST:
99+
SMTP_PORT:
100+
SMTP_SECURE_ENABLED:
101+
SMTP_USER:
102+
SMTP_PASSWORD:
103+
104+
# Uncomment the below and set it to 1 to disable Email Verification for new signups
105+
# EMAIL_VERIFICATION_DISABLED:
106+
107+
# Uncomment the below and set it to 1 to disable Password Reset
108+
# PASSWORD_RESET_DISABLED:
109+
110+
# Uncomment the below and set it to 1 to disable Signups
111+
# SIGNUP_DISABLED:
112+
113+
# Uncomment the below and set it to 1 to disable Invites
114+
# INVITE_DISABLED:
115+
116+
# Uncomment the below and set a value to have your own Privacy Page URL on the signup & login page
117+
# PRIVACY_URL:
118+
119+
# Uncomment the below and set a value to have your own Terms Page URL on the auth and the surveys page
120+
# TERMS_URL:
121+
122+
# Uncomment the below and set a value to have your own Imprint Page URL on the auth and the surveys page
123+
# IMPRINT_URL:
124+
125+
# Uncomment the below and set to 1 if you want to enable GitHub OAuth
126+
# GITHUB_AUTH_ENABLED:
127+
# GITHUB_ID:
128+
# GITHUB_SECRET:
129+
130+
# Uncomment the below and set to 1 if you want to enable Google OAuth
131+
# GOOGLE_AUTH_ENABLED:
132+
# GOOGLE_CLIENT_ID:
133+
# GOOGLE_CLIENT_SECRET:
134+
135+
```
136+
</CodeGroup>
137+
138+
Did we miss something? Are you still facing issues migrating your app? [Join our Discord!](https://formbricks.com/discord) We'd be happy to help!

apps/formbricks-com/components/docs/Navigation.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ export const navigation: Array<NavGroup> = [
246246
{ title: "Production", href: "/docs/self-hosting/production" },
247247
{ title: "Docker", href: "/docs/self-hosting/docker" },
248248
{ title: "From Source", href: "/docs/self-hosting/from-source" },
249+
{ title: "Migration to v1.1", href: "/docs/self-hosting/migrating-to-1.1" },
249250
],
250251
},
251252
{

apps/web/app/(app)/environments/[environmentId]/(actionsAndAttributes)/ActionsAttributesTabs.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ export default function ActionsAttributesTabs({ activeId, environmentId }: Actio
2222
},
2323
];
2424

25-
return <SecondNavbar tabs={tabs} activeId={activeId} />;
25+
return <SecondNavbar tabs={tabs} activeId={activeId} environmentId={environmentId} />;
2626
}

0 commit comments

Comments
 (0)