mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 18:29:17 +00:00
Refactor docker deployment and user setup (#863)
* Fix #862, address #826 and maybe some other tickets: reimplemented the docker-compose user setup to enhance product setup experience and cover much more cases. * make unique DB container name and use it in communication from Photoview * Removed unnecessary healthcheck for photoview from docker-compose.example.yml, as it is defined in the Dockerfile; optimized Dockerfile combining all RUN directives of PROD stage into 1, which will produce single layer and save some space; added Dockerfile-dev, docker-compose-dev.yml, and new "dev" and "dev-down" directives into Makefile, which allows to setup development env in Docker. Instructions of how to use it are in comments at the beginning of Dockerfile-dev and docker-compose-dev.yml files * Set RWX permissions to the application's working folder for any user, so that the image could be later run with non-root permissions and the app still be able to do needed operations in the FS * Enhanced the "Getting started" section in the readme; added the `help` target and enhanced comments in the Makefile; commented out the `docker system prune -f` with the comment about the command and why it is there; added optional and commented by default `7zz` commands to the `backup` section of the Makefile * Use `slim` base image for final photoview image * Implement SQLite support according to the PR #851 * Removed deprecated `version` line from compose files; optimized dockerfile to build with less layers and run as non-root; mapped only Photoview related services to Watchtower by default instead of updating all running images on a host; added template for Postgres to the .env; reverted compose executable definition, so the new compose is called when present; added a tip about `lnav` to help * fix a typo in the username; add support of PostgreSQL; split and optimize backup target in Makefile * Fixed some typos and styling in Readme, excluded dev-environment setup from the PR; added a list of tips on how to secure Photoview in the Advanced setup section of Readme * Implemented many security improvements, suggested by @Omar007, switched to the dedicated Darktable's repo to install the latest released version, as asked in #935; switched Watchtower to labels instead of profiles * forgot the compose file * move face models back to /app folder; comment out and document unnecessary vars in compose; fix a typo in a few vars * Exclude Makefile in the root folder from git; documented multiple mounts case better; fixed incorrect SQLite DB path * Fixed several bugs after complete testing cycle with all 3 DBs * removed hardcoded port in Dockerfile * Pin the major version for the `photoview` image for stability * Revert back to the port 80 inside the container on product owner's request * Provide a minimal compose file and update the readme accordingly * Handle incorrect media file and folder permissions; set correct permissions for storage folder; fix healthcheck command for postgres --------- Co-authored-by: Konstantin Koval <kkb@ukr.net>
This commit is contained in:
101
Dockerfile
101
Dockerfile
@@ -20,84 +20,85 @@ ARG COMMIT_SHA
|
||||
ENV COMMIT_SHA=${COMMIT_SHA:-}
|
||||
ENV REACT_APP_BUILD_COMMIT_SHA=${COMMIT_SHA:-}
|
||||
|
||||
RUN mkdir -p /app
|
||||
WORKDIR /app
|
||||
|
||||
# Download dependencies
|
||||
COPY ui/package*.json /app/
|
||||
RUN npm ci --omit=dev --ignore-scripts
|
||||
|
||||
# Build frontend
|
||||
COPY ui /app
|
||||
RUN npm run build -- --base=$UI_PUBLIC_URL
|
||||
WORKDIR /app
|
||||
RUN npm ci --omit=dev --ignore-scripts \
|
||||
# Build frontend
|
||||
&& npm run build -- --base=$UI_PUBLIC_URL
|
||||
|
||||
### Build API ###
|
||||
FROM --platform=${BUILDPLATFORM:-linux/amd64} debian:bookworm AS api
|
||||
ARG TARGETPLATFORM
|
||||
|
||||
COPY docker/install_build_dependencies.sh /tmp/
|
||||
RUN chmod +x /tmp/install_build_dependencies.sh && /tmp/install_build_dependencies.sh
|
||||
|
||||
COPY docker/go_wrapper.sh /go/bin/go
|
||||
RUN chmod +x /go/bin/go
|
||||
COPY api /app
|
||||
WORKDIR /app
|
||||
|
||||
ENV GOPATH="/go"
|
||||
ENV PATH="${GOPATH}/bin:${PATH}"
|
||||
|
||||
ENV CGO_ENABLED 1
|
||||
|
||||
RUN go env
|
||||
|
||||
RUN mkdir -p /app
|
||||
WORKDIR /app
|
||||
|
||||
# Download dependencies
|
||||
COPY api/go.mod api/go.sum /app/
|
||||
RUN go mod download
|
||||
|
||||
# Patch go-face
|
||||
RUN sed -i 's/-march=native//g' ${GOPATH}/pkg/mod/github.com/!kagami/go-face*/face.go
|
||||
|
||||
# Build dependencies that use CGO
|
||||
RUN go install \
|
||||
github.com/mattn/go-sqlite3 \
|
||||
github.com/Kagami/go-face
|
||||
|
||||
# Copy and build api source
|
||||
COPY api /app
|
||||
RUN go build -v -o photoview .
|
||||
RUN chmod +x /tmp/install_build_dependencies.sh \
|
||||
&& chmod +x /go/bin/go \
|
||||
&& /tmp/install_build_dependencies.sh \
|
||||
&& go env \
|
||||
&& go mod download \
|
||||
# Patch go-face
|
||||
&& sed -i 's/-march=native//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 \
|
||||
# Build api source
|
||||
&& go build -v -o photoview .
|
||||
|
||||
### Copy api and ui to production environment ###
|
||||
FROM debian:bookworm
|
||||
FROM debian:bookworm-slim
|
||||
ARG TARGETPLATFORM
|
||||
WORKDIR /app
|
||||
|
||||
COPY api/data /app/data
|
||||
|
||||
RUN apt update \
|
||||
# Create a user to run Photoview server
|
||||
RUN useradd -r -U -m photoview \
|
||||
# Required dependencies
|
||||
&& apt install -y curl gpg libdlib19.1 ffmpeg exiftool libheif1
|
||||
|
||||
# Install Darktable if building for a supported architecture
|
||||
RUN if [ "${TARGETPLATFORM}" = "linux/amd64" ] || [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
|
||||
apt install -y darktable; fi
|
||||
|
||||
# Remove build dependencies and cleanup
|
||||
RUN apt purge -y gpg \
|
||||
&& apt autoremove -y \
|
||||
&& apt clean \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y curl gnupg gpg libdlib19.1 ffmpeg exiftool libheif1 sqlite3 \
|
||||
# Install Darktable if building for a supported architecture
|
||||
&& if [ "${TARGETPLATFORM}" = "linux/amd64" ] || [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
|
||||
echo 'deb https://download.opensuse.org/repositories/graphics:/darktable/Debian_12/ /' \
|
||||
| tee /etc/apt/sources.list.d/graphics:darktable.list; \
|
||||
curl -fsSL https://download.opensuse.org/repositories/graphics:/darktable/Debian_12/Release.key \
|
||||
| gpg --dearmor | tee /etc/apt/trusted.gpg.d/graphics_darktable.gpg > /dev/null; \
|
||||
apt-get update; \
|
||||
apt-get install -y darktable; \
|
||||
fi \
|
||||
# Remove build dependencies and cleanup
|
||||
&& apt-get purge -y gnupg gpg \
|
||||
&& apt-get autoremove -y \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY --from=ui /app/dist /ui
|
||||
WORKDIR /home/photoview
|
||||
COPY api/data /app/data
|
||||
COPY --from=ui /app/dist /app/ui
|
||||
COPY --from=api /app/photoview /app/photoview
|
||||
|
||||
ENV PHOTOVIEW_LISTEN_IP 127.0.0.1
|
||||
ENV PHOTOVIEW_LISTEN_PORT 80
|
||||
|
||||
ENV PHOTOVIEW_SERVE_UI 1
|
||||
ENV PHOTOVIEW_UI_PATH /ui
|
||||
ENV PHOTOVIEW_UI_PATH /app/ui
|
||||
ENV PHOTOVIEW_FACE_RECOGNITION_MODELS_PATH /app/data/models
|
||||
ENV PHOTOVIEW_MEDIA_CACHE /home/photoview/media-cache
|
||||
|
||||
EXPOSE 80
|
||||
EXPOSE ${PHOTOVIEW_LISTEN_PORT}
|
||||
|
||||
HEALTHCHECK --interval=60s --timeout=10s CMD curl --fail 'http://localhost:80/api/graphql' -X POST -H 'Content-Type: application/json' --data-raw '{"operationName":"CheckInitialSetup","variables":{},"query":"query CheckInitialSetup { siteInfo { initialSetup }}"}'
|
||||
HEALTHCHECK --interval=60s --timeout=10s \
|
||||
CMD curl --fail http://localhost:${PHOTOVIEW_LISTEN_PORT}/api/graphql \
|
||||
-X POST -H 'Content-Type: application/json' \
|
||||
--data-raw '{"operationName":"CheckInitialSetup","variables":{},"query":"query CheckInitialSetup { siteInfo { initialSetup }}"}' \
|
||||
|| exit 1
|
||||
|
||||
USER photoview
|
||||
ENTRYPOINT ["/app/photoview"]
|
||||
|
||||
Reference in New Issue
Block a user