| Adam Israel | 736f9e7 | 2017-02-23 15:36:35 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # This script will create xenial and trusty lxd images that will be used by the |
| 4 | # lxd provider in juju 2.1+ It is for use with the lxd provider for local |
| 5 | # development and preinstalls a common set of production packages. |
| 6 | # |
| 7 | # This dramatically speeds up the install hooks for lxd deploys by |
| 8 | # pre-installing common packages. It is intended to run daily as part of |
| 9 | # a cron job. |
| 10 | set -eux |
| 11 | |
| 12 | # The basic charm layer also installs all the things. 47 packages. |
| Adam Israel | 745eb63 | 2017-10-02 17:51:22 -0400 | [diff] [blame] | 13 | LAYER_BASIC="gcc build-essential python3-pip python3-setuptools libyaml-dev python3-yaml python3-dev" |
| Adam Israel | 736f9e7 | 2017-02-23 15:36:35 +0100 | [diff] [blame] | 14 | |
| 15 | # the basic layer also installs virtualenv, but the name changed in xenial. |
| 16 | TRUSTY_PACKAGES="python-virtualenv" |
| 17 | XENIAL_PACKAGES="virtualenv" |
| 18 | |
| 19 | # Predownload common packages used by your charms in development |
| 20 | DOWNLOAD_PACKAGES="" |
| 21 | |
| 22 | PACKAGES="$LAYER_BASIC $DOWNLOAD_PACKAGES" |
| 23 | |
| Adam Israel | ae197f2 | 2017-06-28 09:27:35 -0400 | [diff] [blame] | 24 | # Packages from pypi to pre-install |
| 25 | PYPI="charms.reactive charmhelpers paramiko>=1.16.0,<1.17" |
| 26 | |
| Adam Israel | 736f9e7 | 2017-02-23 15:36:35 +0100 | [diff] [blame] | 27 | function cache() { |
| 28 | series=$1 |
| 29 | container=juju-${series}-base |
| 30 | alias=juju/$series/amd64 |
| 31 | |
| 32 | lxc delete $container -f || true |
| 33 | lxc launch ubuntu:$series $container |
| Adam Israel | 32a79fc | 2017-04-24 12:53:09 -0400 | [diff] [blame] | 34 | |
| 35 | # Wait for the container to get an IP address |
| 36 | lxc exec $container -- bash -c "for i in {1..60}; do sleep 1; ping -c1 10.44.127.1 &> /dev/null && break; done" |
| Adam Israel | 736f9e7 | 2017-02-23 15:36:35 +0100 | [diff] [blame] | 37 | |
| Adam Israel | b88f494 | 2018-02-15 14:00:36 -0500 | [diff] [blame] | 38 | # Wait for cloud-init to finish |
| 39 | lxc exec $container -- bash -c "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do sleep 1; done" |
| 40 | |
| Adam Israel | 736f9e7 | 2017-02-23 15:36:35 +0100 | [diff] [blame] | 41 | lxc exec $container -- apt-get update -y |
| Adam Israel | 3f761ad | 2018-03-07 12:55:34 -0500 | [diff] [blame] | 42 | lxc exec $container -- apt-get upgrade -y -o Dpkg::Options::='--force-confold' |
| Adam Israel | 736f9e7 | 2017-02-23 15:36:35 +0100 | [diff] [blame] | 43 | lxc exec $container -- apt-get install -y $PACKAGES $2 |
| Adam Israel | 745eb63 | 2017-10-02 17:51:22 -0400 | [diff] [blame] | 44 | lxc exec $container -- pip3 install --upgrade pip |
| Adam Israel | ae197f2 | 2017-06-28 09:27:35 -0400 | [diff] [blame] | 45 | lxc exec $container -- pip3 install --upgrade $PYPI |
| Adam Israel | 736f9e7 | 2017-02-23 15:36:35 +0100 | [diff] [blame] | 46 | lxc stop $container |
| 47 | |
| 48 | lxc image delete $alias || true |
| 49 | lxc publish $container --alias $alias description="$series juju dev image ($(date +%Y%m%d))" |
| 50 | |
| 51 | lxc delete $container -f || true |
| 52 | } |
| 53 | |
| Adam Israel | b5c5532 | 2018-05-17 09:18:21 -0400 | [diff] [blame] | 54 | # Cache the image for the Ubuntu series or series to support |
| 55 | # cache trusty "$TRUSTY_PACKAGES" |
| Adam Israel | 736f9e7 | 2017-02-23 15:36:35 +0100 | [diff] [blame] | 56 | cache xenial "$XENIAL_PACKAGES" |