1
Fork 0

Update `Set up development environment` in README.md. (#995)

This commit is contained in:
Googol Lee 2024-07-16 23:10:38 +02:00 committed by GitHub
parent 7559a609aa
commit 0345bc1481
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 96 additions and 51 deletions

2
.gitignore vendored
View File

@ -5,7 +5,7 @@ cache/
/api/media_cache/
/photos_path
photoview.db
photoview.db-journal
photoview.db-*
.env
testing.env

View File

@ -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

106
README.md
View File

@ -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

View File

@ -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

View File

@ -1,4 +0,0 @@
#!/bin/sh
brew update
brew install libheif dlib jpeg

View File

@ -1,4 +0,0 @@
#!/bin/sh
brew update
brew install exiftool ffmpeg darktable

View File

@ -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"