Skip to content

Commit

Permalink
Add support for ozy self-update (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
apmorton authored Nov 28, 2022
1 parent 905ad51 commit 26a78d9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions conf/sample-team-conf.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
name: Example Team Configuration
ozy_version: 0.0.6
ozy_download: https://github.com/aquanauts/ozy/releases/download/v{version}/ozy-{ozy_os}-{ozy_machine}
templates:
hashicorp:
type: single_binary_zip
Expand Down
18 changes: 17 additions & 1 deletion ozy/__main__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import logging
import os
from pathlib import Path
import shutil
import sys

from packaging import version

import click
import coloredlogs

from ozy import OzyError, __version__
from ozy.app import App, find_app
from ozy.config import load_ozy_user_conf, save_ozy_user_conf, parse_ozy_conf, load_config
from ozy.config import load_ozy_user_conf, save_ozy_user_conf, parse_ozy_conf, load_config, safe_expand
from ozy.files import ensure_ozy_dirs, get_ozy_bin_dir, softlink, get_ozy_dir
from ozy.utils import download_to, restore_overridden_env_vars

Expand Down Expand Up @@ -114,6 +117,19 @@ def update(dry_run, url):
new_conf_root = parse_ozy_conf(tmp_filename)
old_conf_root = parse_ozy_conf(ozy_conf_filename)

new_ozy_version: str = new_conf_root['ozy_version']
if version.parse(__version__) < version.parse(new_ozy_version):
_LOGGER.info('Ozy update to %s is mandated by your team config', new_ozy_version)
download_url = safe_expand(dict(version=new_ozy_version), new_conf_root['ozy_download'])
_LOGGER.info('Downloading from %s', download_url)
download_path = Path(get_ozy_dir()) / 'bin' / 'ozy.tmp'
download_path.unlink(missing_ok=True)
download_to(str(download_path), download_url)
download_path.chmod(0o755)
new_ozy_exe = str(download_path)
environment = restore_overridden_env_vars(os.environ)
os.execve(new_ozy_exe, [new_ozy_exe, 'update'], environment)

changed = False
for app, new_conf in new_conf_root['apps'].items():
old_conf = old_conf_root['apps'].get(app, None)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pytest_watch

click
coloredlogs
packaging
pyinstaller
pyyaml
requests
Expand Down

0 comments on commit 26a78d9

Please sign in to comment.