Static site generator for NextCloud photos

October 22, 2018

Inspired by a tweet from @mattsches on how to host and share photos, many people replied with really good ideas.

Here is my approach:

Hosting with nextcloud

  • I like the idea of hosting by my own with nextcloud.
  • The Android and iOS integration is great and makes it very easy to upload photos
  • You can use the drop function gather photos on an event from other people
  • The gallery is a nice piece of software

Using a static site generator for photos

Configuration

All this stuff is running on the same server.
I’m using all software in containers, using docker and docker-compose.
As web server Traefik is used.

Traefik (web server)

# /srv/docker/traefik/docker-compose.yml

version: '2'

services:
  traefik:
    image: traefik
    restart: always
    expose:
      - "8080"
    labels:
      - "traefik.docker.network=traefik_web"
      - "traefik.enable=true"
      - "traefik.basic.frontend.rule=Host:traefik.mydomain.com"
      - "traefik.basic.port=8080"
      - "traefik.basic.protocol=http"
    ports:
      - "80:80"
      - "443:443"
    networks:
      - web
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./acme.json:/acme.json
      - ./traefik.toml:/traefik.toml

networks:
  web:
    external:
      name: traefik_web

Nextcloud

For nextcloud the nexcloud-base image is used:

# /srv/docker/nextcloud/docker-compose.yml

version: '2'

services:

  db:
    image: mariadb
    restart: always
    volumes:
      - db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=!CHANGEME!
      - MYSQL_PASSWORD=!CHANGEME!
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud

  nextcloud:
    image: nextcloud
    restart: always
    expose:
      - "80"
    links:
      - db
    networks:
      - web
      - default
    volumes:
      - nextcloud:/var/www/html
      - /mnt/sdb2/nextcloud/data:/data:rw
    labels:
      - "traefik.docker.network=traefik_web"
      - "traefik.enable=true"
      - "traefik.frontend.rule=Host:cloud.mydomain.com"
      - "traefik.port=80"
      - "traefik.protocol=http"

volumes:
  db:
  nextcloud:

networks:
  web:
    external:
      name: traefik_web

Thumbsup (static site generator)

Now it’s getting interesting. Here comes the docker-compose.yml for the statiy site generator.

# /srv/docker/thumbsup/docker-compose.yml

version: '2'
services:
  web:
    restart: always
    image: nginx:latest
    expose:
      - "80"
    volumes:
      - static_html:/usr/share/nginx/html
    labels:
      - "traefik.docker.network=traefik_web"
      - "traefik.enable=true"
      - "traefik.basic.frontend.rule=Host:photos.mydomain.com"
      - "traefik.basic.frontend.auth.basic=test:$apr1$ASxYdF4/$EsG.4UNVuNXKRI2.WH7Oa"
      - "traefik.basic.port=80"
      - "traefik.basic.protocol=http"
    networks:
      - web
      - default

  thumbsup:
    restart: always
    build: ./thumbsup
    volumes:
      - /mnt/sdb2/nextcloud/data/ralf/files/Photos:/input
      - static_html:/output
      - ./thumbsup/config:/config

  dyndns:
     restart: always
     build: ./dyndns

volumes:
  static_html:

networks:
  web:
    external:
      name: traefik_web

We can see here 3 containers:

  • web: serves the static content
  • thumbsup: generates the content
  • dyndns: updates the IP on the dyndns-service

Lets look into the thumbsup-container:

Thumbsup

# /srv/docker/thumbsup/thumbsup/Dockerfile

FROM thumbsupgallery/thumbsup

COPY config/cronjobs /etc/crontabs/root

CMD ["crond", "-f", "-d", "8"]

To the original Docker-Container we’re adding a cronjob.

# /srv/docker/thumbsup/thumbsup/config/cronjobs
*/15 * * * * /usr/local/bin/thumbsup --config /config/config.json --input /input --output /output

The thumbsup-config is well documented.

{
    "title": "MyTitle",
    "original-photos": false,
    "theme": "cards",
    "sort-albums-direction": "desc",
    "cleanup": true
}

DONE!!


comments powered by Disqus