Files
komodo/scripts/setup-periphery.py
Maxwell Becker db1cf786ac 1.17.0 (#248)
* resolver v3

add new ec2 instance types

clean up testing config

document the libraries a bit

clean up main

update sysinfo and otel

update client resolver 3.0

resolver v3 prog

clean up gitignore

implement periphery resolver v3

clean up

core read api v3

more prog

execute api

missing apis

compiling

1.16.13

work on more granular traits

prog on crud

* fmt

* format

* resource2 not really a benefit

* axum to 0.8

* bump aws deps

* just make it 1.17.0

* clean up cors

* the komodo env file should be highest priority over additional files

* add entities / message for test alerter

* test alert implementation

* rust 1.84.0

* axum update :param to {param} syntax

* fix last axum updates

* Add test alerter button

* higher quality / colored icons

* komodo-logo

* simplify network stats

* rename Test Alerter button

* escape incoming sync backslashes (BREAKING)

* clean up rust client websocket subscription

* finish oidc comment

* show update available stack table

* update available deployment table

* feature: use the repo path instead of name in GetLatestCommit (#282)

* Update repo path handling in commit fetching

- Changed `name` to `path` for repository identification.
- Updated cache update function to use the new path field.
- Improved error message for non-directory repo paths.

* feat: use optional name and path in GetLatestCommit

* review: don't use optional for name

* review: use helper

* review: remove redundant to_string()

* 1.17.0-dev

* feature: add post_deploy command (#288)

* feature: add post_deploy command

* review: do not run post_deploy if deploy failed

* feature: interpolate secrets in custom alerter (#289)

* feature: interpolate secrets in custom alerter

* fix rust warning

* review: sanitize errors

* review: sanitize error message

* Remove .git from remote_url (#299)

Remove .git from remote_url

Co-authored-by: Deon Marshall <dmarshall@ccp.com.au>

* mbecker20 -> moghtech

* remove example from cargo toml workspace

* dev-1

* fix login screen logo

* more legible favicon

* fix new compose images

* docs new organization

* typescript subscribe_to_update_websocket

* add donate button docsite

* add config save button in desktop sidebar navigator

* add save button to config bottom

* feature: allow docker image text to overflow in table (#301)

* feature: allow docker image text to overflow in table

* review: use break-words

* wip: revert line break in css file

* feature: update devcontainer node release

* improve First Login docs

* FIx PullStack re #302 and record docker compose config on stack deploy

* requery alerts more often

* improve update indicator style and also put on home screen

* Add all services stack log

* 1.17.0-dev-2

* fix api name chnage

* choose which stack services to include in logs

* feature: improve tables quick actions on mobile (#312)

* feature: improve tables quick actions on mobile

* review: fix gap4

* review: use flex-wrap

* improve pull to git init on existing folder without .git

* Fix unclear ComposePull log re #244

* use komodo_client.subscribe_to_update_websocket, and click indicator to reconnect

* dev-3

* ServerTemplate description

* improve WriteComposeContentsToHost instrument fields

* give server stat charts labels

* filters wrap

* show provider usernames from config file

* Stack: Fix git repo new compose file initialization

* init sync file new repo

* set branch on git init folder

* ResourceSync: pending view toggle between "Execute" vs "Commit" sync direction

* Improve resource sync Execute / Pending view selector

* standardize running commands with interpolation / output sanitizations

* fix all clippy lints

* fix rand

* lock certain users username / password, prevent demo creds from being changed.

* revert to login screen whenever the call to check login fails

* ResourceSync state resolution refinement

* make sure parent directories exist whenever writing files

* don't prune images if server not enabled

* update most deps

* update openidconnect dependency, and use reqwest rustls-tls-native-roots

* dev-4

* resource sync only add escaping on toml between the """

* Stacks executions take list of services -- Auto update only redeploys services with update

* auto update all service deploy option

* dev-5 fix the stack service executions

* clean up service_args

* rust 1.85

* store sync edits on localstorage

* stack edits on localstorage and show last deployed config

* add yarn install to runfile

* Fix actions when core on https

* add update_available query parameter to filter for only stacks /deployments with available update

* rust 2024 and fmt

* rename test.compose.yaml to dev.compose.yaml, and update runfile

* update .devcontainer / dev docs for updated runfile

* use png in topbar logo, svg quality sometimes bad

* OIDC: Support PKCE auth (secret optional)

* update docs on OIDC and client secret

* cycle the oidc client on interval to ensure up to date JWKs

* add KOMODO_LOCK_LOGIN_CREDENTIALS_FOR in config doc

* update deps

* resource sync toggle resource / variable / user group inclusion independantly

* use jsonwebtoken

* improve variable value table overflow

* colored tags

* fix sync summary count ok

* default new tag colors to grey

* soften tag opacity a bit

* Update config.tsx (#358)

* isolate stacks / deployments with pending updates

* update some deps

* use Tooltip component instead of HoverCard for mobile compatibility

* batch Build builds

* link to typescript client in the intro

* add link to main docs from client docs

* doc tweaks

* use moghtech/komodo-core and moghtech/komodo-periphery as images

* remove unnecessary explicit network

* periphery.compose.yaml

* clean up periphery compose

* add link to config

* update periphery container compose config

* rust 1.85.1

* update sync docs

* 1.17.0

---------

Co-authored-by: unsync <1211591+unsync@users.noreply.github.com>
Co-authored-by: Deon Marshall <dmarshall@ccp.com.au>
Co-authored-by: komodo <komodo@komo.do>
Co-authored-by: wlatic <jamesoh@gmail.com>
2025-03-23 16:47:06 -07:00

181 lines
4.8 KiB
Python

import sys
import os
import shutil
import platform
import json
import urllib.request
def load_version():
version = ""
for arg in sys.argv:
if arg.count("--version") > 0:
version = arg.split("=")[1]
if len(version) == 0:
version = load_latest_version()
return version
def load_latest_version():
return json.load(urllib.request.urlopen("https://api.github.com/repos/moghtech/komodo/releases/latest"))["tag_name"]
def uses_systemd():
# First check if systemctl is an available command, then check if systemd is the init system
return shutil.which("systemctl") is not None and os.path.exists("/run/systemd/system/")
def load_paths():
home_dir = os.environ['HOME']
# Checks if setup.py is passed --user arg
user_install = sys.argv.count("--user") > 0
if user_install:
return [
True,
# home_dir
home_dir,
# binary location
f'{home_dir}/.local/bin',
# config location
f'{home_dir}/.config/komodo',
# service file location
f'{home_dir}/.config/systemd/user',
]
else:
return [
False,
# home_dir
home_dir,
# binary location
"/usr/local/bin",
# config location
"/etc/komodo",
# service file location
"/etc/systemd/system",
]
def copy_binary(user_install, bin_dir, version):
# stop periphery in case its currently in use
user = ""
if user_install:
user = " --user"
os.popen(f'systemctl{user} stop periphery')
# ensure bin_dir exists
if not os.path.isdir(bin_dir):
os.makedirs(bin_dir)
# delete binary if it already exists
bin_path = f'{bin_dir}/periphery'
if os.path.isfile(bin_path):
os.remove(bin_path)
periphery_bin = "periphery-x86_64"
arch = platform.machine().lower()
if arch == "aarch64" or arch == "arm64":
print("aarch64 detected")
periphery_bin = "periphery-aarch64"
else:
print("using x86_64 binary")
# download the binary to bin path
print(os.popen(f'curl -sSL https://github.com/moghtech/komodo/releases/download/{version}/{periphery_bin} > {bin_path}').read())
# add executable permissions
os.popen(f'chmod +x {bin_path}')
def copy_config(config_dir):
config_file = f'{config_dir}/periphery.config.toml'
# early return if config file already exists
if os.path.isfile(config_file):
print("config already exists, skipping...")
return
print(f'creating config at {config_file}')
# ensure config dir exists
if not os.path.isdir(config_dir):
os.makedirs(config_dir)
print(os.popen(f'curl -sSL https://raw.githubusercontent.com/moghtech/komodo/main/config/periphery.config.toml > {config_dir}/periphery.config.toml').read())
def copy_service_file(home_dir, bin_dir, config_dir, service_dir, user_install):
service_file = f'{service_dir}/periphery.service'
force_service_recopy = sys.argv.count("--force-service-file") > 0
if force_service_recopy:
print("forcing service file recreation")
# early return is service file already exists
if os.path.isfile(service_file):
if force_service_recopy:
print("deleting existing service file")
os.remove(service_file)
else:
print("service file already exists, skipping...")
return
print(f'creating service file at {service_file}')
# ensure service_dir exists
if not os.path.isdir(service_dir):
os.makedirs(service_dir)
f = open(service_file, "x")
f.write((
"[Unit]\n"
"Description=Agent to connect with Komodo Core\n"
"\n"
"[Service]\n"
f'Environment="HOME={home_dir}"\n'
f'ExecStart=/bin/sh -lc "{bin_dir}/periphery --config-path {config_dir}/periphery.config.toml"\n'
"Restart=on-failure\n"
"TimeoutStartSec=0\n"
"\n"
"[Install]\n"
"WantedBy=default.target"
))
user = ""
if user_install:
user = " --user"
os.popen(f'systemctl{user} daemon-reload')
def main():
print("=====================")
print(" PERIPHERY INSTALLER ")
print("=====================")
if not uses_systemd():
print("This installer requires systemd and systemd wasn't found. Exiting")
sys.exit(1)
version = load_version()
[user_install, home_dir, bin_dir, config_dir, service_dir] = load_paths()
print(f'version: {version}')
print(f'user install: {user_install}')
print(f'home dir: {home_dir}')
print(f'bin dir: {bin_dir}')
print(f'config dir: {config_dir}')
print(f'service file dir: {service_dir}')
force_service_recopy = sys.argv.count("--force-service-file") > 0
if force_service_recopy:
print('forcing service file rewrite')
copy_binary(user_install, bin_dir, version)
copy_config(config_dir)
copy_service_file(home_dir, bin_dir, config_dir, service_dir, user_install)
user = ""
if user_install:
user = " --user"
print("starting periphery...")
print(os.popen(f'systemctl{user} start periphery').read())
print("Finished periphery setup.\n")
print(f'Note. Use "systemctl{user} status periphery" to make sure periphery is running')
print(f'Note. Use "systemctl{user} enable periphery" to have periphery start on system boot')
main()