photoview: add config

This commit is contained in:
Jef Roosens 2024-10-01 14:28:28 +02:00
parent 56faa4323b
commit ad36788772
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
12 changed files with 191 additions and 13 deletions

View file

@ -0,0 +1,3 @@
---
dependencies:
- role: caddy

View file

@ -0,0 +1,9 @@
---
- name: Ensure Caddyfile is present
template:
src: 'photoview.Caddyfile.j2'
dest: '/etc/caddy/photoview.Caddyfile'
owner: root
group: root
mode: '0644'
notify: caddy-reload

View file

@ -0,0 +1,3 @@
photos.roosens.me {
reverse_proxy {{ hostvars[groups['photoview'][0]].static_ip }}:8012
}

View file

@ -0,0 +1,35 @@
services:
app:
image: 'viktorstrate/photoview:2.4.0'
restart: 'always'
depends_on:
db:
condition: service_healthy
environment:
PHOTOVIEW_DATABASE_DRIVER: 'postgres'
PHOTOVIEW_POSTGRES_URL: 'postgres://photoview:photoview@db/photoview?sslmode=disable'
ports:
- '8012:80'
volumes:
- '/etc/localtime:/etc/localtime:ro'
- '/etc/timezone:/etc/timezone:ro'
- '/mnt/data1/photoview/cache:/home/photoview/media-cache'
- '/mnt/data1/photos:/photos:ro'
db:
image: 'postgres:17.0-alpine'
restart: 'always'
healthcheck:
test: ["CMD", "pg_isready", "-U", "photoview"]
interval: 10s
start_period: 30s
environment:
POSTGRES_USER: 'photoview'
POSTGRES_PASSWORD: 'photoview'
POSTGRES_DB: 'photoview'
volumes:
- '/mnt/data1/photoview/postgres:/var/lib/postgresql/data'

View file

@ -0,0 +1,5 @@
cd /etc/photoview
/usr/bin/docker compose exec -T db pg_dump -U photoview photoview |
/usr/bin/gzip --rsyncable |
/usr/local/bin/restic backup --stdin --stdin-filename photoview-postgres.sql.gz

View file

@ -0,0 +1,13 @@
[Unit]
Description=Photo gallery for self-hosted personal servers
After=docker.service
Requires=docker.service
[Service]
Type=exec
WorkingDirectory=/etc/photoview
ExecStart=/usr/bin/docker compose up
ExecStop=/usr/bin/docker compose down
[Install]
WantedBy=multi-user.target

View file

@ -0,0 +1,5 @@
---
- name: 'restart photoview'
ansible.builtin.service:
name: 'photoview'
state: 'restarted'

View file

@ -0,0 +1,69 @@
---
- name: Ensure data directory is present
ansible.builtin.file:
path: '/mnt/data1/photoview'
state: directory
mode: '0755'
owner: 'root'
group: 'root'
- name: Ensure data subvolumes are present
community.general.btrfs_subvolume:
name: '/photoview/{{ item }}'
loop:
- 'postgres'
- 'cache'
- name: Ensure subvolume permissions are correct
ansible.builtin.file:
path: "/mnt/data1/photoview/{{ item }}"
state: directory
mode: '0755'
owner: '999'
group: '999'
loop:
- 'cache'
- name: Ensure configuration directory is present
ansible.builtin.file:
path: '/etc/photoview'
state: directory
mode: '0755'
- name: Ensure compose file is present
ansible.builtin.copy:
src: 'compose.yml'
dest: '/etc/photoview/compose.yml'
mode: '0644'
owner: 'root'
group: 'root'
notify: 'restart photoview'
- name: Ensure backup scripts are present
ansible.builtin.copy:
src: "photoview.{{ item }}.backup.sh"
dest: "/etc/backups/photoview.{{ item }}.backup.sh"
owner: 'root'
group: 'root'
mode: '0644'
loop:
- 'postgres'
- name: Ensure service file is present
ansible.builtin.copy:
src: 'photoview.service'
dest: '/lib/systemd/system/photoview.service'
owner: 'root'
group: 'root'
mode: '0644'
register: res
- name: systemd-reload
ansible.builtin.systemd_service:
daemon_reload: true
when: 'res.changed'
- name: Ensure photoview service is enabled
ansible.builtin.service:
name: 'photoview'
enabled: true