2024-11-10 20:42:02 -05:00
|
|
|
# Stage 1: Build stage
|
|
|
|
|
FROM nginx:1.27-alpine AS builder
|
|
|
|
|
# Install required packages
|
|
|
|
|
RUN apk add --no-cache nginx-mod-http-js nginx-mod-http-keyval
|
|
|
|
|
|
|
|
|
|
# Stage 2: Final stage
|
|
|
|
|
FROM alpine:3.19
|
|
|
|
|
|
2024-12-06 18:19:23 -05:00
|
|
|
# Install gettext for envsubst and other dependencies
|
2024-11-10 20:42:02 -05:00
|
|
|
RUN apk add --no-cache \
|
2024-12-06 18:19:23 -05:00
|
|
|
gettext \
|
|
|
|
|
nginx-mod-http-js \
|
|
|
|
|
nginx-mod-http-keyval \
|
2024-11-10 20:42:02 -05:00
|
|
|
pcre2 \
|
|
|
|
|
ca-certificates \
|
|
|
|
|
pcre \
|
|
|
|
|
libgcc \
|
|
|
|
|
libstdc++ \
|
|
|
|
|
zlib \
|
|
|
|
|
libxml2 \
|
|
|
|
|
libedit \
|
|
|
|
|
geoip \
|
2024-12-06 18:19:23 -05:00
|
|
|
libxslt
|
|
|
|
|
|
|
|
|
|
# Create base nginx directory
|
|
|
|
|
RUN mkdir -p /etc/nginx
|
|
|
|
|
|
|
|
|
|
# Copy Nginx and NJS modules from builder
|
|
|
|
|
COPY --from=builder /usr/sbin/nginx /usr/sbin/
|
|
|
|
|
COPY --from=builder /usr/lib/nginx/modules/ /usr/lib/nginx/modules/
|
|
|
|
|
RUN rm -rf /etc/nginx/*
|
|
|
|
|
COPY --from=builder /etc/nginx/ /etc/nginx/
|
|
|
|
|
COPY --from=builder /usr/lib/nginx/ /usr/lib/nginx/
|
|
|
|
|
|
|
|
|
|
# Setup directories and permissions
|
|
|
|
|
RUN mkdir -p /var/cache/nginx \
|
2024-11-10 20:42:02 -05:00
|
|
|
&& mkdir -p /var/log/nginx \
|
|
|
|
|
&& mkdir -p /etc/nginx/conf.d \
|
|
|
|
|
&& mkdir -p /etc/nginx/njs \
|
2024-12-06 18:19:23 -05:00
|
|
|
&& mkdir -p /etc/nginx/templates \
|
|
|
|
|
&& chown -R nginx:nginx /var/cache/nginx \
|
|
|
|
|
&& chown -R nginx:nginx /var/log/nginx \
|
|
|
|
|
&& chown -R nginx:nginx /etc/nginx \
|
|
|
|
|
&& touch /var/run/nginx.pid \
|
|
|
|
|
&& chown nginx:nginx /var/run/nginx.pid \
|
|
|
|
|
&& chmod 777 /var/log/nginx
|
2024-11-10 20:42:02 -05:00
|
|
|
|
|
|
|
|
# Copy necessary libraries from builder
|
|
|
|
|
COPY --from=builder /usr/lib/libxml2.so* /usr/lib/
|
|
|
|
|
COPY --from=builder /usr/lib/libexslt.so* /usr/lib/
|
|
|
|
|
COPY --from=builder /usr/lib/libgd.so* /usr/lib/
|
|
|
|
|
COPY --from=builder /usr/lib/libxslt.so* /usr/lib/
|
|
|
|
|
|
|
|
|
|
# Modify nginx.conf to load modules
|
|
|
|
|
RUN echo 'load_module modules/ngx_http_js_module.so;' > /tmp/nginx.conf && \
|
|
|
|
|
cat /etc/nginx/nginx.conf >> /tmp/nginx.conf && \
|
|
|
|
|
mv /tmp/nginx.conf /etc/nginx/nginx.conf
|
|
|
|
|
|
2024-12-06 18:19:23 -05:00
|
|
|
# Copy configurations
|
|
|
|
|
COPY templates/default.conf /etc/nginx/templates/
|
2024-11-10 20:42:02 -05:00
|
|
|
COPY njs/main.js /etc/nginx/njs/
|
2024-12-06 18:19:23 -05:00
|
|
|
COPY entrypoint.sh /entrypoint.sh
|
2024-11-10 20:42:02 -05:00
|
|
|
|
2024-12-06 18:19:23 -05:00
|
|
|
ENV PORT=80 \
|
|
|
|
|
FRONTEND_HOST=frontend \
|
|
|
|
|
FRONTEND_PORT=5173 \
|
|
|
|
|
BACKEND_HOST=backend \
|
|
|
|
|
BACKEND_PORT=3000
|
2024-11-10 20:42:02 -05:00
|
|
|
|
2024-12-06 18:19:23 -05:00
|
|
|
# Set final permissions
|
|
|
|
|
RUN chmod +x /entrypoint.sh && \
|
|
|
|
|
chown -R nginx:nginx /etc/nginx && \
|
|
|
|
|
chown -R nginx:nginx /var/log/nginx && \
|
|
|
|
|
chown -R nginx:nginx /var/cache/nginx && \
|
|
|
|
|
chmod 755 /etc/nginx && \
|
|
|
|
|
chmod 777 /etc/nginx/conf.d && \
|
|
|
|
|
chmod 644 /etc/nginx/templates/default.conf && \
|
|
|
|
|
chmod 644 /etc/nginx/conf.d/default.conf
|
2024-11-10 20:42:02 -05:00
|
|
|
|
2024-12-06 18:19:23 -05:00
|
|
|
# Switch to nginx user
|
2024-11-27 21:00:52 -05:00
|
|
|
USER nginx
|
|
|
|
|
|
2024-12-06 18:19:23 -05:00
|
|
|
# Start Nginx using entrypoint script
|
|
|
|
|
ENTRYPOINT ["/entrypoint.sh"]
|