2 # Copyright 2019 Canonical Ltd.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 # This script will create lxd images that will be used by the
18 # lxd provider in juju 2.1+ It is for use with the lxd provider for local
19 # development and preinstalls a common set of production packages.
21 # This is important, as between them, basenode and layer-basic install ~111
22 # packages, before we even get to any packages installed by your charm.
24 # It also installs some helpful development tools, and pre-downloads some
25 # commonly used packages.
27 # This dramatically speeds up the install hooks for lxd deploys. On my slow
28 # laptop, average install hook time went from ~7min down to ~1 minute.
30 echo -e "usage: update-juju-lxc-images [Optional flags]"
31 echo -e "This script will automatically cache all LTS series by default (trusty, xenial, bionic)"
33 echo -e "Optional flags"
34 echo -e "=================="
35 echo -e "--trusty It will download only the trusty series"
36 echo -e "--xenial It will download only the xenial series"
37 echo -e "--bionic It will download only the bionic series"
40 echo -e "=================="
41 echo -e "-h | --help Print full help."
75 # The basic charm layer also installs all the things. 47 packages.
76 LAYER_BASIC="gcc build-essential python3-pip python3-setuptools python3-yaml"
78 # the basic layer also installs virtualenv, but the name changed in xenial.
79 TRUSTY_PACKAGES="python-virtualenv"
80 XENIAL_PACKAGES="virtualenv"
81 BIONIC_PACKAGES="virtualenv"
83 # Predownload common packages used by your charms in development
86 CLOUD_INIT_PACKAGES="curl cpu-checker bridge-utils cloud-utils tmux ubuntu-fan"
88 PACKAGES="$LAYER_BASIC $DOWNLOAD_PACKAGES"
90 JUJU_FULL_VERSION=`juju version` # 2.4.4-bionic-amd64
91 JUJU_VERSION=`echo $JUJU_FULL_VERSION | awk -F"-" '{print $1}'`
92 OS_VERSION=`echo $JUJU_FULL_VERSION | awk -F"-" '{print $2}'`
93 ARCH=`echo $JUJU_FULL_VERSION | awk -F"-" '{print $3}'`
97 container=juju-${series}-base
98 alias=juju/$series/amd64
100 lxc delete $container -f || true
101 lxc launch ubuntu:$series $container
102 sleep 15 # wait for network
104 lxc exec $container -- apt-get update -y
105 lxc exec $container -- apt-get upgrade -y
106 lxc exec $container -- apt-get install -y $CLOUD_INIT_PACKAGES $PACKAGES $2
109 echo "Installing Juju agent $JUJU_FULL_VERSION"
110 # TODO: verify if the version exists
112 lxc exec $container -- mkdir -p /var/lib/juju/tools/$JUJU_FULL_VERSION/
114 lxc exec $container -- curl -sS --connect-timeout 20 --noproxy \* --insecure -o /var/lib/juju/tools/$JUJU_FULL_VERSION/tools.tar.gz https://streams.canonical.com/juju/tools/agent/$JUJU_VERSION/juju-$JUJU_VERSION-ubuntu-$ARCH.tgz
116 lxc exec $container -- tar zxf /var/lib/juju/tools/$JUJU_FULL_VERSION/tools.tar.gz -C /var/lib/juju/tools/$JUJU_FULL_VERSION || true
118 # Cache pip packages so installation into venv is faster?
119 # pip3 download --cache-dir ~/.cache/pip charmhelpers
123 lxc image delete $alias || true
124 lxc publish $container --alias $alias description="$series juju dev image ($(date +%Y%m%d))"
126 lxc delete $container -f || true
129 # Enable caching of the serie(s) you're developing for.
130 if [ $FLAGS == 0 ]; then
131 cache xenial "$XENIAL_PACKAGES"
133 [ $trusty == 1 ] && cache trusty "$TRUSTY_PACKAGES"
134 [ $xenial == 1 ] && cache xenial "$XENIAL_PACKAGES"
135 [ $bionic == 1 ] && cache bionic "$BIONIC_PACKAGES"