Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link to with-docker-multi-env example. #35820

Merged
merged 2 commits into from Apr 1, 2022
Merged

Link to with-docker-multi-env example. #35820

merged 2 commits into from Apr 1, 2022

Conversation

leerob
Copy link
Member

@leerob leerob commented Apr 1, 2022

Based on feedback from Twitter to surface this more. A small improvement before improving the deployment docs further 馃槃

@kodiakhq kodiakhq bot merged commit bcd2aa5 into canary Apr 1, 2022
@kodiakhq kodiakhq bot deleted the leerob-patch-1 branch April 1, 2022 15:45
@Janpot
Copy link
Contributor

Janpot commented Apr 4, 2022

@leerob Are there any examples on making docker images that contain Next.js apps runtime configurable? Use case is distributing your app for e.g. on-premise installations. I feel like this becomes harder and harder to do as Next.js keeps adding features that are build time configurable only (next.config.js routing options, middleware, env,...)

@leerob
Copy link
Member Author

leerob commented Apr 4, 2022

What do you mean by runtime configurable here? Sounds like you want something like Vault?

(I ask because diving in further, I've found a lot of people are really looking for this example, and not actual runtime configuration values.)

@mAAdhaTTah
Copy link
Contributor

@leerob Having multiple containers per-environment denies us the ability to ship the same container to every environment, which increases confidence that the code is working as expected in lower environments before going to production. We definitely need actual runtime configuration values.

@leerob
Copy link
Member Author

leerob commented Apr 4, 2022

Have you explored a solution like Vault? I ask because I've used this in the past with a k8s Next.js setup.

@mAAdhaTTah
Copy link
Contributor

@leerob We're on AWS, so we're using Parameter Store.

@Janpot
Copy link
Contributor

Janpot commented Apr 5, 2022

What do you mean by runtime configurable here?

@leerob For example, suppose I'm distributing my app as a docker image, and I'd like users to be able to set environment variables in the container for user/password to enable basic auth. Now I can't implement this through Next.js middleware as there is no way to pass runtime configuration to it.

@leerob
Copy link
Member Author

leerob commented Apr 5, 2022

We're on AWS, so we're using Parameter Store.

And fetching values from Parameter Store isn't working, is that correct?

https://docs.aws.amazon.com/cdk/v2/guide/get_ssm_value.html

@mAAdhaTTah
Copy link
Contributor

@leerob We're able to fetch Parameter Store values fine at runtime. Doing so at buildtime defeats one of the main benefits of Docker, which is to build the code once & ship the same code to every environment. With this current example, you're shipping different images to each environment.

@leerob
Copy link
Member Author

leerob commented Apr 5, 2022

To be more clear, the feedback is about the example here and not Next.js then? E.g. you can use Parameter Store or Vault or other similar tools with Next.js - and your feedback is that you want to see the same Docker image promoted through all environments in this example. Correct?

@mAAdhaTTah
Copy link
Contributor

mAAdhaTTah commented Apr 5, 2022

@leerob Yes & no, I'm specifically piggybacking off @Janpot's comment that Next.js's features (like middleware) are increasingly relying on environment variables being available at buildtime and aren't runtime configurable. This is reflected in this example having environment-specific Dockerfiles but isn't the underlying problem. To put it another way, if you were to take advantage of middleware in the example & used an environment-specific environment variable, and attempted to change it such that you promoted the same image through all environments, it wouldn't work as expected.

@Janpot
Copy link
Contributor

Janpot commented Apr 5, 2022

To be more clear, the feedback is about the example here and not Next.js then?

It's about both:

  1. The example is not representative for many people's workflows using docker (distributing Docker images that are configurable using environment variables). It's essentially just the with-docker example copied three times over.
  2. Next.js increasingly makes new features 'build-time configurable'-only which in turn makes it hard/impossible to use them in such way. Build-time-only configuration makes sense if you host on Vercel's platform, but we need other ways of hosting as well (e.g. I need to distribute a Docker image for on-premise installations).

@leerob
Copy link
Member Author

leerob commented Apr 5, 2022

Build-time-only configuration makes sense if you host on Vercel's platform, but we need other ways of hosting as well (e.g. I need to distribute a Docker image for on-premise installations).

Self-hosted Next.js is the most popular way of deploying Next.js applications, so I think we're just missing a good example here showing how to handle this. When I was running a Docker + K8s + Next.js app we used Vault for runtime config and it worked pretty well 馃憤 Appreciate the feedback.

@mAAdhaTTah
Copy link
Contributor

Self-hosted Next.js is the most popular way of deploying Next.js applications, so I think we're just missing a good example here showing how to handle this.

My guess is most people are setting up environment-specific build processes, similar to how this example was set up. I'd specifically like to see an example of using middleware with environment variables and a single build for multiple environments. My current read is that's actually impossible but if it isn't, would love to take some cues from the team on this.

@carstenblt
Copy link

+1 for a docker example with runtime environment variables.

I still haven't figured it out. I added serverRuntimeConfig to next.config.js with process.env.VARIABLE, but it doesn't read environment variables at runtime. Even adding a entrypoint.sh with env > .env.production doesn't work. This should work like in literally every containerized application. They are always configured via environment variables.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
created-by: Next.js team PRs by the Next.js team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants