Demo: Add setup script

This commit is contained in:
Michael Mayer 2021-12-12 18:21:32 +01:00
parent c777410f30
commit 5d0bf68299
7 changed files with 242 additions and 1 deletions

View File

@ -20,7 +20,7 @@ ENV TF_CPP_MIN_LOG_LEVEL=2 \
PHOTOPRISM_APP_ICON="favicon" \
PHOTOPRISM_SITE_TITLE="PhotoPrism" \
PHOTOPRISM_SITE_CAPTION="Demo" \
PHOTOPRISM_SITE_DESCRIPTION="AI-powered app for browsing, organizing & sharing your photo collection. Tags and finds pictures without getting in your way."
PHOTOPRISM_SITE_DESCRIPTION="AI-Powered Photos App. Tags and finds pictures without getting in your way!"
# Copy assets
COPY /docker/demo/index.tmpl /photoprism/assets/templates

14
docker/demo/Makefile Normal file
View File

@ -0,0 +1,14 @@
.PHONY: all restart terminal logs;
all: restart
restart:
docker-compose pull demo
docker-compose stop demo
docker-compose up -d --force-recreate demo
install:
docker-compose pull
docker-compose stop
docker-compose up -d
terminal:
docker-compose exec demo bash
logs:
docker-compose logs --tail=50 -f

10
docker/demo/README Normal file
View File

