Compare commits

..

2 Commits

Author SHA1 Message Date
notplants
06f3bd5702 Build peach-go-ssb-room package 2021-06-23 16:52:04 -04:00
notplants
62d791f29a Cross compile go-ssb-room 2021-06-18 13:30:31 -04:00
18 changed files with 389 additions and 314 deletions

View File

@ -1,15 +0,0 @@
# For details about go-sbot configuration, please visit the repo: https://github.com/cryptoscope/ssb
repo = "/home/peach/.ssb-go"
debugdir = ""
shscap = "1KHLiKZvAvjbY1ziZEHMXawbCEIM6qwjCDm3VYRan/s="
hmac = ""
hops = 2
lis = "127.0.0.1:8008"
wslis = ":8987"
debuglis = "localhost:6078"
localadv = true
localdiscov = true
enable_ebt = true
promisc = true
nounixsock = false
repair = true

View File

@ -1,4 +1,4 @@
Package: go-sbot
Package: peach-go-sbot
Version: {{version}}
Architecture: all
Maintainer: Andrew Reid <gnomad@cryptolab.net>

View File

@ -2,30 +2,26 @@
set -e
# create user which go-sbot runs as
id -u peach &>/dev/null || adduser --quiet peach
adduser --quiet --system peach-go-sbot
# set permissions
chown peach /usr/bin/go-sbot
chown peach /usr/bin/sbotcli
# create and set permissions for /home/peach/.ssb-go
mkdir -p /home/peach/.ssb-go
chown -R peach:peach /home/peach/.ssb-go
chown peach-go-sbot /usr/bin/go-sbot
chown peach-go-sbot /usr/bin/sbotcli
# Automatically added by cargo-deb
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask go-sbot.service >/dev/null || true
deb-systemd-helper unmask peach-go-sbot.service >/dev/null || true
# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled go-sbot.service; then
if deb-systemd-helper --quiet was-enabled peach-go-sbot.service; then
# Enables the unit on first installation, creates new
# symlinks on upgrades if the unit file has changed.
deb-systemd-helper enable go-sbot.service >/dev/null || true
deb-systemd-helper enable peach-go-sbot.service >/dev/null || true
else
# Update the statefile to add new symlinks (if any), which need to be
# cleaned up on purge. Also remove old symlinks.
deb-systemd-helper update-state go-sbot.service >/dev/null || true
deb-systemd-helper update-state peach-go-sbot.service >/dev/null || true
fi
fi
# End automatically added section
@ -38,7 +34,7 @@ if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-decon
else
_dh_action=start
fi
deb-systemd-invoke $_dh_action go-sbot.service >/dev/null || true
deb-systemd-invoke $_dh_action peach-go-sbot.service >/dev/null || true
fi
fi
# End automatically added section

View File

@ -8,14 +8,14 @@ fi
# Automatically added by cargo-deb
if [ "$1" = "remove" ]; then
if [ -x "/usr/bin/deb-systemd-helper" ]; then
deb-systemd-helper mask go-sbot.service >/dev/null || true
deb-systemd-helper mask peach-go-sbot.service >/dev/null || true
fi
fi
if [ "$1" = "purge" ]; then
if [ -x "/usr/bin/deb-systemd-helper" ]; then
deb-systemd-helper purge go-sbot.service >/dev/null || true
deb-systemd-helper unmask go-sbot.service >/dev/null || true
deb-systemd-helper purge peach-go-sbot.service >/dev/null || true
deb-systemd-helper unmask peach-go-sbot.service >/dev/null || true
fi
fi
# End automatically added section

View File

@ -2,6 +2,6 @@
set -e
# Automatically added by cargo-deb
if [ -d /run/systemd/system ] && [ "$1" = remove ]; then
deb-systemd-invoke stop go-sbot.service >/dev/null || true
deb-systemd-invoke stop peach-go-sbot.service >/dev/null || true
fi
# End automatically added section

View File

@ -1,10 +1,9 @@
[Unit]
Description=peachcloud go-sbot
Description=peachs go-sbot
[Service]
Type=simple
User=peach
Environment="LIBRARIAN_WRITEALL=0"
User=peach-go-sbot
ExecStart=/usr/bin/go-sbot
Restart=always

View File

@ -0,0 +1,5 @@
Package: peach-go-ssb-room
Version: {{version}}
Architecture: all
Maintainer: Andrew Reid <gnomad@cryptolab.net>
Description: debian package for go-ssb-room on arm64

