blob: 07ba90b02b790d6764564b84a2205b3a00bcb808 [file] [log] [blame]
Adam Israel736f9e72017-02-23 15:36:35 +01001#!/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.
10set -eux
11
12# The basic charm layer also installs all the things. 47 packages.
13LAYER_BASIC="gcc build-essential python3-pip python3-setuptools python3-yaml"
14
15# the basic layer also installs virtualenv, but the name changed in xenial.
16TRUSTY_PACKAGES="python-virtualenv"
17XENIAL_PACKAGES="virtualenv"
18
19# Predownload common packages used by your charms in development
20DOWNLOAD_PACKAGES=""
21
22PACKAGES="$LAYER_BASIC $DOWNLOAD_PACKAGES"
23
Adam Israelae197f22017-06-28 09:27:35 -040024# Packages from pypi to pre-install
25PYPI="charms.reactive charmhelpers paramiko>=1.16.0,<1.17"
26
Adam Israel736f9e72017-02-23 15:36:35 +010027function 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 Israel32a79fc2017-04-24 12:53:09 -040034
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 Israel736f9e72017-02-23 15:36:35 +010037
38 lxc exec $container -- apt-get update -y
39 lxc exec $container -- apt-get upgrade -y
40 lxc exec $container -- apt-get install -y $PACKAGES $2
Adam Israelae197f22017-06-28 09:27:35 -040041 lxc exec $container -- pip3 install --upgrade $PYPI
Adam Israel736f9e72017-02-23 15:36:35 +010042 lxc stop $container
43
44 lxc image delete $alias || true
45 lxc publish $container --alias $alias description="$series juju dev image ($(date +%Y%m%d))"
46
47 lxc delete $container -f || true
48}
49
50cache trusty "$TRUSTY_PACKAGES"
51cache xenial "$XENIAL_PACKAGES"