From 2eb9b2fe6d26066bca048144a3508e3622c5c468 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 15 Aug 2021 11:24:04 +0100 Subject: [PATCH 1/7] :whale: #136 Reverts Dockerfile, due to memory consumption --- Dockerfile | 54 ++++++++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/Dockerfile b/Dockerfile index cb9a39e6..8328882f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,53 +1,31 @@ -FROM node:14.17.5-alpine AS BUILD_IMAGE - -ARG TARGETPLATFORM -ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64} - -# Install additional tools needed on arm64 and armv7 -RUN \ - case "${TARGETPLATFORM}" in \ - 'linux/arm64') apk add --no-cache python make g++ ;; \ - 'linux/arm/v7') apk add --no-cache python make g++ ;; \ - esac - -# Create and set the working directory -WORKDIR /app - -COPY package.json yarn.lock ./ -RUN yarn install --frozen-lockfile --network-timeout 1000000 - -# Copy over all project files and folders to the working directory -COPY . ./ - -# Build initial app for production -RUN yarn build - -# # remove development dependencies -# RUN yarn install --production --ignore-scripts --prefer-offline - -# Build the final image -FROM node:14.17.5-alpine +FROM node:lts-alpine3.14 # Define some ENV Vars ENV PORT=80 \ - DIRECTORY=/app \ - IS_DOCKER=true + DIRECTORY=/app \ + IS_DOCKER=true # Create and set the working directory WORKDIR ${DIRECTORY} -# Install tini and tzdata -RUN apk add --no-cache tzdata tini +# Copy over both 'package.json' and 'package-lock.json' (if available) +COPY package*.json ./ +COPY yarn.lock ./ -# copy from build image -COPY --from=BUILD_IMAGE /app ./ +# Install project dependencies +RUN yarn -# Finally, run start command to serve up the built application -ENTRYPOINT [ "/sbin/tini", "--" ] -CMD [ "yarn", "build-and-start" ] +# 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 From 5dedb37279dd197fd3ad9294236c61b1faba2aa0 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 15 Aug 2021 11:25:19 +0100 Subject: [PATCH 2/7] :truck: Move additional Dockerfiles into sub dir --- docker/Dockerfile-arm32v7 | 43 +++++++++++++++++++++++++++++ docker/Dockerfile-arm64v8 | 43 +++++++++++++++++++++++++++++ docker/Dockerfile-multi-arch | 53 ++++++++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 docker/Dockerfile-arm32v7 create mode 100644 docker/Dockerfile-arm64v8 create mode 100644 docker/Dockerfile-multi-arch diff --git a/docker/Dockerfile-arm32v7 b/docker/Dockerfile-arm32v7 new file mode 100644 index 00000000..cb50da2b --- /dev/null +++ b/docker/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/docker/Dockerfile-arm64v8 b/docker/Dockerfile-arm64v8 new file mode 100644 index 00000000..1d85444b --- /dev/null +++ b/docker/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-aarch64.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-aarch64-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/docker/Dockerfile-multi-arch b/docker/Dockerfile-multi-arch new file mode 100644 index 00000000..cb9a39e6 --- /dev/null +++ b/docker/Dockerfile-multi-arch @@ -0,0 +1,53 @@ +FROM node:14.17.5-alpine AS BUILD_IMAGE + +ARG TARGETPLATFORM +ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64} + +# Install additional tools needed on arm64 and armv7 +RUN \ + case "${TARGETPLATFORM}" in \ + 'linux/arm64') apk add --no-cache python make g++ ;; \ + 'linux/arm/v7') apk add --no-cache python make g++ ;; \ + esac + +# Create and set the working directory +WORKDIR /app + +COPY package.json yarn.lock ./ +RUN yarn install --frozen-lockfile --network-timeout 1000000 + +# Copy over all project files and folders to the working directory +COPY . ./ + +# Build initial app for production +RUN yarn build + +# # remove development dependencies +# RUN yarn install --production --ignore-scripts --prefer-offline + +# Build the final image +FROM node:14.17.5-alpine + +# Define some ENV Vars +ENV PORT=80 \ + DIRECTORY=/app \ + IS_DOCKER=true + +# Create and set the working directory +WORKDIR ${DIRECTORY} + +# Install tini and tzdata +RUN apk add --no-cache tzdata tini + +# copy from build image +COPY --from=BUILD_IMAGE /app ./ + +# Finally, run start command to serve up the built application +ENTRYPOINT [ "/sbin/tini", "--" ] +CMD [ "yarn", "build-and-start" ] + +# Expose given port +EXPOSE ${PORT} + +# 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 From 02459645c3e0e314288c470b1e08c27ea3a36939 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 15 Aug 2021 11:38:37 +0100 Subject: [PATCH 3/7] :blowfish: Adds hooks --- Dockerfile-arm32v7 | 43 ------------------------------------------ Dockerfile-arm64v8 | 43 ------------------------------------------ docker/hooks/pre_build | 8 ++++++++ 3 files changed, 8 insertions(+), 86 deletions(-) delete mode 100644 Dockerfile-arm32v7 delete mode 100644 Dockerfile-arm64v8 create mode 100644 docker/hooks/pre_build diff --git a/Dockerfile-arm32v7 b/Dockerfile-arm32v7 deleted file mode 100644 index cb50da2b..00000000 --- a/Dockerfile-arm32v7 +++ /dev/null @@ -1,43 +0,0 @@ -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 deleted file mode 100644 index 1d85444b..00000000 --- a/Dockerfile-arm64v8 +++ /dev/null @@ -1,43 +0,0 @@ -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-aarch64.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-aarch64-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/docker/hooks/pre_build b/docker/hooks/pre_build new file mode 100644 index 00000000..b0621283 --- /dev/null +++ b/docker/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 From 6b527224c854100f4562e30d253a4f9970e096f5 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 15 Aug 2021 12:08:38 +0100 Subject: [PATCH 4/7] :hook: Moves Docker hooks to subdir --- docker/hooks/pre_build | 2 +- hooks/pre_build | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 hooks/pre_build diff --git a/docker/hooks/pre_build b/docker/hooks/pre_build index b0621283..e5feacb7 100644 --- a/docker/hooks/pre_build +++ b/docker/hooks/pre_build @@ -1,7 +1,7 @@ #!/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. +# Source: https://git.io/J0ezo # Register qemu-*-static for all supported processors except the # current one, but also remove all registered binfmt_misc before diff --git a/hooks/pre_build b/hooks/pre_build deleted file mode 100644 index b0621283..00000000 --- a/hooks/pre_build +++ /dev/null @@ -1,8 +0,0 @@ -#!/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 From 52c90bae3142a88b29c9b38ea34b6ef79da7ea64 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 15 Aug 2021 12:10:34 +0100 Subject: [PATCH 5/7] :whale: Updates multi-arch docker image --- docker/Dockerfile-multi-arch | 3 --- 1 file changed, 3 deletions(-) diff --git a/docker/Dockerfile-multi-arch b/docker/Dockerfile-multi-arch index cb9a39e6..b51f847d 100644 --- a/docker/Dockerfile-multi-arch +++ b/docker/Dockerfile-multi-arch @@ -22,9 +22,6 @@ COPY . ./ # Build initial app for production RUN yarn build -# # remove development dependencies -# RUN yarn install --production --ignore-scripts --prefer-offline - # Build the final image FROM node:14.17.5-alpine From aee62fdefe62889b961821fdc2e049c9b2604fb7 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 15 Aug 2021 12:11:52 +0100 Subject: [PATCH 6/7] :whale: Updates docker-compose with option for tagged builds --- docker-compose.yml | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 17aacb7a..e3ee93f3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,25 +1,42 @@ --- # Welcome to Dashy! To get started, run `docker compose up` +# You can configure your container here, by modifying this file version: "3.8" services: dashy: + container_name: Dashy + + # Pull latest image from DockerHub + image: lissy93/dashy + # To build from source, replace 'image: lissy93/dashy' with 'build: .' # build: . - image: lissy93/dashy - container_name: Dashy + + # Or, to use a Dockerfile for your archtecture, uncomment the following + # context: . + # dockerfile: ./docker/Dockerfile-arm32v7 + + # You can also use an image with a different tag, or pull from a different registry, e.g: + # image: ghcr.io/lissy93/dashy or image: lissy93/dashy:arm64v8 + # Pass in your config file below, by specifying the path on your host machine # volumes: # - /root/my-config.yml:/app/public/conf.yml + + # Set port that web service will be served on. Keep container port as 80 ports: - 4000:80 + # Set any environmental variables environment: - NODE_ENV=production # Specify your user ID and group ID. You can find this by running `id -u` and `id -g` # - UID=1000 # - GID=1000 + # Specify restart policy restart: unless-stopped + # Configure healthchecks healthcheck: test: ['CMD', 'node', '/app/services/healthcheck'] From c152b4f5926cf564a52e91b6da67e5b81e5f3ff9 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 15 Aug 2021 12:31:16 +0100 Subject: [PATCH 7/7] :memo: Updates Docker deployment docs --- README.md | 7 ++++++- docs/deployment.md | 17 +++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 83781ae1..b8ab6b20 100644 --- a/README.md +++ b/README.md @@ -121,10 +121,15 @@ docker run -d \ --restart=always \ lissy93/dashy:latest ``` +[![Dashy on Docker Hub](https://dockeri.co/image/lissy93/dashy)](https://hub.docker.com/r/lissy93/dashy) If you prefer to use Docker Compose, [here is an example](./docs/deployment.md#using-docker-compose). -[![Dashy on Docker Hub](https://dockeri.co/image/lissy93/dashy)](https://hub.docker.com/r/lissy93/dashy) +Dashy is also available through GHCR, run: `docker pull ghcr.io/lissy93/dashy`. + +To use Dashy on an system other than `amd64`, then use [one of these tags](https://hub.docker.com/r/lissy93/dashy/tags). There are containers for `arm32-7`, `arm64-v8` and a multi-architecture image. + +The image defaults to `:latest`, but you can instead specify a specific version, e.g. `docker pull lissy93/dashy:release-1.5.0` > Once you've got Dashy running, you can take a look at [App Management Docs](./docs/management.md), for info on using health checks, provisioning assets, configuring web servers, securing your app, logs, performance and more. diff --git a/docs/deployment.md b/docs/deployment.md index db24ffbb..d554f8d3 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -56,19 +56,21 @@ Explanation of the above options: - `-v` Specify volumes, to pass data from your host system to the container, in the format of `[host-path]:[container-path]`, you can use this to pass your config file, directory of assets (like icons), custom CSS or web assets (like favicon.ico, manifest.json etc) - `--name` Give your container a human-readable name - `--restart=always` Spin up the container when the daemon starts, or after it has been stopped -- `lissy93/dashy:latest` This last option is the image the container should be built from, you can also use a specific version, by replacing `:latest` with one of the [tags](https://hub.docker.com/r/lissy93/dashy/tags) +- `lissy93/dashy:latest` This last option is the image the container should be built from, you can also use a specific version or architecture type, by replacing `:latest` with one of the [tags](https://hub.docker.com/r/lissy93/dashy/tags) For all available options, and to learn more, see the [Docker Run Docs](https://docs.docker.com/engine/reference/commandline/run/) -If you're deploying Dashy on a modern ARM-based board, such as a Raspberry Pi (2+), then you'll need to use one of Dashy's ARM images. Set the base image + tag to either `lissy93/dashy:arm64v8` or `lissy93/dashy:arm32v7`, depending on your system architecture. +Dashy is also available through GHCR: `docker pull ghcr.io/lissy93/dashy:latest` + +If you're deploying Dashy on a modern ARM-based board, such as a Raspberry Pi (2+), then you'll need to use one of Dashy's ARM images. Set the base image + tag to either `lissy93/dashy:arm64v8` or `lissy93/dashy:arm32v7`, depending on your system architecture. You can also use the `multi-arch` image, which should work on all system architectures. + +The image defaults to `:latest`, but you can instead specify a specific version, e.g. `docker pull lissy93/dashy:release-1.5.0` ### Using Docker Compose -Using Docker Compose can be useful for saving your specific config in files, without having to type out a long run command each time. Save compose config as a YAML file, and then run `docker compose up` (optionally use the `-f` flag to specify file location, if it isn't located at `./docker-compose.yml`). +Using Docker Compose can be useful for saving your specific config in files, without having to type out a long run command each time. Save compose config as a YAML file, and then run `docker compose up` (optionally use the `-f` flag to specify file location, if it isn't located at `./docker-compose.yml`). Compose is also useful if you are using clusters, as the format is very similar to stack files, used with Docker Swarm. -Compose is also useful if you are using clusters, as the format is very similar to stack files, used with Docker Swarm. - -The following is a complete example of a `docker-compose.yml` for Dashy. Run it as is, or uncomment the additional options you need. +The following is a complete example of a [`docker-compose.yml`](https://github.com/Lissy93/dashy/blob/master/docker-compose.yml) for Dashy. Run it as is, or uncomment the additional options you need. ```yaml --- @@ -100,6 +102,9 @@ services: retries: 3 start_period: 40s ``` +You can use a different tag, by for example setting `image: lissy93/dashy:arm64v8`, or pull from GHCR instead by setting `image: ghcr.io/lissy93/dashy`. + +If you are building from source, and would like to use one of the [other Dockerfiles](https://github.com/Lissy93/dashy/tree/master/docker), then under `services.dashy` first set `context: .`, then specify the the path to the dockerfile, e.g. `dockerfile: ./docker/Dockerfile-arm32v7` ### Build from Source