|
1 | | -#-----------------BUILDER----------------- |
2 | | -#----------------------------------------- |
3 | | -FROM node:22-alpine3.22 AS builder |
4 | | - |
5 | | -ENV SHARP_FORCE_GLOBAL_LIBVIPS=1 |
6 | | -# inspired by https://github.com/lovell/sharp/issues/4273 and https://github.com/lovell/sharp/issues/4267 |
7 | | -RUN apk add --no-cache --update \ |
8 | | - --repository=https://dl-cdn.alpinelinux.org/alpine/edge/main \ |
9 | | - --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community \ |
10 | | - --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing \ |
11 | | - vips \ |
12 | | - vips-dev \ |
13 | | - vips-heif \ |
14 | | - vips-magick \ |
15 | | - libheif \ |
16 | | - libpng \ |
17 | | - libjpeg-turbo \ |
18 | | - libde265 \ |
19 | | - libwebp \ |
20 | | - libraw-dev \ |
21 | | - g++ \ |
22 | | - make \ |
23 | | - gcc \ |
24 | | - build-base \ |
25 | | - python3 \ |
26 | | - pkgconfig |
27 | | - |
28 | | -COPY pigallery2-release /app |
29 | | -WORKDIR /app |
30 | | -RUN npm install --no-package-lock --save-dev node-addon-api@8.5.0 node-gyp@11.5.0 && \ |
31 | | - npm prune --production && \ |
32 | | - npm cache clean --force |
33 | 1 |
|
| 2 | +# ============================================================ |
| 3 | +# Stage 1: Build libvips with full colourspace + loaders |
| 4 | +# ============================================================ |
| 5 | +FROM alpine:3.22 AS vips-build |
| 6 | + |
| 7 | +ARG VIPS_VERSION=8.15.2 |
| 8 | + |
| 9 | +RUN apk add --no-cache \ |
| 10 | + build-base autoconf automake libtool pkgconfig git curl wget \ |
| 11 | + ca-certificates meson ninja cmake \ |
| 12 | + libjpeg-turbo-dev libpng-dev libwebp-dev tiff-dev lcms2-dev \ |
| 13 | + libexif-dev libimagequant-dev orc-dev glib-dev expat-dev zlib-dev |
| 14 | + |
| 15 | +WORKDIR /tmp |
| 16 | + |
| 17 | +RUN wget https://github.com/libvips/libvips/releases/download/v${VIPS_VERSION}/vips-${VIPS_VERSION}.tar.xz && \ |
| 18 | + tar xf vips-${VIPS_VERSION}.tar.xz && \ |
| 19 | + cd vips-${VIPS_VERSION} && \ |
| 20 | + ./configure \ |
| 21 | + --prefix=/usr \ |
| 22 | + --disable-static \ |
| 23 | + --enable-shared \ |
| 24 | + --with-jpeg \ |
| 25 | + --with-png \ |
| 26 | + --with-tiff \ |
| 27 | + --with-webp \ |
| 28 | + --with-lcms \ |
| 29 | + --with-libexif \ |
| 30 | + --with-imagequant \ |
| 31 | + --with-orc \ |
| 32 | + --without-magick \ |
| 33 | + --without-openslide \ |
| 34 | + --without-fftw \ |
| 35 | + --without-heif \ |
| 36 | + --without-poppler \ |
| 37 | + --without-pdfium \ |
| 38 | + --without-libspng \ |
| 39 | + --without-OpenEXR \ |
| 40 | + --without-matio \ |
| 41 | + --without-nifti \ |
| 42 | + --without-gsf \ |
| 43 | + --without-ppm \ |
| 44 | + --without-analyze && \ |
| 45 | + make -j"$(nproc)" && \ |
| 46 | + make install && \ |
| 47 | + ldconfig || true |
34 | 48 |
|
35 | | -RUN mkdir -p /app/data/config && \ |
36 | | - mkdir -p /app/data/db && \ |
37 | | - mkdir -p /app/data/images && \ |
38 | | - mkdir -p /app/data/tmp |
| 49 | +# ============================================================ |
| 50 | +# Stage 2: Runtime image |
| 51 | +# ============================================================ |
| 52 | +FROM node:20-alpine3.22 AS runtime |
39 | 53 |
|
| 54 | +RUN apk add --no-cache \ |
| 55 | + libjpeg-turbo libpng libwebp tiff lcms2 libexif libimagequant \ |
| 56 | + orc glib expat zlib ffmpeg |
40 | 57 |
|
41 | | -#-----------------MAIN-------------------- |
42 | | -#----------------------------------------- |
43 | | -FROM node:22-alpine3.22 AS main |
44 | 58 | WORKDIR /app |
| 59 | + |
| 60 | +# Bring in custom libvips |
| 61 | +COPY --from=vips-build /usr/lib /usr/lib |
| 62 | +COPY --from=vips-build /usr/bin/vips* /usr/bin/ |
| 63 | + |
| 64 | +# Copy prebuilt PiGallery2 release |
| 65 | +COPY pigallery2-release/ /app/ |
| 66 | + |
| 67 | +# Install production dependencies |
| 68 | +RUN npm install --omit=dev && npm cache clean --force |
| 69 | + |
| 70 | +# Create data directories |
| 71 | +RUN mkdir -p /app/data/config \ |
| 72 | + /app/data/db \ |
| 73 | + /app/data/images \ |
| 74 | + /app/data/tmp |
| 75 | + |
45 | 76 | ENV NODE_ENV=production \ |
46 | | - # overrides only the default value of the settings (the actual value can be overwritten through config.json) |
47 | | - default-Database-dbFolder=/app/data/db \ |
48 | | - default-Media-folder=/app/data/images \ |
49 | | - default-Media-tempFolder=/app/data/tmp \ |
50 | | - default-Extensions-folder=/app/data/config/extensions \ |
51 | | - # flagging dockerized environment |
52 | | - PI_DOCKER=true |
| 77 | + default-Database-dbFolder=/app/data/db \ |
| 78 | + default-Media-folder=/app/data/images \ |
| 79 | + default-Media-tempFolder=/app/data/tmp \ |
| 80 | + default-Extensions-folder=/app/data/config/extensions \ |
| 81 | + PI_DOCKER=true |
53 | 82 |
|
54 | 83 | EXPOSE 80 |
55 | | -ARG TARGETARCH |
56 | | -RUN apk add --no-cache \ |
57 | | - vips vips-cpp vips-heif vips-magick ffmpeg \ |
58 | | - && if [ "$TARGETARCH" = "amd64" ]; then \ |
59 | | - echo "Building for amd64, adding intel-media-driver" && \ |
60 | | - apk add --no-cache intel-media-driver; \ |
61 | | - fi \ |
62 | | - && rm -rf /var/cache/apk/* |
63 | | -COPY --from=builder /app /app |
64 | | - |
65 | | -# Run build time diagnostics to make sure the app would work after build is finished |
| 84 | + |
| 85 | +# Diagnostics |
66 | 86 | RUN ["node", "--expose-gc", "./src/backend/index", "--run-diagnostics", "--config-path=/app/diagnostics-config.json", "--Server-Log-level=silly"] |
| 87 | + |
67 | 88 | HEALTHCHECK --interval=40s --timeout=30s --retries=3 --start-period=60s \ |
68 | 89 | CMD wget --quiet --tries=1 --no-check-certificate --spider \ |
69 | 90 | http://127.0.0.1:80/heartbeat || exit 1 |
70 | 91 |
|
71 | | -# after a extensive job (like video converting), pigallery calls gc, to clean up everything as fast as possible |
72 | | -# Exec form entrypoint is need otherwise (using shell form) ENV variables are not properly passed down to the app |
73 | 92 | ENTRYPOINT ["node", "--expose-gc", "./src/backend/index", "--config-path=/app/data/config/config.json"] |
0 commit comments