mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-27 21:42:25 +00:00
dockerfile test
This commit is contained in:
+43
-44
@@ -1,8 +1,24 @@
|
|||||||
# Use an official Node runtime as the base image
|
# Base image with Node for building
|
||||||
FROM node:24-slim AS base
|
FROM node:24-slim AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy and install deps (bypass Husky hooks)
|
||||||
|
ENV HUSKY=0
|
||||||
|
ENV NPM_CONFIG_IGNORE_SCRIPTS=1
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
# Copy source and build app
|
||||||
|
COPY . .
|
||||||
|
ARG GIT_COMMIT=unknown
|
||||||
|
ENV GIT_COMMIT=$GIT_COMMIT
|
||||||
|
RUN npm run build-prod && echo "$GIT_COMMIT" > static/commit.txt
|
||||||
|
|
||||||
|
|
||||||
|
# Stage for installing system packages
|
||||||
|
FROM node:24-slim AS system-deps
|
||||||
|
|
||||||
# Create dependency layer
|
|
||||||
FROM base AS dependencies
|
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
nginx \
|
nginx \
|
||||||
supervisor \
|
supervisor \
|
||||||
@@ -10,65 +26,48 @@ RUN apt-get update && apt-get install -y \
|
|||||||
curl \
|
curl \
|
||||||
jq \
|
jq \
|
||||||
wget \
|
wget \
|
||||||
apache2-utils \
|
apache2-utils && \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Install cloudflared
|
||||||
RUN curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb > cloudflared.deb \
|
RUN curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb > cloudflared.deb \
|
||||||
&& dpkg -i cloudflared.deb \
|
&& dpkg -i cloudflared.deb \
|
||||||
&& rm cloudflared.deb
|
&& rm cloudflared.deb
|
||||||
|
|
||||||
|
|
||||||
# Final image
|
# Final image
|
||||||
FROM base
|
FROM node:24-slim
|
||||||
|
|
||||||
# Copy installed packages from dependencies stage
|
|
||||||
COPY --from=dependencies / /
|
|
||||||
|
|
||||||
ARG GIT_COMMIT=unknown
|
|
||||||
ENV GIT_COMMIT="$GIT_COMMIT"
|
|
||||||
|
|
||||||
# Set the working directory in the container
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
# Copy package.json and package-lock.json
|
# Copy built app from builder stage
|
||||||
COPY package*.json ./
|
COPY --from=builder /app/static ./static
|
||||||
|
COPY --from=builder /app/startup.sh /usr/local/bin/startup.sh
|
||||||
|
COPY --from=builder /app/nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
COPY --from=builder /app/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||||
|
|
||||||
# Install dependencies while bypassing Husky hooks
|
# Copy system packages from the system-deps stage
|
||||||
ENV HUSKY=0
|
COPY --from=system-deps /etc/nginx /etc/nginx
|
||||||
ENV NPM_CONFIG_IGNORE_SCRIPTS=1
|
COPY --from=system-deps /usr/sbin/nginx /usr/sbin/nginx
|
||||||
RUN mkdir -p .git && npm ci
|
COPY --from=system-deps /usr/bin/supervisord /usr/bin/supervisord
|
||||||
|
COPY --from=system-deps /usr/bin/supervisorctl /usr/bin/supervisorctl
|
||||||
|
COPY --from=system-deps /etc/supervisor /etc/supervisor
|
||||||
|
COPY --from=system-deps /usr/local/bin/cloudflared /usr/local/bin/cloudflared
|
||||||
|
|
||||||
# Copy the rest of the application code
|
# Optional: create supervisor log dir
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# Build the client-side application
|
|
||||||
RUN npm run build-prod
|
|
||||||
|
|
||||||
# So we can see which commit was used to build the container
|
|
||||||
# https://openfront.io/commit.txt
|
|
||||||
RUN echo "$GIT_COMMIT" > static/commit.txt
|
|
||||||
|
|
||||||
# Update worker_connections in the existing nginx.conf
|
|
||||||
RUN sed -i 's/worker_connections [0-9]*/worker_connections 8192/' /etc/nginx/nginx.conf
|
|
||||||
|
|
||||||
# Copy Nginx configuration and ensure it's used instead of the default
|
|
||||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
|
||||||
RUN rm -f /etc/nginx/sites-enabled/default
|
|
||||||
|
|
||||||
# Setup supervisor configuration
|
|
||||||
RUN mkdir -p /var/log/supervisor
|
RUN mkdir -p /var/log/supervisor
|
||||||
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
|
||||||
|
|
||||||
# Copy and make executable the startup script
|
# Fix nginx worker_connections
|
||||||
COPY startup.sh /usr/local/bin/
|
RUN sed -i 's/worker_connections [0-9]*/worker_connections 8192/' /etc/nginx/nginx.conf || true
|
||||||
RUN chmod +x /usr/local/bin/startup.sh
|
|
||||||
|
|
||||||
|
# Cloudflared config volume setup
|
||||||
RUN mkdir -p /etc/cloudflared && \
|
RUN mkdir -p /etc/cloudflared && \
|
||||||
chown -R node:node /etc/cloudflared && \
|
chown -R node:node /etc/cloudflared && \
|
||||||
chmod -R 755 /etc/cloudflared
|
chmod -R 755 /etc/cloudflared
|
||||||
|
|
||||||
# Set Cloudflared config directory to a volume mount location
|
|
||||||
ENV CF_CONFIG_PATH=/etc/cloudflared/config.yml
|
ENV CF_CONFIG_PATH=/etc/cloudflared/config.yml
|
||||||
ENV CF_CREDS_PATH=/etc/cloudflared/creds.json
|
ENV CF_CREDS_PATH=/etc/cloudflared/creds.json
|
||||||
|
|
||||||
# Use the startup script as the entrypoint
|
RUN chmod +x /usr/local/bin/startup.sh
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/local/bin/startup.sh"]
|
ENTRYPOINT ["/usr/local/bin/startup.sh"]
|
||||||
|
|||||||
Reference in New Issue
Block a user