mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
template to add env variables
This commit is contained in:
parent
3744bf4347
commit
d4e13b8c36
5 changed files with 69 additions and 33 deletions
|
|
@ -63,6 +63,12 @@ services:
|
|||
networks:
|
||||
- quiz_network
|
||||
restart: always
|
||||
#environment:
|
||||
# - PORT=8000
|
||||
# - FRONTEND_HOST=frontend
|
||||
# - FRONTEND_PORT=5173
|
||||
# - BACKEND_HOST=backend
|
||||
# - BACKEND_PORT=3000
|
||||
|
||||
mongo:
|
||||
image: mongo
|
||||
|
|
|
|||
5
nginx/.env.example
Normal file
5
nginx/.env.example
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
PORT=80
|
||||
FRONTEND_HOST=frontend
|
||||
FRONTEND_PORT=5173
|
||||
BACKEND_HOST=backend
|
||||
BACKEND_PORT=3000
|
||||
|
|
@ -1,20 +1,16 @@
|
|||
# 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
|
||||
|
||||
# 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/
|
||||
COPY --from=builder /etc/nginx/ /etc/nginx/
|
||||
COPY --from=builder /usr/lib/nginx/ /usr/lib/nginx/
|
||||
|
||||
# Install required runtime dependencies
|
||||
# Install gettext for envsubst and other dependencies
|
||||
RUN apk add --no-cache \
|
||||
gettext \
|
||||
nginx-mod-http-js \
|
||||
nginx-mod-http-keyval \
|
||||
pcre2 \
|
||||
ca-certificates \
|
||||
pcre \
|
||||
|
|
@ -24,15 +20,30 @@ RUN apk add --no-cache \
|
|||
libxml2 \
|
||||
libedit \
|
||||
geoip \
|
||||
libxslt \
|
||||
&& mkdir -p /var/cache/nginx \
|
||||
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 \
|
||||
&& mkdir -p /var/log/nginx \
|
||||
&& mkdir -p /etc/nginx/conf.d \
|
||||
&& mkdir -p /etc/nginx/njs \
|
||||
&& ln -sf /dev/stdout /var/log/nginx/access.log \
|
||||
&& ln -sf /dev/stderr /var/log/nginx/error.log \
|
||||
&& addgroup -S nginx \
|
||||
&& adduser -D -S -h /var/cache/nginx -s /sbin/nologin -G nginx nginx
|
||||
&& 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
|
||||
|
||||
# Copy necessary libraries from builder
|
||||
COPY --from=builder /usr/lib/libxml2.so* /usr/lib/
|
||||
|
|
@ -45,25 +56,29 @@ 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
|
||||
|
||||
# Copy our configuration
|
||||
COPY conf.d/default.conf /etc/nginx/conf.d/
|
||||
# Copy configurations
|
||||
COPY templates/default.conf /etc/nginx/templates/
|
||||
COPY njs/main.js /etc/nginx/njs/
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
|
||||
# Set proper permissions
|
||||
RUN chown -R nginx:nginx /var/cache/nginx \
|
||||
&& chown -R nginx:nginx /var/log/nginx \
|
||||
&& chown -R nginx:nginx /etc/nginx/conf.d \
|
||||
&& touch /var/run/nginx.pid \
|
||||
&& chown -R nginx:nginx /var/run/nginx.pid
|
||||
ENV PORT=80 \
|
||||
FRONTEND_HOST=frontend \
|
||||
FRONTEND_PORT=5173 \
|
||||
BACKEND_HOST=backend \
|
||||
BACKEND_PORT=3000
|
||||
|
||||
# Verify the configuration
|
||||
# RUN nginx -t --dry-run
|
||||
# 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
|
||||
|
||||
# Switch to non-root user
|
||||
# Switch to nginx user
|
||||
USER nginx
|
||||
|
||||
# Expose HTTP port
|
||||
EXPOSE 80
|
||||
|
||||
# Start Nginx
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
# Start Nginx using entrypoint script
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
10
nginx/entrypoint.sh
Normal file
10
nginx/entrypoint.sh
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#!/bin/sh
|
||||
# entrypoint.sh
|
||||
|
||||
# We are already running as nginx user
|
||||
envsubst '${PORT} ${FRONTEND_HOST} ${FRONTEND_PORT} ${BACKEND_HOST} ${BACKEND_PORT}' \
|
||||
< /etc/nginx/templates/default.conf \
|
||||
> /etc/nginx/conf.d/default.conf
|
||||
|
||||
# Start nginx
|
||||
exec nginx -g "daemon off;"
|
||||
|
|
@ -8,15 +8,15 @@ map $http_upgrade $connection_upgrade {
|
|||
}
|
||||
|
||||
upstream frontend {
|
||||
server frontend:5173;
|
||||
server ${FRONTEND_HOST}:${FRONTEND_PORT};
|
||||
}
|
||||
|
||||
upstream backend {
|
||||
server backend:3000;
|
||||
server ${BACKEND_HOST}:${BACKEND_PORT};
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
listen ${PORT};
|
||||
|
||||
set $proxy_target "";
|
||||
|
||||
Loading…
Reference in a new issue