From 5d0bf68299fd01e03684e846bf030cb9e798bbce Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Sun, 12 Dec 2021 18:21:32 +0100 Subject: [PATCH] Demo: Add setup script --- docker/demo/Dockerfile | 2 +- docker/demo/Makefile | 14 +++++ docker/demo/README | 10 ++++ docker/demo/docker-compose.yml | 60 ++++++++++++++++++++ docker/demo/jobs.ini | 18 ++++++ docker/demo/setup.sh | 100 +++++++++++++++++++++++++++++++++ docker/demo/traefik.yaml | 39 +++++++++++++ 7 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 docker/demo/Makefile create mode 100644 docker/demo/README create mode 100644 docker/demo/docker-compose.yml create mode 100644 docker/demo/jobs.ini create mode 100755 docker/demo/setup.sh create mode 100644 docker/demo/traefik.yaml diff --git a/docker/demo/Dockerfile b/docker/demo/Dockerfile index e78f2e0f5..7d9a1f172 100644 --- a/docker/demo/Dockerfile +++ b/docker/demo/Dockerfile @@ -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 diff --git a/docker/demo/Makefile b/docker/demo/Makefile new file mode 100644 index 000000000..88b7bd152 --- /dev/null +++ b/docker/demo/Makefile @@ -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 diff --git a/docker/demo/README b/docker/demo/README new file mode 100644 index 000000000..fbfaf74bf --- /dev/null +++ b/docker/demo/README @@ -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 diff --git a/docker/demo/docker-compose.yml b/docker/demo/docker-compose.yml new file mode 100644 index 000000000..e1ccb80e0 --- /dev/null +++ b/docker/demo/docker-compose.yml @@ -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" \ No newline at end of file diff --git a/docker/demo/jobs.ini b/docker/demo/jobs.ini new file mode 100644 index 000000000..08690715e --- /dev/null +++ b/docker/demo/jobs.ini @@ -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 \ No newline at end of file diff --git a/docker/demo/setup.sh b/docker/demo/setup.sh new file mode 100755 index 000000000..bf00c58ba --- /dev/null +++ b/docker/demo/setup.sh @@ -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) diff --git a/docker/demo/traefik.yaml b/docker/demo/traefik.yaml new file mode 100644 index 000000000..7a0bfcf13 --- /dev/null +++ b/docker/demo/traefik.yaml @@ -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 \ No newline at end of file