diff --git a/.gitignore b/.gitignore index 5d83cd15..41757c22 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ cache/ /api/media_cache/ /photos_path photoview.db -photoview.db-journal +photoview.db-* .env testing.env diff --git a/Dockerfile b/Dockerfile index b8ecc60d..125ce44d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,7 +37,7 @@ ARG TARGETPLATFORM # See for details: https://github.com/hadolint/hadolint/wiki/DL4006 SHELL ["/bin/bash", "-o", "pipefail", "-c"] -COPY scripts/apt /app/scripts/apt +COPY scripts /app/scripts COPY api /app/api WORKDIR /app/api @@ -46,9 +46,9 @@ ENV PATH="${GOPATH}/bin:${PATH}" ENV CGO_ENABLED=1 # Download dependencies -RUN chmod +x /app/scripts/apt/*.sh \ - && source /app/scripts/apt/set_compiler_env.sh \ - && /app/scripts/apt/install_build_dependencies.sh \ +RUN chmod +x /app/scripts/*.sh \ + && source /app/scripts/set_compiler_env.sh \ + && /app/scripts/install_build_dependencies.sh \ && go env \ && go mod download \ # Patch go-face @@ -67,14 +67,14 @@ ARG TARGETPLATFORM # See for details: https://github.com/hadolint/hadolint/wiki/DL4006 SHELL ["/bin/bash", "-o", "pipefail", "-c"] -COPY scripts/apt/install_runtime_dependencies.sh /app/scripts/apt/ +COPY scripts/install_runtime_dependencies.sh /app/scripts/ # Create a user to run Photoview server RUN groupadd -g 999 photoview \ && useradd -r -u 999 -g photoview -m photoview \ # Required dependencies - && chmod +x /app/scripts/apt/*.sh \ - && /app/scripts/apt/install_runtime_dependencies.sh + && chmod +x /app/scripts/*.sh \ + && /app/scripts/install_runtime_dependencies.sh WORKDIR /home/photoview COPY api/data /app/data diff --git a/README.md b/README.md index d2f4c262..adaa08d7 100644 --- a/README.md +++ b/README.md @@ -171,43 +171,93 @@ Remember, every contribution counts. Let's make this project better together! ## Set up development environment -### Local setup +### Developing dependencies -1. Install a local mysql server, and make a new database -2. Rename `/api/example.env` to `.env` and update the `MYSQL_URL` field -3. Rename `/ui/example.env` to `.env` +- API + - Required packages: + - `golang` >= 1.22 + - `g++` + - `libc-dev` + - `libheif` >= 1.15.1 + - [go-face Requirements](https://github.com/Kagami/go-face#requirements) + - `dlib` + - `libjpeg` + - `libblas` + - `libcblas`, recommended using `libatlas-base` + - `liblapack` + - Optional tools during developing: + - [`reflex`](https://github.com/cespare/reflex): a source code monitoring tool, which automatically rebuilds and restarts the server, running from the code in development. + - `sqlite`: the SQLite DBMS, useful to interact with Photoview's SQLite DB directly if you use it in your development environment. +- UI + - Required packages: + - `node` = 18 -### Start API server - -Make sure [golang](https://golang.org/) is installed. - -Some C libraries are needed to compile the API, see [go-face requirements](https://github.com/Kagami/go-face#requirements) for more details. -They can be installed as shown below: +In Debian/Ubuntu, install dependencies: ```sh -# Ubuntu -sudo add-apt-repository ppa:strukturag/libheif -sudo add-apt-repository ppa:strukturag/libde265 -sudo apt-get update -sudo apt-get install libdlib-dev libblas-dev libatlas-base-dev liblapack-dev libjpeg-turbo8-dev libheif-dev -# Debian -sudo apt-get install libdlib-dev libblas-dev libatlas-base-dev liblapack-dev libjpeg62-turbo-dev libheif-dev -# macOS -brew install dlib libheif - +$ sudo apt update # Update the package list +$ sudo apt install golang g++ libc-dev libheif-dev libdlib-dev libjpeg-dev libblas-dev libatlas-base-dev liblapack-dev # For API requirement +$ sudo apt install reflex sqlite3 # For API optional tools ``` +In macOS, install dependencies: + +```sh +$ brew update # Update the package list +$ brew install golang gcc libheif dlib jpeg # For API +$ brew install reflex sqlite3 # For API optional tools +``` + +Please follow the package manager guidance if you don't use `apt` or `homebrew`. + +For `node`, recommend to use [nvm](https://github.com/nvm-sh/nvm). Follow [Installing and Updating](https://github.com/nvm-sh/nvm?tab=readme-ov-file#installing-and-updating) to install `nvm` locally, then: + +```sh +$ nvm install 18 +$ nvm use 18 +``` + +You can install `node` with other package manager if you like. + +### Local setup + +1. Rename `/api/example.env` to `.env` + - Update `PHOTOVIEW_SQLITE_PATH` if you don't want to put sqlite file under `/api` + - To set a different DBMS driver + - Comment the SQLite path variable + - Update `PHOTOVIEW_DATABASE_DRIVER` with your driver + - Uncomment the corresponding connection string variable for the new driver + - Optional: modify other variables if needed according to the inline comments +2. Rename `/ui/example.env` to `.env` + +### Start API server + Then run the following commands: ```bash -cd ./api -go install -go run server.go +# Optional: Set the compiler environment in Debian/Ubuntu +$ source ./scripts/set_compiler_env.sh +# Set the compiler environment with `homebrew` +$ export CPLUS_INCLUDE_PATH="$(brew --prefix)/opt/jpeg/include:$(brew --prefix)/opt/dlib/include" +$ export LD_LIBRARY_PATH="$(brew --prefix)/opt/jpeg/lib:$(brew --prefix)/opt/dlib/lib" +$ export LIBRARY_PATH="$(brew --prefix)/opt/jpeg/lib:$(brew --prefix)/opt/dlib/lib" +# Start API server +$ cd ./api +$ go run . ``` +If you want to recompile the server automatically when code changes: + +```sh +# Start API server +$ cd ./api +$ reflex -g '*.go' -s -- go run . +``` + +The graphql playground can now be accessed at [localhost:4001](http://localhost:4001). + ### Start UI server -Make sure [node](https://nodejs.org/en/) is installed. In a new terminal window run the following commands: ```bash @@ -216,8 +266,14 @@ npm install npm start ``` +If you want to recompile the server automatically when code changes: + +```sh +$ cd ./ui +$ npm mon +``` + The site can now be accessed at [localhost:1234](http://localhost:1234). -And the graphql playground at [localhost:4001](http://localhost:4001) ## Sponsors diff --git a/api/example.env b/api/example.env index d23bd53c..62ecd583 100644 --- a/api/example.env +++ b/api/example.env @@ -1,15 +1,17 @@ # Copy this file to .env -PHOTOVIEW_DATABASE_DRIVER=mysql -PHOTOVIEW_MYSQL_URL=user:password@tcp(localhost)/dbname +PHOTOVIEW_DATABASE_DRIVER=sqlite + +# Specifies the filepath for the sqlite database, if PHOTOVIEW_DATABASE_DRIVER is set to 'sqlite' +PHOTOVIEW_SQLITE_PATH=photoview.db + +# Specifies the connection string for the mysql database, if PHOTOVIEW_DATABASE_DRIVER is set to 'mysql' +# PHOTOVIEW_MYSQL_URL=user:password@tcp(localhost)/dbname # Specifies the connection string for the postgres database, if PHOTOVIEW_DATABASE_DRIVER is set to 'postgres' # See https://www.postgresql.org/docs/current/libpq-ssl.html for possible ssl modes # PHOTOVIEW_POSTGRES_URL=postgres://user:password@host:port/dbname?sslmode=(disable|allow|...) -# Specifies the filepath for the sqlite database, if PHOTOVIEW_DATABASE_DRIVER is set to 'sqlite' -# PHOTOVIEW_SQLITE_PATH=photoview.db - PHOTOVIEW_LISTEN_IP=localhost PHOTOVIEW_LISTEN_PORT=4001 diff --git a/scripts/homebrew/install_build_dependencies.sh b/scripts/homebrew/install_build_dependencies.sh deleted file mode 100755 index cf633503..00000000 --- a/scripts/homebrew/install_build_dependencies.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -brew update -brew install libheif dlib jpeg diff --git a/scripts/homebrew/install_runtime_dependencies.sh b/scripts/homebrew/install_runtime_dependencies.sh deleted file mode 100755 index ed2c19c9..00000000 --- a/scripts/homebrew/install_runtime_dependencies.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -brew update -brew install exiftool ffmpeg darktable diff --git a/scripts/homebrew/set_compiler_env.sh b/scripts/homebrew/set_compiler_env.sh deleted file mode 100755 index 98653b49..00000000 --- a/scripts/homebrew/set_compiler_env.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -export CPLUS_INCLUDE_PATH="$(brew --prefix)/opt/jpeg/include:$(brew --prefix)/opt/dlib/include" -export LD_LIBRARY_PATH="$(brew --prefix)/opt/jpeg/lib:$(brew --prefix)/opt/dlib/lib" -export LIBRARY_PATH="$(brew --prefix)/opt/jpeg/lib:$(brew --prefix)/opt/dlib/lib" diff --git a/scripts/apt/install_build_dependencies.sh b/scripts/install_build_dependencies.sh similarity index 100% rename from scripts/apt/install_build_dependencies.sh rename to scripts/install_build_dependencies.sh diff --git a/scripts/apt/install_runtime_dependencies.sh b/scripts/install_runtime_dependencies.sh similarity index 100% rename from scripts/apt/install_runtime_dependencies.sh rename to scripts/install_runtime_dependencies.sh diff --git a/scripts/apt/set_compiler_env.sh b/scripts/set_compiler_env.sh similarity index 100% rename from scripts/apt/set_compiler_env.sh rename to scripts/set_compiler_env.sh