Merge pull request 'Update peach_package_builder to use peach-workspace and rust version of peach-config' (#24) from peach-workspace into main

Reviewed-on: #24
This commit is contained in:
notplants 2022-01-13 15:08:25 +00:00
commit 7efce72f6e
4 changed files with 53 additions and 113 deletions

View File

@ -1,7 +1,6 @@
import argparse import argparse
from peach_package_builder.build_rust_packages import build_rust_packages 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): 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 :param package: if provided, only builds this package
""" """
build_rust_packages(default_branch=default_branch, package=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 ]") 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 sys
import os import os
from peach_package_builder.build_peach_config import build_peach_config
from peach_package_builder.constants import * from peach_package_builder.constants import *
from peach_package_builder.utils import add_deb_to_freight, update_freight_cache 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 :param package: if provided, only builds this package
""" """
print("[ BUILDING AND UPDATING RUST MICROSERVICE PACKAGES ]") 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 argument was provided, then only build that one package, otherwise build all packages
if package: if package:
services = filter(lambda s: s["name"] == package, SERVICES) services = filter(lambda s: s["name"] == package, SERVICES)
else: else:
services = SERVICES services = SERVICES
# iterate through crates and build
for service in services: for service in services:
service_name = service["name"] service_name = service["name"]
service_path = os.path.join(MICROSERVICES_SRC_DIR, service_name) service_path = os.path.join(WORKSPACE_SRC_DIR, service_name)
print("[ BUILIDING SERVICE {} ]".format(service_name)) build_rust_package(service_path, 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])
# 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 def build_rust_package(service_path, service_name):
update_freight_cache() """
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): 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 builds all PeachCloud microservices as .deb files and adds them to the freight repo
""" """
build_rust_packages(default_branch=default_branch) build_rust_packages(default_branch=default_branch)
build_peach_config(default_branch=default_branch)
print("[ MICROSERVICE PACKAGE ARCHIVE UPDATED ]") print("[ MICROSERVICE PACKAGE ARCHIVE UPDATED ]")

View File

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