View File

@ -0,0 +1,41 @@
#!/bin/sh
set -e
# create user which go-ssb-room runs as
adduser --system --quiet --home /var/lib/go-ssb-room peach-go-ssb-room
mkdir -p /var/lib/peachcloud/go-ssb-room
# set permissions
chown peach-go-ssb-room /var/lib/peachcloud/go-ssb-room
chown peach-go-ssb-room /usr/bin/go-ssb-room
# Automatically added by cargo-deb
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask peach-go-ssb-room.service >/dev/null || true
# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled peach-go-ssb-room.service; then
# Enables the unit on first installation, creates new
# symlinks on upgrades if the unit file has changed.
deb-systemd-helper enable peach-go-ssb-room.service >/dev/null || true
else
# Update the statefile to add new symlinks (if any), which need to be
# cleaned up on purge. Also remove old symlinks.
deb-systemd-helper update-state peach-go-ssb-room.service >/dev/null || true
fi
fi
# End automatically added section
# Automatically added by cargo-deb
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
if [ -n "$2" ]; then
_dh_action=restart
else
_dh_action=start
fi
deb-systemd-invoke $_dh_action peach-go-ssb-room.service >/dev/null || true
fi
fi
# End automatically added section

View File

@ -0,0 +1,21 @@
#!/bin/sh
set -e
# Automatically added by cargo-deb
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
fi
# End automatically added section
# Automatically added by cargo-deb
if [ "$1" = "remove" ]; then
if [ -x "/usr/bin/deb-systemd-helper" ]; then
deb-systemd-helper mask peach-go-sbot.service >/dev/null || true
fi
fi
if [ "$1" = "purge" ]; then
if [ -x "/usr/bin/deb-systemd-helper" ]; then
deb-systemd-helper purge peach-go-sbot.service >/dev/null || true
deb-systemd-helper unmask peach-go-sbot.service >/dev/null || true
fi
fi
# End automatically added section

View File

@ -0,0 +1,7 @@
#!/bin/sh
set -e
# Automatically added by cargo-deb
if [ -d /run/systemd/system ] && [ "$1" = remove ]; then
deb-systemd-invoke stop peach-go-sbot.service >/dev/null || true
fi
# End automatically added section

View File

@ -0,0 +1,16 @@
[Unit]
Description="peach-go-ssb-room service"
After=network.target
After=nginx.target
Wants=nginx.target
[Service]
# TODO: dynamically replace roomtest2.commoninternet.net
ExecStart=/usr/bin/go-ssb-room -repo /var/lib/peachcloud/go-ssb-room -lishttp localhost:8899 -https-domain roomtest2.commoninternet.net
WorkingDirectory=/var/lib/peachcloud/go-ssb-room
Restart=always
SyslogIdentifier=gossbroom
User=peach-go-ssb-room
[Install]
WantedBy=multi-user.target

View File

