Separate setup and update

This commit is contained in:
Max Fowler 2020-11-13 12:45:01 +01:00
parent fba90e6e2c
commit 671df65156
2 changed files with 57 additions and 13 deletions

View File

@ -1,24 +1,50 @@
# peach-vps config
Code for configuring the peachcloud vps for various hosting and automation
Scripts for configuring the peachcloud vps for various hosting and automation.
Currently:
- debian repository of microservices
- mdbook builder for devdocs
# setup
# setup debian repo
an idempotent script for initializing the debian repo on the vps
```
apt update
apt install git python python3-pip rsync
git clone https://github.com/peachcloud/peach-vps.git
cd peach-vps
pip3 install -r requirements.txt
python peach_vps_scripts/setup_vps.py
python3 scripts/setup_debian_repo.py -i
```
# update
(for more frequent updates that don't involve the whole initial setup)
# update debian repo
without the -i flag, the setup_debian_repo rebuilds all
microservices (cross-compiled to arm64) and re-adds them to the debian repo
```
cd peach-vps
python peach_vps_scripts/update_vps.py
python3 scripts/setup_debian_repo.py
```
# using the debian repo on the pi
To add the peachcloud debian repo as an apt source,
on the pi,
```
vi /etc/apt/sources.list.d/peach.list
```
and add the following line:
```
deb http://apt.peachcloud.org/debian/ buster main
```
Then add the gpg pub key to the apt-key list:
```
wget -O - http://apt.peachcloud.org/peach_pub.gpg | sudo apt-key add -
```
You can then install peach packages with apt-get:
```
apt-get update
apt-get install peach-oled
```

View File

@ -2,9 +2,10 @@ from utils import render_template
import subprocess
import os
import argparse
INITIALIZE_DEBIAN_REPO = True
# constants
MICROSERVICES_SRC_DIR = "/srv/peachcloud/automation/microservices"
WEB_DIR = "/var/www/"
APT_DIR = "/var/www/repos/apt"
@ -17,10 +18,21 @@ GPG_KEY_ID = "4ACEF251EA3E091167E8F03EBF69A52BE3565476"
SERVICES = [
{"name": "peach-oled", "repo_url": "https://github.com/peachcloud/peach-oled.git"},
{"name": "peach-network", "repo_url": "https://github.com/peachcloud/peach-network.git"}
{"name": "peach-network", "repo_url": "https://github.com/peachcloud/peach-network.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-menu", "repo_url": "https://github.com/peachcloud/peach-menu.git"},
{"name": "peach-buttons", "repo_url": "https://github.com/peachcloud/peach-buttons.git"}
]
if INITIALIZE_DEBIAN_REPO:
# parse CLI args
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--initialize", help="initialize and update debian repo", action="store_true")
args = parser.parse_args()
# initializing debian repo from a blank slate
# (but this code is idempotent so it can be re-run if already initialized)
if args.initialize:
print("[ INSTALLING SYSTEM REQUIREMENTS ]")
subprocess.call(["apt-get", "install", "git", "nginx", "curl", "build-essential", "reprepro", "gcc-aarch64-linux-gnu", ])
@ -91,15 +103,21 @@ if INITIALIZE_DEBIAN_REPO:
)
# below is code for updating the microservices, building the microservices,
# and adding them to the debian repo
# below is code for git updating the microservices, building the microservices,
# and (re)-adding them to the debian repo
print("[ BUILDING AND UPDATING MICROSERVICE PACKAGES ]")
for service in SERVICES:
service_name = service["name"]
service_path = os.path.join(MICROSERVICES_SRC_DIR, service_name)
print("[ BUILIDING SERVICE {} ]".format(service_name))
subprocess.call(["git", "pull"], cwd=service_path)
debian_package_path = subprocess.check_output(["/root/.cargo/bin/cargo", "deb", "--target", "aarch64-unknown-linux-gnu"], cwd=service_path).decode("utf-8").strip()
print('OUTPUT: {}'.format(debian_package_path))
# remove debian package from repo
# (in the future we could look at some way of updating with versions instead of removing and adding)
subprocess.call(["reprepro", "remove", "buster", service_name], cwd=DEBIAN_REPO_DIR)
# add the package
subprocess.call(["reprepro", "includedeb", "buster", debian_package_path], cwd=DEBIAN_REPO_DIR)
print("[ DEBIAN REPO SETUP COMPLETE ]")