From 41037359c302c23428ae3f2bcfe10498b5131933 Mon Sep 17 00:00:00 2001 From: KARTIK ASHOK PAWAR Date: Tue, 21 Oct 2025 13:46:18 +0530 Subject: [PATCH] Refactor Dockerfile for build and healthcheck Updated Dockerfile to improve build process and healthcheck. --- Dockerfile | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index d9f48e1..37e4704 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,38 +1,62 @@ +# Stage 1: Build the application using the bun container FROM oven/bun AS builder +# Set the working directory inside the container WORKDIR /app +# Build-time arguments (do NOT include secrets here) ARG PUB_ENV ARG PUB_HOSTNAME ARG PUB_PLAUSIBLE_URL -ARG PUB_VERTD_URL ARG PUB_DISABLE_ALL_EXTERNAL_REQUESTS ARG PUB_DONATION_URL ARG PUB_STRIPE_KEY -ENV PUB_ENV=${PUB_ENV} -ENV PUB_HOSTNAME=${PUB_HOSTNAME} -ENV PUB_PLAUSIBLE_URL=${PUB_PLAUSIBLE_URL} -ENV PUB_VERTD_URL=${PUB_VERTD_URL} -ENV PUB_DISABLE_ALL_EXTERNAL_REQUESTS=${PUB_DISABLE_ALL_EXTERNAL_REQUESTS} -ENV PUB_DONATION_URL=${PUB_DONATION_URL} -ENV PUB_STRIPE_KEY=${PUB_STRIPE_KEY} +# Expose ARGs as environment variables during build +ENV PUB_ENV=${PUB_ENV} \ + PUB_HOSTNAME=${PUB_HOSTNAME} \ + PUB_PLAUSIBLE_URL=${PUB_PLAUSIBLE_URL} \ + PUB_DISABLE_ALL_EXTERNAL_REQUESTS=${PUB_DISABLE_ALL_EXTERNAL_REQUESTS} \ + PUB_DONATION_URL=${PUB_DONATION_URL} \ + PUB_STRIPE_KEY=${PUB_STRIPE_KEY} -COPY package.json ./ +# Copy dependency manifest files first (for efficient caching) +COPY package.json ./ # Node dependencies manifest +COPY bun.lockb ./ # Bun lockfile +# Install dependencies RUN bun install -COPY . ./ +# Copy source files +COPY . ./ +# Run build script to create production assets RUN bun run build +# Stage 2: Serve static files with Nginx FROM nginx:stable-alpine +# Add labels for source and maintainer info +LABEL org.opencontainers.image.source="https://github.com/VERT-sh/VERT" \ + maintainer="VERT-sh" + +# Expose port 80 EXPOSE 80/tcp +# Install curl for healthcheck +RUN apk add --no-cache curl + +# Copy custom nginx configuration if exists COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf +# Copy build output from previous stage to nginx's serving directory COPY --from=builder /app/build /usr/share/nginx/html +# Change ownership to nginx user for proper permission handling +RUN chown -R nginx:nginx /usr/share/nginx/html + +# Define a simple HTTP healthcheck HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ - CMD curl --fail --silent --output /dev/null http://localhost || exit 1 \ No newline at end of file + CMD curl --fail --silent --output /dev/null http://127.0.0.1/ || exit 1 + +# Use nginx's default command to start serving