Skip to content

API url environment not used when running with docker production stage #4

Description

@bobvandevijver

Consider the following snippet from docker compose, where the 'gui' folder contains a clone of this repository.

  hawkbit-gui:
    build:
      context: ./gui
      target: production-build-stage
      dockerfile: Dockerfile
    environment:
      - NEXTAUTH_SECRET=<some-secret>
      - NEXTAUTH_URL=https://<some-hawkbitgui-url>
      - NEXT_PUBLIC_HAWKBIT_API_URL=https://<some-hawkbit-url>

This will, when run, result in the following error being logged when trying to login:

Attaching to hawkbit-gui-1                                                                                                                        
hawkbit-gui-1  | $ next start                                                                                                                     
hawkbit-gui-1  |    ▲ Next.js 16.0.10                                                                                                             
hawkbit-gui-1  |    - Local:         http://localhost:3000                                                                                        
hawkbit-gui-1  |    - Network:       http://172.24.0.4:3000                                                                                       
hawkbit-gui-1  |                                                                                                                                  
hawkbit-gui-1  |  ✓ Starting...                                                                                                                   
hawkbit-gui-1  | [baseline-browser-mapping] The data in this module is over two months old.  To ensure accurate Baseline data, please update: `npm i baseline-browser-mapping@latest -D`
hawkbit-gui-1  |  ✓ Ready in 649ms
hawkbit-gui-1  | TypeError: Invalid URL
hawkbit-gui-1  |     at t (.next/server/chunks/_06c8e80d._.js:3:4782)
hawkbit-gui-1  |     at <unknown> (.next/server/chunks/_06c8e80d._.js:3:12885)
hawkbit-gui-1  |     at new Promise (<anonymous>)
hawkbit-gui-1  |     at http (.next/server/chunks/_06c8e80d._.js:3:12805)
hawkbit-gui-1  |     at tU.tF (.next/server/chunks/_06c8e80d._.js:3:22901)
hawkbit-gui-1  |     at tU._request (.next/server/chunks/_06c8e80d._.js:3:25921)
hawkbit-gui-1  |     at tU.request (.next/server/chunks/_06c8e80d._.js:3:24280)
hawkbit-gui-1  |     at tU.<computed> [as get] (.next/server/chunks/_06c8e80d._.js:3:26235)
hawkbit-gui-1  |     at Function.get (.next/server/chunks/_06c8e80d._.js:1:62984)
hawkbit-gui-1  |     at tU.request (.next/server/chunks/_06c8e80d._.js:3:24365) {
hawkbit-gui-1  |   code: 'ERR_INVALID_URL',
hawkbit-gui-1  |   input: '/rest/v1/userinfo'
hawkbit-gui-1  | }

It looks like the environment variable has been replaced during the bun run build, and no longer uses the env that is actually set. I have validated that the environment values are available when opening a bash instance inside the running container.

When passing the environment as 'args' during the container build (as below), it does work as expected.

  hawkbit-gui:
    build:
      context: ./gui
      target: production-build-stage
      dockerfile: Dockerfile
      args:
        - NEXTAUTH_SECRET=<some-secret>
        - NEXTAUTH_URL=https://<some-hawkbitgui-url>
        - NEXT_PUBLIC_HAWKBIT_API_URL=https://<some-hawkbit-url>
    environment:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions