Skip to content

Commit c794d3f

Browse files
mrTuomoKcursoragent
andcommitted
fix(docker): further reduce OpenShift next build memory use
Hoist pnpm node_modules, cap static-generation workers to one, and set CI build env vars directly in the Dockerfile. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent b1d9860 commit c794d3f

6 files changed

Lines changed: 29 additions & 3 deletions

File tree

.npmrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
engine-strict=true
2+
3+
# Flat node_modules layout (yarn-like). Reduces memory during Next.js build workers
4+
# with pnpm's default isolated linker + symlinks. Required for standalone tracing.
5+
# @see https://github.com/vercel/next.js/issues/48017
6+
node-linker=hoisted

Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ FROM ${BUILDER_FROM_IMAGE} AS builder
8080
# Build ARGS
8181
ARG PROJECT
8282
ARG CMS_ORIGIN
83-
ARG SKIP_BUILD_STATIC_GENERATION
83+
# Default 1 for review/dev image builds; release pipelines override with 0.
84+
ARG SKIP_BUILD_STATIC_GENERATION=1
8485
ARG NEXT_DISABLE_SOURCEMAPS
8586
ARG FEDERATION_ROUTER_ENDPOINT
8687
ARG LINKEDEVENTS_EVENT_ENDPOINT
@@ -140,7 +141,13 @@ USER default
140141
ENV HUSKY=0
141142
RUN pnpm install --frozen-lockfile --filter ${PROJECT}...
142143
RUN pnpm --filter ${PROJECT} run share-static-hardlink
143-
ENV SKIP_BUILD_STATIC_GENERATION=${SKIP_BUILD_STATIC_GENERATION}
144+
# OpenShift build pods are memory-constrained. Match GitHub CI build settings and
145+
# limit Next.js static-generation workers (default is 4 parallel child processes).
146+
ENV SKIP_BUILD_STATIC_GENERATION=${SKIP_BUILD_STATIC_GENERATION} \
147+
NEXTJS_IGNORE_ESLINT=1 \
148+
NEXTJS_IGNORE_TYPECHECK=1 \
149+
NEXT_BUILD_CPUS=1 \
150+
NEXT_TELEMETRY_DISABLED=1
144151
RUN pnpm --filter ${PROJECT} run build
145152

146153
# Does not play well with buildkit on CI

next.base.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const trueEnv = ['true', '1', 'yes'];
1515
// const isProd = process.env.NODE_ENV === 'production';
1616
const isDevelopment = process.env.NODE_ENV === 'development';
1717
const isCI = trueEnv.includes(process.env?.CI ?? 'false');
18+
const nextBuildCpus = process.env.NEXT_BUILD_CPUS
19+
? Number(process.env.NEXT_BUILD_CPUS)
20+
: undefined;
1821

