From a96ed753b21192bbaa0eb8611050baa2b55cdc40 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Fri, 12 Jun 2020 11:55:52 -0600 Subject: [PATCH] Improve deployment script --- scripts/{install.py => deploy-phase1.py} | 14 ++------------ scripts/deploy-phase2.py | 23 +++++++++++++++++++++++ scripts/install-scripts.bash | 2 +- 3 files changed, 26 insertions(+), 13 deletions(-) rename scripts/{install.py => deploy-phase1.py} (60%) create mode 100755 scripts/deploy-phase2.py diff --git a/scripts/install.py b/scripts/deploy-phase1.py similarity index 60% rename from scripts/install.py rename to scripts/deploy-phase1.py index 4c0ec75..832e2fa 100755 --- a/scripts/install.py +++ b/scripts/deploy-phase1.py @@ -10,7 +10,7 @@ import sys import tempfile import time -result = subprocess.run(["pgrep", "-x", "riju-install"], stdout=subprocess.PIPE) +result = subprocess.run(["pgrep", "-x", "riju-deploy"], stdout=subprocess.PIPE) assert result.returncode in {0, 1} for pid in result.stdout.decode().splitlines(): print(f"Found existing process {pid}, trying to kill ...", file=sys.stderr) @@ -38,14 +38,4 @@ with tempfile.TemporaryDirectory() as tmpdir: check=True, ) os.chdir("riju") - subprocess.run(["make", "image-prod"], check=True) - subprocess.run(["scripts/install-scripts.bash"], check=True) - subprocess.run(["docker", "system", "prune", "-f"], check=True) - existing_containers = subprocess.run( - ["docker", "ps", "-q"], check=True, stdout=subprocess.PIPE - ).output.splitlines() - if existing_containers: - subprocess.run(["docker", "kill", *existing_containers], check=True) - subprocess.run(["systemctl", "restart", "riju"], check=True) - -print("==> Successfully deployed Riju! <==", file=sys.stderr) + subprocess.run(["scripts/deploy-phase2.py"]) diff --git a/scripts/deploy-phase2.py b/scripts/deploy-phase2.py new file mode 100755 index 0000000..e161eff --- /dev/null +++ b/scripts/deploy-phase2.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +import argparse +import errno +import os +import re +import signal +import subprocess +import sys +import tempfile +import time + +subprocess.run(["make", "image-prod"], check=True) +subprocess.run(["docker", "system", "prune", "-f"], check=True) +existing_containers = subprocess.run( + ["docker", "ps", "-q"], check=True, stdout=subprocess.PIPE +).output.splitlines() +subprocess.run(["scripts/install-scripts.bash"], check=True) +if existing_containers: + subprocess.run(["docker", "kill", *existing_containers], check=True) +subprocess.run(["systemctl", "restart", "riju"], check=True) + +print("==> Successfully deployed Riju! <==", file=sys.stderr) diff --git a/scripts/install-scripts.bash b/scripts/install-scripts.bash index 4c3e6c9..c0e3154 100755 --- a/scripts/install-scripts.bash +++ b/scripts/install-scripts.bash @@ -6,6 +6,6 @@ set -o pipefail cp scripts/riju.service /etc/systemd/system/riju.service cp scripts/certbot-pre.bash /etc/letsencrypt/renewal-hooks/pre/riju cp scripts/certbot-post.bash /etc/letsencrypt/renewal-hooks/post/riju -cp scripts/install.py /usr/bin/riju-install +cp scripts/deploy-phase1.py /usr/bin/riju-deploy systemctl daemon-reload