-
-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Dockerfile: Added Comments to briefly explain the instructions. #2683
Open
Piyush-r-bhaskar
wants to merge
1
commit into
altair-graphql:master
Choose a base branch
from
Piyush-r-bhaskar:patch-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,102 @@ | ||
# This Dockerfile defines a multi-stage build process for building and deploying an application using Yarn workspaces, TurboRepo for efficient monorepo management, and Alpine Linux for a minimal image size. | ||
|
||
# === Base Stage === | ||
# Builds a base image with necessary system dependencies. | ||
FROM node:20-alpine3.19 AS base | ||
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed | ||
RUN apk update && apk add --no-cache libc6-compat python3 make g++ py3-pip && rm -rf /var/cache/apk/* | ||
RUN ln -sf python3 /usr/bin/python | ||
ENV TURBO_TELEMETRY_DISABLED=1 | ||
|
||
# === | ||
# Install system packages required for building and running the application. | ||
# - libc6-compat: Provides compatibility for libraries compiled against glibc. [# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed] | ||
# - python3, make, g++: Essential build tools for various dependencies. | ||
# - py3-pip: Package installer for Python 3. | ||
RUN apk update && \ | ||
apk add --no-cache libc6-compat python3 make g++ py3-pip && \ | ||
rm -rf /var/cache/apk/* && \ | ||
ln -sf python3 /usr/bin/python | ||
|
||
# Disable telemetry in the Turbo build system. | ||
ENV TURBO_TELEMETRY_DISABLED=1 | ||
|
||
# === Builder Stage === | ||
# Builds the application using TurboRepo, taking advantage of its caching mechanisms. | ||
FROM base AS builder | ||
# Set working directory | ||
|
||
# Set the working directory inside the container to /app. | ||
WORKDIR /app | ||
|
||
# Install TurboRepo globally for managing the monorepo build. | ||
RUN yarn global add turbo@^2 | ||
|
||
# Copy the entire project directory into the container. | ||
COPY . . | ||
# copy packages that @altairgraphql/api depends on to out directory | ||
RUN turbo prune --scope=@altairgraphql/api --docker | ||
|
||
# === | ||
# Prune the workspace to prepare for building the @altairgraphql/api sub-project, ensuring only its dependencies are included, minimizing the final image size. | ||
RUN turbo prune --scope=@altairgraphql/api --docker | ||
|
||
# Add lockfile and package.json's of isolated subworkspace | ||
# === Installer Stage === | ||
# This stage prepares the final runtime image by copying build artifacts and installing production dependencies. | ||
FROM base AS installer | ||
|
||
# Set the working directory inside the container to /app. | ||
WORKDIR /app | ||
# First install dependencies (as they change less often) | ||
|
||
# Copy the .gitignore file to avoid adding unnecessary files to the image. | ||
COPY .gitignore .gitignore | ||
|
||
# FIXME: running yarn install with --ignore-scripts means that some packages may not get built correctly. Skipping these steps for now. | ||
# COPY --from=builder /app/out/json/ . | ||
# COPY --from=builder /app/out/yarn.lock ./yarn.lock | ||
# # install node_modules without running scripts (scripts depend on the source files) | ||
# RUN yarn install --ignore-scripts | ||
# Build the project and its dependencies | ||
|
||
# Copy the built application code from the builder stage. | ||
COPY --from=builder /app/out/full/ . | ||
|
||
# Copy configuration files for TurboRepo and Nx (a build system used within the project). | ||
COPY turbo.json turbo.json | ||
COPY nx.json nx.json | ||
COPY tsconfig.json tsconfig.json | ||
COPY CHECKS CHECKS | ||
# build the project, running the prepare scripts | ||
|
||
# Install production dependencies. | ||
RUN yarn | ||
RUN yarn turbo run build --filter=@altairgraphql/api... | ||
|
||
# === | ||
# Build the @altairgraphql/api project, utilizing Turbo's caching for speed. | ||
RUN yarn turbo run build --filter=@altairgraphql/api... | ||
|
||
# === Runner Stage === | ||
# This stage defines the final runtime environment for the application. | ||
FROM base AS runner | ||
|
||
# Set the working directory inside the container to /app. | ||
WORKDIR /app | ||
|
||
# Set the NODE_ENV environment variable to "production". | ||
ARG NODE_ENV=production | ||
ENV NODE_ENV=${NODE_ENV} | ||
|
||
# Set the application port. | ||
ARG PORT=3000 | ||
ENV PORT=${PORT} | ||
# Don't run production as root | ||
|
||
# Create a non-root user for running the application for improved security. | ||
RUN addgroup --system --gid 1001 nodejs | ||
RUN adduser --system --uid 1001 nodejs | ||
|
||
# Switch to the newly created user. | ||
USER nodejs | ||
|
||
# Copy the built application and its dependencies from the installer stage. | ||
COPY --from=installer /app . | ||
# new relic env variables | ||
|
||
# Configure New Relic monitoring. | ||
ENV NEW_RELIC_NO_CONFIG_FILE=true | ||
ENV NEW_RELIC_DISTRIBUTED_TRACING_ENABLED=true | ||
ENV NEW_RELIC_LOG=stdout | ||
|
||
# EXPOSE ${PORT} | ||
#-------------- | ||
# SUGGESTION - Define a health check to ensure the container is running correctly. This example assumes a /health endpoint is available. Adjust according to your application. | ||
# HEALTHCHECK --interval=30s --timeout=10s CMD curl --fail http://localhost:${PORT}/health || exit 1 | ||
#-------------- | ||
|
||
# Start the application. | ||
CMD ["yarn", "start:api:prod"] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / SonarCloud
Arguments in long RUN instructions should be sorted Low