Merge pull request #8 from peachcloud/release

Add python script for publishing image
This commit is contained in:
Max Fowler 2021-03-16 14:40:30 +01:00 committed by GitHub
commit aa8ca29398
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 161 additions and 15 deletions

View File

@ -1,20 +1,27 @@
#!/usr/bin/env bash
# remove old files
rm -f raspi_3.img
rm -f raspi_3.img.xz
rm -f raspi_3.log
rm -f peach-img-manifest.log
# build image
make raspi_3.img
# copy to releases
# compress image
echo "++ successful image build, performing compression"
xz -k raspi_3.img
# make releases dir
TODAY=$(date +"%Y%m%d")
RELEASE_DIR=/var/www/releases.peachcloud.org/html/peach-imgs/$TODAY
echo "++ copy output to ${RELEASE_DIR}"
mkdir -p $RELEASE_DIR
echo "++ successful image build, performing compression"
xz -k raspi.img
status=$?
if [ $status -eq 0 ]; then
echo "++ compression successful, copying compressed img to ${RELEASE_DIR}"
cp raspi_3.img.xz $RELEASE_DIR/${TODAY}_peach_raspi3.img.xz
else
echo "++ compression failed, copying uncompressed img to ${RELEASE_DIR}"
cp raspi_3.img $RELEASE_DIR/${TODAY}_peach_raspi3.img
fi
# copy over files
cp raspi_3.img.xz $RELEASE_DIR/${TODAY}_peach_raspi3.img.xz
cp raspi_3.log $RELEASE_DIR/${TODAY}_peach_raspi3.log
cp peach-img-manifest.log $RELEASE_DIR/${TODAY}_peach_manifest.log
# publish image to releases.peachcloud.org
python3 publish_img.py $RELEASE_DIR

72
publish_img.py Normal file
View File

@ -0,0 +1,72 @@
import os
import sys
import jinja2
import json
PROJECT_PATH = os.path.dirname(os.path.realpath(__file__))
# load jinja templates
template_path = os.path.join(PROJECT_PATH, 'templates')
template_loader = jinja2.FileSystemLoader(searchpath=template_path)
template_env = jinja2.Environment(loader=template_loader, keep_trailing_newline=True)
def render_template(src, dest, template_vars=None):
"""
helper function fo rendering jinja template
:param src: relative string path to jinja template file
:param dest: absolute string path of output destination file
:param template_vars: variables to render template with
:return: None
"""
template = template_env.get_template(src)
if not template_vars:
template_vars= {}
output_text = template.render(**template_vars)
if os.path.exists(dest):
os.remove(dest)
with open(dest, 'w') as f:
f.write(output_text)
def publish_img(release_dir):
"""
takes in a string path to a directory containing a release
it expected the directory to be named YEARMONTHDAY
and to contain the following three files:
- YEARMONTHDAY_peach_raspi3.img.xz
- YEARMONTHDAY_peach_raspi3.log
- YEARMONTHDAY_peach_manifest.log
The script re-builds index.html for releases.peachcloud.org to point to
the files in this releases directory.
"""
# get release name (last part of path)
release_name = os.path.basename(os.path.normpath(release_dir))
# expected file paths within release_dir
img_name = "{}_peach_raspi3.img.xz".format(release_name)
img_path = os.path.join(release_dir, img_name)
manifest_path = os.path.join(release_dir, "{}_peach_manifest.log".format(release_name))
# 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())
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_name,
"packages": packages
}
)
if __name__ == '__main__':
publish_img(sys.argv[1])

View File

@ -136,14 +136,30 @@ steps:
- apt: install
packages:
- git
- python
- python3
- python3-pip
- wget
- gnupg2
tag: /
- chroot: /
shell: |
git clone -b dev https://github.com/peachcloud/peach-config.git /srv/peach-config
cd /srv/peach-config/ && python3 /srv/peach-config/scripts/setup_dev_env.py -i -n peach
pip3 install setuptools
echo "deb http://apt.peachcloud.org/ buster main" > /etc/apt/sources.list.d/peach.list
wget -O /tmp/pubkey.gpg http://apt.peachcloud.org/pubkey.gpg
apt-key add /tmp/pubkey.gpg
apt-get update
apt-get install -y python3-peach-config
/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: |
/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
root-fs: /
# END OF PEACH CONFIG
@ -151,4 +167,4 @@ steps:
# clears /etc/resolv.conf on its own.
- shell: |
rm "${ROOT?}/etc/resolv.conf"
root-fs: /
root-fs: /

View File

@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<title>PeachCloud Release Builds</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>PeachCloud Image Builds</h1>
<p>The latest PeachCloud disc image for Raspberry Pi 3+ with all PeachCloud microservices pre-installed.</p>
<ul>
<li>
<a href="{{release_img_url}}">{{release_img_name}}</a>
</li>
</ul>
<br/>
<hr>
<br/>
<h1>PeachCloud Package Builds</h1>
<p>The above image contains the following packages:</p>
<ul>
<li><a href="http://apt.peachcloud.org/pool/buster/main/p/peach-config/python3-peach-config_{{packages['python3-peach-config']}}_all.deb">peach-config</a> - {{packages["python3-peach-config"]}}</li>
<li><a href="http://apt.peachcloud.org/pool/buster/main/p/peach-buttons/peach-buttons_{{packages['peach-buttons']}}_arm64.deb">peach-buttons</a> - {{packages["peach-buttons"]}}</li>
<li><a href="http://apt.peachcloud.org/pool/buster/main/p/peach-buttons/peach-menu_{{packages['peach-menu']}}_arm64.deb">peach-menu</a> - {{packages["peach-menu"]}}</li>
<li><a href="http://apt.peachcloud.org/pool/buster/main/p/peach-monitor/peach-monitor_{{packages['peach-monitor']}}_arm64.deb">peach-monitor</a> - {{packages["peach-monitor"]}}</li>
<li><a href="http://apt.peachcloud.org/pool/buster/main/p/peach-network/peach-network_{{packages['peach-network']}}_arm64.deb">peach-network</a> - {{packages["peach-network"]}}</li>
<li><a href="http://apt.peachcloud.org/pool/buster/main/p/peach-oled/peach-oled_{{packages['peach-oled']}}_arm64.deb">peach-oled</a> - {{packages["peach-oled"]}}</li>
<li><a href="http://apt.peachcloud.org/pool/buster/main/p/peach-stats/peach-stats_{{packages['peach-stats']}}_arm64.deb">peach-stats</a> - {{packages["peach-stats"]}}</li>
<li><a href="http://apt.peachcloud.org/pool/buster/main/p/peach-go-sbot/peach-go-sbot_{{packages['peach-go-sbot']}}_all.deb">peach-go-sbot</a> - {{packages["peach-go-sbot"]}}</li>
</ul>
<hr>
<p>For online documentation please refer to
<a href="http://docs.peachcloud.org/">docs.peachcloud.org</a>.<br/>
Code repositories can be found at
<a href="https://github.com/peachcloud">github.com/peachcloud</a>.<br/>
Support our efforts at
<a href="https://opencollective.com/peachcloud">opencollective.com/peachcloud</a>.</p>
<p><em>Thank you for your interest in PeachCloud.</em></p>
</body>
</html>