Skip to content

Commit

Permalink
Revert "feat(dockerfile): use ubi9/nodejs-20 image & upgrade router v…
Browse files Browse the repository at this point in the history
…1.35->v1.40"

This reverts commit eb2fbec.
  • Loading branch information
karisal-anders committed Mar 1, 2024
1 parent 01f2b27 commit da5e8d6
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 96 deletions.
67 changes: 31 additions & 36 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,17 @@
# 2. depend on .dockerignore, you must at least #
# ignore: all **/node_modules folders and .yarn/cache #
###################################################################
ARG BUILDER_FROM_IMAGE=registry.access.redhat.com/ubi9/nodejs-20
ARG BUILDER_FROM_IMAGE=helsinkitest/node:20-slim

FROM registry.access.redhat.com/ubi9/nodejs-20 AS deps
FROM helsinkitest/node:20-slim AS deps

# install yarn
USER root
RUN curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo
RUN yum -y install yarn

RUN yum update -y && \
yum install -y rsync
RUN apt-get update && \
apt-get install -y --no-install-recommends rsync

WORKDIR /workspace-install

COPY --chown=default:root yarn.lock .yarnrc.yml ./
COPY --chown=default:root .yarn/ ./.yarn/
COPY --chown=appuser:appuser yarn.lock .yarnrc.yml ./
COPY --chown=appuser:appuser .yarn/ ./.yarn/

# Specific to monerepo's as docker COPY command is pretty limited
# we use buidkit to prepare all files that are necessary for install
Expand All @@ -34,25 +29,25 @@ COPY --chown=default:root .yarn/ ./.yarn/
#
# Copy all files
WORKDIR /docker-context
COPY --chown=default:root . /docker-context
COPY --chown=appuser:appuser . /docker-context

# mount type bind is not supported on current version (4.10.35) of OpenShift build
# RUN --mount=type=bind,source=./,target=/docker-context \
RUN rsync -amv \
--chown=default:root \
--chown=appuser:appuser \
--exclude='node_modules' \
--exclude='*/node_modules' \
--include='package.json' \
--include='*/' --exclude='*' \
/docker-context/ /workspace-install/;

RUN chown -R default:root .
RUN chown -R appuser:appuser .

# remove rsync, unused dependencies, and clean yum cache
RUN yum remove -y rsync && \
yum autoremove -y && \
yum clean all && \
rm -rf /var/cache/yum
# remove rsync and apt cache
RUN apt-get remove -y rsync && \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/cache/apt/archives

#
# To speed up installations, we override the default yarn cache folder
Expand All @@ -77,7 +72,7 @@ RUN yum remove -y rsync && \
###################################################################
# Stage 2: Build the app #
###################################################################
FROM ${BUILDER_FROM_IMAGE} AS builder
FROM ${BUILDER_FROM_IMAGE} AS builder
# Build ARGS
ARG PROJECT
ARG CMS_ORIGIN
Expand Down Expand Up @@ -121,8 +116,8 @@ ARG NEXT_PUBLIC_COMMITHASH

WORKDIR /app

COPY --chown=default:root . .
COPY --from=deps --chown=default:root /workspace-install ./
COPY --chown=appuser:appuser . .
COPY --from=deps --chown=appuser:appuser /workspace-install ./

# Optional: if the app depends on global /static shared assets like images, locales...

Expand All @@ -146,10 +141,10 @@ CMD ["sh", "-c", "echo ${PROJECT}"]
# last stage should be the production build." #
###################################################################

FROM registry.access.redhat.com/ubi9/nodejs-20 AS develop
FROM helsinkitest/node:20-slim AS develop

# Use non-root user
USER default
USER appuser

# Build ARGS
ARG PROJECT
Expand All @@ -159,7 +154,7 @@ ENV NODE_ENV=development

WORKDIR /app

COPY --from=deps --chown=default:root /workspace-install ./
COPY --from=deps --chown=appuser:appuser /workspace-install ./

ENV PORT ${APP_PORT:-3000}

Expand All @@ -177,10 +172,10 @@ CMD ["sh", "-c", "${DEV_START}"]
# Stage 3: Extract a minimal image from the build #
###################################################################

FROM registry.access.redhat.com/ubi9/nodejs-20 AS runner
FROM helsinkitest/node:20-slim AS runner

# Use non-root user
USER default
USER appuser

# Build ARGS
ARG PROJECT
Expand All @@ -192,29 +187,29 @@ ENV PATH $PATH:/app/node_modules/.bin
ENV NODE_ENV production

# Copy the configuration files to the apps/project root
COPY --from=builder --chown=default:root /app/apps/${PROJECT}/next.config.js \
COPY --from=builder --chown=appuser:appuser /app/apps/${PROJECT}/next.config.js \
/app/apps/${PROJECT}/i18nRoutes.config.js \
/app/apps/${PROJECT}/next-i18next.config.js \
/app/apps/${PROJECT}/package.json \
./apps/${PROJECT}/

# Copy common-i18n to share localization files after build
COPY --from=builder --chown=default:root /app/packages/common-i18n/src/locales \
COPY --from=builder --chown=appuser:appuser /app/packages/common-i18n/src/locales \
./packages/common-i18n/src/locales

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
# copy only the necessary files for a production deployment including select files in node_modules.
COPY --from=builder --chown=default:root /app/apps/${PROJECT}/.next/standalone .
COPY --from=builder --chown=default:root /app/apps/${PROJECT}/.next/static ./apps/${PROJECT}/.next/static
COPY --from=builder --chown=default:root /app/apps/${PROJECT}/public ./apps/${PROJECT}/public
COPY --from=builder --chown=default:root /app/next.base.config.js .
COPY --from=builder --chown=appuser:appuser /app/apps/${PROJECT}/.next/standalone .
COPY --from=builder --chown=appuser:appuser /app/apps/${PROJECT}/.next/static ./apps/${PROJECT}/.next/static
COPY --from=builder --chown=appuser:appuser /app/apps/${PROJECT}/public ./apps/${PROJECT}/public
COPY --from=builder --chown=appuser:appuser /app/next.base.config.js .
RUN cp -r /app/apps/${PROJECT}/.next/ /app/.next_orig/

