Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a Development dockerfile #650

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ Password: **demo**
## Contents

- [Demo site](#demo-site)
- [Contents](#contents)
- [Main features](#main-features)
- [Supported Platforms](#supported-platforms)
- [Supported platforms](#supported-platforms)
- [Why yet another self-hosted photo gallery](#why-yet-another-self-hosted-photo-gallery)
- [Getting started - Setup with Docker](#getting-started---setup-with-docker)
- [Set up development environment](#setup-development-environment)
- [Initial Setup](#initial-setup)
- [Set up development environment](#set-up-development-environment)
- [Using Docker](#using-docker)
- [Local setup](#local-setup)
- [Start API server](#start-api-server)
- [Start UI server](#start-ui-server)
- [Sponsors](#sponsors)

## Main features
Expand Down Expand Up @@ -113,6 +119,14 @@ The photos will have to be scanned before they show up, you can start a scan man

## Set up development environment

### Using Docker

The steps below may not work for you. You can also use a Docker-based development environment, using the docker-compose.yml file in development/ . You may need to increase the resources available to Docker beyond the default 2GB. (Preferences->Resources if you're using Docker Desktop gui)

On an M1, you may need to build it with `TARGETPLATFORM='linux/arm64' docker-compose build`.

After that, `docker-compose up -d`, wait up to a few minutes, then hit http://localhost:1234/. You'll need to go to Settings->Scan All Users to see the photos.

### Local setup

1. Install a local mysql server, and make a new database
Expand Down
44 changes: 44 additions & 0 deletions api/.air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# .air.conf
# Config file for [Air](https://github.com/cosmtrek/air) in TOML format

# Working directory
# . or absolute path, please note that the directories following must be under root.
root = "."
tmp_dir = "tmp"

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -o ./tmp/main server.go"
# Binary file yields from `cmd`.
bin = "tmp/main"
# Customize binary.
full_bin = "./tmp/main"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl", "html"]
# Ignore these filename extensions or directories.
exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules"]
# Watch these directories if you specified.
include_dir = []
# Exclude files.
exclude_file = []
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 1000 # ms
# Stop to run old binary when build errors occur.
stop_on_error = true
# This log file places in your tmp_dir.
log = "air_errors.log"

[log]
# Show log time
time = false

[color]
# Customize each part's color. If no color found, use the raw app log.
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"

[misc]
# Delete tmp directory on exit
clean_on_exit = true
59 changes: 59 additions & 0 deletions development/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Expects /src to be mounted to the source folder (by docker-compose.yml)

FROM debian:bookworm
ARG TARGETPLATFORM
RUN mkdir -p /development
WORKDIR /development

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
ENV GOPATH="/go"
ENV PATH="${GOPATH}/bin:${PATH}"

ENV CGO_ENABLED 1

RUN go env

# Download dependencies
COPY ../api/go.mod ../api/go.sum /development/
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

# Install tools
RUN apt-get update && apt-get install -y curl procps exiftool

# Setup node
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
RUN apt-get update && apt-get install -y nodejs

# Install Air for Go live reload
RUN go get -u github.com/cosmtrek/air

# Install Delve debugger
RUN go install github.com/go-delve/delve/cmd/dlv@latest

ENV PHOTOVIEW_LISTEN_IP localhost
ENV PHOTOVIEW_LISTEN_PORT 4001
ENV REACT_APP_API_ENDPOINT http://localhost:4001/
ENV PHOTOVIEW_API_ENDPOINT http://localhost:4001/
ENV PHOTOVIEW_UI_ENDPOINT http://localhost:1234/
ENV PHOTOVIEW_SERVE_UI 0
ENV PHOTOVIEW_UI_PATH /ui
ENV PHOTOVIEW_DEVELOPMENT_MODE 1
ENV COMPILER_ARCH aarch64-linux-gnu
EXPOSE 4001
EXPOSE 1234

COPY ../development/dev_startup.sh /development/
RUN chmod +x /development/dev_startup.sh
ENTRYPOINT ["/development/dev_startup.sh"]
8 changes: 8 additions & 0 deletions development/dev_startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
cd /src/ui
npm install
npm start &
cd /src/api
go install
air
tail -f /dev/null
51 changes: 51 additions & 0 deletions development/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: "3"

services:
db:
image: mariadb:10.5
restart: always
environment:
- MYSQL_DATABASE=photoview
- MYSQL_USER=photoview
- MYSQL_PASSWORD=photosecret
- MYSQL_RANDOM_ROOT_PASSWORD=1
volumes:
- db_data:/var/lib/mysql
ports:
- "3307:3306"

photoview:
build:
context: ..
dockerfile: development/Dockerfile
restart: always
ports:
- "1234:1234"
- "4001:4001"
depends_on:
- db

environment:
- PHOTOVIEW_DATABASE_DRIVER=mysql
- PHOTOVIEW_MYSQL_URL=photoview:photosecret@tcp(db)/photoview
- PHOTOVIEW_MEDIA_CACHE=/app/cache
- PHOTOVIEW_DEVELOPMENT_MODE=1

# Optional: If you are using Samba/CIFS-Share and experience problems with "directory not found"
# Enable the following Godebug
# - GODEBUG=asyncpreemptoff=1


# Optional: To enable map related features, you need to create a mapbox token.
# A token can be generated for free here https://account.mapbox.com/access-tokens/
# It's a good idea to limit the scope of the token to your own domain, to prevent others from using it.
# - MAPBOX_TOKEN=<YOUR TOKEN HERE>

volumes:
- api_cache:/app/cache
- ./photos:/photos:ro
- ../:/src

volumes:
db_data:
api_cache:
Binary file added development/photos/cat1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added development/photos/cat2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added development/photos/cat3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.