From 7088a588215675dd5839887e63935313b533e39e Mon Sep 17 00:00:00 2001 From: KARTIK ASHOK PAWAR Date: Tue, 21 Oct 2025 13:44:59 +0530 Subject: [PATCH] Enhance Dockerfile with build args and healthcheck Added build arguments and environment variables for configuration. Updated healthcheck command for nginx. --- Dockerfile | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d9f48e1..6a8fc21 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,10 @@ +# Use the oven/bun image as the build stage FROM oven/bun AS builder +# Set working directory inside the container WORKDIR /app +# Declare build arguments (for environment variables to be passed in during build) ARG PUB_ENV ARG PUB_HOSTNAME ARG PUB_PLAUSIBLE_URL @@ -10,6 +13,7 @@ ARG PUB_DISABLE_ALL_EXTERNAL_REQUESTS ARG PUB_DONATION_URL ARG PUB_STRIPE_KEY +# Set environment variables inside the container using ARG values ENV PUB_ENV=${PUB_ENV} ENV PUB_HOSTNAME=${PUB_HOSTNAME} ENV PUB_PLAUSIBLE_URL=${PUB_PLAUSIBLE_URL} @@ -18,21 +22,30 @@ 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} +# Copy only package.json to leverage cached layer for dependencies COPY package.json ./ +# Install dependencies using bun package manager RUN bun install +# Copy the rest of the application files COPY . ./ +# Build the application (usually producing a production-ready bundle) RUN bun run build +# Use nginx stable alpine image as the final stage for serving static files FROM nginx:stable-alpine +# Open port 80 for HTTP traffic EXPOSE 80/tcp +# Copy custom nginx configuration into the container COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf +# Copy the built application from the builder stage to nginx's html directory COPY --from=builder /app/build /usr/share/nginx/html +# Define a healthcheck to ensure the nginx server is responsive 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://localhost || exit 1