Skip to content

Commit

Permalink
Merge pull request #640 from Epic-Breakfast-Productions/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
GregJohnStewart authored Jul 12, 2024
2 parents 2c398d0 + d38b617 commit d140aef
Show file tree
Hide file tree
Showing 37 changed files with 891 additions and 242 deletions.
13 changes: 13 additions & 0 deletions deployment/Kubernetes/argocd/docs/devSetup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Developer Setup

## Argo Setup

1. Have minikube running
2. `kubectl create ns argocd`
3. `kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/v2.5.8/manifests/install.yaml`
- Get latest yaml from: https://github.com/argoproj/argo-cd/releases
4. Verify: `kubectl get all -n argocd`
5. Access by: `kubectl port-forward svc/argocd-server -n argocd 8080:443`
- username: `admin`
- pass via: `kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo`
6.
5 changes: 5 additions & 0 deletions deployment/Kubernetes/docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ Prerequisites:
- Working Kubernetes cluster
- Minikube is a good option for local dev

## MiniKube Setup

1. Download minikube from latest docs, install
2. Start cluster with "minikube start"

You now have an operational kube cluster.


## Resources
Expand Down
3 changes: 2 additions & 1 deletion deployment/Single Host/Station-Captain/docs/Features.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ These installers can be used to install the `oqm-captain` management script.

==== First time run

If the Open Quarter Base station package is not installed, the script will prompt the user if they want it installed.
If the Open Quarter Base station package is not installed, the script will prompt the user with a setup wizard. The user
can choose to use this wizard to help them get started.

If no, continue to the menu.

Expand Down
5 changes: 5 additions & 0 deletions deployment/Single Host/Station-Captain/docs/User Guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ TODO- document better
.. *Plugins* TODO
.. *Uninstall All* TODO

. *Plugins*
.. *Review Available Plugins* +
Select from a list of plugins to install
.. *Select Plugins* +
Select from a list of plugins to uninstall
. *Snapshots* +
Snapshots allow you to take a current state of you system, and save it or back it up for later.

