Skip to content

Commit

Permalink
Add script to build release binary in LXC container
Browse files Browse the repository at this point in the history
  • Loading branch information
timsueberkrueb committed Feb 3, 2018
1 parent 79bf93d commit 79e0f08
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
7 changes: 7 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <version>
# Replace <version> with the version number (following semver)
```

## Contributing

Contributions in form of bug reports, feature proposals or pull requests are highly
Expand Down
65 changes: 65 additions & 0 deletions scripts/build_release.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 79e0f08

Please sign in to comment.