# OpenShift write access to Next cache folder
USER root
RUN chgrp -R 0 /app/apps/${PROJECT}/.next/server/pages && chmod g+w -R /app/apps/${PROJECT}/.next/server/pages
USER default
USER appuser

ENV NEXT_TELEMETRY_DISABLED 1
ENV PORT ${APP_PORT:-3000}
Expand All @@ -223,9 +218,9 @@ ENV PORT ${APP_PORT:-3000}
EXPOSE $PORT

USER root
COPY --chown=default:root run_node.sh /app/run_node.sh
COPY --chown=appuser:appuser run_node.sh /app/run_node.sh
RUN chgrp 0 /app/run_node.sh && chmod +x /app/run_node.sh
USER default
USER appuser

# ENV PROD_START "./node_modules/.bin/next start apps/${PROJECT}/ -p ${PORT}"
# ENV PROD_START "node ./apps/${PROJECT}/server.js"
Expand Down
44 changes: 20 additions & 24 deletions DockerfileCache
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,15 @@
# ignore: all **/node_modules folders and .yarn/cache #
###################################################################

FROM registry.access.redhat.com/ubi9/nodejs-20 AS deps
FROM helsinkitest/node:20-slim AS deps

# install yarn
USER root
RUN curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo
RUN yum -y install yarn

RUN yum update -y && \
yum install -y rsync
RUN apt-get update && \
apt-get install -y --no-install-recommends rsync

WORKDIR /workspace-install

COPY --chown=default:root yarn.lock .yarnrc.yml ./
COPY --chown=default:root .yarn/ ./.yarn/
COPY --chown=appuser:appuser yarn.lock .yarnrc.yml ./
COPY --chown=appuser:appuser .yarn/ ./.yarn/

# Specific to monerepo's as docker COPY command is pretty limited
# we use buidkit to prepare all files that are necessary for install
Expand All @@ -33,25 +28,25 @@ COPY --chown=default:root .yarn/ ./.yarn/
#
# Copy all files
WORKDIR /docker-context
COPY --chown=default:root . /docker-context
COPY --chown=appuser:appuser . /docker-context

# mount type bind is not supported on current version (4.10.35) of OpenShift build
# RUN --mount=type=bind,source=./,target=/docker-context \
RUN rsync -amv \
--chown=default:root \
--chown=appuser:appuser \
--exclude='node_modules' \
--exclude='*/node_modules' \
--include='package.json' \
--include='*/' --exclude='*' \
/docker-context/ /workspace-install/;

RUN chown -R default:root .
RUN chown -R appuser:appuser .

# remove rsync, unused dependencies, and clean yum cache
RUN yum remove -y rsync && \
yum autoremove -y && \
yum clean all && \
rm -rf /var/cache/yum
# remove rsync and apt cache
RUN apt-get remove -y rsync && \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/cache/apt/archives

#
# To speed up installations, we override the default yarn cache folder
Expand All @@ -78,7 +73,7 @@ RUN yum remove -y rsync && \
# This is used to speedup OpenShift builds #
###################################################################
# Build cache layer
FROM registry.access.redhat.com/ubi9/nodejs-20 AS build_cache
FROM helsinkitest/node:20-slim AS build_cache
# Build ARGS
ARG PROJECT
ARG CMS_ORIGIN
Expand Down Expand Up @@ -118,20 +113,21 @@ ARG DOCKER_NEXTJS_DISABLE_SENTRY

WORKDIR /app

COPY --chown=default:root . .
COPY --from=deps --chown=default:root /workspace-install ./
COPY --chown=appuser:appuser . .
COPY --from=deps --chown=appuser:appuser /workspace-install ./

# install cache
RUN yarn install --immutable --inline-builds
RUN yarn workspace ${PROJECT} share-static-hardlink
RUN yarn workspace ${PROJECT} build

# Create cache image
FROM registry.access.redhat.com/ubi9/nodejs-20 AS cache
#FROM gcr.io/distroless/static-debian11 AS cache
FROM helsinkitest/node:20-slim AS cache
ARG PROJECT

WORKDIR /app/.yarn/cache/
COPY --from=build_cache --chown=default:root /app/.yarn/cache/ ./
COPY --from=build_cache --chown=appuser:appuser /app/.yarn/cache/ ./

WORKDIR /app
COPY --from=build_cache --chown=default:root /app/apps/${PROJECT}/.next/cache ./apps/${PROJECT}/.next/cache
COPY --from=build_cache --chown=appuser:appuser /app/apps/${PROJECT}/.next/cache ./apps/${PROJECT}/.next/cache
2 changes: 1 addition & 1 deletion proxies/events-graphql-federation/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/apollographql/router:v1.40.0 AS router
FROM ghcr.io/apollographql/router:v1.35.0 AS router

COPY ./supergraph.graphql /dist/schema/supergraph.graphql
COPY ./router.yaml /dist/config/router.yaml
Expand Down
Loading

0 comments on commit da5e8d6

Please sign in to comment.