diff --git a/README.md b/README.md index e4e1474..b265253 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# peach-vps +# peach-package-builder -![Generic badge](https://img.shields.io/badge/version-0.3.1-.svg) +![Generic badge](https://img.shields.io/badge/version-0.3.2-.svg) -Scripts for configuring the PeachCloud VPS for various hosting and automation functions. +Scripts for building debian packages for PeachCloud microservices. ## Setup Build Environment -`scripts/setup_build_env.py` +`python3 peach_package_builder/setup_build_env.py` An idempotent script for initializing a build and deployment environment for PeachCloud packages. @@ -35,7 +35,7 @@ cd peach-vps pip3 install -r requirements.txt ``` -Open `scripts/setup_build_env.py` and set the following constants: +Open `peach_package_builder/setup_build_env.py` and set the following constants: - USER_PATH - GPG_KEY_EMAIL @@ -44,30 +44,40 @@ Open `scripts/setup_build_env.py` and set the following constants: Then execute the script to run the full system initialization process (_note: several commands executed by the script require `sudo` permissions. You will be prompted for the user password during the execution of the scipt._): ``` -python3 -u scripts/setup_build_env.py +python3 -u peach_package_builder/setup_build_env.py ``` -## Build and Serve Debian Packages +## Build Packages -`scripts/build_packages.py` +`peach_package_builder/build_packages.py` An idempotent script for building the latest versions of all PeachCloud packages and adding them to the Debian package archive. The script currently performs the following actions: - - Builds and updates microservice packages + - Builds and updates Rust microservice packages + - Builds and updates peach-config python package - Adds packages to Freight library - Adds packages to Freight cache ``` -python3 -u scripts/build_packages.py +python3 -d peach_package_builder/build_packages.py ``` +The -d flag ensures that all packages are built from the latest version of the default branch currently on GitHub. +Without the -d flag, whatever version of the code is locally stored will be used (which can be useful for testing). + Freight supports the ability to have multiple versions of a package in a single Debian package archive. If a particular version of a package already exists in the Freight library, it will not be readded or overwritten. + ## Build peach-go-sbot Debian package -`sudo python3 scripts/build_peach_go_sbot.py -v ` +First, open peach_package_builder/build_peach_go_sbot.py and manually edit PEACH_GO_SBOT_VERSION. + +We manually increment the version number when we want to build a new version of peach-go-sbot. + +Then run, +`python3 peach_package_builder/build_peach_go_sbot.py` This builds the peach-go-sbot package using the latest code from go-ssb, along with a systemd unit file, and adds the Debian package to the Freight library. diff --git a/peach_package_builder/build_packages.py b/peach_package_builder/build_packages.py index 4de9723..108f1c1 100644 --- a/peach_package_builder/build_packages.py +++ b/peach_package_builder/build_packages.py @@ -4,12 +4,12 @@ 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=False): +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) - build_peach_config(default_branch=default) + build_rust_packages(default_branch=default_branch) + build_peach_config(default_branch=default_branch) print("[ MICROSERVICE PACKAGE ARCHIVE UPDATED ]") @@ -22,4 +22,4 @@ if __name__ == '__main__': action="store_true" ) args = parser.parse_args() - build_packages(default=args.default) \ No newline at end of file + build_packages(default_branch=args.default) \ No newline at end of file diff --git a/peach_package_builder/build_peach_config.py b/peach_package_builder/build_peach_config.py index 7a3c18b..9afb0f9 100644 --- a/peach_package_builder/build_peach_config.py +++ b/peach_package_builder/build_peach_config.py @@ -1,8 +1,6 @@ -#!/usr/bin/env python3 """ script to build the peach-config debian module and add it to the freight repository """ - import argparse import subprocess import sys @@ -22,6 +20,12 @@ def build_peach_config(default_branch=True): subprocess.check_call(["git", "checkout", branch], cwd=service_path) subprocess.check_call(["git", "reset", "HEAD", "--hard"], cwd=service_path) subprocess.check_call(["git", "pull"], 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", diff --git a/peach_package_builder/build_peach_go_sbot.py b/peach_package_builder/build_peach_go_sbot.py index cf8350c..3cb3fed 100644 --- a/peach_package_builder/build_peach_go_sbot.py +++ b/peach_package_builder/build_peach_go_sbot.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """ script to create debian packages for cross-compiled go binaries for go-sbot based off of this post @@ -6,14 +5,18 @@ https://unix.stackexchange.com/questions/627689/how-to-create-a-debian-package-f """ import subprocess import argparse -import sys -import os +import re import shutil +import sys +from packaging import version as pversion from peach_package_builder.constants import * from peach_package_builder.utils import render_template, add_deb_to_freight, update_freight_cache +# manually update this version when we want to build a new peach-go-sbot package +PEACH_GO_SBOT_VERSION = '0.1.4' +# constants DEB_CONF_DIR = os.path.join(PROJECT_PATH, 'conf/templates/peach_go_sbot') DEB_BUILD_DIR = "/tmp/peach_go_sbot" GO_SSB_DIR = "/srv/peachcloud/automation/go-ssb" @@ -21,7 +24,6 @@ GO_SSB_DIR = "/srv/peachcloud/automation/go-ssb" def crosscompile_peach_go_sbot(): subprocess.check_call(["git", "pull"], cwd=GO_SSB_DIR) - # TODO: confirm that version number in the repo matches the version number we set for the package we are building print("[CROSS-COMPILING sbotcli]") subprocess.check_call(["env", "GOOS=linux", "GOARCH=arm64", "go", "build", "./cmd/sbotcli"], cwd=GO_SSB_DIR) print("[CROSS-COMPILING go-sbot]") @@ -29,7 +31,6 @@ def crosscompile_peach_go_sbot(): def package_peach_go_sbot(version): - print("[ PACKAGING peach-go-sbot ]") # copy debian conf files into correct locations in package build directory DEBIAN_SRC_DIR = os.path.join(DEB_CONF_DIR, 'DEBIAN') @@ -84,24 +85,18 @@ def package_peach_go_sbot(version): def build_peach_go_sbot(): - parser = argparse.ArgumentParser() - parser.add_argument( - "-v", - "--version", - help="Set version number for go-sbot", - ) - args = parser.parse_args() - - print("[ BUILDING PEACH-GO-SBOT VERSION {}]".format(args.version)) + # gets the most recently built peach_go_sbot version, and increments the micro-number by 1 + version = PEACH_GO_SBOT_VERSION + print("[ BUILDING PEACH-GO-SBOT VERSION {}]".format(version)) # delete build directory if it already exists or create it subprocess.check_call(["rm", "-rf", DEB_BUILD_DIR]) if not os.path.exists(DEB_BUILD_DIR): os.makedirs(DEB_BUILD_DIR) + # cross-compile and package peach-go-sbot with new version number crosscompile_peach_go_sbot() - package_peach_go_sbot(version=args.version) - + package_peach_go_sbot(version=version) if __name__ == '__main__': diff --git a/peach_package_builder/build_rust_packages.py b/peach_package_builder/build_rust_packages.py index 1a8d1e1..68a821c 100644 --- a/peach_package_builder/build_rust_packages.py +++ b/peach_package_builder/build_rust_packages.py @@ -35,29 +35,28 @@ def build_rust_packages(default_branch=False): default_branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'origin/HEAD'], cwd=service_path).decode(sys.stdout.encoding) branch = default_branch.replace('origin/', '').strip() - subprocess.run(["git", "checkout", branch], cwd=service_path) - subprocess.run(["git", "reset", "HEAD", "--hard"], cwd=service_path) - subprocess.run(["git", "pull"], cwd=service_path) - debian_package_path = subprocess.run( + subprocess.check_call(["git", "checkout", branch], cwd=service_path) + subprocess.check_call(["git", "reset", "HEAD", "--hard"], cwd=service_path) + subprocess.check_call(["git", "pull"], cwd=service_path) + debian_package_path = subprocess.check_output( [ CARGO_PATH, "deb", "--target", "aarch64-unknown-linux-gnu"], - cwd=service_path, - stdout=subprocess.PIPE).stdout.decode("utf-8").strip() + cwd=service_path).decode("utf-8").strip() subprocess.call(["cp", debian_package_path, MICROSERVICES_DEB_DIR]) - # this function adds all .deb files in MICROSERVICES_DEB_DIR to freight - add_debs_dir_to_freight() + # this function adds all .deb files in MICROSERVICES_DEB_DIR to freight + add_debs_dir_to_freight() -def build_packages(default=False): +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) - build_peach_config(default_branch=default) + build_rust_packages(default_branch=default_branch) + build_peach_config(default_branch=default_branch) print("[ MICROSERVICE PACKAGE ARCHIVE UPDATED ]") @@ -70,4 +69,4 @@ if __name__ == '__main__': action="store_true" ) args = parser.parse_args() - build_packages(default=args.default) \ No newline at end of file + build_packages(default_branch=args.default) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 758129b..a4e73ce 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ Jinja2==2.11.2 +packaging==20.9 \ No newline at end of file