@ -1,112 +0,0 @@
"""
script to create debian packages for cross-compiled go binaries for go-sbot
based off of this post
https://unix.stackexchange.com/questions/627689/how-to-create-a-debian-package-from-a-bash-script-and-a-systemd-service
"""
import subprocess
import argparse
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
GO_SBOT_VERSION = '0.1.25'
# constants
DEB_CONF_DIR = os.path.join(PROJECT_PATH, 'conf/templates/go_sbot')
DEB_BUILD_DIR = "/tmp/go_sbot"
GO_SSB_DIR = "/srv/peachcloud/automation/go-ssb"
def crosscompile_go_sbot():
subprocess.check_call(["git", "pull"], cwd=GO_SSB_DIR)
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]")
subprocess.check_call(["env", "GOOS=linux", "GOARCH=arm64", "go", "build", "./cmd/go-sbot"], cwd=GO_SSB_DIR)
def package_go_sbot(version):
print("[ PACKAGING go-sbot ]")
# copy debian conf files into correct locations in package build directory
DEBIAN_SRC_DIR = os.path.join(DEB_CONF_DIR, 'DEBIAN')
DEBIAN_DEST_DIR = os.path.join(DEB_BUILD_DIR, 'DEBIAN')
os.makedirs(DEBIAN_DEST_DIR)
maintainer_scripts = ['postinst', 'postrm', 'prerm']
for script in maintainer_scripts:
src = os.path.join(DEBIAN_SRC_DIR, script)
dest = os.path.join(DEBIAN_DEST_DIR, script)
shutil.copyfile(src, dest)
subprocess.check_call(["chmod", "775", dest])
# copy control file putting in correct version number
src = os.path.join("go_sbot/DEBIAN/control")
dest = os.path.join(DEBIAN_DEST_DIR, "control")
render_template(src=src, dest=dest, template_vars={"version": version})
# copy systemd service file
SERVICE_DIR = os.path.join(DEB_BUILD_DIR, 'lib/systemd/system')
os.makedirs(SERVICE_DIR)
shutil.copyfile(
os.path.join(DEB_CONF_DIR, 'go-sbot.service'),
os.path.join(SERVICE_DIR, 'go-sbot.service')
)
# copy go-sbot config.toml
SBOT_CONFIG_DIR = os.path.join(DEB_BUILD_DIR, 'home/peach/.ssb-go')
os.makedirs(SBOT_CONFIG_DIR)
shutil.copyfile(
os.path.join(DEB_CONF_DIR, 'config.toml'),
os.path.join(SBOT_CONFIG_DIR, 'config.toml')
)
# copy cross-compiled binaries
GO_BINARIES = ['go-sbot', 'sbotcli']
BIN_DIR = os.path.join(DEB_BUILD_DIR, 'usr/bin')
os.makedirs(BIN_DIR)
for go_binary in GO_BINARIES:
destination = os.path.join(BIN_DIR, go_binary)
shutil.copyfile(
os.path.join(os.path.join(GO_SSB_DIR), go_binary),
destination
)
subprocess.check_call(["chmod", "770", destination])
# create deb package
deb_file_name = "go-sbot_{}_arm64.deb".format(version)
print("[ CREATING {}]".format(deb_file_name))
subprocess.check_call(["dpkg-deb", "-b", ".", deb_file_name], cwd=DEB_BUILD_DIR)
# copy deb package to MICROSERVICES_DEB_DIR
deb_path = os.path.join(DEB_BUILD_DIR, deb_file_name)
subprocess.check_call(["cp", deb_path, MICROSERVICES_DEB_DIR])
# add deb package to freight
add_deb_to_freight(package_name=deb_file_name, package_path=deb_path)
# update freight cache
update_freight_cache()
def build_go_sbot():
# gets the most recently built go_sbot version, and increments the micro-number by 1
version = GO_SBOT_VERSION
print("[ BUILDING 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 go-sbot with new version number
crosscompile_go_sbot()
package_go_sbot(version=version)
if __name__ == '__main__':
build_go_sbot()

View File

@ -1,6 +1,7 @@
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):
@ -9,11 +10,13 @@ def build_packages(default_branch=False, package=None):
:param default_branch: checks out main git branch if True
:param package: if provided, only builds this package
"""
if package:
print("[ BUILDING ONLY {} ]".format(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 ]")
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
@ -25,9 +28,7 @@ if __name__ == '__main__':
parser.add_argument(
"-p",
"--package",
help="Optionally specify package to build",
required=False,
default=None
help="Ensure default branch for all repos for build",
)
args = parser.parse_args()
build_packages(default_branch=args.default, package=args.package)

View File

@ -0,0 +1,73 @@
"""
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

