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

Make Docker image compatible with multiple environments #361

Open
sidemt opened this issue Nov 29, 2023 · 0 comments
Open

Make Docker image compatible with multiple environments #361

sidemt opened this issue Nov 29, 2023 · 0 comments

Comments

@sidemt
Copy link
Member

sidemt commented Nov 29, 2023

Currently, we are using an environment variable NEXT_PUBLIC_STRAPI_BACKEND_URL in the frontend app.
But this variable gets fixed at build time, making the Docker image only compatible with a single environment.

Current situation:

  • To make an environment variable accessible in the browser, we have to prefix the variable with NEXT_PUBLIC_
  • But by doing so, the value will be fixed at build time -> this is causing the problem now
    • We are passing in the variable at the build time here:
      run: |
      docker build . \
      --tag registry.digitalocean.com/${{ secrets.DOCR_NAME }}/${{ matrix.site_tlds }}/publish-${{ matrix.apps }}:$tagname \
      --tag registry.digitalocean.com/${{ secrets.DOCR_NAME }}/${{ matrix.site_tlds }}/publish-${{ matrix.apps }}:latest \
      --build-arg NEXT_PUBLIC_STRAPI_BACKEND_URL=${{ secrets.NEXT_PUBLIC_STRAPI_BACKEND_URL }} \
      --file docker/${{ matrix.apps }}/Dockerfile

To fix the issue, we have to either:

  • use getServerSideProps
  • use App Router
  • if we can't avoid using NEXT_PUBLIC_ variable, build the frontend Docker image for each environment

Reference:
https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#runtime-environment-variables

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