diff --git a/deploy.py b/deploy.py new file mode 100644 index 0000000..3afe8e5 --- /dev/null +++ b/deploy.py @@ -0,0 +1,102 @@ +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, +) diff --git a/files/photoprism.service b/files/photoprism.service new file mode 100644 index 0000000..eb3128e --- /dev/null +++ b/files/photoprism.service @@ -0,0 +1,18 @@ +[Unit] +Description=photoprism +After=network.target + +[Service] +Type=simple +User=photoprism +Group=photoprism +StateDirectory=photoprism +EnvironmentFile=/etc/photoprism.env +WorkingDirectory=/photoprism +RootDirectory=/opt/photoprism +BindPaths=/home/photoprism/storage:/photoprism/storage /home/photoprism/originals:/photoprism/originals /home/photoprism/import:/photoprism/import +ExecStart=/photoprism/bin/photoprism start +Restart=on-failure + +[Install] +WantedBy=multi-user.target diff --git a/group_data/all.py b/group_data/all.py new file mode 100644 index 0000000..0448a19 --- /dev/null +++ b/group_data/all.py @@ -0,0 +1,34 @@ +# Undocker source +undocker_url='https://git.sr.ht/~motiejus/undocker/refs/download/v1.0.2/undocker-linux-amd64-v1.0.2' + +# Used for the system + +# From Dockerfile + +# From docker-compose +photoprism_admin_password='insecure' # File size limit for originals in MB (increase for high-res video) +photoprism_originals_limit=5000 # File size limit for originals in MB (increase for high-res video) +photoprism_http_compression="GZIP" # Improves transfer speed and bandwidth utilization (none or gzip) +photoprism_debug="false" # Run in debug mode (shows additional log messages) +photoprism_public="false" # No authentication required (disables password protection) +photoprism_readonly="false" # Don't modify originals directory (reduced functionality) +photoprism_experimental="false" # Enables experimental features +photoprism_disable_webdav="false" # Disables built-in WebDAV server +photoprism_disable_settings="false" # Disables Settings in Web UI +photoprism_disable_tensorflow="false" # Disables all features depending on TensorFlow +photoprism_disable_faces="false" # Disables facial recognition +photoprism_disable_classification="false" # Disables image classification +photoprism_darktable_presets="false" # Enables Darktable presets and disables concurrent RAW conversion +photoprism_detect_nsfw="false" # Flag photos as private that MAY be offensive (requires TensorFlow) +photoprism_upload_nsfw="true" # Allow uploads that MAY be offensive +photoprism_database_driver="mysql" # Use MariaDB (or MySQL) instead of SQLite for improved performance +photoprism_database_server="127.0.0.1:3306" # MariaDB database server (hostname=port) +photoprism_database_name="photoprism" # MariaDB database schema name +photoprism_database_user="photoprism" # MariaDB database user name +photoprism_database_password='insecure' +photoprism_site_url="http://localhost:2342/" # Public PhotoPrism URL +photoprism_site_title="PhotoPrism" +photoprism_site_caption="Browse Your Life" +photoprism_site_description="" +photoprism_site_author="" +home="/photoprism" diff --git a/templates/env.j2 b/templates/env.j2 new file mode 100644 index 0000000..3b0023d --- /dev/null +++ b/templates/env.j2 @@ -0,0 +1,33 @@ +PHOTOPRISM_ASSETS_PATH="/photoprism/assets" +PHOTOPRISM_STORAGE_PATH="/photoprism/storage" +PHOTOPRISM_BACKUP_PATH="/var/lib/photoprism" +PHOTOPRISM_ORIGINALS_PATH="/photoprism/originals" +PHOTOPRISM_IMPORT_PATH="/photoprism/import" +PHOTOPRISM_LOG_FILENAME="/photoprism/photoprism.log" +PHOTOPRISM_PID_FILENAME="/photoprism/photoprism.pid" +PHOTOPRISM_ADMIN_PASSWORD="{{ host.data.photoprism_admin_password }}" +PHOTOPRISM_ORIGINALS_LIMIT={{ host.data.photoprism_originals_limit }} +PHOTOPRISM_HTTP_COMPRESSION="{{ host.data.photoprism_http_compression }}" +PHOTOPRISM_DEBUG="false" +PHOTOPRISM_PUBLIC="false" +PHOTOPRISM_READONLY="false" +PHOTOPRISM_EXPERIMENTAL="false" +PHOTOPRISM_DISABLE_WEBDAV="false" +PHOTOPRISM_DISABLE_SETTINGS="false" +PHOTOPRISM_DISABLE_TENSORFLOW="false" +PHOTOPRISM_DISABLE_FACES="false" +PHOTOPRISM_DISABLE_CLASSIFICATION="false" +PHOTOPRISM_DARKTABLE_PRESETS="false" +PHOTOPRISM_DETECT_NSFW="false" +PHOTOPRISM_UPLOAD_NSFW="true" +PHOTOPRISM_DATABASE_DRIVER="mysql" +PHOTOPRISM_DATABASE_SERVER="{{ host.data.photoprism_database_server }}" +PHOTOPRISM_DATABASE_NAME="{{ host.data.photoprism_database_name }}" +PHOTOPRISM_DATABASE_USER="{{ host.data.photoprism_database_user }}" +PHOTOPRISM_DATABASE_PASSWORD="{{ host.data.photoprism_database_password }}" +PHOTOPRISM_SITE_URL="http://localhost:2342/" +PHOTOPRISM_SITE_TITLE="PhotoPrism" +PHOTOPRISM_SITE_CAPTION="Browse Your Life" +PHOTOPRISM_SITE_DESCRIPTION="" +PHOTOPRISM_SITE_AUTHOR="" +HOME="/photoprism"