diff --git a/build.sh b/build.sh index 1fa72c7..7e5ad1b 100755 --- a/build.sh +++ b/build.sh @@ -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 \ No newline at end of file diff --git a/publish_img.py b/publish_img.py new file mode 100644 index 0000000..2321ef7 --- /dev/null +++ b/publish_img.py @@ -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]) \ No newline at end of file diff --git a/raspi_master.yaml b/raspi_master.yaml index 585441e..22be6e7 100644 --- a/raspi_master.yaml +++ b/raspi_master.yaml @@ -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: / \ No newline at end of file + root-fs: / diff --git a/templates/release_index.html b/templates/release_index.html new file mode 100644 index 0000000..e813b0e --- /dev/null +++ b/templates/release_index.html @@ -0,0 +1,51 @@ + + + +PeachCloud Release Builds + + + + +

PeachCloud Image Builds

+

The latest PeachCloud disc image for Raspberry Pi 3+ with all PeachCloud microservices pre-installed.

+ + +
+
+
+ +

PeachCloud Package Builds

+

The above image contains the following packages:

+ + +
+ +

For online documentation please refer to +docs.peachcloud.org.
+Code repositories can be found at +github.com/peachcloud.
+Support our efforts at +opencollective.com/peachcloud.

+ +

Thank you for your interest in PeachCloud.

+ + \ No newline at end of file