@ -0,0 +1,154 @@
"""
script to create debian packages for cross-compiled go binaries for go-sbot
based off of this post
https://unix.stackexchange.com/questions/627689/how-to-create-a-debian-package-from-a-bash-script-and-a-systemd-service
"""
import subprocess
import argparse
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.5'
PEACH_GO_SSB_ROOM_VERSION = '0.1.12'
def crosscompile_peach_go_sbot(src_dir):
subprocess.check_call(["git", "pull"], cwd=src_dir)
print("[CROSS-COMPILING sbotcli]")
subprocess.check_call(["env", "GOOS=linux", "GOARCH=arm64", "go", "build", "./cmd/sbotcli"], cwd=src_dir)
print("[CROSS-COMPILING go-sbot]")
subprocess.check_call(["env", "GOOS=linux", "GOARCH=arm64", "go", "build", "./cmd/go-sbot"], cwd=src_dir)
def crosscompile_peach_go_ssb_room(src_dir):
subprocess.check_call(["git", "pull"], cwd=src_dir)
print("[CROSS-COMPILING go-ssb-room/server]")
subprocess.check_call(["env", "CGO_ENABLED=1", "CC=aarch64-linux-gnu-gcc",
"CC_FOR_TARGET=gcc-aarch64-linux-gnu", "GOOS=linux",
"GOARCH=arm64", "go", "build", "./cmd/server"], cwd=src_dir)
print("[CROSS-COMPILING go-ssb-room/insert-user]")
subprocess.check_call(["env", "CGO_ENABLED=1", "CC=aarch64-linux-gnu-gcc",
"CC_FOR_TARGET=gcc-aarch64-linux-gnu", "GOOS=linux",
"GOARCH=arm64", "go", "build", "./cmd/insert-user"], cwd=src_dir)
def package_go_package(src_dir, package_name, deb_conf_dir, build_dir, go_binary_names, version):
print("[ PACKAGING {} ]".format(package_name))
# copy debian conf files into correct locations in package build directory
DEBIAN_SRC_DIR = os.path.join(deb_conf_dir, 'DEBIAN')
DEBIAN_DEST_DIR = os.path.join(build_dir, 'DEBIAN')
os.makedirs(DEBIAN_DEST_DIR)
maintainer_scripts = ['postinst', 'postrm', 'prerm']
for script in maintainer_scripts:
src = os.path.join(DEBIAN_SRC_DIR, script)
dest = os.path.join(DEBIAN_DEST_DIR, script)
shutil.copyfile(src, dest)
subprocess.check_call(["chmod", "775", dest])
# copy control file putting in correct version number
src = os.path.join(package_name.replace("-", "_"), "DEBIAN/control")
dest = os.path.join(DEBIAN_DEST_DIR, "control")
render_template(src=src, dest=dest, template_vars={"version": version})
# copy systemd service file
SERVICE_DIR = os.path.join(build_dir, 'lib/systemd/system')
os.makedirs(SERVICE_DIR)
shutil.copyfile(
os.path.join(deb_conf_dir, '{}.service'.format(package_name)),
os.path.join(SERVICE_DIR, '{}.service'.format(package_name))
)
# copy cross-compiled binaries
BIN_DIR = os.path.join(build_dir, 'usr/bin')
os.makedirs(BIN_DIR)
for go_binary_src, go_binary_dest in go_binary_names:
destination = os.path.join(BIN_DIR, go_binary_dest)
shutil.copyfile(
os.path.join(os.path.join(src_dir), go_binary_src),
destination
)
subprocess.check_call(["chmod", "770", destination])
# create deb package
deb_file_name = "{}_{}_arm64.deb".format(package_name, version)
print("[ CREATING {}]".format(deb_file_name))
subprocess.check_call(["dpkg-deb", "-b", ".", deb_file_name], cwd=build_dir)
# copy deb package to MICROSERVICES_DEB_DIR
deb_path = os.path.join(build_dir, deb_file_name)
subprocess.check_call(["cp", deb_path, MICROSERVICES_DEB_DIR])
# add deb package to freight
add_deb_to_freight(package_name=deb_file_name, package_path=deb_path)
# update freight cache
update_freight_cache()
def build_peach_go_sbot():
# constants
DEB_CONF_DIR = os.path.join(PROJECT_PATH, 'conf/templates/peach_go_sbot')
DEB_BUILD_DIR = "/tmp/peach_go_sbot"
# GO_BINARIES is a list of tuples of src_name and dest_name,
# which will be callable via /usr/bin/dest_name after installation
GO_BINARIES = [('go-sbot', 'go-sbot'), ('sbotcli', 'sbotcli')]
SRC_DIR = "/srv/peachcloud/automation/go-ssb"
# 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(src_dir=SRC_DIR)
package_go_package(src_dir=SRC_DIR,
package_name="peach-go-sbot",
deb_conf_dir=DEB_CONF_DIR,
build_dir=DEB_BUILD_DIR,
go_binary_names=GO_BINARIES,
version=version)
def build_peach_go_ssb_room():
# constants
DEB_CONF_DIR = os.path.join(PROJECT_PATH, 'conf/templates/peach_go_ssb_room')
DEB_BUILD_DIR = "/tmp/peach_go_ssb_room"
# GO_BINARIES is a list of tuples of src_name and dest_name,
# which will be callable via /usr/bin/dest_name after installation
GO_BINARIES = [('server', 'go-ssb-room'), ('insert-user', 'go-ssb-room-insert-user')]
SRC_DIR = "/srv/peachcloud/automation/go-ssb-room"
# gets the most recently built peach_go_sbot version, and increments the micro-number by 1
version = PEACH_GO_SSB_ROOM_VERSION
print("[ BUILDING PEACH-GO-SSB-ROOM 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_ssb_room(src_dir=SRC_DIR)
package_go_package(src_dir=SRC_DIR,
package_name="peach-go-ssb-room",
deb_conf_dir=DEB_CONF_DIR,
build_dir=DEB_BUILD_DIR,
go_binary_names=GO_BINARIES,
version=version)
if __name__ == '__main__':
build_peach_go_sbot()
build_peach_go_ssb_room()

View File

@ -4,6 +4,7 @@ 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
@ -26,57 +27,52 @@ 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(WORKSPACE_SRC_DIR, service_name)
build_rust_package(service_path, 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)
# for packages which depend on peach-lib (peach-web and peach-dyndns-udpater)
# run cargo update, so that we get the latest peach-lib version from git
if service_name in ["peach-web", "peach-dyndns-updater"]:
subprocess.check_call([CARGO_PATH, "update"], cwd=service_path)
# build debian pacakge
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
update_freight_cache()
def build_rust_package(service_path, service_name):
def build_packages(default_branch=False):
"""
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:
builds all PeachCloud microservices as .deb files and adds them to the freight repo
"""
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)
build_rust_packages(default_branch=default_branch)
build_peach_config(default_branch=default_branch)
print("[ MICROSERVICE PACKAGE ARCHIVE UPDATED ]")
if __name__ == '__main__':
@ -87,12 +83,5 @@ if __name__ == '__main__':
help="Ensure default branch for all repos for build",
action="store_true"
)
parser.add_argument(
"-p",
"--package",
help="Optionally specify package to build",
required=False,
default=None
)
args = parser.parse_args()
build_rust_packages(default_branch=args.default, package=args.package)
build_packages(default_branch=args.default)

