This commit is contained in:
Max Fowler 2021-06-23 21:04:06 +00:00 committed by GitHub
commit ca8aee7430
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 249 additions and 104 deletions

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

@ -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

@ -1,104 +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
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"
def crosscompile_peach_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_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')
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("peach_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, 'peach-go-sbot.service'),
os.path.join(SERVICE_DIR, 'peach-go-sbot.service')
)
# 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 = "peach-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_peach_go_sbot():
# 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=version)
if __name__ == '__main__':
build_peach_go_sbot()

View File

@ -44,6 +44,11 @@ def build_rust_packages(default_branch=False, package=None):
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,