|
|
|
|
|
|
|
|
|
FROM node:18-alpine as frontend-build |
|
|
|
WORKDIR /app/client |
|
|
|
|
|
COPY client/package*.json ./ |
|
|
|
|
|
RUN npm ci |
|
|
|
|
|
COPY client/ ./ |
|
|
|
|
|
RUN npm run build |
|
|
|
|
|
FROM node:18-alpine as backend-build |
|
|
|
WORKDIR /app/server |
|
|
|
|
|
COPY server/package*.json ./ |
|
|
|
|
|
RUN npm ci --only=production |
|
|
|
|
|
COPY server/ ./ |
|
|
|
|
|
FROM node:18-alpine |
|
|
|
|
|
RUN apk add --no-cache \ |
|
nginx \ |
|
wget \ |
|
curl \ |
|
supervisor \ |
|
&& rm -rf /var/cache/apk/* |
|
|
|
|
|
RUN addgroup -g 1001 -S appuser && \ |
|
adduser -S appuser -u 1001 |
|
|
|
|
|
WORKDIR /app |
|
|
|
|
|
COPY --from=backend-build --chown=appuser:appuser /app/server ./server |
|
|
|
|
|
COPY --from=frontend-build --chown=appuser:appuser /app/client/dist ./client/dist |
|
|
|
|
|
RUN mkdir -p /etc/nginx/conf.d |
|
COPY --chown=appuser:appuser client/nginx.conf /etc/nginx/conf.d/default.conf |
|
|
|
|
|
RUN mkdir -p /etc/supervisor/conf.d |
|
COPY --chown=appuser:appuser <<EOF /etc/supervisor/conf.d/supervisord.conf |
|
[supervisord] |
|
nodaemon=true |
|
user=root |
|
logfile=/var/log/supervisor/supervisord.log |
|
pidfile=/var/run/supervisord.pid |
|
|
|
[program:nginx] |
|
command=nginx -g "daemon off;" |
|
autostart=true |
|
autorestart=true |
|
stderr_logfile=/var/log/nginx/error.log |
|
stdout_logfile=/var/log/nginx/access.log |
|
user=appuser |
|
|
|
[program:node] |
|
command=node server/index.js |
|
directory=/app |
|
autostart=true |
|
autorestart=true |
|
stderr_logfile=/var/log/node/error.log |
|
stdout_logfile=/var/log/node/access.log |
|
user=appuser |
|
environment=NODE_ENV=production |
|
EOF |
|
|
|
|
|
RUN mkdir -p /var/log/nginx /var/log/node /var/log/supervisor && \ |
|
chown -R appuser:appuser /var/log/nginx /var/log/node /var/log/supervisor |
|
|
|
|
|
RUN sed -i 's/proxy_pass http:\/\/localhost:5000/proxy_pass http:\/\/127.0.0.1:5000/g' /etc/nginx/conf.d/default.conf |
|
|
|
|
|
EXPOSE 80 5000 |
|
|
|
|
|
ENV NODE_ENV=production |
|
ENV PORT=5000 |
|
ENV MONGODB_URI=mongodb://mongo:27017/chatapp |
|
|
|
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ |
|
CMD wget --no-verbose --tries=1 --spider http://localhost:80 && \ |
|
wget --no-verbose --tries=1 --spider http://localhost:5000/api/health || exit 1 |
|
|
|
|
|
USER appuser |
|
|
|
|
|
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] |
|
|