Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Service plugins #369

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config.yaml.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,5 @@ security:
# - interval: 5
# script: tools/5_minute.py
# limit: ["01:00", "02:00"]

plugins:
49 changes: 49 additions & 0 deletions tools/setup_services.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,59 @@
import os
from collections import Counter
from os.path import join as pjoin
import subprocess

from baselayer.app.env import load_env
from baselayer.log import make_log

log = make_log("baselayer")

def download_plugin_services():
env, cfg = load_env()

services_path = cfg["services.paths"]

plugins = cfg.get("plugins", {})
plugin_services = []

log(f"Discovered {len(plugins)} plugins")

for plugin_name, plugin_info in plugins.items():
if "url" not in plugin_info:
log(f"Skipping plugin {plugin_name} because it has no URL")
continue

git_repo = plugin_info["url"].split(".git")[0].split("/")[-1]
plugin_path = pjoin(services_path[-1], git_repo)

if os.path.exists(plugin_path):
if os.path.exists(pjoin(plugin_path, ".git")):
log(f"Updating plugin {plugin_name}")
_, stderr = subprocess.Popen(
f"cd {plugin_path} && git pull",
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
).communicate()
if stderr and len(stderr) > 0:
log(f"Error updating plugin {plugin_name}: {stderr}")
continue
else:
log(f"Skipping plugin {plugin_name} because a microservice with the same name exists at {plugin_path}")
continue
else:
log(f"Cloning plugin {plugin_name}")
_, stderr = subprocess.Popen(
f"cd {services_path[-1]} && git clone {plugin_info['url']}",
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
).communicate()
if stderr and len(stderr) > 0:
log(f"Error cloning plugin {plugin_name}: {stderr}")
continue
plugin_services.append(plugin_name)
return plugin_services

def copy_supervisor_configs():
env, cfg = load_env()
Expand Down Expand Up @@ -56,4 +103,6 @@ def copy_supervisor_configs():


if __name__ == "__main__":
download_plugin_services()
print()
copy_supervisor_configs()
Loading