This repository was archived by the owner on Sep 28, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.py
76 lines (61 loc) · 2.17 KB
/
deploy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
This is an example pyinfra deploy file for installing xdcstore and xdcget.
Its usage is documented in https://github.com/deltachat/pyinfra-xdcstore/#deploy-with-few-cli-commands
"""
import os
import importlib
import pyinfra
from pyinfra.facts.server import Users
from pyinfra.operations import server, files
from pyinfra_xdcstore import deploy_xdcstore
def create_unix_user(unix_user):
"""Create a UNIX user for the bot.
:param unix_user: the username for the UNIX user
"""
server.user(
name=f"Add user {unix_user}",
user=unix_user,
present=True,
shell="/bin/bash",
home=f"/home/{unix_user}",
)
server.shell(
name=f"enable {unix_user}'s systemd units to auto-start at boot",
commands=[f"loginctl enable-linger {unix_user}"],
)
files.put(
name=f"upload {unix_user} .profile",
src=importlib.resources.files('pyinfra_xdcstore').joinpath("xstore.profile"),
dest=f"/home/{unix_user}/.profile",
user=unix_user,
group=unix_user,
)
def main():
unix_user = os.getenv("XDCGET_UNIX_USER", "xdcstore")
bot_email = os.getenv("XDCSTORE_EMAIL")
bot_password = os.getenv("XDCSTORE_PASSWORD")
codeberg_user = os.getenv("XDCGET_CODEBERG_USER", "")
codeberg_token = os.getenv("XDCGET_CODEBERG_TOKEN", "")
github_user = os.getenv("XDCGET_GITHUB_USER", "")
github_token = os.getenv("XDCGET_GITHUB_TOKEN", "")
required_variables_missing = False
if bot_email is None:
pyinfra.logger.error("[error] XDCSTORE_EMAIL can't be empty.")
required_variables_missing = True
if bot_password is None:
pyinfra.logger.error("[error] XDCSTORE_PASSWORD can't be empty.")
required_variables_missing = True
if required_variables_missing:
return # end pyinfra run prematurely
if unix_user not in [user for user in pyinfra.host.get_fact(Users)]:
create_unix_user(unix_user)
deploy_xdcstore(
unix_user,
bot_email,
bot_password,
codeberg_user=codeberg_user,
codeberg_token=codeberg_token,
github_user=github_user,
github_token=github_token,
)
main()