Fix formatting and remove unnecessary comments
This commit is contained in:
parent
973e663eb0
commit
85c0bf323a
|
@ -5,16 +5,6 @@ import os
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
# constants
|
|
||||||
AUTOMATION_DIR = "/srv/peachcloud/automation"
|
|
||||||
MICROSERVICES_SRC_DIR = "/srv/peachcloud/automation/microservices"
|
|
||||||
MICROSERVICES_DEB_DIR = "/srv/peachcloud/debs"
|
|
||||||
FREIGHT_CONF = "/etc/freight.conf"
|
|
||||||
FREIGHT_LIB = "/var/lib/freight"
|
|
||||||
FREIGHT_CACHE = "/var/www/apt.peachcloud.org"
|
|
||||||
# define user path before running the script
|
|
||||||
USER_PATH = "/home/rust"
|
|
||||||
|
|
||||||
# before running this script run `gpg --gen-key` on the server
|
# before running this script run `gpg --gen-key` on the server
|
||||||
# assign the email address of the key id here:
|
# assign the email address of the key id here:
|
||||||
GPG_KEY_EMAIL = "andrew@mycelial.technology"
|
GPG_KEY_EMAIL = "andrew@mycelial.technology"
|
||||||
|
@ -23,11 +13,25 @@ GPG_KEY_EMAIL = "andrew@mycelial.technology"
|
||||||
GPG_KEY_PASS_FILE = "/home/rust/passphrase.txt"
|
GPG_KEY_PASS_FILE = "/home/rust/passphrase.txt"
|
||||||
# if you need to list the existing keys: `gpg --list-keys`
|
# if you need to list the existing keys: `gpg --list-keys`
|
||||||
|
|
||||||
|
|
||||||
|
# constants
|
||||||
|
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"
|
||||||
|
MICROSERVICES_DEB_DIR = "/srv/peachcloud/debs"
|
||||||
|
USER_PATH = "/home/rust"
|
||||||
|
|
||||||
|
|
||||||
SERVICES = [
|
SERVICES = [
|
||||||
{"name": "peach-buttons", "repo_url": "https://github.com/peachcloud/peach-buttons.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-menu", "repo_url": "https://github.com/peachcloud/peach-menu.git"},
|
||||||
{"name": "peach-monitor", "repo_url": "https://github.com/peachcloud/peach-monitor.git"},
|
{"name": "peach-monitor",
|
||||||
{"name": "peach-network", "repo_url": "https://github.com/peachcloud/peach-network.git"},
|
"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-oled", "repo_url": "https://github.com/peachcloud/peach-oled.git"},
|
||||||
{"name": "peach-stats", "repo_url": "https://github.com/peachcloud/peach-stats.git"},
|
{"name": "peach-stats", "repo_url": "https://github.com/peachcloud/peach-stats.git"},
|
||||||
# {"name": "peach-web", "repo_url": "https://github.com/peachcloud/peach-web.git"}, # currently build fails because it needs rust nightly for pear
|
# {"name": "peach-web", "repo_url": "https://github.com/peachcloud/peach-web.git"}, # currently build fails because it needs rust nightly for pear
|
||||||
|
@ -35,7 +39,11 @@ SERVICES = [
|
||||||
|
|
||||||
# parse CLI args
|
# parse CLI args
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("-i", "--initialize", help="initialize and update debian repo", action="store_true")
|
parser.add_argument(
|
||||||
|
"-i",
|
||||||
|
"--initialize",
|
||||||
|
help="initialize and update debian repo",
|
||||||
|
action="store_true")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
cargo_path = os.path.join(USER_PATH, ".cargo/bin/cargo")
|
cargo_path = os.path.join(USER_PATH, ".cargo/bin/cargo")
|
||||||
|
@ -45,7 +53,15 @@ cargo_path = os.path.join(USER_PATH, ".cargo/bin/cargo")
|
||||||
if args.initialize:
|
if args.initialize:
|
||||||
|
|
||||||
print("[ INSTALLING SYSTEM REQUIREMENTS ]")
|
print("[ INSTALLING SYSTEM REQUIREMENTS ]")
|
||||||
subprocess.call(["sudo", "apt-get", "install", "git", "nginx", "curl", "build-essential", "gcc-aarch64-linux-gnu", ])
|
subprocess.call(["sudo",
|
||||||
|
"apt-get",
|
||||||
|
"install",
|
||||||
|
"git",
|
||||||
|
"nginx",
|
||||||
|
"curl",
|
||||||
|
"build-essential",
|
||||||
|
"gcc-aarch64-linux-gnu",
|
||||||
|
])
|
||||||
|
|
||||||
print("[ CREATING DIRECTORIES ]")
|
print("[ CREATING DIRECTORIES ]")
|
||||||
folders = [MICROSERVICES_SRC_DIR, FREIGHT_CACHE, FREIGHT_LIB]
|
folders = [MICROSERVICES_SRC_DIR, FREIGHT_CACHE, FREIGHT_LIB]
|
||||||
|
@ -56,8 +72,10 @@ if args.initialize:
|
||||||
print("[ INSTALLING RUST ]")
|
print("[ INSTALLING RUST ]")
|
||||||
rustc_path = os.path.join(USER_PATH, ".cargo/bin/rustc")
|
rustc_path = os.path.join(USER_PATH, ".cargo/bin/rustc")
|
||||||
if not os.path.exists(rustc_path):
|
if not os.path.exists(rustc_path):
|
||||||
first_command = subprocess.Popen(["curl", "https://sh.rustup.rs", "-sSf"], stdout=subprocess.PIPE)
|
first_command = subprocess.Popen(
|
||||||
output = subprocess.check_output(["sh", "-s", "--", "-y"], stdin=first_command.stdout)
|
["curl", "https://sh.rustup.rs", "-sSf"], stdout=subprocess.PIPE)
|
||||||
|
output = subprocess.check_output(
|
||||||
|
["sh", "-s", "--", "-y"], stdin=first_command.stdout)
|
||||||
first_command.wait()
|
first_command.wait()
|
||||||
|
|
||||||
print("[ INSTALLING CARGO-DEB ]")
|
print("[ INSTALLING CARGO-DEB ]")
|
||||||
|
@ -67,13 +85,16 @@ if args.initialize:
|
||||||
|
|
||||||
print("[ INSTALL TOOLCHAIN FOR CROSS-COMPILATION ]")
|
print("[ INSTALL TOOLCHAIN FOR CROSS-COMPILATION ]")
|
||||||
rustup_path = os.path.join(USER_PATH, ".cargo/bin/rustup")
|
rustup_path = os.path.join(USER_PATH, ".cargo/bin/rustup")
|
||||||
subprocess.call([rustup_path, "target", "add", "aarch64-unknown-linux-gnu"])
|
subprocess.call([rustup_path, "target", "add",
|
||||||
subprocess.call([rustup_path, "toolchain", "install", "nightly-aarch64-unknown-linux-gnu"])
|
"aarch64-unknown-linux-gnu"])
|
||||||
|
subprocess.call([rustup_path, "toolchain", "install",
|
||||||
|
"nightly-aarch64-unknown-linux-gnu"])
|
||||||
|
|
||||||
print("[ INSTALLING FREIGHT ]")
|
print("[ INSTALLING FREIGHT ]")
|
||||||
freight_path = os.path.join(AUTOMATION_DIR, "freight")
|
freight_path = os.path.join(AUTOMATION_DIR, "freight")
|
||||||
if not os.path.exists(freight_path):
|
if not os.path.exists(freight_path):
|
||||||
subprocess.call(["git", "clone", "https://github.com/freight-team/freight.git", freight_path])
|
subprocess.call(
|
||||||
|
["git", "clone", "https://github.com/freight-team/freight.git", freight_path])
|
||||||
|
|
||||||
print("[ CONFIGURING FREIGHT ]")
|
print("[ CONFIGURING FREIGHT ]")
|
||||||
freight_conf_tmp_path = os.path.join(USER_PATH, "freight.conf")
|
freight_conf_tmp_path = os.path.join(USER_PATH, "freight.conf")
|
||||||
|
@ -99,18 +120,20 @@ if args.initialize:
|
||||||
print("[ EXPORTING PUBLIC GPG KEY ]")
|
print("[ EXPORTING PUBLIC GPG KEY ]")
|
||||||
output_path = "{}/peach_pub.gpg".format(FREIGHT_CACHE)
|
output_path = "{}/peach_pub.gpg".format(FREIGHT_CACHE)
|
||||||
if not os.path.exists(output_path):
|
if not os.path.exists(output_path):
|
||||||
subprocess.call(["gpg", "--armor", "--output", output_path, "--export", GPG_KEY_EMAIL])
|
subprocess.call(["gpg", "--armor", "--output",
|
||||||
|
output_path, "--export", GPG_KEY_EMAIL])
|
||||||
|
|
||||||
print("[ COPYING NGINX CONFIG ]")
|
print("[ COPYING NGINX CONFIG ]")
|
||||||
nginx_conf_tmp_path = os.path.join(USER_PATH, "apt.peachcloud.org")
|
nginx_conf_tmp_path = os.path.join(USER_PATH, "apt.peachcloud.org")
|
||||||
render_template(
|
render_template(
|
||||||
src="nginx_debian.conf",
|
src="nginx_debian.conf",
|
||||||
dest=nginx_conf_tmp_path,
|
dest=nginx_conf_tmp_path,
|
||||||
template_vars = {
|
template_vars={
|
||||||
"apt_dir": FREIGHT_CACHE
|
"apt_dir": FREIGHT_CACHE
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
subprocess.call(["sudo", "cp", nginx_conf_tmp_path, "/etc/nginx/sites-enabled/apt.peachcloud.org"])
|
subprocess.call(["sudo", "cp", nginx_conf_tmp_path,
|
||||||
|
"/etc/nginx/sites-enabled/apt.peachcloud.org"])
|
||||||
|
|
||||||
# update the microservices from git and build the debian packages
|
# update the microservices from git and build the debian packages
|
||||||
print("[ BUILDING AND UPDATING MICROSERVICE PACKAGES ]")
|
print("[ BUILDING AND UPDATING MICROSERVICE PACKAGES ]")
|
||||||
|
@ -119,20 +142,26 @@ for service in SERVICES:
|
||||||
service_path = os.path.join(MICROSERVICES_SRC_DIR, service_name)
|
service_path = os.path.join(MICROSERVICES_SRC_DIR, service_name)
|
||||||
print("[ BUILIDING SERVICE {} ]".format(service_name))
|
print("[ BUILIDING SERVICE {} ]".format(service_name))
|
||||||
subprocess.call(["git", "pull"], cwd=service_path)
|
subprocess.call(["git", "pull"], cwd=service_path)
|
||||||
debian_package_path = subprocess.run([cargo_path, "deb", "--target", "aarch64-unknown-linux-gnu"], cwd=service_path, stdout=subprocess.PIPE).stdout.decode("utf-8").strip()
|
debian_package_path = subprocess.run(
|
||||||
# copy package to staging folder
|
[
|
||||||
|
cargo_path,
|
||||||
|
"deb",
|
||||||
|
"--target",
|
||||||
|
"aarch64-unknown-linux-gnu"],
|
||||||
|
cwd=service_path,
|
||||||
|
stdout=subprocess.PIPE).stdout.decode("utf-8").strip()
|
||||||
subprocess.call(["cp", debian_package_path, MICROSERVICES_DEB_DIR])
|
subprocess.call(["cp", debian_package_path, MICROSERVICES_DEB_DIR])
|
||||||
|
|
||||||
print("[ ADDING PACKAGES TO FREIGHT LIBRARY ]")
|
print("[ ADDING PACKAGES TO FREIGHT LIBRARY ]")
|
||||||
# loop through all files in the microservices deb directory
|
|
||||||
for package in os.scandir(MICROSERVICES_DEB_DIR):
|
for package in os.scandir(MICROSERVICES_DEB_DIR):
|
||||||
# avoid any files which are not debian packages
|
|
||||||
if package.name.endswith(".deb"):
|
if package.name.endswith(".deb"):
|
||||||
print("[ ADDING PACKAGE {} ]".format(package.name))
|
print("[ ADDING PACKAGE {} ]".format(package.name))
|
||||||
subprocess.call(["freight", "add", "-c", FREIGHT_CONF, package.path, "apt/buster"])
|
subprocess.call(["freight", "add", "-c", FREIGHT_CONF,
|
||||||
|
package.path, "apt/buster"])
|
||||||
|
|
||||||
print("[ ADDING PACKAGES TO FREIGHT CACHE ]")
|
print("[ ADDING PACKAGES TO FREIGHT CACHE ]")
|
||||||
# needs to be run as sudo user
|
# needs to be run as sudo user
|
||||||
subprocess.call(["sudo", "freight", "cache", "-g", GPG_KEY_EMAIL, "-p", GPG_KEY_PASS_FILE])
|
subprocess.call(["sudo", "freight", "cache", "-g",
|
||||||
|
GPG_KEY_EMAIL, "-p", GPG_KEY_PASS_FILE])
|
||||||
|
|
||||||
print("[ DEBIAN REPO SETUP COMPLETE ]")
|
print("[ DEBIAN REPO SETUP COMPLETE ]")
|
||||||
|
|
Loading…
Reference in New Issue