Compare commits
No commits in common. "93e11c515ff1a0e355ad433c395b7912b721e894" and "52fbc871b2edaed106a0189bc6ff5e86ac097f80" have entirely different histories.
93e11c515f
...
52fbc871b2
4 changed files with 9 additions and 120 deletions
|
@ -1,4 +1,3 @@
|
||||||
from pathlib import Path
|
|
||||||
from packaging import version
|
from packaging import version
|
||||||
from pyinfra.operations import apk, server, files
|
from pyinfra.operations import apk, server, files
|
||||||
from pyinfra.facts.server import LinuxName
|
from pyinfra.facts.server import LinuxName
|
||||||
|
@ -8,14 +7,9 @@ from pyinfra import host
|
||||||
CROC_ALPINE_VERSION = version.parse("3.14")
|
CROC_ALPINE_VERSION = version.parse("3.14")
|
||||||
|
|
||||||
|
|
||||||
@deploy(
|
@deploy("install croc")
|
||||||
"install croc",
|
|
||||||
data_defaults={
|
|
||||||
"croc_install_directory": "/opt/croc",
|
|
||||||
"croc_bin_directory": "/usr/bin",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
def install_croc():
|
def install_croc():
|
||||||
|
|
||||||
# alpine provides croc in-repo as of 3.14
|
# alpine provides croc in-repo as of 3.14
|
||||||
if host.get_fact(LinuxName) == "Alpine":
|
if host.get_fact(LinuxName) == "Alpine":
|
||||||
host_alpine_version = version.parse(host.data.alpine_version)
|
host_alpine_version = version.parse(host.data.alpine_version)
|
||||||
|
@ -24,15 +18,11 @@ def install_croc():
|
||||||
return
|
return
|
||||||
|
|
||||||
# for everyone else, install manually
|
# for everyone else, install manually
|
||||||
croc_dir = Path(host.data.croc_install_directory)
|
files.directory("/opt/croc")
|
||||||
target_dir = host.data.croc_bin_directory
|
files.download(
|
||||||
files.directory(str(croc_dir))
|
|
||||||
files.directory(target_dir)
|
|
||||||
result = files.download(
|
|
||||||
"https://github.com/schollz/croc/releases/download/v9.6.3/croc_9.6.3_Linux-64bit.tar.gz",
|
"https://github.com/schollz/croc/releases/download/v9.6.3/croc_9.6.3_Linux-64bit.tar.gz",
|
||||||
str(croc_dir / "croc.tar.gz"),
|
"/opt/croc/croc.tar.gz",
|
||||||
md5sum="5550b0bfb50d0541cba790562c180bd7",
|
md5sum="5550b0bfb50d0541cba790562c180bd7",
|
||||||
)
|
)
|
||||||
if result.changed:
|
server.shell("tar xvf /opt/croc/croc.tar.gz", _chdir="/opt/croc")
|
||||||
server.shell(f"tar xvf {croc_dir}/croc.tar.gz", _chdir=str(croc_dir))
|
server.shell("mv /opt/croc/croc /usr/bin/croc", _chdir="/opt/croc")
|
||||||
server.shell(f"mv {croc_dir}/croc {target_dir}/croc", _chdir=str(croc_dir))
|
|
||||||
|
|
|
@ -29,7 +29,6 @@ class GitFetch(FactBase):
|
||||||
|
|
||||||
class GitRevListComparison(FactBase):
|
class GitRevListComparison(FactBase):
|
||||||
def command(self, repo: str, branch: str):
|
def command(self, repo: str, branch: str):
|
||||||
assert branch
|
|
||||||
return f"git -C {repo} rev-list HEAD..origin/{branch} | wc -l"
|
return f"git -C {repo} rev-list HEAD..origin/{branch} | wc -l"
|
||||||
|
|
||||||
def process(self, output):
|
def process(self, output):
|
||||||
|
@ -123,7 +122,7 @@ def repo(
|
||||||
# always fetch upstream branches (that way we can compare if the latest
|
# always fetch upstream branches (that way we can compare if the latest
|
||||||
# commit has changed, and then we don't need to execute anything!)
|
# commit has changed, and then we don't need to execute anything!)
|
||||||
host.get_fact(GitFetch, repo=dest)
|
host.get_fact(GitFetch, repo=dest)
|
||||||
stdout = host.get_fact(GitRevListComparison, repo=dest, branch=current_branch)
|
stdout = host.get_fact(GitRevListComparison, repo=dest, branch=branch)
|
||||||
repository_has_updates = stdout[0] != "0"
|
repository_has_updates = stdout[0] != "0"
|
||||||
|
|
||||||
# since we immediately always fetch, we will always be modifying the
|
# since we immediately always fetch, we will always be modifying the
|
||||||
|
|
100
tasks/piped.py
100
tasks/piped.py
|
@ -1,100 +0,0 @@
|
||||||
from pyinfra import host
|
|
||||||
from pyinfra.api import deploy
|
|
||||||
from pyinfra.operations import files, server, dnf, postgresql, lxd
|
|
||||||
from pyinfra.facts.server import Which
|
|
||||||
from pyinfra.facts.lxd import LxdContainers
|
|
||||||
|
|
||||||
from .operations.git import repo
|
|
||||||
from .postgresql import install as install_postgresql
|
|
||||||
from .pleroma import WithSecrets
|
|
||||||
from .install_consul_server import template_and_install_systemd
|
|
||||||
from .yts import lxc_shell
|
|
||||||
|
|
||||||
|
|
||||||
@deploy(
|
|
||||||
"create lxc container that'll run piped",
|
|
||||||
data_defaults={"piped_container_name": "piped"},
|
|
||||||
)
|
|
||||||
def install_lxc_container():
|
|
||||||
containers = host.get_fact(LxdContainers)
|
|
||||||
ct_name = host.data.piped_container_name
|
|
||||||
|
|
||||||
found_piped_container = False
|
|
||||||
for container in containers:
|
|
||||||
if container["name"] == ct_name:
|
|
||||||
found_piped_container = True
|
|
||||||
|
|
||||||
if not found_piped_container:
|
|
||||||
lxd.container(
|
|
||||||
name="create piped container",
|
|
||||||
id=ct_name,
|
|
||||||
image="images:fedora/38",
|
|
||||||
)
|
|
||||||
|
|
||||||
# validate the ct is good
|
|
||||||
lxc_shell(ct_name, "env")
|
|
||||||
|
|
||||||
|
|
||||||
@deploy("install piped backend")
|
|
||||||
def install():
|
|
||||||
install_postgresql()
|
|
||||||
dnf.packages(
|
|
||||||
[
|
|
||||||
"java-17-openjdk-headless",
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
with_secrets = WithSecrets(("piped_db_password",))
|
|
||||||
|
|
||||||
# TODO remove copypaste of this between piped and pleroma
|
|
||||||
has_postgres = host.get_fact(Which, command="psql")
|
|
||||||
postgres_kwargs = {}
|
|
||||||
if has_postgres:
|
|
||||||
postgres_kwargs = {"_sudo": True, "_sudo_user": "postgres"}
|
|
||||||
|
|
||||||
postgresql.role(
|
|
||||||
role=host.data.piped_db_user,
|
|
||||||
password=with_secrets.piped_db_password,
|
|
||||||
login=True,
|
|
||||||
**postgres_kwargs,
|
|
||||||
)
|
|
||||||
|
|
||||||
postgresql.database(
|
|
||||||
database=host.data.piped_db_name,
|
|
||||||
owner=host.data.piped_db_user,
|
|
||||||
encoding="UTF8",
|
|
||||||
**postgres_kwargs,
|
|
||||||
)
|
|
||||||
|
|
||||||
runner_user = "piped"
|
|
||||||
remote_main_home_path = f"/opt/piped"
|
|
||||||
|
|
||||||
# we really dont need to build the whole thing
|
|
||||||
# just croc the jar file manually
|
|
||||||
|
|
||||||
server.group(runner_user)
|
|
||||||
server.user(
|
|
||||||
user=runner_user,
|
|
||||||
present=True,
|
|
||||||
home=remote_main_home_path,
|
|
||||||
shell="/bin/false",
|
|
||||||
group=runner_user,
|
|
||||||
ensure_home=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
config_output = files.template(
|
|
||||||
"./files/piped/config.properties",
|
|
||||||
dest=f"{remote_main_home_path}/config.properties",
|
|
||||||
user=runner_user,
|
|
||||||
group=runner_user,
|
|
||||||
mode=500,
|
|
||||||
env_dict=with_secrets,
|
|
||||||
)
|
|
||||||
|
|
||||||
template_and_install_systemd(
|
|
||||||
"./files/piped/piped.service.j2",
|
|
||||||
env_dict={
|
|
||||||
"user": runner_user,
|
|
||||||
"remote_main_home_path": remote_main_home_path,
|
|
||||||
},
|
|
||||||
)
|
|
|
@ -5,7 +5,7 @@ from pyinfra.operations import dnf, systemd, server
|
||||||
from pyinfra.facts.server import LinuxName, LinuxDistribution
|
from pyinfra.facts.server import LinuxName, LinuxDistribution
|
||||||
|
|
||||||
|
|
||||||
@deploy("Install PostgreSQL", data_defaults={"postgresql_version": 15})
|
@deploy("Install PostgreSQL")
|
||||||
def install():
|
def install():
|
||||||
linux_name = host.get_fact(LinuxName)
|
linux_name = host.get_fact(LinuxName)
|
||||||
version = host.data.postgresql_version
|
version = host.data.postgresql_version
|
||||||
|
|
Loading…
Reference in a new issue