This repository has been archived on 2023-02-05. You can view files and clone it, but cannot push or open issues or pull requests.
pyinfra-photoprism/deploy.py

103 lines
2.2 KiB
Python
Raw Normal View History

2021-09-26 09:42:30 +00:00
from pyinfra import host
from pyinfra.operations import apt, server, files, systemd, mysql
apt.update(
name='Update apt repositories',
)
apt.upgrade(
name='Upgrade apt packages',
)
apt.packages(
name='Install dependencies',
packages=['mariadb-server', 'skopeo'],
update=False,
)
server.user(
name='Create UNIX user',
user='photoprism',
shell='/bin/false',
present=True,
)
for items in ['storage', 'originals', 'import']:
files.directory(
name='Make required directories /home/photoprism/{}'.format(items),
path='/home/photoprism/{}'.format(items),
user='photoprism',
group='photoprism',
mode=755
)
mysql.user(
name='Create MariaDB user',
user=host.data.photoprism_database_user,
password=host.data.photoprism_database_password,
)
mysql.database(
name='Create MariaDB database',
database=host.data.photoprism_database_name,
user=host.data.photoprism_database_user,
)
files.download(
name='Download undocker',
src=host.data.undocker_url,
dest='/usr/local/bin/undocker',
user='root',
group='root',
mode='755',
sha256sum='b937e69e774c530c080c1f6685763ca7db4dc58520a5a2054d111e1504f47688',
)
if not host.fact.file('/tmp/photoprism.tar'):
server.shell(
name='Download photoprism Docker image',
chdir='/tmp',
commands=['skopeo copy docker://docker.io/photoprism/photoprism:latest docker-archive:photoprism.tar'],
)
files.directory(
name='Ensure /opt/photoprism exists',
path='/opt/photoprism',
user='root',
group='root',
mode=755
)
server.shell(
name='Undocker the Docker image',
chdir='/opt/photoprism',
commands=['undocker /tmp/photoprism.tar - | tar -xv'],
)
files.template(
name='Set env file',
src='templates/env.j2',
dest='/etc/photoprism.env',
mode='600',
)
files.put(
name='Set systemd service file',
src='files/photoprism.service',
dest='/etc/systemd/system/photoprism.service',
mode='644',
)
systemd.daemon_reload(
name='Reload systemd',
user_mode=False,
)
systemd.service(
name='Enable systemd service',
service='photoprism.service',
running=True,
restarted=True,
enabled=True,
)