@@ -71,7 +71,7 @@ WORKDIR /usr/src/app
71
71
72
72
# Install Node.js and supervisord with retry logic
73
73
RUN apt-get update && \
74
- apt-get install -y curl supervisor && \
74
+ apt-get install -y curl supervisor nginx && \
75
75
curl -fsSL --retry 3 --retry-delay 10 https://deb.nodesource.com/setup_20.x | bash - && \
76
76
apt-get install -y nodejs && \
77
77
rm -rf /var/lib/apt/lists/*
@@ -88,6 +88,10 @@ ARG NEXT_PORT=3000
88
88
ENV NEXT_PORT=${NEXT_PORT}
89
89
EXPOSE ${NEXT_PORT}
90
90
91
+ # Internal Next.js port (not exposed)
92
+ ARG NEXT_INTERNAL_PORT=3001
93
+ ENV NEXT_INTERNAL_PORT=${NEXT_INTERNAL_PORT}
94
+
91
95
# Copy application files
92
96
COPY ./ ./
93
97
@@ -99,6 +103,72 @@ COPY --from=frontend-builder /app/frontend/nextjs/package.json ./frontend/nextjs
99
103
# Ensure next.config.mjs and other necessary files are present
100
104
COPY --from=frontend-builder /app/frontend/nextjs/next.config.mjs ./frontend/nextjs/next.config.mjs
101
105
106
+ # Create nginx configuration
107
+ RUN echo 'events {' > /etc/nginx/nginx.conf && \
108
+ echo ' worker_connections 1024;' >> /etc/nginx/nginx.conf && \
109
+ echo '}' >> /etc/nginx/nginx.conf && \
110
+ echo '' >> /etc/nginx/nginx.conf && \
111
+ echo 'http {' >> /etc/nginx/nginx.conf && \
112
+ echo ' include /etc/nginx/mime.types;' >> /etc/nginx/nginx.conf && \
113
+ echo ' default_type application/octet-stream;' >> /etc/nginx/nginx.conf && \
114
+ echo '' >> /etc/nginx/nginx.conf && \
115
+ echo ' # Logging' >> /etc/nginx/nginx.conf && \
116
+ echo ' access_log /var/log/nginx/access.log;' >> /etc/nginx/nginx.conf && \
117
+ echo ' error_log /var/log/nginx/error.log;' >> /etc/nginx/nginx.conf && \
118
+ echo '' >> /etc/nginx/nginx.conf && \
119
+ echo ' # Gzip compression' >> /etc/nginx/nginx.conf && \
120
+ echo ' gzip on;' >> /etc/nginx/nginx.conf && \
121
+ echo ' gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;' >> /etc/nginx/nginx.conf && \
122
+ echo '' >> /etc/nginx/nginx.conf && \
123
+ echo ' # WebSocket support' >> /etc/nginx/nginx.conf && \
124
+ echo ' map $http_upgrade $connection_upgrade {' >> /etc/nginx/nginx.conf && \
125
+ echo ' default upgrade;' >> /etc/nginx/nginx.conf && \
126
+ echo ' '"'"''"'"' close;' >> /etc/nginx/nginx.conf && \
127
+ echo ' }' >> /etc/nginx/nginx.conf && \
128
+ echo '' >> /etc/nginx/nginx.conf && \
129
+ echo ' server {' >> /etc/nginx/nginx.conf && \
130
+ echo ' listen 3000;' >> /etc/nginx/nginx.conf && \
131
+ echo ' server_name _;' >> /etc/nginx/nginx.conf && \
132
+ echo '' >> /etc/nginx/nginx.conf && \
133
+ echo ' # Proxy backend routes to FastAPI server' >> /etc/nginx/nginx.conf && \
134
+ echo ' location /outputs {' >> /etc/nginx/nginx.conf && \
135
+ echo ' proxy_pass http://127.0.0.1:8000;' >> /etc/nginx/nginx.conf && \
136
+ echo ' proxy_set_header Host $host;' >> /etc/nginx/nginx.conf && \
137
+ echo ' proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/nginx.conf && \
138
+ echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/nginx.conf && \
139
+ echo ' proxy_set_header X-Forwarded-Proto $scheme;' >> /etc/nginx/nginx.conf && \
140
+ echo ' }' >> /etc/nginx/nginx.conf && \
141
+ echo '' >> /etc/nginx/nginx.conf && \
142
+ echo ' location /reports {' >> /etc/nginx/nginx.conf && \
143
+ echo ' proxy_pass http://127.0.0.1:8000;' >> /etc/nginx/nginx.conf && \
144
+ echo ' proxy_set_header Host $host;' >> /etc/nginx/nginx.conf && \
145
+ echo ' proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/nginx.conf && \
146
+ echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/nginx.conf && \
147
+ echo ' proxy_set_header X-Forwarded-Proto $scheme;' >> /etc/nginx/nginx.conf && \
148
+ echo ' }' >> /etc/nginx/nginx.conf && \
149
+ echo '' >> /etc/nginx/nginx.conf && \
150
+ echo ' location /ws {' >> /etc/nginx/nginx.conf && \
151
+ echo ' proxy_pass http://127.0.0.1:8000;' >> /etc/nginx/nginx.conf && \
152
+ echo ' proxy_http_version 1.1;' >> /etc/nginx/nginx.conf && \
153
+ echo ' proxy_set_header Upgrade $http_upgrade;' >> /etc/nginx/nginx.conf && \
154
+ echo ' proxy_set_header Connection $connection_upgrade;' >> /etc/nginx/nginx.conf && \
155
+ echo ' proxy_set_header Host $host;' >> /etc/nginx/nginx.conf && \
156
+ echo ' proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/nginx.conf && \
157
+ echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/nginx.conf && \
158
+ echo ' proxy_set_header X-Forwarded-Proto $scheme;' >> /etc/nginx/nginx.conf && \
159
+ echo ' }' >> /etc/nginx/nginx.conf && \
160
+ echo '' >> /etc/nginx/nginx.conf && \
161
+ echo ' # Proxy all other requests to Next.js' >> /etc/nginx/nginx.conf && \
162
+ echo ' location / {' >> /etc/nginx/nginx.conf && \
163
+ echo ' proxy_pass http://127.0.0.1:3001;' >> /etc/nginx/nginx.conf && \
164
+ echo ' proxy_set_header Host $host;' >> /etc/nginx/nginx.conf && \
165
+ echo ' proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/nginx.conf && \
166
+ echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/nginx.conf && \
167
+ echo ' proxy_set_header X-Forwarded-Proto $scheme;' >> /etc/nginx/nginx.conf && \
168
+ echo ' }' >> /etc/nginx/nginx.conf && \
169
+ echo ' }' >> /etc/nginx/nginx.conf && \
170
+ echo '}' >> /etc/nginx/nginx.conf
171
+
102
172
# Create supervisord configuration
103
173
# stdout/stderr_maxbytes prevents log file rotation and ensures continuous output
104
174
RUN echo '[supervisord]' > /etc/supervisor/conf.d/supervisord.conf && \
@@ -118,13 +188,22 @@ RUN echo '[supervisord]' > /etc/supervisor/conf.d/supervisord.conf && \
118
188
echo 'stderr_logfile_maxbytes=0' >> /etc/supervisor/conf.d/supervisord.conf && \
119
189
echo '' >> /etc/supervisor/conf.d/supervisord.conf && \
120
190
echo '[program:frontend]' >> /etc/supervisor/conf.d/supervisord.conf && \
121
- echo 'command=npm run start -- -p %(ENV_NEXT_PORT )s' >> /etc/supervisor/conf.d/supervisord.conf && \
191
+ echo 'command=npm run start -- -p %(ENV_NEXT_INTERNAL_PORT )s' >> /etc/supervisor/conf.d/supervisord.conf && \
122
192
echo 'directory=/usr/src/app/frontend/nextjs' >> /etc/supervisor/conf.d/supervisord.conf && \
123
193
echo 'autostart=true' >> /etc/supervisor/conf.d/supervisord.conf && \
124
194
echo 'autorestart=true' >> /etc/supervisor/conf.d/supervisord.conf && \
125
195
echo 'stdout_logfile=/dev/stdout' >> /etc/supervisor/conf.d/supervisord.conf && \
126
196
echo 'stdout_logfile_maxbytes=0' >> /etc/supervisor/conf.d/supervisord.conf && \
127
197
echo 'stderr_logfile=/dev/stderr' >> /etc/supervisor/conf.d/supervisord.conf && \
198
+ echo 'stderr_logfile_maxbytes=0' >> /etc/supervisor/conf.d/supervisord.conf && \
199
+ echo '' >> /etc/supervisor/conf.d/supervisord.conf && \
200
+ echo '[program:nginx]' >> /etc/supervisor/conf.d/supervisord.conf && \
201
+ echo 'command=nginx -g "daemon off;"' >> /etc/supervisor/conf.d/supervisord.conf && \
202
+ echo 'autostart=true' >> /etc/supervisor/conf.d/supervisord.conf && \
203
+ echo 'autorestart=true' >> /etc/supervisor/conf.d/supervisord.conf && \
204
+ echo 'stdout_logfile=/dev/stdout' >> /etc/supervisor/conf.d/supervisord.conf && \
205
+ echo 'stdout_logfile_maxbytes=0' >> /etc/supervisor/conf.d/supervisord.conf && \
206
+ echo 'stderr_logfile=/dev/stderr' >> /etc/supervisor/conf.d/supervisord.conf && \
128
207
echo 'stderr_logfile_maxbytes=0' >> /etc/supervisor/conf.d/supervisord.conf
129
208
130
209
# Start supervisord to manage both services
0 commit comments