Update Dockerfile

Added the comments to make it readable
This commit is contained in:
KARTIK ASHOK PAWAR 2025-10-21 13:27:42 +05:30 committed by GitHub
parent 00e38b6e2c
commit ca60c53cda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 1 deletions

View File

@ -1,7 +1,10 @@
# Use the oven/bun image as the build stage
FROM oven/bun AS builder FROM oven/bun AS builder
# Set working directory inside the container
WORKDIR /app WORKDIR /app
# Declare build arguments (for environment variables to be passed in during build)
ARG PUB_ENV ARG PUB_ENV
ARG PUB_HOSTNAME ARG PUB_HOSTNAME
ARG PUB_PLAUSIBLE_URL ARG PUB_PLAUSIBLE_URL
@ -10,6 +13,7 @@ ARG PUB_DISABLE_ALL_EXTERNAL_REQUESTS
ARG PUB_DONATION_URL ARG PUB_DONATION_URL
ARG PUB_STRIPE_KEY ARG PUB_STRIPE_KEY
# Set environment variables inside the container using ARG values
ENV PUB_ENV=${PUB_ENV} ENV PUB_ENV=${PUB_ENV}
ENV PUB_HOSTNAME=${PUB_HOSTNAME} ENV PUB_HOSTNAME=${PUB_HOSTNAME}
ENV PUB_PLAUSIBLE_URL=${PUB_PLAUSIBLE_URL} 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_DONATION_URL=${PUB_DONATION_URL}
ENV PUB_STRIPE_KEY=${PUB_STRIPE_KEY} ENV PUB_STRIPE_KEY=${PUB_STRIPE_KEY}
# Copy only package.json to leverage cached layer for dependencies
COPY package.json ./ COPY package.json ./
# Install dependencies using bun package manager
RUN bun install RUN bun install
# Copy the rest of the application files
COPY . ./ COPY . ./
# Build the application (usually producing a production-ready bundle)
RUN bun run build RUN bun run build
# Use nginx stable alpine image as the final stage for serving static files
FROM nginx:stable-alpine FROM nginx:stable-alpine
# Open port 80 for HTTP traffic
EXPOSE 80/tcp EXPOSE 80/tcp
# Copy custom nginx configuration into the container
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf 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 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 \ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl --fail --silent --output /dev/null http://localhost || exit 1 CMD curl --fail --silent --output /dev/null http://localhost || exit 1