View File

@ -1,105 +0,0 @@
"""
script to cross-compile PeachCloud packages for arm64 and other architectures
"""
import subprocess
from peach_package_builder.constants import *
from peach_package_builder.build_go_sbot import GO_SBOT_VERSION, GO_SSB_DIR
# constants
PEACHCLOUD_VERSION = "1.0"
PROJECT_PATH = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
RUST_WORKSPACE_DIR = WORKSPACE_SRC_DIR
BINARIES_DIR = "/srv/files.commoninternet.net/binaries"
PEACH_WORKSPACE_GIT_URL = "https://git.coopcloud.tech/PeachCloud/peach-workspace"
GO_SBOT_GIT_URL = "https://github.com/cryptoscope/ssb.git"
OUTPUT_DIR = "/srv/files.commoninternet.net"
def pull_go_repo():
if not os.path.exists(GO_SSB_DIR):
subprocess.check_call(["git", "clone", GO_SBOT_GIT_URL, GO_SSB_DIR])
else:
subprocess.check_call(["git", "pull"], cwd=GO_SSB_DIR)
def crosscompile_go_sbot(architecture, binaries_dir):
subprocess.check_call(["git", "pull"], cwd=GO_SSB_DIR)
if architecture == "arm7":
base_cmd = ["env", "CGO_ENABLED=1", "CC=arm-linux-gnueabi-gcc",
"GOOS=linux",
"GOARCH=arm", "GOARM=7", "go", "build"]
else:
base_cmd = ["env", "GOOS=linux", "GOARCH={}".format(architecture), "go", "build"]
print("[CROSS-COMPILING sbotcli]")
cmd = base_cmd + ["./cmd/sbotcli"]
subprocess.check_call(cmd, cwd=GO_SSB_DIR)
print("[CROSS-COMPILING go-sbot]")
cmd = base_cmd + ["./cmd/go-sbot"]
subprocess.check_call(cmd, cwd=GO_SSB_DIR)
for binary in ["sbotcli", "go-sbot"]:
binary_path = os.path.join(GO_SSB_DIR, binary)
output_path = os.path.join(binaries_dir, binary)
print("[COPYING {} TO {}]".format(binary_path, output_path))
subprocess.check_call(["cp", binary_path, output_path])
def build_rust_binary(service_name, binaries_dir, target="aarch64-unknown-linux-gnu"):
"""
this function builds a specific binary
:param service_name: string name of the service
:param target: architecture to build for
:return:
"""
print("[ BUILIDING SERVICE {} ]".format(service_name))
service_path = os.path.join(RUST_WORKSPACE_DIR, service_name)
subprocess.check_output(
[
CARGO_PATH,
"build",
"--release",
"--target",
target],
cwd=service_path).decode("utf-8").strip()
binary_path = os.path.join(RUST_WORKSPACE_DIR, "target/{}/release/{}".format(target, service_name))
output_path = os.path.join(binaries_dir, service_name)
print("[ COPYING {} TO {} ]".format(binary_path, output_path))
subprocess.call(["cp", binary_path, output_path])
def publish(binaries_dir, architecture):
subprocess.check_call(["mkdir", "-p", OUTPUT_DIR])
binaries = ["peach-web", "peach-config", "go-sbot", "sbotcli"]
output_folder_name = "peachcloud_{}_Linux_{}".format(PEACHCLOUD_VERSION, architecture)
output_folder_path = os.path.join(OUTPUT_DIR, output_folder_name)
subprocess.check_call(["mkdir", "-p", output_folder_path])
for binary in binaries:
f_path = os.path.join(binaries_dir, binary)
output_path = os.path.join(output_folder_path, binary)
subprocess.check_call(["cp", f_path, output_path])
# copy static files for peach-web
peach_web_static_path = os.path.join(RUST_WORKSPACE_DIR, "peach-web/static")
output_static_path = os.path.join(binaries_dir, "static")
subprocess.check_call(["cp", "-r", peach_web_static_path, output_static_path])
# create a tar
tar_path = output_folder_path + ".tar.gz"
subprocess.check_call(["tar", "-czvf", tar_path, "-C", binaries_dir, "."], cwd=binaries_dir)
if __name__ == '__main__':
subprocess.check_call(["mkdir", "-p", OUTPUT_DIR])
subprocess.check_call(["mkdir", "-p", BINARIES_DIR])
pull_go_repo()
architectures = [
("aarch64-unknown-linux-gnu", "arm64", "aarch64"),
("x86_64-unknown-linux-gnu", "amd64", "amd64"),
("armv7-unknown-linux-gnueabihf", "arm7", "arm7"),
]
for rust_architecture, go_architecture, yunohost_architecture in architectures:
print("BUILDING WITH ARCHITECTURE {}, {}, {}".format(rust_architecture, go_architecture, yunohost_architecture))
binaries_dir = os.path.join(BINARIES_DIR, yunohost_architecture)
subprocess.check_call(["mkdir", "-p", binaries_dir])
crosscompile_go_sbot(architecture=go_architecture, binaries_dir=binaries_dir)
build_rust_binary("peach-web", target=rust_architecture, binaries_dir=binaries_dir)
build_rust_binary("peach-config", target=rust_architecture, binaries_dir=binaries_dir)
publish(binaries_dir=binaries_dir, architecture=yunohost_architecture)

