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:
|
networks:
|
||||||
- quiz_network
|
- quiz_network
|
||||||
restart: always
|
restart: always
|
||||||
|
#environment:
|
||||||
|
# - PORT=8000
|
||||||
|
# - FRONTEND_HOST=frontend
|
||||||
|
# - FRONTEND_PORT=5173
|
||||||
|
# - BACKEND_HOST=backend
|
||||||
|
# - BACKEND_PORT=3000
|
||||||
|
|
||||||
mongo:
|
mongo:
|
||||||
image: 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
|
# Stage 1: Build stage
|
||||||
FROM nginx:1.27-alpine AS builder
|
FROM nginx:1.27-alpine AS builder
|
||||||
|
|
||||||
# Install required packages
|
# Install required packages
|
||||||
RUN apk add --no-cache nginx-mod-http-js nginx-mod-http-keyval
|
RUN apk add --no-cache nginx-mod-http-js nginx-mod-http-keyval
|
||||||
|
|
||||||
# Stage 2: Final stage
|
# Stage 2: Final stage
|
||||||
FROM alpine:3.19
|
FROM alpine:3.19
|
||||||
|
|
||||||
# Copy Nginx and NJS modules from builder
|
# Install gettext for envsubst and other dependencies
|
||||||
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
|
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
|
gettext \
|
||||||
|
nginx-mod-http-js \
|
||||||
|
nginx-mod-http-keyval \
|
||||||
pcre2 \
|
pcre2 \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
pcre \
|
pcre \
|
||||||
|
|
@ -24,15 +20,30 @@ RUN apk add --no-cache \
|
||||||
libxml2 \
|
libxml2 \
|
||||||
libedit \
|
libedit \
|
||||||
geoip \
|
geoip \
|
||||||
libxslt \
|
libxslt
|
||||||
&& mkdir -p /var/cache/nginx \
|
|
||||||
|
# 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 /var/log/nginx \
|
||||||
&& mkdir -p /etc/nginx/conf.d \
|
&& mkdir -p /etc/nginx/conf.d \
|
||||||
&& mkdir -p /etc/nginx/njs \
|
&& mkdir -p /etc/nginx/njs \
|
||||||
&& ln -sf /dev/stdout /var/log/nginx/access.log \
|
&& mkdir -p /etc/nginx/templates \
|
||||||
&& ln -sf /dev/stderr /var/log/nginx/error.log \
|
&& chown -R nginx:nginx /var/cache/nginx \
|
||||||
&& addgroup -S nginx \
|
&& chown -R nginx:nginx /var/log/nginx \
|
||||||
&& adduser -D -S -h /var/cache/nginx -s /sbin/nologin -G nginx 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 necessary libraries from builder
|
||||||
COPY --from=builder /usr/lib/libxml2.so* /usr/lib/
|
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 && \
|
cat /etc/nginx/nginx.conf >> /tmp/nginx.conf && \
|
||||||
mv /tmp/nginx.conf /etc/nginx/nginx.conf
|
mv /tmp/nginx.conf /etc/nginx/nginx.conf
|
||||||
|
|
||||||
# Copy our configuration
|
# Copy configurations
|
||||||
COPY conf.d/default.conf /etc/nginx/conf.d/
|
COPY templates/default.conf /etc/nginx/templates/
|
||||||
COPY njs/main.js /etc/nginx/njs/
|
COPY njs/main.js /etc/nginx/njs/
|
||||||
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
|
|
||||||
# Set proper permissions
|
ENV PORT=80 \
|
||||||
RUN chown -R nginx:nginx /var/cache/nginx \
|
FRONTEND_HOST=frontend \
|
||||||
&& chown -R nginx:nginx /var/log/nginx \
|
FRONTEND_PORT=5173 \
|
||||||
&& chown -R nginx:nginx /etc/nginx/conf.d \
|
BACKEND_HOST=backend \
|
||||||
&& touch /var/run/nginx.pid \
|
BACKEND_PORT=3000
|
||||||
&& chown -R nginx:nginx /var/run/nginx.pid
|
|
||||||
|
|
||||||
# Verify the configuration
|
# Set final permissions
|
||||||
# RUN nginx -t --dry-run
|
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
|
USER nginx
|
||||||
|
|
||||||
# Expose HTTP port
|
# Start Nginx using entrypoint script
|
||||||
EXPOSE 80
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
|
||||||
# Start Nginx
|
|
||||||
CMD ["nginx", "-g", "daemon off;"]
|
|
||||||
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 {
|
upstream frontend {
|
||||||
server frontend:5173;
|
server ${FRONTEND_HOST}:${FRONTEND_PORT};
|
||||||
}
|
}
|
||||||
|
|
||||||
upstream backend {
|
upstream backend {
|
||||||
server backend:3000;
|
server ${BACKEND_HOST}:${BACKEND_PORT};
|
||||||
}
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen ${PORT};
|
||||||
|
|
||||||
set $proxy_target "";
|
set $proxy_target "";
|
||||||
|
|
||||||
Loading…
Reference in a new issue