Expand Down
2 changes: 1 addition & 1 deletion deployment/Single Host/Station-Captain/properties.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"packageName":"oqm-manager-station+captain",
"version":"2.2.2",
"version":"2.3.0",
"description":"Utility for setting up and maintaining an instance of Open QuarterMaster.",
"maintainer": {
"name":"EBP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def packageLogs() -> (bool, str):
sysInfoFile.write(LogManagement.getSystemInfo())

with open(compilingDir + "/01-installed.txt", "w") as sysInfoFile:
sysInfoFile.write(PackageManagement.getInstalledPackages())
sysInfoFile.write(PackageManagement.getOqmPackagesStr(installed=True, notInstalled=False))

logging.info("Writing log messages.")
result, services = ServiceUtils.getServiceNames()
Expand Down
126 changes: 118 additions & 8 deletions deployment/Single Host/Station-Captain/src/lib/PackageManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import platform

from ServiceUtils import *

class PackageManagement:
"""
Expand All @@ -16,6 +17,7 @@ class PackageManagement:
"""
BASE_STATION_PACKAGE = "oqm-core-base+station"
ALL_OQM = "oqm-*"
OQM_PLUGINS = "oqm-plugin-*"
SYSTEM_PACKAGE_MANAGER = None

@staticmethod
Expand All @@ -25,7 +27,8 @@ def getSystemPackageManager() -> str:
logging.debug("Determining the system's package manager.")

systemReleaseInfo = platform.freedesktop_os_release()
if ("ID_LIKE" in systemReleaseInfo and systemReleaseInfo['ID_LIKE'].casefold() == "debian".casefold()) or systemReleaseInfo['ID'].casefold() == "Debian".casefold():
if ("ID_LIKE" in systemReleaseInfo and systemReleaseInfo['ID_LIKE'].casefold() == "debian".casefold()) or \
systemReleaseInfo['ID'].casefold() == "Debian".casefold():
PackageManagement.SYSTEM_PACKAGE_MANAGER = "apt"

logging.info("Determined system using %s", PackageManagement.SYSTEM_PACKAGE_MANAGER)
Expand All @@ -51,8 +54,37 @@ def coreInstalled() -> bool:
logging.debug("Error Output of listing core components: " + result.stderr)
return "installed" in result.stdout

@staticmethod
def installPackages(packages:list) -> (bool, str):
logging.info("Installing packages: %s", packages)
command:list = ["apt-get", "install", "-y"]
command.extend(packages)
result = subprocess.run(
command,
shell=False, capture_output=True, text=True, check=False
)
if result.returncode != 0:
logging.error("Failed to run install packages command: %s", result.stderr)
return False, result.stderr
return True

@staticmethod
def removePackages(packages:list) -> (bool, str):
logging.info("Removing packages: %s", packages)
command:list = ["apt-get", "remove", "-y", "--purge"]
command.extend(packages)
result = subprocess.run(
command,
shell=False, capture_output=True, text=True, check=False
)
if result.returncode != 0:
logging.error("Failed to run remove packages command: %s", result.stderr)
return False, result.stderr
return True

@staticmethod
def installCore():
# TODO:: update to use new install, package get features
# TODO:: update with error handling, return
logging.info("Installing core components.")
# TODO:: will likely need updated for yum
Expand All @@ -72,7 +104,8 @@ def updateSystem() -> (bool, str):
return False, result.stderr
logging.debug("Upgrading apt packages.")
subprocess.run(["clear"], shell=False, capture_output=False, text=True, check=False)
result = subprocess.run(["apt-get", "dist-upgrade"], shell=False, capture_output=False, text=True, check=False)
result = subprocess.run(["apt-get", "dist-upgrade"], shell=False, capture_output=False, text=True,
check=False)
if result.returncode != 0:
logging.error("Failed to run upgrade command: %s", result.stderr)
return False, result.stderr
Expand All @@ -90,21 +123,98 @@ def updateSystem() -> (bool, str):
def promptForAutoUpdates() -> (bool, str):
if "Ubuntu" in platform.version():
logging.debug("Prompting user through unattended-upgrades.")
subprocess.run(["dpkg-reconfigure", "-plow", "unattended-upgrades"], shell=False, capture_output=False, text=True, check=True)
subprocess.run(["dpkg-reconfigure", "-plow", "unattended-upgrades"], shell=False, capture_output=False,
text=True, check=True)
logging.info("Done.")
# TODO:: doublecheck automatic restart, setting alert email
else:
return False, "Unsupported OS to setup auto updates on."
return True, None

@staticmethod
def getInstalledPackages() -> (bool, str):
logging.debug("Ensuring core components are installed.")
# TODO:: will likely need updated for yum
result = PackageManagement.runPackageCommand("list", PackageManagement.ALL_OQM, "-qq")
def getOqmPackagesStr(filter: str = ALL_OQM, installed: bool = True, notInstalled: bool = True):
logging.debug("Getting OQM packages.")
result = PackageManagement.runPackageCommand("list", filter, "-qq")
logging.debug("Output of listing core components: " + result.stdout)
logging.debug("Error Output of listing core components: " + result.stderr)

result = os.linesep.join([s for s in result.stdout.splitlines() if "installed" in s])
result = result.stdout
output = []
for curLine in result.splitlines():
if installed and notInstalled:
output.append(curLine)
continue
if installed:
if "installed" in curLine:
output.append(curLine)
continue
if notInstalled:
if not "installed" in curLine:
output.append(curLine)
return os.linesep.join(output)

@staticmethod
def getPluginDisplayName(package:str):
# print("Package: " + package)
return package.split("-")[2].replace("+", " ")

@staticmethod
def getPackageInfo(package:str) -> (bool, str):
output = {}
packageShow = subprocess.run(['apt-cache', 'show', package], shell=False, capture_output=True, text=True, check=False).stdout
packageShow = packageShow.splitlines()

for curLine in packageShow:
if not curLine.strip():
continue
split = curLine.split(": ", 1)
name = split[0]
value = split[1]
output[name] = value
return output

@staticmethod
def packageLineToArray(curLine:str) -> (dict):
output = {}
# print("cur line: ", curLine)
output['package'] = curLine.split("/")[0]
output['displayName'] = PackageManagement.getPluginDisplayName(output['package'])
lineParts = curLine.split(" ")
# print("lineParts: ", lineParts)
output['version'] = lineParts[1]
output['installed'] = "installed" in curLine

packageInfo = PackageManagement.getPackageInfo(output['package'])
# print(packageInfo)
output['description'] = packageInfo['Description']
output['fullInfo'] = packageInfo

return output

@staticmethod
def getOqmPackagesList(filter: str = ALL_OQM, installed: bool = True, notInstalled: bool = True):
logging.debug("Getting OQM packages.")
result = PackageManagement.getOqmPackagesStr(filter, installed, notInstalled)
# print("Package list str: " + result)
result = result.splitlines()
result = map(PackageManagement.packageLineToArray,result)
# TODO:: debug
# print("Package list: ", list(result))
return result

@staticmethod
def ensureOnlyPluginsInstalled(pluginList:list) -> (bool, str):
logging.debug("Ensuring only plugins in list installed.")

allInstalledPlugins = map(
lambda i: i['package'],
PackageManagement.getOqmPackagesList(PackageManagement.OQM_PLUGINS, installed=True)
)
pluginsToRemove = [i for i in allInstalledPlugins if i not in pluginList]

# TODO Try to figure out how to remove unwanted plugins while not bouncing dependency plugins
# TODO:: error check
PackageManagement.removePackages(pluginsToRemove)
PackageManagement.installPackages(pluginList)

ServiceUtils.doServiceCommand(ServiceStateCommand.restart, ServiceUtils.SERVICE_ALL)
Loading

0 comments on commit d140aef

Please sign in to comment.