1922
const NEXTJS_IGNORE_ESLINT = trueEnv.includes(
2023
process.env?.NEXTJS_IGNORE_ESLINT ?? 'false'
@@ -136,6 +139,9 @@ const nextBaseConfig = ({
136139
// Experimental monorepo support
137140
externalDir: true,
138141
scrollRestoration: true,
142+
// Limit parallel page-data workers in memory-constrained Docker/OpenShift builds.
143+
...(nextBuildCpus ? { cpus: nextBuildCpus } : {}),
144+
...(nextBuildCpus ? { webpackMemoryOptimizations: true } : {}),
139145
},
140146

141147
// 🚨 TURBOPACK CONFIGURATION

pipelines/harrastukset-ui-release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ extends:
3636
# Does not contain all buildArguments, the rest located in harrastukset-pipelines/harrastukset-variables-staging.yml and harrastukset-variables-common.yml
3737
# The values here will override the values defined in the harrastukset-pipelines repository
3838
buildArgs:
39+
SKIP_BUILD_STATIC_GENERATION: 0
3940
FEDERATION_ROUTER_ENDPOINT: https://harrastukset-router.api.hel.fi/
4041
CMS_ORIGIN: https://harrastus.content.api.hel.fi
4142
LINKEDEVENTS_EVENT_ENDPOINT: https://api.hel.fi/linkedevents/v1/event
@@ -44,6 +45,7 @@ extends:
4445
NEXT_PUBLIC_DEBUG: 0
4546
NEXT_PUBLIC_MATOMO_ENABLED: 1
4647
buildArgsStage:
48+
SKIP_BUILD_STATIC_GENERATION: 0
4749
FEDERATION_ROUTER_ENDPOINT: https://events-graphql-federation-hobbies.stage.hel.ninja/
4850
CMS_ORIGIN: https://harrastus.content.api.hel.fi
4951
LINKEDEVENTS_EVENT_ENDPOINT: https://api.hel.fi/linkedevents/v1/event
@@ -52,6 +54,7 @@ extends:
5254
NEXT_PUBLIC_DEBUG: 0
5355
NEXT_PUBLIC_MATOMO_ENABLED: 1
5456
buildArgsTest:
57+
SKIP_BUILD_STATIC_GENERATION: 0
5558
FEDERATION_ROUTER_ENDPOINT: https://events-graphql-federation-hobbies.test.hel.ninja/
5659
CMS_ORIGIN: https://harrastus.app-staging.hkih.hion.dev
5760
LINKEDEVENTS_EVENT_ENDPOINT: https://api.hel.fi/linkedevents/v1/event
@@ -72,4 +75,3 @@ extends:
7275
FEDERATION_ROUTER_ENDPOINT: https://events-graphql-federation-hobbies.test.hel.ninja/
7376
CMS_ORIGIN: https://harrastus.app-staging.hkih.hion.dev
7477
LINKEDEVENTS_EVENT_ENDPOINT: https://api.hel.fi/linkedevents/v1/event
75-

pipelines/liikunta-ui-release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ extends:
3636
# Does not contain all buildArguments, the rest located in liikunta-pipelines/liikunta-variables-staging.yml and liikunta-variables-common.yml
3737
# The values here will override the values defined in the liikunta-pipelines repository
3838
buildArgs: # build time arguments
39+
SKIP_BUILD_STATIC_GENERATION: 0
3940
FEDERATION_ROUTER_ENDPOINT: https://liikunta-router.api.hel.fi/
4041
CMS_ORIGIN: https://liikunta2.content.api.hel.fi
4142
LINKEDEVENTS_EVENT_ENDPOINT: https://api.hel.fi/linkedevents/v1/event
@@ -45,6 +46,7 @@ extends:
4546
NEXT_PUBLIC_MATOMO_ENABLED: 1
4647
NEXT_PUBLIC_ASKEM_ENABLED: 1
4748
buildArgsStage:
49+
SKIP_BUILD_STATIC_GENERATION: 0
4850
FEDERATION_ROUTER_ENDPOINT: https://events-graphql-federation-sports.stage.hel.ninja/
4951
CMS_ORIGIN: https://liikunta2.content.api.hel.fi
5052
LINKEDEVENTS_EVENT_ENDPOINT: https://api.hel.fi/linkedevents/v1/event
@@ -54,6 +56,7 @@ extends:
5456
NEXT_PUBLIC_MATOMO_ENABLED: 1
5557
NEXT_PUBLIC_ASKEM_ENABLED: 1
5658
buildArgsTest:
59+
SKIP_BUILD_STATIC_GENERATION: 0
5760
FEDERATION_ROUTER_ENDPOINT: https://events-graphql-federation-sports.test.hel.ninja/
5861
CMS_ORIGIN: https://liikunta.app-staging.hkih.hion.dev
5962
LINKEDEVENTS_EVENT_ENDPOINT: https://api.hel.fi/linkedevents/v1/event

pipelines/tapahtumat-ui-release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ extends:
3636
# Does not contain all buildArguments, the rest located in tapahtumat-pipelines/tapahtumat-variables-staging.yml and tapahtumat-variables-common.yml
3737
# The values here will override the values defined in the tapahtumat-pipelines repository
3838
buildArgs:
39+
SKIP_BUILD_STATIC_GENERATION: 0
3940
FEDERATION_ROUTER_ENDPOINT: https://tapahtumat-router.api.hel.fi/
4041
CMS_ORIGIN: https://tapahtumat.content.api.hel.fi
4142
LINKEDEVENTS_EVENT_ENDPOINT: https://api.hel.fi/linkedevents/v1/event
@@ -44,6 +45,7 @@ extends:
4445
NEXT_PUBLIC_DEBUG: 0
4546
NEXT_PUBLIC_MATOMO_ENABLED: 1
4647
buildArgsStage:
48+
SKIP_BUILD_STATIC_GENERATION: 0
4749
FEDERATION_ROUTER_ENDPOINT: https://events-graphql-federation-events.stage.hel.ninja/
4850
CMS_ORIGIN: https://tapahtumat.content.api.hel.fi
4951
LINKEDEVENTS_EVENT_ENDPOINT: https://api.hel.fi/linkedevents/v1/event
@@ -52,6 +54,7 @@ extends:
5254
NEXT_PUBLIC_DEBUG: 0
5355
NEXT_PUBLIC_MATOMO_ENABLED: 1
5456
buildArgsTest:
57+
SKIP_BUILD_STATIC_GENERATION: 0
5558
FEDERATION_ROUTER_ENDPOINT: https://events-graphql-federation-events.test.hel.ninja/
5659
CMS_ORIGIN: https://tapahtumat.app-staging.hkih.hion.dev
5760
LINKEDEVENTS_EVENT_ENDPOINT: https://api.hel.fi/linkedevents/v1/event

0 commit comments

Comments
 (0)