From fbdbafaa9a00b2b97dd0d975e0a85734a77db996 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sat, 14 Dec 2019 10:16:17 +0100 Subject: [PATCH] refactoring Dockerfiles, adding arm32v6 support --- .gitignore | 2 +- README.md | 21 ++------- docker/README.md | 45 +++++++++++++++++++ docker/alpine/Dockerfile | 25 ----------- docker/amd64/alpine/Dockerfile | 34 ++++++++++++++ docker/amd64/debian-stretch/Dockerfile | 34 ++++++++++++++ .../debian-stretch/selfcontained/Dockerfile | 32 +++++++++++++ docker/arm32v6/debian-stretch/Dockerfile | 40 +++++++++++++++++ docker/arm32v6/debian-stretch/hooks/pre_build | 4 ++ docker/arm32v7/debian/stretch/Dockerfile | 14 ------ docker/debian/stretch/Dockerfile | 14 ------ src/common/SupportedFormats.ts | 19 ++------ .../private/PrivateConfigDefaultsClass.ts | 2 +- 13 files changed, 198 insertions(+), 88 deletions(-) create mode 100644 docker/README.md delete mode 100644 docker/alpine/Dockerfile create mode 100644 docker/amd64/alpine/Dockerfile create mode 100644 docker/amd64/debian-stretch/Dockerfile create mode 100644 docker/amd64/debian-stretch/selfcontained/Dockerfile create mode 100644 docker/arm32v6/debian-stretch/Dockerfile create mode 100644 docker/arm32v6/debian-stretch/hooks/pre_build delete mode 100644 docker/arm32v7/debian/stretch/Dockerfile delete mode 100644 docker/debian/stretch/Dockerfile diff --git a/.gitignore b/.gitignore index 1f797b89..8eb694b4 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,7 @@ benchmark/**/*.js benchmark/**/*.js.map gulpfile.js gulpfile.js.map -demo/TEMP/ +demo/tmp/ config.json users.db sqlite.db diff --git a/README.md b/README.md index 7c54b211..f30caa16 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ wget https://github.com/bpatrik/pigallery2/archive/master.zip unzip master.zip cd pigallery2-master # enter the unzipped directory npm install +npm build ``` **Note**: if you run `npm run create-release`, it creates a clean, minified, production ready version from the app in the `release` folder, that is ready to deploy. @@ -69,24 +70,8 @@ The app has a nice UI for settings, you may use that too. Default user: `admin` pass: `admin` ### 1.2 Run with Docker -If you have `docker` and don't want to install all the dependencies, use this: -```bash -docker run \ - -p 80:80 \ - -e NODE_ENV=production \ - -v /config.json:/pigallery2-release/config.json \ - -v /sqlite.db:/pigallery2-release/sqlite.db \ - -v :/pigallery2-release/demo/images \ - -v :/pigallery2-release/demo/TEMP \ - bpatrik/pigallery2:1.7.0-stretch -``` -Make sure that a file at `/config.json` and `sqlite.db` files exists before running it. - -You do not need the `/sqlite.db` line if you don't use the sqlite database. - -After the container is up and running, you go to `http://localhost` and log in with user: `admin` pass: `admin` and set up the page in the settings. - -**All docker builds**: https://hub.docker.com/r/bpatrik/pigallery2/tags/ +If you have `docker` and don't want to install all the dependencies, you can use one of our docker build. +For configuration read more [here](docker/README.md) or check all builds: https://hub.docker.com/r/bpatrik/pigallery2/tags/ **Note**: You dont need to do the installation steps if you are using docker. diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000..d35ad19e --- /dev/null +++ b/docker/README.md @@ -0,0 +1,45 @@ +# PiGallery2 docker installation [![Docker Build Status](https://img.shields.io/docker/build/bpatrik/pigallery2.svg)](https://hub.docker.com/r/bpatrik/pigallery2/) + +You can use [docker](https://docs.docker.com/install/) to run PiGallery2. + +## all docker tags +https://hub.docker.com/r/bpatrik/pigallery2/tags/ + +## Usage + +If you have `docker` and don't want to install all the dependencies, use this: +```bash +docker run \ + -p 80:80 \ + -v /config.json:/app/data/config/config.json \ + -v :/app/data/db \ + -v :/app/data/images \ + -v :/app/data/tmp \ + bpatrik/pigallery2:nightly-stretch +``` + +After the container is up and running, you go to `http://localhost` and log in with user: `admin` pass: `admin` and set up the page in the settings. + +**Note**: even with `memory` db, pigallery2 creates a db file for storing user credentials (if enabled), so mounting (with `-v`) the `/app/data/db` folder is recommended. + +### before v1.7.0 +There was a breaking change in Docker files after v1.7.0. Use this to run earlier versions: + +```bash +docker run \ + -p 80:80 \ + -e NODE_ENV=production \ + -v /config.json:/pigallery2-release/config.json \ + -v /sqlite.db:/pigallery2-release/sqlite.db \ + -v :/pigallery2-release/demo/images \ + -v :/pigallery2-release/demo/TEMP \ + bpatrik/pigallery2:1.7.0-stretch +``` +Make sure that a file at `/config.json` and `sqlite.db` files exists before running it. + +You do not need the `/sqlite.db` line if you don't use the sqlite database. + + + ### Build the Docker image on your own + + You can clone the repository and build the image, or you can just use the 'self-contained' Dockerfile: [debian/stretch/selfcontained/Dockerfile](amd64/debian-stretch/selfcontained/Dockerfile) diff --git a/docker/alpine/Dockerfile b/docker/alpine/Dockerfile deleted file mode 100644 index c1b73b55..00000000 --- a/docker/alpine/Dockerfile +++ /dev/null @@ -1,25 +0,0 @@ -FROM node:alpine -RUN apk add python build-base -COPY . /build -WORKDIR /build -RUN set -x && npm install --unsafe-perm && npm run create-release && \ - cd /build/release && npm install --unsafe-perm -RUN mkdir -p /build/release/data/config && \ - mkdir -p /build/release/data/db && \ - mkdir -p /build/release/data/image && \ - mkdir -p /build/release/data/TEMP && \ - cd /build/release && npm start -- --config-only || true && \ - sed -i 's/demo/data/g' config.json && sed -i 's@sqlite\.db@data/db/sqlite\.db@' config.json && \ - mv /build/release/config.json /build/release/data/config/config.json - -FROM node:alpine -WORKDIR /app -ENTRYPOINT ["npm", "start"] -EXPOSE 80 -ENV NODE_ENV=production -COPY --from=0 /build/release /app -RUN ln -s /app/data/config/config.json config.json -VOLUME ["/app/data/config", "/app/data/db", "/app/data/images", "/app/data/TEMP"] -HEALTHCHECK --interval=15s --timeout=5s --retries=4 --start-period=30s \ - CMD wget --quiet --tries=1 --no-check-certificate --spider \ - http://localhost:80 || exit 1 diff --git a/docker/amd64/alpine/Dockerfile b/docker/amd64/alpine/Dockerfile new file mode 100644 index 00000000..3ba2da6d --- /dev/null +++ b/docker/amd64/alpine/Dockerfile @@ -0,0 +1,34 @@ +FROM node:12-alpine AS builder +RUN apk add python build-base +# copying only package{-lock}.json to make node_modules cachable +COPY package*.json /build/ +WORKDIR /build +RUN set -x && npm install --unsafe-perm +# build app +COPY . /build +RUN mkdir -p /build/release/data/config && \ + mkdir -p /build/release/data/db && \ + mkdir -p /build/release/data/images && \ + mkdir -p /build/release/data/tmp && \ + npm run create-release && \ + cd /build/release && npm install --unsafe-perm && \ + npm start -- --config-only --force-rewrite-config \ + --config-path=data/config/config.json \ + --Server-Database-sqlite-storage='data/db/sqlite.db' \ + --Server-Database-memory-usersFile='data/db/users.db' \ + --Server-imagesFolder='data/images' \ + --Server-Thumbnail-folder='data/tmp' || true + + +FROM node:12-alpine +WORKDIR /app +ENTRYPOINT ["npm", "start"] +EXPOSE 80 +ENV NODE_ENV=production +COPY --from=builder /build/release /app +RUN ln -s /app/data/config/config.json config.json +VOLUME ["/app/data/config", "/app/data/db", "/app/data/images", "/app/data/TEMP"] +HEALTHCHECK --interval=30s --timeout=10s --retries=4 --start-period=60s \ + CMD wget --quiet --tries=1 --no-check-certificate --spider \ + http://localhost:80 || exit 1 + diff --git a/docker/amd64/debian-stretch/Dockerfile b/docker/amd64/debian-stretch/Dockerfile new file mode 100644 index 00000000..217e4e29 --- /dev/null +++ b/docker/amd64/debian-stretch/Dockerfile @@ -0,0 +1,34 @@ +FROM node:12-stretch AS builder +# LABEL maintainer="Patrik J. Braun" +# copying only package{-lock}.json to make node_modules cachable +COPY package*.json /build/ +WORKDIR /build +RUN set -x && npm install --unsafe-perm +# build app +COPY stretch /build +RUN mkdir -p /build/release/data/config && \ + mkdir -p /build/release/data/db && \ + mkdir -p /build/release/data/images && \ + mkdir -p /build/release/data/tmp && \ + npm run create-release && \ + cd /build/release && npm install --unsafe-perm && \ + npm start -- --config-only --force-rewrite-config \ + --config-path=data/config/config.json \ + --Server-Database-sqlite-storage='data/db/sqlite.db' \ + --Server-Database-memory-usersFile='data/db/users.db' \ + --Server-imagesFolder='data/images' \ + --Server-Thumbnail-folder='data/tmp' || true + + +FROM node:12-stretch-slim +WORKDIR /app +ENTRYPOINT ["npm", "start"] +EXPOSE 80 +ENV NODE_ENV=production +COPY --from=builder /build/release /app +RUN ln -s /app/data/config/config.json config.json +VOLUME ["/app/data/config", "/app/data/db", "/app/data/images", "/app/data/TEMP"] +HEALTHCHECK --interval=30s --timeout=10s --retries=4 --start-period=60s \ + CMD wget --quiet --tries=1 --no-check-certificate --spider \ + http://localhost:80 || exit 1 + diff --git a/docker/amd64/debian-stretch/selfcontained/Dockerfile b/docker/amd64/debian-stretch/selfcontained/Dockerfile new file mode 100644 index 00000000..618c16dc --- /dev/null +++ b/docker/amd64/debian-stretch/selfcontained/Dockerfile @@ -0,0 +1,32 @@ +FROM node:12-stretch AS BUILDER +# LABEL maintainer="Patrik J. Braun" +# copying only package{-lock}.json to make node_modules cachable +RUN git clone https://github.com/bpatrik/pigallery2.git /build +WORKDIR /build +RUN set -x && npm install --unsafe-perm && \ + mkdir -p /build/release/data/config && \ + mkdir -p /build/release/data/db && \ + mkdir -p /build/release/data/images && \ + mkdir -p /build/release/data/tmp && \ + npm run create-release && \ + cd /build/release && npm install --unsafe-perm && \ + npm start -- --config-only --force-rewrite-config \ + --config-path=data/config/config.json \ + --Server-Database-sqlite-storage='data/db/sqlite.db' \ + --Server-Database-memory-usersFile='data/db/users.db' \ + --Server-imagesFolder='data/images' \ + --Server-Thumbnail-folder='data/tmp' || true + + +FROM node:12-stretch-slim +WORKDIR /app +ENTRYPOINT ["npm", "start"] +EXPOSE 80 +ENV NODE_ENV=production +COPY --from=BUILDER /build/release /app +RUN ln -s /app/data/config/config.json config.json +VOLUME ["/app/data/config", "/app/data/db", "/app/data/images", "/app/data/TEMP"] +HEALTHCHECK --interval=30s --timeout=10s --retries=4 --start-period=60s \ + CMD wget --quiet --tries=1 --no-check-certificate --spider \ + http://localhost:80 || exit 1 + diff --git a/docker/arm32v6/debian-stretch/Dockerfile b/docker/arm32v6/debian-stretch/Dockerfile new file mode 100644 index 00000000..a6fe97d8 --- /dev/null +++ b/docker/arm32v6/debian-stretch/Dockerfile @@ -0,0 +1,40 @@ +FROM alpine AS qemu-builder +RUN wget https://github.com/multiarch/qemu-user-static/releases/download/v4.1.1-1/x86_64_qemu-arm-static.tar.gz && \ + tar -xvf x86_64_qemu-arm-static.tar.gz + +FROM arm32v6/node:12-stretch AS builder +COPY --from=qemu-builder /qemu-arm-static /usr/bin +# LABEL maintainer="Patrik J. Braun" +# copying only package{-lock}.json to make node_modules cachable +COPY package*.json /build/ +WORKDIR /build +RUN set -x && npm install --unsafe-perm +# build app +COPY stretch /build +RUN mkdir -p /build/release/data/config && \ + mkdir -p /build/release/data/db && \ + mkdir -p /build/release/data/images && \ + mkdir -p /build/release/data/tmp && \ + npm run create-release && \ + cd /build/release && npm install --unsafe-perm && \ + npm start -- --config-only --force-rewrite-config \ + --config-path=data/config/config.json \ + --Server-Database-sqlite-storage='data/db/sqlite.db' \ + --Server-Database-memory-usersFile='data/db/users.db' \ + --Server-imagesFolder='data/images' \ + --Server-Thumbnail-folder='data/tmp' || true + + +FROM arm32v6/node:12-stretch-slim +COPY --from=qemu-builder /qemu-arm-static /usr/bin +WORKDIR /app +ENTRYPOINT ["npm", "start"] +EXPOSE 80 +ENV NODE_ENV=production +COPY --from=builder /build/release /app +RUN ln -s /app/data/config/config.json config.json +VOLUME ["/app/data/config", "/app/data/db", "/app/data/images", "/app/data/TEMP"] +HEALTHCHECK --interval=30s --timeout=10s --retries=4 --start-period=60s \ + CMD wget --quiet --tries=1 --no-check-certificate --spider \ + http://localhost:80 || exit 1 + diff --git a/docker/arm32v6/debian-stretch/hooks/pre_build b/docker/arm32v6/debian-stretch/hooks/pre_build new file mode 100644 index 00000000..927718e0 --- /dev/null +++ b/docker/arm32v6/debian-stretch/hooks/pre_build @@ -0,0 +1,4 @@ +#!/bin/bash +# 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 diff --git a/docker/arm32v7/debian/stretch/Dockerfile b/docker/arm32v7/debian/stretch/Dockerfile deleted file mode 100644 index f499f9f4..00000000 --- a/docker/arm32v7/debian/stretch/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM arm32v7/node:10-stretch -LABEL maintainer="Patrik J. Braun" -# build tutorial: https://collabnix.com/building-arm-based-docker-images-on-docker-desktop-made-possible-using-buildx/ - -RUN git clone https://github.com/bpatrik/pigallery2.git && \ - cd /pigallery2 && \ - npm install --unsafe-perm && \ - npm run create-release && \ - cp -r /pigallery2/release /pigallery2-release && \ - rm /pigallery2 -R && \ - cd /pigallery2-release && \ - npm install --unsafe-perm - -CMD cd /pigallery2-release && npm start diff --git a/docker/debian/stretch/Dockerfile b/docker/debian/stretch/Dockerfile deleted file mode 100644 index 25c970f8..00000000 --- a/docker/debian/stretch/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM node:10-stretch -LABEL maintainer="Patrik J. Braun" - - -RUN git clone https://github.com/bpatrik/pigallery2.git && \ - cd /pigallery2 && \ - npm install --unsafe-perm && \ - npm run create-release && \ - cp -r /pigallery2/release /pigallery2-release && \ - rm /pigallery2 -R && \ - cd /pigallery2-release && \ - npm install --unsafe-perm - -CMD cd /pigallery2-release && npm start diff --git a/src/common/SupportedFormats.ts b/src/common/SupportedFormats.ts index e2dc73da..d61b54eb 100644 --- a/src/common/SupportedFormats.ts +++ b/src/common/SupportedFormats.ts @@ -19,23 +19,12 @@ export const SupportedFormats = { ], // These formats need to be transcoded (with the build-in ffmpeg support) TranscodeNeed: { + // based on libvips, all supported formats for sharp: https://github.com/libvips/libvips + // all supported formats for gm: http://www.graphicsmagick.org/GraphicsMagick.html Photos: [], Videos: [ - 'avi', - 'mkv', - 'mov', - 'wmv', - 'flv', - 'mts', - 'm2ts', - 'mpg', - '3gp', - 'm4v', - 'mpeg', - 'vob', - 'divx', - 'xvid', - 'ts' + 'avi', 'mkv', 'mov', 'wmv', 'flv', 'mts', 'm2ts', 'mpg', '3gp', 'm4v', 'mpeg', 'vob', + 'divx', 'xvid', 'ts' ], }, WithDots: { diff --git a/src/common/config/private/PrivateConfigDefaultsClass.ts b/src/common/config/private/PrivateConfigDefaultsClass.ts index 4b24058f..4e57c361 100644 --- a/src/common/config/private/PrivateConfigDefaultsClass.ts +++ b/src/common/config/private/PrivateConfigDefaultsClass.ts @@ -13,7 +13,7 @@ export class PrivateConfigDefaultsClass extends PublicConfigClass implements IPr host: '0.0.0.0', imagesFolder: 'demo/images', Thumbnail: { - folder: 'demo/TEMP', + folder: 'demo/tmp', processingLibrary: ServerConfig.ThumbnailProcessingLib.sharp, qualityPriority: true, personFaceMargin: 0.6