-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3783 from bcgov/NDT-308-Rework-build-and-move-to-…
…Next.js-compiler Ndt 308 rework build and move to next.js compiler
- Loading branch information
Showing
53 changed files
with
3,571 additions
and
1,390 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
This file was deleted.
Oops, something went wrong.
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,3 +1,4 @@ | ||
*.js | ||
!*.cy.js | ||
!e2e.js | ||
instrumentation.ts |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
FROM registry.access.redhat.com/ubi9/s2i-base@sha256:77267c08bec417e9abc486241cab8ebc2c39693ed649ebc0a82f775db679b16a | ||
# Base stage to install global dependencies | ||
FROM node:20-alpine AS base | ||
|
||
ENV SUMMARY="An image for the CONN-CCBC-portal app" \ | ||
DESCRIPTION="This image contains the compiled CONN-CCBC-portal node app" | ||
|
@@ -12,79 +13,109 @@ LABEL summary="$SUMMARY" \ | |
vendor="Province of British Columbia" \ | ||
maintainer="Romer, Meherzad CITZ:EX <[email protected]>" | ||
|
||
ENV USER_ID=1001 | ||
ENV APP_HOME=/root | ||
ENV HOME=/root | ||
# Environment variables | ||
ARG GIT_HASH | ||
ENV GIT_HASH=${GIT_HASH} | ||
ARG SENTRY_AUTH_TOKEN | ||
Check warning on line 18 in app/Dockerfile GitHub Actions / build / appSensitive data should not be used in the ARG or ENV commands
|
||
ENV USER_ID=1001 | ||
ENV APP_HOME=/application | ||
ENV GIT_HASH=${GIT_HASH} | ||
ENV SENTRY_AUTH_TOKEN=${SENTRY_AUTH_TOKEN} | ||
Check warning on line 22 in app/Dockerfile GitHub Actions / build / appSensitive data should not be used in the ARG or ENV commands
|
||
ENV UPLOAD_DIR=${APP_HOME}/uploads | ||
|
||
WORKDIR ${APP_HOME} | ||
|
||
RUN INSTALL_PKGS="yarn-1.22.18-1" && \ | ||
yum -y update && \ | ||
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo > /etc/yum.repos.d/yarn.repo && \ | ||
rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg && \ | ||
yum -y install --setopt=tsflags=nodocs $INSTALL_PKGS && \ | ||
rpm -V $INSTALL_PKGS && \ | ||
yum -y clean all --enablerepo='*' && \ | ||
rm -rf /var/cache | ||
|
||
# Install asdf package manager | ||
RUN git clone https://github.com/asdf-vm/asdf.git ${APP_HOME}/asdf --branch v0.8.1 && \ | ||
cd ${APP_HOME}/asdf && \ | ||
git checkout v0.8.1 | ||
ENV BASH_ENV="${APP_HOME}/asdf/asdf.sh" | ||
# Because asdf is loaded via BASH_ENV, all commands using adsf need to be executed using /usr/bin/env bash -c | ||
SHELL ["/usr/bin/env", "bash", "-c"] | ||
|
||
# The app container only needs yarn and node; make sure they're installed | ||
COPY .tool-versions ${APP_HOME}/.tool-versions | ||
RUN sed -i -nr '/node|yarn/p' ${APP_HOME}/.tool-versions && \ | ||
cat ${APP_HOME}/.tool-versions | cut -f 1 -d ' ' | xargs -n 1 asdf plugin-add && \ | ||
asdf plugin-update --all && \ | ||
asdf install && \ | ||
asdf reshim && \ | ||
pushd ${APP_HOME}/.asdf/installs/nodejs/$(awk '/^nodejs/ { print $2 }' .tool-versions)/lib && \ | ||
npm i npm corepack && \ | ||
rm -f package.json package-lock.json && \ | ||
popd | ||
|
||
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init | ||
RUN chmod +x /usr/local/bin/dumb-init | ||
ENTRYPOINT ["dumb-init", "--", "/usr/bin/env", "bash", "-c"] | ||
|
||
COPY app/ ${APP_HOME}/ | ||
|
||
# FIX CVE-2022-29244 | ||
RUN rm -rf /usr/local/bin/npm \ | ||
&& rm -rf /root/.npm | ||
# Install system dependencies | ||
RUN apk add --no-cache libc6-compat | ||
|
||
# 1ST STAGE: INSTALL ALL DEPENDENCIES NEEDED FOR BUILD -- | ||
|
||
# Install both dev and prod dependencies during build | ||
FROM base AS deps | ||
|
||
# Copy only package.json yarn.lock and the patches for caching purposes | ||
COPY app/patches patches | ||
COPY app/package.json . | ||
COPY app/yarn.lock . | ||
|
||
# Install all dependencies (including dev) to ensure build tools are available | ||
RUN yarn --frozen-lockfile | ||
|
||
# -- END OF 1ST STAGE -- | ||
|
||
# -- 2ND STAGE: BUILD THE APP -- | ||
|
||
# Build the app | ||
FROM base AS builder | ||
|
||
# Copy node_modules from the deps stage | ||
COPY --from=deps ${APP_HOME}/node_modules ./node_modules | ||
|
||
# Copy the application source code | ||
COPY app/ . | ||
|
||
# Build the app (compile Relay, server, and Next.js) | ||
ENV NODE_ENV=production | ||
RUN yarn build:relay | ||
RUN yarn build:server | ||
RUN yarn build:next | ||
|
||
# -- END OF 2ND STAGE -- | ||
|
||
# -- 3RD STAGE: PRODUCTION DEPENDENCIES -- | ||
|
||
# Separate stage for production dependencies to leverage Docker caching | ||
FROM base AS prod-deps | ||
|
||
# Copy only package.json yarn.lock and the patches for caching purposes | ||
COPY app/patches patches | ||
COPY app/package.json . | ||
COPY app/yarn.lock . | ||
|
||
# Install only production dependencies so this layer can be cached separately | ||
RUN yarn install --frozen-lockfile --production=true --prefer-offline | ||
|
||
# -- END OF 3RD STAGE -- | ||
|
||
# -- FINAL STAGE -- | ||
# Production image to run the application | ||
FROM node:20-alpine AS runner | ||
|
||
# Env variables for the final image | ||
ENV APP_HOME=/application | ||
ENV UPLOAD_DIR=${APP_HOME}/uploads | ||
ENV USER_ID=1001 | ||
ENV NODE_ENV=production | ||
ENV ENABLE_ANALYTICS=true | ||
|
||
RUN PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1 CYPRESS_INSTALL_BINARY=0 \ | ||
yarn install --frozen-lockfile --production=false && \ | ||
yarn build:relay && \ | ||
yarn build:server && \ | ||
yarn build:next && \ | ||
yarn install --frozen-lockfile --production=true && \ | ||
yarn cache clean && \ | ||
# Make everything in the home group-writable to support OpenShift's restricted SCC | ||
# Needs to be done as root to chown | ||
# same layer as yarn install to keep re-chowned files from using up several hundred MBs more space | ||
chown -R ${USER_ID}:0 ${APP_HOME} && \ | ||
chmod -R g+rwX ${APP_HOME} | ||
|
||
# Create a directory for uploads | ||
RUN mkdir -p ${UPLOAD_DIR} && \ | ||
chown -R ${USER_ID}:0 ${UPLOAD_DIR} && \ | ||
chmod -R g+rw ${UPLOAD_DIR} | ||
|
||
EXPOSE 3000 9000 | ||
USER ${USER_ID} | ||
WORKDIR ${APP_HOME} | ||
|
||
CMD ["yarn start"] | ||
# Create a non-root user for OCP | ||
RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001 | ||
|
||
COPY --from=builder --chown=${USER_ID}:0 ${APP_HOME}/public ./public | ||
COPY --from=builder --chown=${USER_ID}:0 ${APP_HOME}/.next ./.next | ||
COPY --from=builder --chown=${USER_ID}:0 ${APP_HOME}/.persisted_operations ./.persisted_operations | ||
COPY --from=builder --chown=${USER_ID}:0 ${APP_HOME}/config ./config | ||
COPY --from=builder --chown=${USER_ID}:0 ${APP_HOME}/schema ./schema | ||
COPY --from=builder --chown=${USER_ID}:0 ${APP_HOME}/*.json5 . | ||
COPY --from=builder --chown=${USER_ID}:0 ${APP_HOME}/*.ts . | ||
COPY --from=builder --chown=${USER_ID}:0 ${APP_HOME}/*.js . | ||
COPY --from=builder --chown=${USER_ID}:0 ${APP_HOME}/*.properties . | ||
COPY --from=builder --chown=${USER_ID}:0 ${APP_HOME}/*.json . | ||
COPY --from=builder --chown=${USER_ID}:0 ${APP_HOME}/dist ./dist | ||
|
||
# Copy production dependencies | ||
COPY --from=prod-deps --chown=${USER_ID}:0 ${APP_HOME}/node_modules ./node_modules | ||
|
||
# Make sure uploads directory has proper permission | ||
RUN mkdir -p ${UPLOAD_DIR} | ||
RUN chown -PR ${USER_ID}:0 ${UPLOAD_DIR} | ||
RUN chmod -R g+rw ${UPLOAD_DIR} | ||
|
||
# Run as the non-root user | ||
USER ${USER_ID} | ||
|
||
# Expose ports | ||
EXPOSE 3000 9000 | ||
|
||
# Command to run the application | ||
CMD ["node", "--unhandled-rejections=strict", "--enable-network-family-autoselection", "dist/server.js"] |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.