@ -0,0 +1,10 @@
# PhotoPrism Demo Environment
Run to install a pre-configured demo instance on Ubuntu 20.04 LTS:
bash <(curl -s https://dl.photoprism.org/docker/demo/setup.sh)
Note:
- demo.yourdomain.com must be replaced with the actual hostname
- The demo is frequently restarted to remove uploaded content
- There is no password protection, it is running in public mode

View File

@ -0,0 +1,60 @@
version: '3.5'
services:
demo:
restart: always
command: photoprism --public start
image: photoprism/demo:latest
container_name: demo
depends_on:
- traefik
labels:
- "traefik.enable=true"
- "traefik.http.routers.demo.rule=Host(`demo.yourdomain.com`)"
- "traefik.http.routers.demo.tls=true"
- "traefik.http.routers.demo.tls.certresolver=myresolver"
volumes:
- "./config:/photoprism/storage/config"
environment:
PHOTOPRISM_SITE_URL: "https://demo.yourdomain.com/"
# PHOTOPRISM_CDN_URL: "https://demo-cdn.yourdomain.com/"
PHOTOPRISM_SITE_TITLE: "PhotoPrism"
PHOTOPRISM_SITE_CAPTION: "Demo"
PHOTOPRISM_SITE_DESCRIPTION: "AI-Powered Photos App. Tags and finds pictures without getting in your way!"
PHOTOPRISM_SITE_PREVIEW: "https://i.photoprism.app/logo?cover=17&title=Demo"
PHOTOPRISM_SITE_AUTHOR: "PhotoPrism"
PHOTOPRISM_HTTP_COMPRESSION: "gzip"
PHOTOPRISM_SPONSOR: "true"
traefik:
restart: always
image: traefik:v2.5
container_name: traefik
ports:
- "80:80"
- "443:443"
expose:
- "80"
- "443"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "./traefik/:/data/"
- "./traefik.yaml:/etc/traefik/traefik.yaml"
scheduler:
restart: always
image: mcuadros/ofelia:latest
container_name: scheduler
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./jobs.ini:/etc/ofelia/config.ini"
watchtower:
restart: always
image: containrrr/watchtower
container_name: watchtower
environment:
WATCHTOWER_CLEANUP: "true"
WATCHTOWER_POLL_INTERVAL: 1800
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"

18
docker/demo/jobs.ini Normal file
View File

@ -0,0 +1,18 @@
# See https://github.com/mcuadros/ofelia/blob/master/docs/jobs.md for job settings!
#
# Cron expressions in "schedule" represent times using 6 space-separated fields:
#
# Field name | Mandatory? | Allowed values | Allowed special characters
# ---------- | ---------- | -------------- | --------------------------
# Seconds | Yes | 0-59 | * / , -
# Minutes | Yes | 0-59 | * / , -
# Hours | Yes | 0-23 | * / , -
# Day of month | Yes | 1-31 | * / , - ?
# Month | Yes | 1-12 or JAN-DEC | * / , -
# Day of week | Yes | 0-6 or SUN-SAT | * / , - ?
[job-local "restart demo"]
schedule = @every 3h
command = make restart
dir = /opt/photoprism
no-overlap = true

100
docker/demo/setup.sh Executable file
View File

@ -0,0 +1,100 @@
#!/usr/bin/env bash
# PhotoPrism Demo Environment - Setup Script
#
# Usage:
# bash <(curl -s https://dl.photoprism.org/docker/demo/setup.sh)
#
# Note:
# - demo.yourdomain.com must be replaced with the actual hostname
# - The demo is frequently restarted to remove uploaded content
# - There is no password protection, it is running in public mode
# check if user is root
if [[ $(id -u) != "0" ]]; then
echo "You need to be root to run this script." 1>&2
exit 1
fi
# fail on errors
set -eu
# disable user interactions
export DEBIAN_FRONTEND="noninteractive"
export TMPDIR="/tmp"
# add 4 GB of swap if no swap was configured yet
if [[ -z $(swapon --show) ]]; then
fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
swapon --show
free -h
echo '/swapfile none swap sw 0 0' | tee -a /etc/fstab
fi
# set apt defaults
echo 'Acquire::Retries "10";' > /etc/apt/apt.conf.d/80retry && \
echo 'APT::Install-Recommends "false";' > /etc/apt/apt.conf.d/80recommends && \
echo 'APT::Install-Suggests "false";' > /etc/apt/apt.conf.d/80suggests && \
echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/80forceyes && \
echo 'APT::Get::Fix-Missing "true";' > /etc/apt/apt.conf.d/80fixmissing
# update operating system
apt-get update
apt dist-upgrade 2>/dev/null
# install dependencies
apt-get -qq install --no-install-recommends apt-transport-https ca-certificates \
curl wget make software-properties-common net-tools openssl ufw
# install docker if needed
if ! command -v docker &> /dev/null; then
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
apt-get update
apt-get -qq install docker-ce
fi
# install docker-compose if needed
if ! command -v docker-compose &> /dev/null; then
apt-get update
apt-get -qq install docker-compose
fi
# Basic ufw firewall setup allowing ssh, http, and https
ufw default deny incoming
ufw default allow outgoing
ufw allow ssh
ufw allow http
ufw allow https
ufw logging off
rm -f /var/log/ufw.log
ufw --force enable
# create user
useradd -o -m -U -u 1000 -G docker -d /opt/photoprism photoprism || echo "User 'photoprism' already exists. Proceeding."
mkdir -p /opt/photoprism/config /opt/photoprism/traefik
# detect public server ip address
PUBLIC_IP=$(curl -sfSL ifconfig.me)
# download service config
COMPOSE_CONFIG=$(curl -fsSL https://dl.photoprism.org/docker/demo/docker-compose.yml)
COMPOSE_CONFIG=${COMPOSE_CONFIG//_public_ip_/$PUBLIC_IP}
echo "${COMPOSE_CONFIG}" > /opt/photoprism/docker-compose.yml
curl -fsSL https://dl.photoprism.org/docker/demo/jobs.ini > /opt/photoprism/jobs.ini
curl -fsSL https://dl.photoprism.org/docker/demo/traefik.yaml > /opt/photoprism/traefik.yaml
curl -fsSL https://dl.photoprism.org/docker/demo/Makefile > /opt/photoprism/Makefile
# change permissions
chown -Rf photoprism:photoprism /opt/photoprism
# clear package cache
apt-get autoclean
apt-get autoremove
# start services using docker-compose
(cd /opt/photoprism && make install)

39
docker/demo/traefik.yaml Normal file
View File

@ -0,0 +1,39 @@
# Uncomment to enable debug mode:
# log:
# level: DEBUG
serversTransport:
# Required to proxy services with self-signed HTTPS certificates:
insecureSkipVerify: true
# Open ports ond protocols (HTTP will be redirected to HTTPS):
entryPoints:
web:
address: ":80"
http:
redirections:
entryPoint:
to: websecure
scheme: https
websecure:
address: ":443"
certificatesResolvers:
myresolver:
# See https://doc.traefik.io/traefik/https/acme/
acme:
email: tls@yourdomain.com
storage: /data/letsencrypt.json
httpChallenge:
entryPoint: web
providers:
# Always keep this:
docker:
exposedByDefault: false
watch: true
# Disable API & Dashboard by default, please read Traefik docs before enabling this:
api:
insecure: false
dashboard: false