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

All environment variables for the dockerized application are set by the backend #53

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions .env
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL="http"
NEXT_PUBLIC_BACKEND_SERVICE_PORT=4000
NEXT_PUBLIC_BACKEND_SERVICE_HOST="localhost"
NEXT_PUBLIC_BACKEND_API_VERSION="0.0.1"
# Use this file to set these environment variables when developing/running
# the application locally outside of a Docker container environment. This
# will have no effect on the values passed into the containers as those are
# all set in the backend's .env file.

FRONTEND_SERVICE_PORT=3000
FRONTEND_SERVICE_INTERFACE=0.0.0.0
# NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL="http"
# NEXT_PUBLIC_BACKEND_SERVICE_PORT=4000
# NEXT_PUBLIC_BACKEND_SERVICE_HOST="localhost"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming these are meant to be commented out as a default?

# NEXT_PUBLIC_BACKEND_API_VERSION="0.0.1"

# FRONTEND_SERVICE_INTERFACE=0.0.0.0
# FRONTEND_SERVICE_PORT=3000
31 changes: 25 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,28 @@ FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# This will do the trick, use the corresponding env file for each environment.
COPY .env .env

# Receive the build args from docker-compose.yaml
ARG NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL
ARG NEXT_PUBLIC_BACKEND_SERVICE_HOST
ARG NEXT_PUBLIC_BACKEND_SERVICE_PORT
ARG NEXT_PUBLIC_BACKEND_API_VERSION
ARG FRONTEND_SERVICE_INTERFACE
ARG FRONTEND_SERVICE_PORT

# And convert them to environment variables for runtime
ENV NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL=$NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL
ENV NEXT_PUBLIC_BACKEND_SERVICE_HOST=$NEXT_PUBLIC_BACKEND_SERVICE_HOST
ENV NEXT_PUBLIC_BACKEND_SERVICE_PORT=$NEXT_PUBLIC_BACKEND_SERVICE_PORT
ENV NEXT_PUBLIC_BACKEND_API_VERSION=$NEXT_PUBLIC_BACKEND_API_VERSION

RUN echo "NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL: ${NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL}"
RUN echo "NEXT_PUBLIC_BACKEND_SERVICE_HOST: ${NEXT_PUBLIC_BACKEND_SERVICE_HOST}"
RUN echo "NEXT_PUBLIC_BACKEND_SERVICE_HOST: ${NEXT_PUBLIC_BACKEND_SERVICE_PORT}"
RUN echo "NEXT_PUBLIC_BACKEND_SERVICE_HOST: ${NEXT_PUBLIC_BACKEND_API_VERSION}"
RUN echo "FRONTEND_SERVICE_INTERFACE: ${FRONTEND_SERVICE_INTERFACE}}"
RUN echo "FRONTEND_SERVICE_PORT: ${FRONTEND_SERVICE_PORT}}"

RUN npm run build

# 3. Production image, copy all the files and run next
Expand All @@ -44,11 +64,10 @@ COPY --from=builder /app/package.json ./
USER nextjs

# Expose the port Next.js runs on
EXPOSE 3000
EXPOSE $FRONTEND_SERVICE_PORT

ENV PORT=3000
ENV HOSTNAME=0.0.0.0
ENV HOSTNAME=$FRONTEND_SERVICE_INTERFACE
ENV PORT=$FRONTEND_SERVICE_PORT

# Run the app using JSON array notation
CMD ["node", "server.js"]
#CMD HOSTNAME="0.0.0.0" node server.js
Loading