From 64372e9cc906c1756e330bb6af4aadd3b3423f59 Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Wed, 13 Dec 2017 19:55:26 -0800 Subject: [PATCH 1/2] Do the webpack build in an amd64 image to improve build times Change-Type: patch Signed-off-by: Pablo Carranza Velez --- Dockerfile | 54 ++++++++++++++++++++++++++++++--------------- Makefile | 11 +++++---- automation/build.sh | 15 ++++++++++++- 3 files changed, 57 insertions(+), 23 deletions(-) diff --git a/Dockerfile b/Dockerfile index cf648d39..e586aec8 100644 --- a/Dockerfile +++ b/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 diff --git a/Makefile b/Makefile index 7cda3ac1..126ecfbd 100644 --- a/Makefile +++ b/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 diff --git a/automation/build.sh b/automation/build.sh index 2c92b8c2..56f55dac 100755 --- a/automation/build.sh +++ b/automation/build.sh @@ -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 From e80c9af3c73661575d0ea1e7c31f192c7a6481d7 Mon Sep 17 00:00:00 2001 From: "resin-io-versionbot[bot]" Date: Thu, 14 Dec 2017 11:18:40 +0000 Subject: [PATCH 2/2] v6.5.4 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37f7af14..48de21e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY! This project adheres to [Semantic Versioning](http://semver.org/). +## v6.5.4 - 2017-12-14 + +* Do the webpack build in an amd64 image to improve build times #539 [Pablo Carranza Velez] + ## v6.5.3 - 2017-12-12 * Gosuper: When getting IP addresses, ignore balena and the resin-dns bridge #536 [Pablo Carranza Velez] diff --git a/package.json b/package.json index 22fb1563..4f2e219f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "resin-supervisor", "description": "This is resin.io's Supervisor, a program that runs on IoT devices and has the task of running user Apps (which are Docker containers), and updating them as Resin's API informs it to.", - "version": "6.5.3", + "version": "6.5.4", "license": "Apache-2.0", "repository": { "type": "git",