@Lawton Mizell I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.
Issue: Your next.Js frontend was not able to call your flask API backend.
Solution: I have fixed my issue. According to the Next Documentation https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#bundling-environment-variables-for-the-browser
if you build and deploy a single Docker image to multiple environments, all NEXT_PUBLIC_ variables will be frozen with the value evaluated at build time, so these values need to be set appropriately when the project is built. If you need access to runtime environment values, you'll have to setup your own API to provide them to the client (either on demand or during initialization)
When building a containerized application for a Next application you must pass environment variable as a build argument for docker then pass it before running yarn build In my Github settings I setup a secret for the environment variable
Then in my actions I exposed the variable as a build argument for docker
- name: Build and push container image to registry
uses: docker/build-push-action@v4
with:
push: true
tags: ghcr.io/${{ env.REPO }}/myContainerName:${{ github.sha }}
file: ./Dockerfile
context: .
build-args: |
NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }}
env:
NEXT_PUBLIC_API_URL: ${{ secrets.NEXT_PUBLIC_API_URL }}
In my dockerfile before running yarn build
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ARG NEXT_PUBLIC_API_URL
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
RUN echo "NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}"
Run yarn build
See this for more information on Next docker buildtime vs runtime and what is exposed to server and client
https://www.saltycrane.com/blog/2021/04/buildtime-vs-runtime-environment-variables-nextjs-docker/"
If you have any other questions or are still running into more issues, please let me know.
Thank you again for your time and patience throughout this issue.
Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.