From da5a86620e18b0a274dcb6b85af8b982c2f1b69a Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 20 Aug 2023 16:53:16 -0300 Subject: [PATCH] update --- tasks/croc.py | 24 +++++++++++++++++------- tasks/operations/git.py | 3 ++- tasks/postgresql.py | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/tasks/croc.py b/tasks/croc.py index 8b02c15..14a92a2 100644 --- a/tasks/croc.py +++ b/tasks/croc.py @@ -1,3 +1,4 @@ +from pathlib import Path from packaging import version from pyinfra.operations import apk, server, files from pyinfra.facts.server import LinuxName @@ -7,9 +8,14 @@ from pyinfra import host CROC_ALPINE_VERSION = version.parse("3.14") -@deploy("install croc") +@deploy( + "install croc", + data_defaults={ + "croc_install_directory": "/opt/croc", + "croc_bin_directory": "/usr/bin", + }, +) def install_croc(): - # alpine provides croc in-repo as of 3.14 if host.get_fact(LinuxName) == "Alpine": host_alpine_version = version.parse(host.data.alpine_version) @@ -18,11 +24,15 @@ def install_croc(): return # for everyone else, install manually - files.directory("/opt/croc") - files.download( + croc_dir = Path(host.data.croc_install_directory) + target_dir = host.data.croc_bin_directory + 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", - "/opt/croc/croc.tar.gz", + str(croc_dir / "croc.tar.gz"), md5sum="5550b0bfb50d0541cba790562c180bd7", ) - server.shell("tar xvf /opt/croc/croc.tar.gz", _chdir="/opt/croc") - server.shell("mv /opt/croc/croc /usr/bin/croc", _chdir="/opt/croc") + if result.changed: + server.shell(f"tar xvf {croc_dir}/croc.tar.gz", _chdir=str(croc_dir)) + server.shell(f"mv {croc_dir}/croc {target_dir}/croc", _chdir=str(croc_dir)) diff --git a/tasks/operations/git.py b/tasks/operations/git.py index ab452bd..c90e835 100644 --- a/tasks/operations/git.py +++ b/tasks/operations/git.py @@ -29,6 +29,7 @@ class GitFetch(FactBase): class GitRevListComparison(FactBase): def command(self, repo: str, branch: str): + assert branch return f"git -C {repo} rev-list HEAD..origin/{branch} | wc -l" def process(self, output): @@ -122,7 +123,7 @@ def repo( # always fetch upstream branches (that way we can compare if the latest # commit has changed, and then we don't need to execute anything!) host.get_fact(GitFetch, repo=dest) - stdout = host.get_fact(GitRevListComparison, repo=dest, branch=branch) + stdout = host.get_fact(GitRevListComparison, repo=dest, branch=current_branch) repository_has_updates = stdout[0] != "0" # since we immediately always fetch, we will always be modifying the diff --git a/tasks/postgresql.py b/tasks/postgresql.py index 841e132..45b053c 100644 --- a/tasks/postgresql.py +++ b/tasks/postgresql.py @@ -5,7 +5,7 @@ from pyinfra.operations import dnf, systemd, server from pyinfra.facts.server import LinuxName, LinuxDistribution -@deploy("Install PostgreSQL") +@deploy("Install PostgreSQL", data_defaults={"postgresql_version": 15}) def install(): linux_name = host.get_fact(LinuxName) version = host.data.postgresql_version