Next.js Discord

Discord Forum

How to handle docker image promotion with Nextjs and Dotenv?

Unanswered
Giant panda posted this in #help-forum
Open in Discord
Avatar
Giant pandaOP
Hello,
I am facing an issue I cannot find a solution for.
I am trying to build an image once and reuse it in different steps of a CD pipeline.
The idea is that an image gets built and deployed to staging using a dockerfile. When a given commit is tagged in GH, the image will be promoted from staging to production.
I am using dotenv, which injects an api url into my app.
The problem:
If an image gets built using the staging dotenv env key, then the image cannot subsequently be promoted to prod. Running the image injecting production credentials will not result in env vars being updated. I.e if I run the staging image, api url remains staging.myapi.com instead of prod.myapi.com

How should I work around this?

I cannot believe that Next would not allow image promotions, considering the inherent risks of rebuilding an image in different steps of a pipeline.

Any help would be much appreciated.

I considered disabling static pages which make queries to my api using said credentials but it would remove one of the main reasons why we use Next in the first place.

0 Replies