✅ - local system uses .env ✅ - local system uses system variables ✅ - eb local run, with docker container uses .env ✅ - eb local run, with docker container uses .env.local
❌ - eb local run, with docker container uses environment variables passed through
eb local run --envvars NEXT_PUBLIC_APP_VERSION=docker_test
# tested with
docker exec -it 93555a461718 /bin/sh env
# local variable is available, but not used while building
✅ - eb local run, with docker container uses environment variables in dockerfile
# this has to explicitly run in the build block 🙃
ENV NEXT_PUBLIC_APP_VERSION test_local_docker
RUN yarn build
Here is some discussion how to fix this problem. But this only helps if you're able to set build params. We're not able to use this in elastic beanstalk.
At least I would discard this scenario because it's to complicated for the outcome.
-
You have to understand the difference between 'static site generation' and 'dynamic site generation' in nextjs context and especially why information is only available in a certain point of time.
-
You have also to understand how docker builds work and how to parameterize them. (build-args)
I think it's a better approach to use dynamic rest-api endpoints to get the information you need.
export default (req: NextApiRequest, res: NextApiResponse): void => {
res.status(200).json({
name: 'John Doe',
version: process.env.NEXT_PUBLIC_APP_VERSION,
env: process.env.NODE_ENV,
});
};