mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-20 22:23:13 +00:00
Do the webpack build in an amd64 image to improve build times
Change-Type: patch Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
This commit is contained in:
parent
f965db86b5
commit
64372e9cc9
54
Dockerfile
54
Dockerfile
@ -117,8 +117,38 @@ RUN echo '#!/bin/sh\nexit 0' > /usr/bin/cross-build-start && chmod +x /usr/bin/c
|
||||
|
||||
FROM i386-node-base as i386-nlp-node-base
|
||||
|
||||
##############################################################################
|
||||
|
||||
# We always do the webpack build on amd64, cause it's way faster
|
||||
FROM amd64-node-base as node-build
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y \
|
||||
g++ \
|
||||
git \
|
||||
libsqlite3-dev \
|
||||
make \
|
||||
python \
|
||||
rsync \
|
||||
wget \
|
||||
&& rm -rf /var/lib/apt/lists/
|
||||
|
||||
COPY package.json /usr/src/app/
|
||||
|
||||
RUN JOBS=MAX npm install --no-optional --unsafe-perm
|
||||
|
||||
COPY webpack.config.js fix-jsonstream.js /usr/src/app/
|
||||
COPY src /usr/src/app/src
|
||||
|
||||
RUN npm run lint \
|
||||
&& npm run build
|
||||
|
||||
##############################################################################
|
||||
|
||||
# Build nodejs dependencies
|
||||
FROM $ARCH-node-base as node
|
||||
FROM $ARCH-node-base as node-deps
|
||||
ARG ARCH
|
||||
|
||||
RUN [ "cross-build-start" ]
|
||||
@ -142,20 +172,8 @@ RUN mkdir -p rootfs-overlay && \
|
||||
COPY package.json /usr/src/app/
|
||||
|
||||
# Install only the production modules that have C extensions
|
||||
# Save the modules and then install devDependencies for build
|
||||
RUN JOBS=MAX npm install --production --no-optional --unsafe-perm \
|
||||
&& npm dedupe \
|
||||
&& cp -R node_modules node_modules_prod \
|
||||
&& npm install --no-optional --unsafe-perm
|
||||
|
||||
COPY webpack.config.js fix-jsonstream.js /usr/src/app/
|
||||
COPY src /usr/src/app/src
|
||||
|
||||
# Build the coffeescript and then restore the production modules
|
||||
RUN npm run lint \
|
||||
&& npm run build \
|
||||
&& rm -rf node_modules \
|
||||
&& mv node_modules_prod node_modules
|
||||
&& npm dedupe
|
||||
|
||||
# Remove various uneeded filetypes in order to reduce space
|
||||
# We also remove the spurious node.dtps, see https://github.com/mapbox/node-sqlite3/issues/861
|
||||
@ -177,7 +195,7 @@ COPY entry.sh run.sh package.json rootfs-overlay/usr/src/app/
|
||||
|
||||
COPY inittab rootfs-overlay/etc/inittab
|
||||
|
||||
RUN rsync -a --delete node_modules dist rootfs-overlay /build
|
||||
RUN rsync -a --delete node_modules rootfs-overlay /build
|
||||
|
||||
RUN [ "cross-build-end" ]
|
||||
|
||||
@ -195,10 +213,10 @@ COPY --from=base /dest/ /
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY --from=node /build/dist ./dist
|
||||
COPY --from=node /build/node_modules ./node_modules
|
||||
COPY --from=node-build /usr/src/app/dist ./dist
|
||||
COPY --from=node-deps /build/node_modules ./node_modules
|
||||
COPY --from=gosuper /build/gosuper ./gosuper
|
||||
COPY --from=node /build/rootfs-overlay/ /
|
||||
COPY --from=node-deps /build/rootfs-overlay/ /
|
||||
|
||||
VOLUME /data
|
||||
|
||||
|
11
Makefile
11
Makefile
@ -8,7 +8,7 @@
|
||||
# * deploy - pushes a resin-supervisor image to the registry, retrying up to 3 times
|
||||
# * base - builds the "base" component (a yocto builder with the output rootfs at /dest)
|
||||
# * gosuper - builds the "gosuper" component (a golang image with the Go supervisor component at /go/bin/gosuper and /build/gosuper)
|
||||
# * nodesuper - builds the node component, with the node_modules and src at /usr/src/app and /build (also includes a rootfs-overlay there)
|
||||
# * nodedeps, nodebuild - builds the node component, with the node_modules and src at /usr/src/app and /build (also includes a rootfs-overlay there)
|
||||
# * supervisor-dind: build the development docker-in-docker supervisor that run-supervisor uses (requires a SUPERVISOR_IMAGE to be available locally)
|
||||
#
|
||||
# Variables for build targets:
|
||||
@ -191,8 +191,11 @@ deploy:
|
||||
base:
|
||||
$(MAKE) -f $(THIS_FILE) TARGET_COMPONENT=base IMAGE=$(IMAGE) ARCH=$(ARCH) supervisor-image
|
||||
|
||||
nodesuper:
|
||||
$(MAKE) -f $(THIS_FILE) TARGET_COMPONENT=node IMAGE=$(IMAGE) ARCH=$(ARCH) supervisor-image
|
||||
nodedeps:
|
||||
$(MAKE) -f $(THIS_FILE) TARGET_COMPONENT=node-deps IMAGE=$(IMAGE) ARCH=$(ARCH) supervisor-image
|
||||
|
||||
nodebuild:
|
||||
$(MAKE) -f $(THIS_FILE) TARGET_COMPONENT=node-build IMAGE=$(IMAGE) ARCH=$(ARCH) supervisor-image
|
||||
|
||||
gosuper:
|
||||
$(MAKE) -f $(THIS_FILE) TARGET_COMPONENT=gosuper IMAGE=$(IMAGE) ARCH=$(ARCH) supervisor-image
|
||||
@ -223,4 +226,4 @@ test-integration: gosuper
|
||||
$(IMAGE) \
|
||||
go test -v ./supertest
|
||||
|
||||
.PHONY: supervisor deploy base nodesuper gosuper supervisor-dind run-supervisor
|
||||
.PHONY: supervisor deploy base nodedeps nodebuild gosuper supervisor-dind run-supervisor
|
||||
|
@ -55,17 +55,20 @@ TARGET_IMAGE=resin/$ARCH-supervisor:$TAG
|
||||
# Intermediate images and cache
|
||||
BASE_IMAGE=resin/$ARCH-supervisor-base:$TAG
|
||||
NODE_IMAGE=resin/$ARCH-supervisor-node:$TAG
|
||||
NODE_BUILD_IMAGE=resin/$ARCH-supervisor-node:$TAG-build
|
||||
GO_IMAGE=resin/$ARCH-supervisor-go:$TAG
|
||||
|
||||
TARGET_CACHE=$TARGET_IMAGE
|
||||
BASE_CACHE=$BASE_IMAGE
|
||||
GO_CACHE=$GO_IMAGE
|
||||
NODE_CACHE=$NODE_IMAGE
|
||||
NODE_BUILD_CACHE=$NODE_BUILD_IMAGE
|
||||
|
||||
TARGET_CACHE_MASTER=resin/$ARCH-supervisor:master
|
||||
BASE_CACHE_MASTER=resin/$ARCH-supervisor-base:master
|
||||
GO_CACHE_MASTER=resin/$ARCH-supervisor-go:master
|
||||
NODE_CACHE_MASTER=resin/$ARCH-supervisor-node:master
|
||||
NODE_BUILD_CACHE_MASTER=resin/$ARCH-supervisor-node:master-build
|
||||
|
||||
CACHE_FROM=""
|
||||
function tryPullForCache() {
|
||||
@ -85,6 +88,8 @@ tryPullForCache $GO_CACHE
|
||||
tryPullForCache $GO_CACHE_MASTER
|
||||
tryPullForCache $NODE_CACHE
|
||||
tryPullForCache $NODE_CACHE_MASTER
|
||||
tryPullForCache $NODE_BUILD_CACHE
|
||||
tryPullForCache $NODE_BUILD_CACHE_MASTER
|
||||
|
||||
if [ "$ENABLE_TESTS" = "true" ]; then
|
||||
make ARCH=$ARCH IMAGE=$GO_IMAGE test-gosuper
|
||||
@ -108,7 +113,13 @@ if [ "$PUSH_IMAGES" = "true" ]; then
|
||||
fi
|
||||
export DOCKER_BUILD_OPTIONS="${DOCKER_BUILD_OPTIONS} --cache-from ${GO_IMAGE}"
|
||||
|
||||
make IMAGE=$NODE_IMAGE nodesuper
|
||||
make IMAGE=$NODE_BUILD_IMAGE nodebuild
|
||||
if [ "$PUSH_IMAGES" = "true" ]; then
|
||||
make IMAGE=$NODE_BUILD_IMAGE deploy || true
|
||||
fi
|
||||
export DOCKER_BUILD_OPTIONS="${DOCKER_BUILD_OPTIONS} --cache-from ${NODE_BUILD_IMAGE}"
|
||||
|
||||
make IMAGE=$NODE_IMAGE nodedeps
|
||||
if [ "$PUSH_IMAGES" = "true" ]; then
|
||||
make IMAGE=$NODE_IMAGE deploy || true
|
||||
fi
|
||||
@ -132,9 +143,11 @@ if [ "$CLEANUP" = "true" ]; then
|
||||
tryRemove $BASE_IMAGE
|
||||
tryRemove $GO_IMAGE
|
||||
tryRemove $NODE_IMAGE
|
||||
tryRemove $NODE_BUILD_IMAGE
|
||||
|
||||
tryRemove $TARGET_CACHE
|
||||
tryRemove $BASE_CACHE
|
||||
tryRemove $GO_CACHE
|
||||
tryRemove $NODE_BUILD_CACHE
|
||||
tryRemove $NODE_CACHE
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user