View File

@ -13,18 +13,23 @@ AUTOMATION_DIR = "/srv/peachcloud/automation"
FREIGHT_CONF = "/etc/freight.conf"
FREIGHT_LIB = "/var/lib/freight"
FREIGHT_CACHE = "/var/www/apt.peachcloud.org"
WORKSPACE_SRC_DIR = "/srv/peachcloud/automation/peach-workspace"
MICROSERVICES_SRC_DIR = "/srv/peachcloud/automation/microservices"
MICROSERVICES_DEB_DIR = "/srv/peachcloud/debs"
USER_PATH = "/home/rust"
CARGO_PATH = os.path.join(USER_PATH, ".cargo/bin/cargo")
SERVICES = [
# peach-probe is disabled until it is fixed
# {"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-menu", "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-buttons", "repo_url": "https://git.coopcloud.tech/PeachCloud/peach-workspace.git"},
{"name": "peach-config", "repo_url": "https://git.coopcloud.tech/PeachCloud/peach-workspace.git"},
{"name": "peach-buttons",
"repo_url": "https://github.com/peachcloud/peach-buttons.git"},
{"name": "peach-menu", "repo_url": "https://github.com/peachcloud/peach-menu.git"},
{"name": "peach-monitor",
"repo_url": "https://github.com/peachcloud/peach-monitor.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"},
]