Skip to content

Avoid redundant frontend builds #707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
ARG TARGETARCH
FROM docker.io/library/node:18-alpine as web-builder

USER node

ARG BUILDSCRIPT
WORKDIR /opt/app-root

COPY --chown=node web/package.json web/package.json
COPY --chown=node web/package-lock.json web/package-lock.json
WORKDIR /opt/app-root/web
RUN CYPRESS_INSTALL_BINARY=0 npm --legacy-peer-deps ci

WORKDIR /opt/app-root
COPY --chown=node web web
COPY mocks mocks

WORKDIR /opt/app-root/web
RUN npm run format-all
RUN npm run build$BUILDSCRIPT
FROM localhost/local-front-build:latest as web-builder

ARG TARGETARCH
FROM docker.io/library/golang:1.23 as go-builder

ARG TARGETARCH=amd64
Expand Down
23 changes: 23 additions & 0 deletions Dockerfile.front
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM docker.io/library/node:18-alpine as web-builder

USER node

ARG BUILDSCRIPT
WORKDIR /opt/app-root

COPY --chown=node web/package-lock.json web/package-lock.json
COPY --chown=node web/package.json web/package.json
WORKDIR /opt/app-root/web
RUN CYPRESS_INSTALL_BINARY=0 npm --legacy-peer-deps ci

WORKDIR /opt/app-root
COPY --chown=node web web
COPY mocks mocks

WORKDIR /opt/app-root/web
RUN npm run format-all
RUN npm run build$BUILDSCRIPT

FROM scratch

COPY --from=web-builder /opt/app-root/web/dist /opt/app-root/web/dist
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ CMDLINE_ARGS ?= --loglevel trace --config config/config.yaml
# build a single arch target provided as argument
define build_target
echo 'building image for arch $(1)'; \
DOCKER_BUILDKIT=1 $(OCI_BIN) buildx build --ulimit nofile=20480:20480 --load --build-arg LDFLAGS="${LDFLAGS}" --build-arg BUILDSCRIPT=${BUILDSCRIPT} --build-arg TARGETARCH=$(1) ${OCI_BUILD_OPTS} -t ${IMAGE}-$(1) -f Dockerfile .;
DOCKER_BUILDKIT=1 $(OCI_BIN) buildx build --load --build-arg LDFLAGS="${LDFLAGS}" --build-arg TARGETARCH=$(1) ${OCI_BUILD_OPTS} -t ${IMAGE}-$(1) -f Dockerfile .;
endef

# push a single arch target image
Expand Down Expand Up @@ -196,6 +196,7 @@ serve-mock: YQ ## Run backend using mocks
# note: to build and push custom image tag use: IMAGE_ORG=myuser VERSION=dev make images
.PHONY: image-build
image-build: ## Build MULTIARCH_TARGETS images
$(OCI_BIN) build --ulimit nofile=20480:20480 --build-arg BUILDSCRIPT=${BUILDSCRIPT} ${OCI_BUILD_OPTS} -t localhost/local-front-build:latest -f Dockerfile.front .
trap 'exit' INT; \
$(foreach target,$(MULTIARCH_TARGETS),$(call build_target,$(target)))

Expand Down
Loading