Basic working script
This commit is contained in:
parent
ce55310c65
commit
e9feefa035
|
@ -1,4 +1,5 @@
|
|||
deploy.sh
|
||||
secret*
|
||||
secret_files*
|
||||
ssh.sh
|
||||
ssh.sh
|
||||
notes.txt
|
|
@ -3,17 +3,17 @@ from utils import render_template
|
|||
import subprocess
|
||||
import os
|
||||
|
||||
|
||||
INITIALIZE_DEBIAN_REPO = True
|
||||
|
||||
MICROSERVICES_SRC_DIR = "/srv/peachcloud/src"
|
||||
MICROSERVICES_SRC_DIR = "/srv/peachcloud/automation/microservices"
|
||||
WEB_DIR = "/var/www/"
|
||||
APT_DIR = "/var/www/repos/apt"
|
||||
DEBIAN_REPO_DIR = "/var/www/repos/apt/debian"
|
||||
DEBIAN_REPO_CONF_DIR = "/var/www/repos/apt/debian/conf"
|
||||
|
||||
# before running this script run `gpg --gen-key` on the server, and put the key id here
|
||||
GPG_KEY_ID = "E62CD13A85763FCEC3EDBA8EA98440817F1A3CE5",
|
||||
# `gpg --list-keys`
|
||||
GPG_KEY_ID = "4ACEF251EA3E091167E8F03EBF69A52BE3565476"
|
||||
|
||||
SERVICES = [
|
||||
{"name": "peach-oled", "repo_url": "https://github.com/peachcloud/peach-oled.git"},
|
||||
|
@ -38,10 +38,12 @@ if INITIALIZE_DEBIAN_REPO:
|
|||
first_command.wait()
|
||||
|
||||
print("[ INSTALLING CARGO-DEB ]")
|
||||
subprocess.call(['cargo', 'install', 'cargo-deb'])
|
||||
if not os.path.exists("/root/.cargo/bin/cargo-deb"):
|
||||
subprocess.call(["/root/.cargo/bin/cargo", "install", "cargo-deb"])
|
||||
|
||||
print("[ INSTALL TOOLCHAIN FOR CROSS-COMPILATION ]")
|
||||
subprocess.call(['rustup', 'toolchain', 'install', 'nightly-aarch64-unknown-linux-gnu'])
|
||||
subprocess.call(["/root/.cargo/bin/rustup", "target", "add", "aarch64-unknown-linux-gnu"])
|
||||
subprocess.call(["/root/.cargo/bin/rustup", "toolchain", "install", "nightly-aarch64-unknown-linux-gnu"])
|
||||
|
||||
print("[ PULLING MICROSERVICES CODE FROM GITHUB ]")
|
||||
for service in SERVICES:
|
||||
|
@ -76,7 +78,8 @@ if INITIALIZE_DEBIAN_REPO:
|
|||
|
||||
print("[ EXPORTING PUBLIC GPG KEY ]")
|
||||
output_path = "{}/peach_pub.gpg".format(APT_DIR)
|
||||
subprocess.call(["gpg", "--armor", "--output", output_path, "--export", GPG_KEY_ID])
|
||||
if not os.path.exists(output_path):
|
||||
subprocess.call(["gpg", "--armor", "--output", output_path, "--export", GPG_KEY_ID])
|
||||
|
||||
print("[ COPYING NGINX CONFIG ]")
|
||||
render_template(
|
||||
|
@ -91,15 +94,15 @@ if INITIALIZE_DEBIAN_REPO:
|
|||
# below is code for updating the microservices, building the microservices,
|
||||
# and adding them to the debian repo
|
||||
for service in SERVICES:
|
||||
service_name = service['name']
|
||||
service_name = service["name"]
|
||||
service_path = os.path.join(MICROSERVICES_SRC_DIR, service_name)
|
||||
print("[ BUILIDING SERVICE {} ]".format(service_name))
|
||||
subprocess.call("cd {} && git pull;".format(service_path))
|
||||
subprocess.call("cd {} && cargo deb --target aarch64-unknown-linux-gnu;".format(service_path))
|
||||
deb_path = '?'
|
||||
subprocess.call("cd {debian_dir} && reprepro includedeb buster {deb_path}".format(
|
||||
subprocess.call(["git", "pull"], cwd=service_path)
|
||||
debian_package_path = str(subprocess.check_output(["/root/.cargo/bin/cargo", "deb", "--target", "aarch64-unknown-linux-gnu"], cwd=service_path))
|
||||
print('OUTPUT: {}'.format(debian_package_path))
|
||||
subprocess.call("reprepro includedeb buster {deb_path}".format(
|
||||
debian_dir=DEBIAN_REPO_DIR,
|
||||
deb_path=deb_path
|
||||
))
|
||||
deb_path=debian_package_path
|
||||
), cwd=DEBIAN_REPO_DIR)
|
||||
|
||||
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
from utils import render_template, cargo_install
|
||||
from vars import VARS
|
||||
|
||||
import subprocess
|
||||
import os
|
||||
import pwd
|
||||
import grp
|
||||
|
||||
|
||||
print("[ UPDATING OPERATING SYSTEM ]")
|
||||
subprocess.check_call(["apt-get", "update", "-y"])
|
||||
subprocess.check_call(["apt-get", "upgrade", "-y"])
|
||||
|
||||
print("[ INSTALLING SYSTEM REQUIREMENTS ]")
|
||||
subprocess.check_call(["apt-get", "install", "git", "nginx", "curl", "build-essential", "mosh"])
|
||||
|
||||
print("[ CREATING SYSTEM GROUPS ]")
|
||||
group = 'peach'
|
||||
try:
|
||||
grp.getgrnam(group)
|
||||
# if group exists
|
||||
except KeyError:
|
||||
# if group doesn't eixst
|
||||
subprocess.check_call(["/usr/sbin/groupadd", "peach"])
|
||||
|
||||
print("[ ADDING SYSTEM USER ]")
|
||||
users = ["notplants", "glyph"]
|
||||
for user in users:
|
||||
try:
|
||||
# if user exists
|
||||
pwd.getpwnam(user)
|
||||
except:
|
||||
# if user does not exist
|
||||
subprocess.check_call(["/usr/sbin/adduser", user])
|
||||
subprocess.check_call(["usermod", "-aG", "sudo", user])
|
||||
subprocess.check_call(["/usr/sbin/usermod", "-a", "-G", user, "peach"])
|
||||
|
||||
print("[ CREATING DIRECTORIES ]")
|
||||
folders = [VARS["src_dir"], VARS["web_dir"], VARS["debian_rep_dir"]]
|
||||
for folder in folders:
|
||||
if not os.path.exists(folder):
|
||||
os.makedirs(folder)
|
||||
|
||||
print("[ INSTALLING RUST ]")
|
||||
if not os.path.exists('/root/.cargo/bin/rustc'):
|
||||
first_command = subprocess.Popen(["curl", "https://sh.rustup.rs", "-sSf"], stdout=subprocess.PIPE)
|
||||
output = subprocess.check_output(["sh", "-s", "--", "-y"], stdin=first_command.stdout)
|
||||
first_command.wait()
|
||||
|
||||
print("[ INSTALLING CARGO PACKAGES ]")
|
||||
cargo_install("cargo-deb")
|
||||
|
||||
print("[ COPYING NGINX CONFIG ]")
|
||||
render_template(src='nginx/nginx.conf', dest='/etc/nginx/nginx.conf')
|
||||
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
VARS = {
|
||||
'log_dir': '/srv/log',
|
||||
'src_dir': '/srv/src',
|
||||
'web_dir': 'srv/www',
|
||||
'debian_rep_dir': '/srv/www/repos/apt/debian',
|
||||
'gpg_key_id': 'E62CD13A85763FCEC3EDBA8EA98440817F1A3CE5',
|
||||
'services': [
|
||||
{'name': 'peach-oled', 'repo_url': 'https://github.com/peachcloud/peach-oled.git'},
|
||||
{'name': 'peach-oled', 'repo_url': 'https://github.com/peachcloud/peach-oled.git'}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue