From 79e0f08792e402e7a8abc56c0c0ae7fc53e80811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20S=C3=BCberkr=C3=BCb?= Date: Sat, 3 Feb 2018 22:23:58 +0100 Subject: [PATCH] Add script to build release binary in LXC container --- DEVELOPMENT.md | 7 +++++ scripts/build_release.py | 65 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100755 scripts/build_release.py diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 73f9de0..83d36a9 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -77,6 +77,13 @@ pyinstaller -F -n ubup main.py Release packages should be build on the oldest Ubuntu version supported by ubup to [ensure compatibility](https://pythonhosted.org/PyInstaller/usage.html#making-linux-apps-forward-compatible). +To create a release binary in a LXC container, run: + +```bash +./scripts/build_release.py +# Replace with the version number (following semver) +``` + ## Contributing Contributions in form of bug reports, feature proposals or pull requests are highly diff --git a/scripts/build_release.py b/scripts/build_release.py new file mode 100755 index 0000000..9242ae5 --- /dev/null +++ b/scripts/build_release.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import os +import subprocess + +import click + +import container_utils + + +SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) + +UBUNTU_RELEASE = 'xenial' # 16.04 +RELEASE_ARCH = 'x86_64' + + +def _build_release(release_version: str): + container_image = 'ubuntu:{}'.format(UBUNTU_RELEASE) + container_name = 'ubup-release-builder-{}'.format(UBUNTU_RELEASE) + subprocess.check_call(['lxc', 'launch', '-e', container_image, container_name]) + try: + # Push the source code to the container + subprocess.check_call(['lxc', 'file', 'push', '-r', SOURCE_ROOT, container_name + '/root']) + container_utils.lxd_wait_for_network(container_name) + # Update and upgrade our fresh container + subprocess.check_call(['lxc', 'exec', container_name, '--', 'apt-get', 'update']) + subprocess.check_call(['lxc', 'exec', container_name, '--', 'apt-get', '-y', 'upgrade']) + # Install squashfs (required for snaps to work) + subprocess.check_call(['lxc', 'exec', container_name, '--', + 'apt-get', '-y', 'install', 'squashfuse']) + # Install Python and pip + subprocess.check_call(['lxc', 'exec', container_name, '--', + 'apt-get', '-y', 'install', 'python3', 'python3-pip']) + # Install ubup dependencies as well as pyinstaller + subprocess.check_call(['lxc', 'exec', container_name, '--', + 'pip3', 'install', 'click', 'ruamel.yaml', 'schema', 'progressbar2', 'pyinstaller']) + # Make a release build + subprocess.check_call(['lxc', 'exec', container_name, '--', 'bash', '-c', + 'cd /root/ubup && pyinstaller -F -n ubup main.py']) + # Fetch the release executable + os.makedirs(os.path.join(SOURCE_ROOT, 'dist'), exist_ok=True) + subprocess.check_call(['lxc', 'file', 'pull', container_name + '/root/ubup/dist/ubup', + os.path.join(SOURCE_ROOT, 'dist', 'ubup-{}-{}-{}'.format(release_version, + UBUNTU_RELEASE, + RELEASE_ARCH))]) + + # Delete the container + subprocess.check_call(['lxc', 'delete', '-f', container_name]) + except subprocess.CalledProcessError as e: + print('An error occurred, trying to destroy container ...') + subprocess.check_call(['lxc', 'delete', '-f', container_name]) + print('Container destroyed.') + raise e + + +@click.command() +@click.argument('release_version') +def main(release_version: str): + container_utils.check_is_lxd_installed() + _build_release(release_version) + + +if __name__ == '__main__': + main()