Skip to content

Commit

Permalink
fix: next.js harcode frontend env variables during the build so we ha…
Browse files Browse the repository at this point in the history
…d to set up one of the possible workarounds
  • Loading branch information
sneko committed Feb 22, 2024
1 parent 4ea16d4 commit 3a3770c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ jobs:
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
SENTRY_RELEASE_UPLOAD: true
# [WORKAROUND] When building Next.js in a standalone mode the frontend `NEXT_PUBLIC_*` environement variables are hardcoded
# So they are not switchable at runtime. Since ours won't change overtime, we are fine to retrigger a build in needed
# but it would be painful for someone reusing directly the Docker image. Some workarounds exist but they are by far too hacky, see:
# - https://github.com/vercel/next.js/discussions/17641
# - https://phase.dev/blog/nextjs-public-runtime-variables/
# - https://www.tomoliver.net/posts/nextjs-docker-public-env-vars
NEXT_PUBLIC_APP_BASE_URL: ${{ secrets.NEXT_PUBLIC_APP_BASE_URL }}
NEXT_PUBLIC_CRISP_WEBSITE_ID: ${{ secrets.NEXT_PUBLIC_CRISP_WEBSITE_ID }}
NEXT_PUBLIC_MATOMO_SITE_ID: ${{ secrets.NEXT_PUBLIC_MATOMO_SITE_ID }}
NEXT_PUBLIC_MATOMO_URL: ${{ secrets.NEXT_PUBLIC_MATOMO_URL }}
NEXT_PUBLIC_SENTRY_DSN: ${{ secrets.NEXT_PUBLIC_SENTRY_DSN }}
run: make build

- name: Test end-to-end
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ The following ones must be repository secrets (not environment ones):
- `SENTRY_ORG`: [SECRET]
- `SENTRY_PROJECT`: [SECRET]

**IMPORTANT: When building Next.js in a standalone mode the frontend `NEXT_PUBLIC_*` environement variables are hardcoded. It means you have to set all of them here too. This is a workaround but we have no simple other choice as of today. For more information have a look at the build step comment into `.github/workflows/ci.yml`.**

#### Default branch

The default branch is `main`.
Expand Down Expand Up @@ -198,6 +200,8 @@ For each build and runtime (since they are shared), you should have set some env
- `NEXT_PUBLIC_MATOMO_SITE_ID`: [GENERATED] _(format `https://xxx.yyy.zzz/`)_
- `MISTRAL_API_KEY`: [SECRET] _(you can create an API key from your MistralAI "La plateforme" account)_

**IMPORTANT: When building Next.js in a standalone mode the frontend `NEXT_PUBLIC_*` environement variables are hardcoded. It means you have to set them into the build environment too. For more information have a look at the build step comment into `.github/workflows/ci.yml`.**

_Note: `OPENAI_API_KEY` variable can be found in the code even if not used in production. It remains for comparing purposes, but also as a legacy since the proof of concept of Établi was based on GPT models._

#### Monitoring
Expand Down

0 comments on commit 3a3770c

Please sign in to comment.