From ba318533e9ce0b68ee5384e56c80ae04d60e5b9c Mon Sep 17 00:00:00 2001 From: Benoit S Date: Mon, 27 Sep 2021 21:38:10 +0900 Subject: [PATCH] Add upgrade procedure with remove/deploy --- README.md | 9 +++++++++ deploy.py | 11 ++++++----- remove.py | 16 ++++++++++++++++ templates/systemd-run.sh.j2 | 1 + 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 remove.py diff --git a/README.md b/README.md index cf18def..643d017 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,15 @@ Pyinfra that deploy PhotoPrism un-dockerized on a Debian 11 LXD container. # pyinfra inventories/production.py deploy.py ``` +## Upgrade + +Run `remove.py` then `deploy.py`. + +``` +# pyinfra inventories/production.py remove.py +# pyinfra inventories/production.py deploy.py +``` + # Attach a pictures volume If required, you can mount external volumes. Example: diff --git a/deploy.py b/deploy.py index a74a177..19b347c 100644 --- a/deploy.py +++ b/deploy.py @@ -88,11 +88,12 @@ files.directory( mode=755 ) -server.shell( - name='Undocker the Docker image', - chdir=host.data.undocker_dst, - commands=['undocker '+host.data.undocker_cache+'/photoprism.tar - | tar -xv'], -) +if not host.fact.directory(host.data.undocker_dst): + server.shell( + name='Undocker the Docker image', + chdir=host.data.undocker_dst, + commands=['undocker '+host.data.undocker_cache+'/photoprism.tar - | tar -xv'], + ) files.template( name='Set env file', diff --git a/remove.py b/remove.py new file mode 100644 index 0000000..d9e434a --- /dev/null +++ b/remove.py @@ -0,0 +1,16 @@ +from pyinfra import host +from pyinfra.operations import server, files + +if host.fact.file(host.data.undocker_cache+'/photoprism.tar'): + server.shell( + name='Remove photoprism Docker image', + chdir=host.data.undocker_cache, + commands=['rm photoprism.tar'], + ) + +if host.fact.directory(host.data.undocker_dst): + server.shell( + name='Remove undocker destination', + commands=['rm -rf {}'.format(host.data.undocker_dst)], + ) + diff --git a/templates/systemd-run.sh.j2 b/templates/systemd-run.sh.j2 index aec3021..66ebb30 100644 --- a/templates/systemd-run.sh.j2 +++ b/templates/systemd-run.sh.j2 @@ -3,6 +3,7 @@ set -euo pipefail systemd-run \ --pty \ + --unit='photoprism-run' \ --description='photoprism binary call' \ --property=User={{ host.data.unix_user }} \ --property=Group={{ host.data.unix_group }} \