Working on release script

This commit is contained in:
notplants 2021-03-16 11:37:18 +01:00
parent 48393605bb
commit 5ed956048d
3 changed files with 89 additions and 42 deletions

View File

@ -1,6 +1,8 @@
import os
import subprocess
import jinja2
import json
import argparse
from datetime import date
@ -29,38 +31,81 @@ def render_template(src, dest, template_vars=None):
with open(dest, 'w') as f:
f.write(output_text)
# remove old files
os.remove(os.path.join(PROJECT_PATH, 'raspi_3.img'))
os.remove(os.path.join(PROJECT_PATH, 'raspi_3.log'))
# build img
subprocess.check_call(['make', 'raspi_3.img'])
def build_img(build=True, publish=True):
"""
if build=True,
builds a new PeachCloud image,
compresses the image,
creates a manifest for what was included in that image
and a log for the build of the image
# create releases dir
today = date.today()
today_str = "{}{}{}".format(today.year, today.month, today.day)
release_dir = "/var/www/releases.peachcloud.org/html/peach-imgs/{}".format(today_str)
os.makedirs(release_dir)
if publish=True
copies the following files to release dir with the current date
- log of build
- compressed img file
- manifest for that image
rebuilds releases.peachcloud.org to point to the release
# copy image and log to releases dir
print("++ successful image build, copying output to {}", release_dir)
img_path = os.path.join(PROJECT_PATH, 'raspi_3.img')
log_path = os.path.join(PROJECT_PATH, 'raspi_3.log')
release_img_name = "{}_peach_raspi3.img".format(today_str)
release_log_name = "{}_peach_raspi3.log".format(today_str)
img_release_path = os.path.join(release_dir, release_img_name)
log_release_path = os.path.join(release_dir, release_log_name)
subprocess.check_call(['cp', img_path, img_release_path])
subprocess.check_call(['cp', log_path, log_release_path])
running with both flags as true is standard usage,
but building and publishing separately can be useful for testing
"""
# rebuild release index.html
release_index_path = "/var/www/releases.peachcloud.org/html/index.html"
release_img_url = img_release_path.replace('/var/www/releases.peachcloud.org/html/', '/')
render_template(
src="release_index.html",
dest=release_index_path,
template_vars={
"release_img_url": release_img_url,
"release_img_name": release_img_name,
}
)
# these are the three files created by the build
img_path = os.path.join(PROJECT_PATH, 'raspi_3.img')
log_path = os.path.join(PROJECT_PATH, 'raspi_3.log')
manifest_path = os.path.join(PROJECT_PATH, 'peach-img-manifest.log')
# if build=True, then remove old files and re-build
if build:
# remove old files
if os.path.exists(img_path):
os.remove(img_path)
if os.path.exists(log_path):
os.remove(log_path)
if os.path.exists(manifest_path):
os.remove(manifest_path)
# build img
subprocess.check_call(['make', 'raspi_3.img'])
if publish:
# create release dir for this release
today = date.today()
today_str = "{}{}{}".format(today.year, today.month, today.day)
release_dir = "/var/www/releases.peachcloud.org/html/peach-imgs/{}".format(today_str)
os.makedirs(release_dir)
# copy image, log and manifest to release dir
print("++ successful image build, copying output to {}", release_dir)
img_release_name = "{}_peach_raspi3.img".format(today_str)
release_log_name = "{}_peach_raspi3.log".format(today_str)
manifest_name = "{}_peach_manifest.log".format(today_str)
img_release_path = os.path.join(release_dir, img_release_name)
log_release_path = os.path.join(release_dir, release_log_name)
manifest_release_path = os.path.join(release_dir, manifest_name)
subprocess.check_call(['cp', img_path, img_release_path])
subprocess.check_call(['cp', log_path, log_release_path])
subprocess.check_call(['cp', manifest_path, manifest_release_path])
# rebuild index.html to point to the new release
release_index_path = "/var/www/releases.peachcloud.org/html/index.html"
release_img_url = img_path.replace('/var/www/releases.peachcloud.org/html/', '/')
with open(manifest_path, 'r') as f:
manifest = json.loads(f.read())
for k, v in manifest.items():
print("{}: {}".format(k, v))
packages = manifest['packages']
render_template(
src="release_index.html",
dest=release_index_path,
template_vars={
"release_img_url": release_img_url,
"release_img_name": img_release_name,
"packages": packages
}
)
if __name__ == '__main__':
build_img(build=True, publish=True)

View File

@ -150,12 +150,12 @@ steps:
apt-key add /tmp/pubkey.gpg
apt-get update
apt-get install -y python3-peach-config
/usr/bin/peach-config -i -n -d peach
/usr/bin/peach-config setup -i -n -d peach
# lastly log which versions of microservices were installed and copy the provenance to the host machine
- chroot: /
shell: |
apt list --installed | grep peach > /srv/peach-img-manifest.log
/usr/bin/peach-config manifest > /srv/peach-img-manifest.log
- shell: |
cp "${ROOT?}/srv/peach-img-manifest.log" /srv/peachcloud/automation/peach-img-builder/peach-img-manifest.log
@ -167,4 +167,4 @@ steps:
# clears /etc/resolv.conf on its own.
- shell: |
rm "${ROOT?}/etc/resolv.conf"
root-fs: /
root-fs: /

View File

@ -24,15 +24,17 @@
<hr>
<br/>
<h1>PeachCloud Release Builds</h1>
<p>The latest aarch64 release builds of PeachCloud microservices and other software components.</p>
<h1>PeachCloud Microservices</h1>
<p>The above image contains the following packages:</p>
<ul>
<li><a href="/peach-buttons">peach-buttons</a> - 0.1.0</li>
<li><a href="/peach-menu">peach-menu</a> - 0.2.0</li>
<li><a href="/peach-monitor">peach-monitor</a> - 0.1.0</li>
<li><a href="/peach-network">peach-network</a> - 0.2.0</li>
<li><a href="/peach-oled">peach-oled</a> - 0.1.0</li>
<li><a href="/peach-stats">peach-stats</a> - 0.1.0</li>
<li><a href="/peach-buttons">peach-config</a> - {{packages["python3-peach-config"]}}</li>
<li><a href="/peach-buttons">peach-buttons</a> - {{packages["peach-buttons"]}}</li>
<li><a href="/peach-menu">peach-menu</a> - {{packages["peach-menu"]}}</li>
<li><a href="/peach-monitor">peach-monitor</a> - {{packages["peach-monitor"]}}</li>
<li><a href="/peach-network">peach-network</a> - {{packages["peach-network"]}}</li>
<li><a href="/peach-oled">peach-oled</a> - {{packages["peach-oled"]}}</li>
<li><a href="/peach-stats">peach-stats</a> - {{packages["peach-stats"]}}</li>
<li><a href="/peach-go-sbot">peach-go-sbot</a> - {{packages["peach-go-sbot"]}}</li>
</ul>
<hr>