diff --git a/.env b/.env index 1079e48..7a1eebd 100644 --- a/.env +++ b/.env @@ -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 \ No newline at end of file +# 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" + +# FRONTEND_SERVICE_INTERFACE=0.0.0.0 +# FRONTEND_SERVICE_PORT=3000 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4358e86..afe4c5e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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