From ec5bc2c730778d2d1f2f690461b6081df3cbd865 Mon Sep 17 00:00:00 2001 From: Erik Vroon Date: Sat, 7 Aug 2021 16:35:45 +0200 Subject: [PATCH 1/2] Small optimization in Dockerfile --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 034d3a4991..5814f88049 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,9 @@ FROM node:lts-alpine # Define some ENV Vars -ENV PORT 80 -ENV DIRECTORY /app -ENV IS_DOCKER true +ENV PORT=80 \ + DIRECTORY=/app \ + IS_DOCKER=true # Create and set the working directory WORKDIR ${DIRECTORY} From 8f1201b4d3cd11d5011a23b272019b10f297d10a Mon Sep 17 00:00:00 2001 From: Erik Vroon Date: Sat, 7 Aug 2021 16:39:10 +0200 Subject: [PATCH 2/2] Include arm Dockerfiles Uses QEMU to build the docker images on amd64 architectures, such that Docker Hub can build the images. --- Dockerfile-arm32v7 | 43 +++++++++++++++++++++++++++++++++++++++++++ Dockerfile-arm64v8 | 43 +++++++++++++++++++++++++++++++++++++++++++ hooks/pre-build | 8 ++++++++ 3 files changed, 94 insertions(+) create mode 100644 Dockerfile-arm32v7 create mode 100644 Dockerfile-arm64v8 create mode 100644 hooks/pre-build diff --git a/Dockerfile-arm32v7 b/Dockerfile-arm32v7 new file mode 100644 index 0000000000..cb50da2b0c --- /dev/null +++ b/Dockerfile-arm32v7 @@ -0,0 +1,43 @@ +FROM alpine:3.12 AS builder + +# Download QEMU, see https://github.com/docker/hub-feedback/issues/1261 +RUN QEMU_URL=https://github.com/balena-io/qemu/releases/download/v5.2.0%2Bbalena4/qemu-5.2.0.balena4-arm.tar.gz \ + && apk add curl && curl -L $QEMU_URL | tar zxvf - -C . --strip-components 1 + +# Start second (arm32v7) stage +FROM arm32v7/alpine:3.12 + +# Add QEMU from build stage +COPY --from=builder qemu-arm-static /usr/bin + +# Install Node and Yarn +RUN apk add --update --no-cache nodejs npm yarn + +# Define some ENV Vars +ENV PORT=80 \ + DIRECTORY=/app \ + IS_DOCKER=true + +# Create and set the working directory +WORKDIR ${DIRECTORY} + +# Copy over both 'package.json' and 'package-lock.json' (if available) +COPY package*.json ./ + +# Install project dependencies +RUN yarn + +# Copy over all project files and folders to the working directory +COPY . . + +# Build initial app for production +RUN yarn build + +# Expose given port +EXPOSE ${PORT} + +# Finally, run start command to serve up the built application +CMD [ "yarn", "build-and-start"] + +# Run simple healthchecks every 5 mins, to check the Dashy's everythings great +HEALTHCHECK --interval=5m --timeout=2s --start-period=30s CMD yarn health-check diff --git a/Dockerfile-arm64v8 b/Dockerfile-arm64v8 new file mode 100644 index 0000000000..774e7b5f33 --- /dev/null +++ b/Dockerfile-arm64v8 @@ -0,0 +1,43 @@ +FROM alpine:3.12 AS builder + +# Download QEMU, see https://github.com/docker/hub-feedback/issues/1261 +RUN QEMU_URL=https://github.com/balena-io/qemu/releases/download/v5.2.0%2Bbalena4/qemu-5.2.0.balena4-arm.tar.gz \ + && apk add curl && curl -L $QEMU_URL | tar zxvf - -C . --strip-components 1 + +# Start second (arm64v8) stage +FROM arm64v8/alpine:3.12 + +# Add QEMU from build stage +COPY --from=builder qemu-arm-static /usr/bin + +# Install Node and Yarn +RUN apk add --update --no-cache nodejs npm yarn + +# Define some ENV Vars +ENV PORT=80 \ + DIRECTORY=/app \ + IS_DOCKER=true + +# Create and set the working directory +WORKDIR ${DIRECTORY} + +# Copy over both 'package.json' and 'package-lock.json' (if available) +COPY package*.json ./ + +# Install project dependencies +RUN yarn + +# Copy over all project files and folders to the working directory +COPY . . + +# Build initial app for production +RUN yarn build + +# Expose given port +EXPOSE ${PORT} + +# Finally, run start command to serve up the built application +CMD [ "yarn", "build-and-start"] + +# Run simple healthchecks every 5 mins, to check the Dashy's everythings great +HEALTHCHECK --interval=5m --timeout=2s --start-period=30s CMD yarn health-check diff --git a/hooks/pre-build b/hooks/pre-build new file mode 100644 index 0000000000..b062128388 --- /dev/null +++ b/hooks/pre-build @@ -0,0 +1,8 @@ +#!/bin/bash + +# Source: https://github.com/ckulka/docker-multi-arch-example/blob/master/hooks/pre_build +# Used to setup QEMU to build arm images on amd64 processors. + +# Register qemu-*-static for all supported processors except the +# current one, but also remove all registered binfmt_misc before +docker run --rm --privileged multiarch/qemu-user-static:register --reset