Update peach_package_builder to use peach-workspace and rust version of peach-config

This commit is contained in:
notplants 2021-12-16 12:41:22 -05:00
parent 75275bc5ca
commit 2fcc95d7f9
4 changed files with 53 additions and 113 deletions

View File

@ -1,7 +1,6 @@
import argparse
from peach_package_builder.build_rust_packages import build_rust_packages
from peach_package_builder.build_peach_config import build_peach_config
def build_packages(default_branch=False, package=None):
@ -11,9 +10,6 @@ def build_packages(default_branch=False, package=None):
:param package: if provided, only builds this package
"""
build_rust_packages(default_branch=default_branch, package=package)
# only build peach-config if no package argument was provided or if peach-config is what is being built
if not package or package == 'peach-config':
build_peach_config(default_branch=default_branch)
print("[ MICROSERVICE PACKAGE ARCHIVE UPDATED ]")

View File

@ -1,73 +0,0 @@
"""
script to build the peach-config debian module and add it to the freight repository
"""
import argparse
import subprocess
import sys
import re
import os
from peach_package_builder.constants import *
from peach_package_builder.utils import add_deb_to_freight, update_freight_cache
def get_version_from_setup_file(file_path):
with open(file_path, 'r') as f:
lines = f.read().splitlines()
for line in lines:
match = re.match('.*version = "(\S+)",', line)
if match:
version = match.group(1)
return version
# if a version wasn't found then raise an exception
raise Exception("version not found")
def build_peach_config(default_branch=True):
service_path = os.path.join(MICROSERVICES_SRC_DIR, "peach-config")
if default_branch:
# because some repo have main as default and some as master, we get the default
default_branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'origin/HEAD'],
cwd=service_path).decode(sys.stdout.encoding).strip()
branch = default_branch.replace('origin/', '')
subprocess.check_call(["git", "checkout", branch], cwd=service_path)
subprocess.check_call(["git", "fetch", "--all"], cwd=service_path)
subprocess.check_call(["git", "reset", "--hard", default_branch], cwd=service_path)
# remove old build dir
subprocess.check_call([
"rm",
"-rf",
os.path.join(service_path, 'deb_dist')
])
# build .deb
subprocess.check_call([
"python3",
"setup.py",
"--command-packages=stdeb.command",
"bdist_deb"
],
cwd=service_path)
# get version number of peach-config from setup.py file
setup_file = os.path.join(service_path, 'setup.py')
version = get_version_from_setup_file(setup_file)
# build the deb
deb_name = "python3-peach-config_{version}-1_all.deb".format(version=version)
debian_package_path = os.path.join(
service_path,
"deb_dist/{}".format(deb_name)
)
subprocess.check_call(["cp", debian_package_path, MICROSERVICES_DEB_DIR])
add_deb_to_freight(package_name=debian_package_path, package_path=debian_package_path)
update_freight_cache()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
"-d",
"--default",
help="Ensure default branch for all repos for build",
action="store_true"
)
args = parser.parse_args()
build_peach_config(default_branch=args.default)

View File

@ -4,7 +4,6 @@ import argparse
import sys
import os
from peach_package_builder.build_peach_config import build_peach_config
from peach_package_builder.constants import *
from peach_package_builder.utils import add_deb_to_freight, update_freight_cache
@ -27,38 +26,57 @@ def build_rust_packages(default_branch=False, package=None):
:param package: if provided, only builds this package
"""
print("[ BUILDING AND UPDATING RUST MICROSERVICE PACKAGES ]")
build_peach_workspace_rust_packages(default_branch=default_branch, package=package)
# update freight cache
update_freight_cache()
def build_peach_workspace_rust_packages(default_branch=False, package=None):
print("[ BUILDING AND UPDATING PEACH WORKSPACE RUST PACKAGES ]")
# this arg ensures we build the default branch, otherwise we build what ever is found locally
if default_branch:
remote_branch = 'origin/main'
branch = 'main'
subprocess.check_call(["git", "reset", "HEAD", "--hard"])
subprocess.check_call(["git", "checkout", branch], cwd=WORKSPACE_SRC_DIR)
subprocess.check_call(["git", "fetch", "--all"], cwd=WORKSPACE_SRC_DIR)
subprocess.check_call(["git", "reset", "--hard", remote_branch], cwd=WORKSPACE_SRC_DIR)
# if package argument was provided, then only build that one package, otherwise build all packages
if package:
services = filter(lambda s: s["name"] == package, SERVICES)
else:
services = SERVICES
# iterate through crates and build
for service in services:
service_name = service["name"]
service_path = os.path.join(MICROSERVICES_SRC_DIR, service_name)
print("[ BUILIDING SERVICE {} ]".format(service_name))
# this arg ensures we build the default branch, otherwise we build what ever is found locally
if default_branch:
remote_branch = 'origin/main'
branch = 'main'
subprocess.check_call(["git", "reset", "HEAD", "--hard"])
subprocess.check_call(["git", "checkout", branch], cwd=service_path)
subprocess.check_call(["git", "fetch", "--all"], cwd=service_path)
subprocess.check_call(["git", "reset", "--hard", remote_branch], cwd=service_path)
debian_package_path = subprocess.check_output(
[
CARGO_PATH,
"deb",
"--target",
"aarch64-unknown-linux-gnu"],
cwd=service_path).decode("utf-8").strip()
subprocess.call(["cp", debian_package_path, MICROSERVICES_DEB_DIR])
service_path = os.path.join(WORKSPACE_SRC_DIR, service_name)
build_rust_package(service_path, service_name)
# add deb to freight
package_name = os.path.basename(debian_package_path)
add_deb_to_freight(package_name=package_name, package_path=debian_package_path)
# update freight cache
update_freight_cache()
def build_rust_package(service_path, service_name):
"""
this function builds a specific service and adds the deb to the deb dir
:param service_path: string path to where the package src code is
:param service_name: string name of the service
:return:
"""
print("[ BUILIDING SERVICE {} ]".format(service_name))
debian_package_path = subprocess.check_output(
[
CARGO_PATH,
"deb",
"--target",
"aarch64-unknown-linux-gnu"],
cwd=service_path).decode("utf-8").strip()
subprocess.call(["cp", debian_package_path, MICROSERVICES_DEB_DIR])
# add deb to freight
package_name = os.path.basename(debian_package_path)
add_deb_to_freight(package_name=package_name, package_path=debian_package_path)
def build_packages(default_branch=False):
@ -66,7 +84,6 @@ def build_packages(default_branch=False):
builds all PeachCloud microservices as .deb files and adds them to the freight repo
"""
build_rust_packages(default_branch=default_branch)
build_peach_config(default_branch=default_branch)
print("[ MICROSERVICE PACKAGE ARCHIVE UPDATED ]")

View File

@ -13,23 +13,23 @@ AUTOMATION_DIR = "/srv/peachcloud/automation"
FREIGHT_CONF = "/etc/freight.conf"
FREIGHT_LIB = "/var/lib/freight"
FREIGHT_CACHE = "/var/www/apt.peachcloud.org"
MICROSERVICES_SRC_DIR = "/srv/peachcloud/automation/microservices"
WORKSPACE_SRC_DIR = "/srv/peachcloud/automation/peach-workspace"
MICROSERVICES_DEB_DIR = "/srv/peachcloud/debs"
USER_PATH = "/home/rust"
CARGO_PATH = os.path.join(USER_PATH, ".cargo/bin/cargo")
SERVICES = [
{"name": "peach-buttons",
"repo_url": "https://github.com/peachcloud/peach-buttons.git"},
{"name": "peach-menu", "repo_url": "https://github.com/peachcloud/peach-menu.git"},
"repo_url": "https://git.coopcloud.tech/PeachCloud/peach-workspace.git"},
{"name": "peach-menu", "repo_url": "https://git.coopcloud.tech/PeachCloud/peach-workspace.git"},
{"name": "peach-monitor",
"repo_url": "https://github.com/peachcloud/peach-monitor.git"},
"repo_url": "https://git.coopcloud.tech/PeachCloud/peach-workspace.git"},
{"name": "peach-network",
"repo_url": "https://github.com/peachcloud/peach-network.git"},
{"name": "peach-oled", "repo_url": "https://github.com/peachcloud/peach-oled.git"},
{"name": "peach-stats", "repo_url": "https://github.com/peachcloud/peach-stats.git"},
{"name": "peach-probe", "repo_url": "https://github.com/peachcloud/peach-probe.git"},
{"name": "peach-dyndns-updater", "repo_url": "https://github.com/peachcloud/peach-dyndns-updater.git"},
{"name": "peach-web", "repo_url": "https://github.com/peachcloud/peach-web.git"},
{"name": "peach-tbot", "repo_url": "https://github.com/peachcloud/peach-tbot.git"},
"repo_url": "https://git.coopcloud.tech/PeachCloud/peach-workspace.git"},
{"name": "peach-oled", "repo_url": "https://git.coopcloud.tech/PeachCloud/peach-workspace.git"},
{"name": "peach-stats", "repo_url": "https://git.coopcloud.tech/PeachCloud/peach-workspace.git"},
# {"name": "peach-probe", "repo_url": "https://git.coopcloud.tech/PeachCloud/peach-workspace.git"},
{"name": "peach-dyndns-updater", "repo_url": "https://git.coopcloud.tech/PeachCloud/peach-workspace.git"},
{"name": "peach-web", "repo_url": "https://git.coopcloud.tech/PeachCloud/peach-workspace.git"},
# {"name": "peach-tbot", "repo_url": "https://git.coopcloud.tech/PeachCloud/peach-tbot.git"},
]