-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(root): introducing graceful shutdown and optimise docker ima…
…ges (#6754)
- Loading branch information
Showing
35 changed files
with
684 additions
and
480 deletions.
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Ignore node_modules to avoid copying them into the image | ||
node_modules | ||
|
||
# Ignore local environment files | ||
.env | ||
.env.local | ||
.env.*.local | ||
|
||
# Ignore logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Ignore build directories | ||
dist | ||
build | ||
|
||
# Ignore test directories and files | ||
coverage | ||
*.test.js | ||
*.spec.js | ||
*.test.ts | ||
*.spec.ts | ||
|
||
# Ignore Docker-related files | ||
Dockerfile* | ||
.dockerignore | ||
|
||
# Ignore IDE/editor config files | ||
.vscode | ||
.idea | ||
*.swp | ||
|
||
# Ignore OS-specific files | ||
.DS_Store | ||
Thumbs.db | ||
|
||
# Ignore temporary files | ||
tmp | ||
temp | ||
*.tmp | ||
*.temp |
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,72 +1,54 @@ | ||
FROM node:20-alpine3.19 AS dev_base | ||
RUN apk add g++ make py3-pip | ||
|
||
ENV NX_DAEMON=false | ||
|
||
RUN npm i pm2 -g | ||
RUN npm --no-update-notifier --no-fund --global install [email protected] | ||
RUN pnpm --version | ||
|
||
USER 1000 | ||
WORKDIR /usr/src/app | ||
|
||
# ------- DEV BUILD ---------- | ||
FROM dev_base AS dev | ||
# Use the base image for development | ||
FROM ghcr.io/novuhq/novu/base:1.0.0 AS dev | ||
ARG PACKAGE_PATH | ||
|
||
COPY --chown=1000:1000 ./meta . | ||
COPY --chown=1000:1000 ./deps . | ||
COPY --chown=1000:1000 ./pkg . | ||
|
||
RUN --mount=type=secret,id=BULL_MQ_PRO_NPM_TOKEN,uid=1000 export BULL_MQ_PRO_NPM_TOKEN=$(cat /run/secrets/BULL_MQ_PRO_NPM_TOKEN) && \ | ||
if [ -n "${BULL_MQ_PRO_NPM_TOKEN}" ] ; then echo 'Building with Enterprise Edition of Novu'; rm -f .npmrc ; cp .npmrc-cloud .npmrc ; fi | ||
|
||
RUN --mount=type=cache,id=pnpm-store-api,target=/root/.pnpm-store\ | ||
--mount=type=secret,id=BULL_MQ_PRO_NPM_TOKEN,uid=1000 export BULL_MQ_PRO_NPM_TOKEN=$(cat /run/secrets/BULL_MQ_PRO_NPM_TOKEN) && \ | ||
pnpm install --filter "novuhq" --filter "{${PACKAGE_PATH}}..."\ | ||
--frozen-lockfile\ | ||
--unsafe-perm | ||
# Copy necessary directories to the image | ||
COPY --chown=1000:1000 ./meta ./deps ./pkg ./ | ||
|
||
RUN --mount=type=secret,id=BULL_MQ_PRO_NPM_TOKEN,uid=1000 export BULL_MQ_PRO_NPM_TOKEN=$(cat /run/secrets/BULL_MQ_PRO_NPM_TOKEN) && NODE_ENV=production NX_DAEMON=false pnpm build:api | ||
# Install dependencies and build the project | ||
RUN --mount=type=secret,id=BULL_MQ_PRO_NPM_TOKEN,uid=1000 \ | ||
BULL_MQ_PRO_NPM_TOKEN=$(cat /run/secrets/BULL_MQ_PRO_NPM_TOKEN) && \ | ||
[ -n "$BULL_MQ_PRO_NPM_TOKEN" ] && echo 'Building with Enterprise Edition of Novu' && \ | ||
rm -f .npmrc && cp .npmrc-cloud .npmrc || true && \ | ||
pnpm install --filter "novuhq" --filter "{${PACKAGE_PATH}}..." --frozen-lockfile --unsafe-perm && \ | ||
NODE_ENV=production NX_DAEMON=false pnpm build:api | ||
|
||
# Set the working directory to the API app and copy example environment file | ||
WORKDIR /usr/src/app/apps/api | ||
|
||
RUN cp src/.example.env dist/.env | ||
RUN cp src/.env.test dist/.env.test | ||
RUN cp src/.env.development dist/.env.development | ||
RUN cp src/.env.production dist/.env.production | ||
|
||
# Set the working directory to the root of the app | ||
WORKDIR /usr/src/app | ||
|
||
# ------- ASSETS BUILD ---------- | ||
# Create a new stage for building assets | ||
FROM dev AS assets | ||
|
||
WORKDIR /usr/src/app | ||
|
||
# Remove all dependencies so later we can only install prod dependencies without devDependencies | ||
# Remove node_modules and source directories | ||
RUN rm -rf node_modules && pnpm recursive exec -- rm -rf ./src ./node_modules | ||
|
||
# ------- PRODUCTION BUILD ---------- | ||
FROM dev_base AS prod | ||
# Use the base image for production | ||
FROM ghcr.io/novuhq/novu/base:1.0.0 AS prod | ||
|
||
ARG PACKAGE_PATH | ||
|
||
# Set environment variables for production | ||
ENV CI=true | ||
ENV NEW_RELIC_NO_CONFIG_FILE=true | ||
|
||
# Set the working directory to the root of the app | ||
WORKDIR /usr/src/app | ||
|
||
COPY --chown=1000:1000 ./meta . | ||
|
||
# Get the build artifacts that only include dist folders | ||
# Copy necessary directories from the build stage | ||
COPY --chown=1000:1000 ./meta ./ | ||
COPY --chown=1000:1000 --from=assets /usr/src/app . | ||
|
||
RUN --mount=type=cache,id=pnpm-store-api,target=/root/.pnpm-store\ | ||
--mount=type=secret,id=BULL_MQ_PRO_NPM_TOKEN,uid=1000 export BULL_MQ_PRO_NPM_TOKEN=$(cat /run/secrets/BULL_MQ_PRO_NPM_TOKEN) && \ | ||
pnpm install --filter "{${PACKAGE_PATH}}..." \ | ||
--frozen-lockfile \ | ||
--unsafe-perm | ||
|
||
ENV NEW_RELIC_NO_CONFIG_FILE=true | ||
# Install production dependencies | ||
RUN --mount=type=cache,id=pnpm-store-api,target=/root/.pnpm-store \ | ||
--mount=type=secret,id=BULL_MQ_PRO_NPM_TOKEN,uid=1000 \ | ||
pnpm install --filter "{${PACKAGE_PATH}}..." --frozen-lockfile --unsafe-perm --prod | ||
|
||
# Set the working directory to the API app and start the application using pm2-runtime | ||
WORKDIR /usr/src/app/apps/api | ||
CMD [ "pm2-runtime","start", "dist/main.js" ] | ||
CMD [ "pm2-runtime", "start", "dist/main.js" ] |
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Ignore node_modules to avoid copying them into the image | ||
node_modules | ||
|
||
# Ignore local environment files | ||
.env | ||
.env.local | ||
.env.*.local | ||
|
||
# Ignore logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Ignore build directories | ||
dist | ||
build | ||
|
||
# Ignore test directories and files | ||
coverage | ||
*.test.js | ||
*.spec.js | ||
*.test.ts | ||
*.spec.ts | ||
|
||
# Ignore Docker-related files | ||
Dockerfile* | ||
.dockerignore | ||
|
||
# Ignore IDE/editor config files | ||
.vscode | ||
.idea | ||
*.swp | ||
|
||
# Ignore OS-specific files | ||
.DS_Store | ||
Thumbs.db | ||
|
||
# Ignore temporary files | ||
tmp | ||
temp | ||
*.tmp | ||
*.temp |
Oops, something went wrong.