forked from photoview/photoview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
166 lines (141 loc) · 6.02 KB
/
Copy pathDockerfile
File metadata and controls
166 lines (141 loc) · 6.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
### Build UI ###
FROM --platform=${BUILDPLATFORM:-linux/amd64} node:18 AS ui
# See for details: https://github.com/hadolint/hadolint/wiki/DL4006
SHELL ["/bin/bash", "-euo", "pipefail", "-c"]
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /app/ui
COPY ui/package.json ui/package-lock.json /app/ui/
# NPM 10.x is the latest supported version for Node.js 18.x
RUN npm install --global npm@10 \
&& if [ "$NODE_ENV" = "production" ]; then \
echo "Installing production dependencies only..."; \
npm ci --omit=dev --no-audit --no-fund; \
else \
echo "Installing all dependencies..."; \
npm ci --no-audit --no-fund; \
fi
COPY ui/ /app/ui
# Set environment variable REACT_APP_API_ENDPOINT from build args, uses "<web server>/api" as default
ARG REACT_APP_API_ENDPOINT
ENV REACT_APP_API_ENDPOINT=${REACT_APP_API_ENDPOINT}
# Set environment variable UI_PUBLIC_URL from build args, uses "<web server>/" as default
ARG UI_PUBLIC_URL=/
ENV UI_PUBLIC_URL=${UI_PUBLIC_URL}
ARG VERSION=unknown-branch
ENV VERSION=${VERSION}
ARG TARGETARCH
ENV TARGETARCH=${TARGETARCH}
# hadolint ignore=SC2155
RUN export REACT_APP_BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%S+00:00(UTC)')"; \
export REACT_APP_BUILD_COMMIT_SHA="-=<GitHub-CI-commit-sha-placeholder>=-"; \
export REACT_APP_BUILD_VERSION="${VERSION}-${TARGETARCH}"; \
export REACT_APP_API_ENDPOINT="${REACT_APP_API_ENDPOINT}"; \
npm run build"$( [ "$NODE_ENV" != "production" ] && echo :dev )" -- --base="${UI_PUBLIC_URL}"
### Build API ###
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.26-trixie AS api
ARG TARGETPLATFORM
# See for details: https://github.com/hadolint/hadolint/wiki/DL4006
SHELL ["/bin/bash", "-euo", "pipefail", "-c"]
ENV GOPATH="/go"
ENV PATH="${GOPATH}/bin:${PATH}"
ENV CGO_ENABLED=1
# Download dependencies
COPY scripts/set_compiler_env.sh /app/scripts/
RUN chmod +x /app/scripts/*.sh \
&& source /app/scripts/set_compiler_env.sh
COPY scripts/install_*.sh /app/scripts/
RUN chmod +x /app/scripts/*.sh \
&& set -a && source /env && set +a \
&& /app/scripts/install_build_dependencies.sh \
&& /app/scripts/install_runtime_dependencies.sh
# hadolint ignore=DL3022
COPY --from=photoview/dependencies:trixie /artifacts.tar.gz /dependencies/
WORKDIR /dependencies
RUN set -a && source /env && set +a \
&& git config --global --add safe.directory /app \
&& tar xfv artifacts.tar.gz \
&& cp -a include/* /usr/local/include/ \
&& cp -a pkgconfig/* "${PKG_CONFIG_PATH}" \
&& cp -a lib/* /usr/local/lib/ \
&& ldconfig \
&& apt-get install -y ./deb/jellyfin-ffmpeg.deb \
&& ln -s /usr/lib/jellyfin-ffmpeg/ffmpeg /usr/local/bin/ \
&& ln -s /usr/lib/jellyfin-ffmpeg/ffprobe /usr/local/bin/
COPY api/go.mod api/go.sum /app/api/
WORKDIR /app/api
# hadolint ignore=DL3062
RUN set -a && source /env && set +a \
&& go env \
&& go mod download \
# Patch go-face
&& sed -i 's/-march=native//g' ${GOPATH}/pkg/mod/github.com/!kagami/go-face*/face.go \
&& sed -i 's/-lcblas//g' ${GOPATH}/pkg/mod/github.com/!kagami/go-face*/face.go \
# Build dependencies that use CGO
&& go install \
github.com/mattn/go-sqlite3 \
github.com/Kagami/go-face
COPY api /app/api
RUN set -a && source /env && set +a \
&& go env \
&& go build -v -o photoview .
### Build release image ###
FROM debian:trixie-slim AS release
ARG TARGETPLATFORM
# See for details: https://github.com/hadolint/hadolint/wiki/DL4006
SHELL ["/bin/bash", "-euo", "pipefail", "-c"]
COPY scripts/install_runtime_dependencies.sh /app/scripts/
WORKDIR /dependencies
RUN --mount=type=bind,from=api,source=/dependencies/,target=/dependencies/ \
chmod +x /app/scripts/install_runtime_dependencies.sh \
# Create a user to run Photoview server
&& groupadd -g 999 photoview \
&& useradd -r -u 999 -g photoview -m photoview \
# Install required dependencies
&& /app/scripts/install_runtime_dependencies.sh \
# Install self-building libs
&& cp -a lib/*.so* /usr/local/lib/ \
&& ldconfig \
&& apt-get install -y ./deb/jellyfin-ffmpeg.deb gzip brotli zstd \
&& ln -s /usr/lib/jellyfin-ffmpeg/ffmpeg /usr/local/bin/ \
&& ln -s /usr/lib/jellyfin-ffmpeg/ffprobe /usr/local/bin/ \
# Cleanup
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY api/data /app/data
COPY --from=ui /app/ui/dist /app/ui
COPY --from=api /app/api/photoview /app/photoview
# This is a w/a for letting the UI build stage to be cached
# and not rebuilt every new commit because of the build_arg value change.
ARG COMMIT_SHA=NoCommit
RUN find /app/ui/assets -type f -name "SettingsPage.*.js" \
-exec sed -i 's/"-=<GitHub-CI-commit-sha-placeholder>=-"/"'"${COMMIT_SHA}"'"/g' {} \; \
# Archive static files for better performance
&& find /app/ui -type f \( \
-name "*.js" -o -name "*.mjs" -o -name "*.json" \
-o -name "*.css" -o -name "*.html" -o -name "*.svg" \
-o -name "*.txt" -o -name "*.xml" -o -name "*.wasm" -o -name "*.map" \
\) ! -name "*.gz" ! -name "*.br" ! -name "*.zst" \
-exec sh -c 'for file; do \
gzip -k -f -9 "$file"; \
brotli -k -f -q 11 -s "$file"; \
zstd -k -f -19 -T0 --no-progress "$file"; \
done' sh {} +
WORKDIR /home/photoview
ENV PHOTOVIEW_LISTEN_IP=127.0.0.1
ENV PHOTOVIEW_LISTEN_PORT=80
ENV PHOTOVIEW_API_ENDPOINT=/api
ENV PHOTOVIEW_SERVE_UI=1
ENV PHOTOVIEW_UI_PATH=/app/ui
ENV PHOTOVIEW_FACE_RECOGNITION_MODELS_PATH=/app/data/models
ENV PHOTOVIEW_MEDIA_CACHE=/home/photoview/media-cache
EXPOSE ${PHOTOVIEW_LISTEN_PORT}
HEALTHCHECK --interval=60s --timeout=10s --start-period=10s --retries=2 \
CMD curl --fail "http://localhost:${PHOTOVIEW_LISTEN_PORT}${PHOTOVIEW_API_ENDPOINT}/graphql" \
-X POST -H 'Content-Type: application/json' \
--data-raw '{"operationName":"CheckInitialSetup","variables":{},"query":"query CheckInitialSetup { siteInfo { initialSetup }}"}' \
|| exit 1
LABEL org.opencontainers.image.source=https://github.com/photoview/photoview/
USER photoview
ENTRYPOINT ["/app/photoview"]