Add publish_img.py script
This commit is contained in:
commit
1ec6a68ece
24
build.sh
24
build.sh
|
@ -1,13 +1,27 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# remove old files
|
||||||
rm -f raspi_3.img
|
rm -f raspi_3.img
|
||||||
|
rm -f raspi_3.img.xz
|
||||||
rm -f raspi_3.log
|
rm -f raspi_3.log
|
||||||
|
rm -f peach-img-manifest.log
|
||||||
|
|
||||||
|
# build image
|
||||||
make raspi_3.img
|
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")
|
TODAY=$(date +"%Y%m%d")
|
||||||
RELEASE_DIR=/var/www/releases.peachcloud.org/html/peach-imgs/$TODAY
|
RELEASE_DIR=/var/www/releases.peachcloud.org/html/peach-imgs/$TODAY
|
||||||
echo "++ successful image build, copying output to ${RELEASE_DIR}"
|
echo "++ copy output to ${RELEASE_DIR}"
|
||||||
mkdir -p $RELEASE_DIR
|
mkdir -p $RELEASE_DIR
|
||||||
cp raspi_3.img $RELEASE_DIR/${TODAY}_peach_raspi3.img
|
|
||||||
cp peach-img-manifest.log $RELEASE_DIR/${TODAY}_img_manifest.log
|
# copy over files
|
||||||
cp raspi_3.log $RELEASE_DIR/${TODAY}_peach_raspi3.log
|
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
|
105
publish_img.py
105
publish_img.py
|
@ -1,9 +1,7 @@
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import sys
|
||||||
import jinja2
|
import jinja2
|
||||||
import json
|
import json
|
||||||
import argparse
|
|
||||||
from datetime import date
|
|
||||||
|
|
||||||
|
|
||||||
PROJECT_PATH = os.path.dirname(os.path.realpath(__file__))
|
PROJECT_PATH = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
@ -32,80 +30,45 @@ def render_template(src, dest, template_vars=None):
|
||||||
f.write(output_text)
|
f.write(output_text)
|
||||||
|
|
||||||
|
|
||||||
def build_img(build=True, publish=True):
|
def publish_img(release_dir):
|
||||||
"""
|
"""
|
||||||
if build=True,
|
takes in a string path to a directory containing a release
|
||||||
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
|
|
||||||
|
|
||||||
if publish=True
|
it expected the directory to be named YEARMONTHDAY
|
||||||
copies the following files to release dir with the current date
|
and to contain the following three files:
|
||||||
- log of build
|
- YEARMONTHDAY_peach_raspi3.img.xz
|
||||||
- compressed img file
|
- YEARMONTHDAY_peach_raspi3.log
|
||||||
- manifest for that image
|
- YEARMONTHDAY_peach_manifest.log
|
||||||
rebuilds releases.peachcloud.org to point to the release
|
|
||||||
|
|
||||||
running with both flags as true is standard usage,
|
The script re-builds index.html for releases.peachcloud.org to point to
|
||||||
but building and publishing separately can be useful for testing
|
the files in this releases directory.
|
||||||
"""
|
"""
|
||||||
|
# get release name (last part of path)
|
||||||
|
release_name = os.path.basename(os.path.normpath(release_dir))
|
||||||
|
|
||||||
# these are the three files created by the build
|
# expected file paths within release_dir
|
||||||
img_path = os.path.join(PROJECT_PATH, 'raspi_3.img')
|
img_name = "{}_peach_raspi3.img.xz".format(release_name)
|
||||||
log_path = os.path.join(PROJECT_PATH, 'raspi_3.log')
|
img_path = os.path.join(release_dir, img_name)
|
||||||
manifest_path = os.path.join(PROJECT_PATH, 'peach-img-manifest.log')
|
manifest_path = os.path.join(release_dir, "{}_peach_manifest.log".format(release_name))
|
||||||
|
|
||||||
# if build=True, then remove old files and re-build
|
# rebuild index.html to point to the new release
|
||||||
if build:
|
release_index_path = "/var/www/releases.peachcloud.org/html/index.html"
|
||||||
# remove old files
|
release_img_url = img_path.replace('/var/www/releases.peachcloud.org/html/', '/')
|
||||||
if os.path.exists(img_path):
|
with open(manifest_path, 'r') as f:
|
||||||
os.remove(img_path)
|
manifest = json.loads(f.read())
|
||||||
if os.path.exists(log_path):
|
for k, v in manifest.items():
|
||||||
os.remove(log_path)
|
print("{}: {}".format(k, v))
|
||||||
if os.path.exists(manifest_path):
|
packages = manifest['packages']
|
||||||
os.remove(manifest_path)
|
render_template(
|
||||||
|
src="release_index.html",
|
||||||
# build img
|
dest=release_index_path,
|
||||||
subprocess.check_call(['make', 'raspi_3.img'])
|
template_vars={
|
||||||
|
"release_img_url": release_img_url,
|
||||||
if publish:
|
"release_img_name": img_name,
|
||||||
# create release dir for this release
|
"packages": packages
|
||||||
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__':
|
if __name__ == '__main__':
|
||||||
build_img(build=True, publish=True)
|
publish_img(sys.argv[1])
|
|
@ -24,17 +24,17 @@
|
||||||
<hr>
|
<hr>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
<h1>PeachCloud Microservices</h1>
|
<h1>PeachCloud Package Builds</h1>
|
||||||
<p>The above image contains the following packages:</p>
|
<p>The above image contains the following packages:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/peach-buttons">peach-config</a> - {{packages["python3-peach-config"]}}</li>
|
<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="/peach-buttons">peach-buttons</a> - {{packages["peach-buttons"]}}</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="/peach-menu">peach-menu</a> - {{packages["peach-menu"]}}</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="/peach-monitor">peach-monitor</a> - {{packages["peach-monitor"]}}</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="/peach-network">peach-network</a> - {{packages["peach-network"]}}</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="/peach-oled">peach-oled</a> - {{packages["peach-oled"]}}</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="/peach-stats">peach-stats</a> - {{packages["peach-stats"]}}</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="/peach-go-sbot">peach-go-sbot</a> - {{packages["peach-go-sbot"]}}</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>
|
</ul>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
Loading…
Reference in New Issue