From 5a67158734599566a9b5b26e74edff204bd4b90f Mon Sep 17 00:00:00 2001 From: Brian Gann Date: Tue, 19 Aug 2025 14:22:59 -0400 Subject: [PATCH] Build: Adds option to build debug frontend docker images (#108202) * Add env support for different build environment targets * Add NX target for dev builds * Add option to build in dev mode * skip immutable flag for dev builds --- Dockerfile | 20 +++++++++++++++----- Makefile | 32 +++++++++++++++++++++++++++++--- project.json | 11 +++++++++++ 3 files changed, 55 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 82e0053f42c..bb4fe895684 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,9 +18,11 @@ FROM alpine:3.21.3 AS alpine-base FROM ubuntu:22.04 AS ubuntu-base FROM golang:1.24.6-alpine AS go-builder-base FROM --platform=${JS_PLATFORM} node:22-alpine AS js-builder-base - # Javascript build stage FROM --platform=${JS_PLATFORM} ${JS_IMAGE} AS js-builder +ARG JS_NODE_ENV=production +ARG JS_YARN_INSTALL_FLAG=--immutable +ARG JS_YARN_BUILD_FLAG=build ENV NODE_OPTIONS=--max_old_space_size=8000 @@ -35,15 +37,23 @@ COPY conf/defaults.ini ./conf/defaults.ini COPY e2e e2e RUN apk add --no-cache make build-base python3 - -RUN yarn install --immutable +# +# Set the node env according to defaults or argument passed +# +ENV NODE_ENV=${JS_NODE_ENV} +# +RUN if [ "$JS_YARN_INSTALL_FLAG" = "" ]; then \ + yarn install; \ + else \ + yarn install --immutable; \ + fi COPY tsconfig.json eslint.config.js .editorconfig .browserslistrc .prettierrc.js ./ COPY scripts scripts COPY emails emails -ENV NODE_ENV=production -RUN yarn build +# Set the build argument according to default or argument passed +RUN yarn ${JS_YARN_BUILD_FLAG} # Golang build stage FROM ${GO_IMAGE} AS go-builder diff --git a/Makefile b/Makefile index 28595926660..2dc98f53460 100644 --- a/Makefile +++ b/Makefile @@ -400,13 +400,36 @@ shellcheck: $(SH_FILES) ## Run checks for shell scripts. TAG_SUFFIX=$(if $(WIRE_TAGS)!=oss,-$(WIRE_TAGS)) PLATFORM=linux/amd64 +# default to a production build for frontend +# +DOCKER_JS_NODE_ENV_FLAG = production +DOCKER_JS_YARN_BUILD_FLAG = build +DOCKER_JS_YARN_INSTALL_FLAG = --immutable +# +# if go is in dev mode, also build node in dev mode +ifeq ($(GO_BUILD_DEV), dev) + DOCKER_JS_NODE_ENV_FLAG = dev + DOCKER_JS_YARN_BUILD_FLAG = dev + DOCKER_JS_YARN_INSTALL_FLAG = +endif +# if NODE_ENV is set in the environment to dev, build frontend in dev mode, and allow go builds to use their default +ifeq (${NODE_ENV}, dev) + DOCKER_JS_NODE_ENV_FLAG = dev + DOCKER_JS_YARN_BUILD_FLAG = dev + DOCKER_JS_YARN_INSTALL_FLAG = +endif + .PHONY: build-docker-full build-docker-full: ## Build Docker image for development. - @echo "build docker container" + @echo "build docker container mode=($(DOCKER_JS_NODE_ENV_FLAG))" tar -ch . | \ docker buildx build - \ --platform $(PLATFORM) \ --build-arg BINGO=false \ + --build-arg NODE_ENV=$(DOCKER_JS_NODE_ENV_FLAG) \ + --build-arg JS_NODE_ENV=$(DOCKER_JS_NODE_ENV_FLAG) \ + --build-arg JS_YARN_INSTALL_FLAG=$(DOCKER_JS_YARN_INSTALL_FLAG) \ + --build-arg JS_YARN_BUILD_FLAG=$(DOCKER_JS_YARN_BUILD_FLAG) \ --build-arg GO_BUILD_TAGS=$(GO_BUILD_TAGS) \ --build-arg WIRE_TAGS=$(WIRE_TAGS) \ --build-arg COMMIT_SHA=$$(git rev-parse HEAD) \ @@ -416,11 +439,15 @@ build-docker-full: ## Build Docker image for development. .PHONY: build-docker-full-ubuntu build-docker-full-ubuntu: ## Build Docker image based on Ubuntu for development. - @echo "build docker container" + @echo "build docker container mode=($(DOCKER_JS_NODE_ENV_FLAG))" tar -ch . | \ docker buildx build - \ --platform $(PLATFORM) \ --build-arg BINGO=false \ + --build-arg NODE_ENV=$(DOCKER_JS_NODE_ENV_FLAG) \ + --build-arg JS_NODE_ENV=$(DOCKER_JS_NODE_ENV_FLAG) \ + --build-arg JS_YARN_INSTALL_FLAG=$(DOCKER_JS_YARN_INSTALL_FLAG) \ + --build-arg JS_YARN_BUILD_FLAG=$(DOCKER_JS_YARN_BUILD_FLAG) \ --build-arg GO_BUILD_TAGS=$(GO_BUILD_TAGS) \ --build-arg WIRE_TAGS=$(WIRE_TAGS) \ --build-arg COMMIT_SHA=$$(git rev-parse HEAD) \ @@ -546,4 +573,3 @@ help: ## Display this help. # container/check-licenses target) check-licenses: license_finder --decisions-file .github/license_finder.yaml - diff --git a/project.json b/project.json index b67053dbbe6..24ba18921de 100644 --- a/project.json +++ b/project.json @@ -23,6 +23,17 @@ "outputs": ["{workspaceRoot}/public/build"], "cache": true }, + "dev": { + "dependsOn": [ + "themes-generate", + { + "projects": ["tag:scope:plugin"], + "target": "build" + } + ], + "outputs": ["{workspaceRoot}/public/build"], + "cache": true + }, "themes-generate": { "inputs": [ "{workspaceRoot}/scripts/cli/generateSassVariableFiles.ts",