@@ -19,8 +19,28 @@ FROM base AS builder
19
19
WORKDIR /app
20
20
COPY --from=deps /app/node_modules ./node_modules
21
21
COPY . .
22
- # This will do the trick, use the corresponding env file for each environment.
23
- COPY .env .env
22
+
23
+ # Receive the build args from docker-compose.yaml
24
+ ARG NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL
25
+ ARG NEXT_PUBLIC_BACKEND_SERVICE_HOST
26
+ ARG NEXT_PUBLIC_BACKEND_SERVICE_PORT
27
+ ARG NEXT_PUBLIC_BACKEND_API_VERSION
28
+ ARG FRONTEND_SERVICE_INTERFACE
29
+ ARG FRONTEND_SERVICE_PORT
30
+
31
+ # And convert them to environment variables for runtime
32
+ ENV NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL=$NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL
33
+ ENV NEXT_PUBLIC_BACKEND_SERVICE_HOST=$NEXT_PUBLIC_BACKEND_SERVICE_HOST
34
+ ENV NEXT_PUBLIC_BACKEND_SERVICE_PORT=$NEXT_PUBLIC_BACKEND_SERVICE_PORT
35
+ ENV NEXT_PUBLIC_BACKEND_API_VERSION=$NEXT_PUBLIC_BACKEND_API_VERSION
36
+
37
+ RUN echo "NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL: ${NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL}"
38
+ RUN echo "NEXT_PUBLIC_BACKEND_SERVICE_HOST: ${NEXT_PUBLIC_BACKEND_SERVICE_HOST}"
39
+ RUN echo "NEXT_PUBLIC_BACKEND_SERVICE_HOST: ${NEXT_PUBLIC_BACKEND_SERVICE_PORT}"
40
+ RUN echo "NEXT_PUBLIC_BACKEND_SERVICE_HOST: ${NEXT_PUBLIC_BACKEND_API_VERSION}"
41
+ RUN echo "FRONTEND_SERVICE_INTERFACE: ${FRONTEND_SERVICE_INTERFACE}}"
42
+ RUN echo "FRONTEND_SERVICE_PORT: ${FRONTEND_SERVICE_PORT}}"
43
+
24
44
RUN npm run build
25
45
26
46
# 3. Production image, copy all the files and run next
@@ -44,11 +64,10 @@ COPY --from=builder /app/package.json ./
44
64
USER nextjs
45
65
46
66
# Expose the port Next.js runs on
47
- EXPOSE 3000
67
+ EXPOSE $FRONTEND_SERVICE_PORT
48
68
49
- ENV PORT=3000
50
- ENV HOSTNAME=0.0.0.0
69
+ ENV HOSTNAME=$FRONTEND_SERVICE_INTERFACE
70
+ ENV PORT=$FRONTEND_SERVICE_PORT
51
71
52
72
# Run the app using JSON array notation
53
73
CMD ["node" , "server.js" ]
54
- # CMD HOSTNAME="0.0.0.0" node server.js
0 commit comments