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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider passing in the NEXT_PUBLIC_SERVER_URL at build time to the Dockerfile templates. #10473

Open
karlapsite opened this issue Jan 9, 2025 · 0 comments

Comments

@karlapsite
Copy link

karlapsite commented Jan 9, 2025

I was reviewing changes to the templates to pull in changes into my project, and figured I'd share some of my learnings here as I've been using this Dockerfile template for a while now.

next.config.js is baked at build time :(

Any environment variables used in next.config.js need to be provided at build time, regardless of whether --experimental-build-mode compile is used or not.

This means that any suggested builder, such as a github action, will need to be aware of the NEXT_PUBLIC_SERVER_URL and be able to pass it in:

      # Make sure to pass NEXT_PUBLIC_SERVER_URL
      - name: Build and Push to container registry
        uses: docker/build-push-action@v5
        with:
          push: ${{ github.event_name != 'pull_request' }}
          tags: ${{ env.IMAGE_TAG }}
          build-args: |
            NEXT_PUBLIC_SERVER_URL=${{ vars.NEXT_PUBLIC_SERVER_URL }}

Along with a change to the Dockerfile in the build stage

--- a/Dockerfile
+++ b/Dockerfile
@@ -20,6 +20,8 @@ RUN \

 # Rebuild the source code only when needed
 FROM base AS builder
+ARG NEXT_PUBLIC_SERVER_URL

I'd recommend adding this line to the website template for sure as the website template's next.config.js references NEXT_PUBLIC_SERVER_URL here

This may also affects VERCEL_PROJECT_PRODUCTION_URL... I'm unfamiliar with Vercel, and whether they own the build process or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant