diff --git a/build_img.py b/build_img.py index 06618a3..8b5ac0a 100644 --- a/build_img.py +++ b/build_img.py @@ -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, - } -) \ No newline at end of file + # 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) \ No newline at end of file diff --git a/raspi_master.yaml b/raspi_master.yaml index 25845eb..22be6e7 100644 --- a/raspi_master.yaml +++ b/raspi_master.yaml @@ -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: / \ No newline at end of file + root-fs: / diff --git a/templates/release_index.html b/templates/release_index.html index 2993e50..52f8cb1 100644 --- a/templates/release_index.html +++ b/templates/release_index.html @@ -24,15 +24,17 @@

-

PeachCloud Release Builds

-

The latest aarch64 release builds of PeachCloud microservices and other software components.

+

PeachCloud Microservices

+

The above image contains the following packages: