From 6caa81852c7fead3dfd8d341856ffc49115f212a Mon Sep 17 00:00:00 2001 From: Scott Anderson <662325+scottanderson@users.noreply.github.com> Date: Fri, 20 Jun 2025 16:41:16 -0400 Subject: [PATCH] dockerfile test --- Dockerfile | 87 +++++++++++++++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/Dockerfile b/Dockerfile index f4adffac4..edea9a12b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,24 @@ -# Use an official Node runtime as the base image -FROM node:24-slim AS base +# Base image with Node for building +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 \ nginx \ supervisor \ @@ -10,65 +26,48 @@ RUN apt-get update && apt-get install -y \ curl \ jq \ wget \ - apache2-utils \ - && rm -rf /var/lib/apt/lists/* + apache2-utils && \ + 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 \ && dpkg -i cloudflared.deb \ && rm cloudflared.deb + # 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 -# Copy package.json and package-lock.json -COPY package*.json ./ +# Copy built app from builder stage +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 -ENV HUSKY=0 -ENV NPM_CONFIG_IGNORE_SCRIPTS=1 -RUN mkdir -p .git && npm ci +# Copy system packages from the system-deps stage +COPY --from=system-deps /etc/nginx /etc/nginx +COPY --from=system-deps /usr/sbin/nginx /usr/sbin/nginx +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 -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 +# Optional: create supervisor log dir RUN mkdir -p /var/log/supervisor -COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf -# Copy and make executable the startup script -COPY startup.sh /usr/local/bin/ -RUN chmod +x /usr/local/bin/startup.sh +# Fix nginx worker_connections +RUN sed -i 's/worker_connections [0-9]*/worker_connections 8192/' /etc/nginx/nginx.conf || true +# Cloudflared config volume setup RUN mkdir -p /etc/cloudflared && \ chown -R node:node /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_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"]