pyinfra deploy.py to deploy a local bot user unit

This commit is contained in:
missytake 2023-12-14 23:34:26 +01:00
parent 7711c106b7
commit 0dcec5dce2
3 changed files with 49 additions and 0 deletions

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
*.swp
.env
*.egg-info/
__pycache__/
/.tox/

36
local-deploy.py Normal file
View file

@ -0,0 +1,36 @@
import os
import importlib.resources
from pyinfra.operations import apt, files, pip, server, systemd
# install into .local/lib
def install(unix_user) -> None:
remember_package = importlib.resources.files("remember_remember_bot")
working_directory = os.getcwd()
remote_venv_dir = f"{working_directory}/venv"
# install systemd units
fn = "remember-remember-bot"
service_file = remember_package / "pyinfra_assets" / f"{fn}.service.j2"
files.template(
name=f"Upload {fn}.service",
src=service_file,
dest=f"/home/{unix_user}/.config/systemd/user/{fn}.service",
execpath=f"{remote_venv_dir}/bin/{fn}",
working_directory=working_directory,
unix_user=unix_user,
)
systemd.service(
name=f"Setup {fn} service",
service=f"{fn}.service",
running=True,
enabled=True,
restarted=True,
daemon_reload=True,
user_mode=True,
)
unix_user = os.environ.get("REMEMBER_PYINFRA_USER", os.environ.get("USER"))
install(unix_user)

View file

@ -0,0 +1,12 @@
[Unit]
Description=run deltachat remember-remember-bot
[Service]
ExecStart={{ execpath }} --debug
EnvironmentFile={{ working_directory }}/.env
WorkingDirectory={{ working_directory }}
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target