Skip to content

Instantly share code, notes, and snippets.

@bloodearnest
Last active October 22, 2023 12:14
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bloodearnest/3474741411c4fdd6c2bb64d08dc75040 to your computer and use it in GitHub Desktop.
Save bloodearnest/3474741411c4fdd6c2bb64d08dc75040 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# This script will create xenial and trusty lxd images that will be used by the
# lxd provider in juju 2.1+ It is for use with the lxd provider for local
# development and preinstalls a common set of production packages.
#
# This is important, as between them, basenode and layer-basic install ~111
# packages, before we even get to any packages installed by your charm.
#
# It also installs some helpful development tools, and pre-downloads some
# commonly used packages.
#
# This dramatically speeds up the install hooks for lxd deploys. On my slow
# laptop, average install hook time went from ~7min down to ~1 minute.
set -eu
# basenode installs all the things. 64 packages on xenial to be exact,
# including python2 and ruby :(
BASENODE="python-cheetah python-yaml python-netaddr facter lldpd bzr rsync snmpd ethtool ntp"
# Basenode also installs and configures postfix via preseed, so we don't
# install it here, we instead download it in $DOWNLOAD_PACKAGES below
# The basic layer also installs all the things. 47 packages.
LAYER_BASIC="gcc build-essential python3-pip python3-setuptools python3-yaml python3-dev"
# the basic layer also installs virtualenv, but the name changed in xenial.
TRUSTY_PACKAGES="python-virtualenv"
XENIAL_PACKAGES="virtualenv"
# as an optimisation, predownload common packages for charms we use a lot
DOWNLOAD_PACKAGES="postgresql memcached haproxy postfix postgresql-contrib python3-psycopg2"
OTHERS="libpq-dev telegraf run-one"
# these are just developer conveniences
DEVEL="make tree vim curl jq silversearcher-ag postgresql-client"
PACKAGES="$BASENODE $LAYER_BASIC $DEVEL $OTHERS"
start()
{
series=$1
container=juju-${series}-base
alias=juju/$series/amd64
lxc delete $container -f 2>&1 || true
lxc launch ubuntu:$series $container
}
run()
{
series=$1
container=juju-${series}-base
alias=juju/$series/amd64
# Note: using apt-get rather than apt for trusty compat and avoid the waring about stable cli
lxc exec $container --env DEBIAN_FRONTEND=noninteractive -- add-apt-repository -y ppa:telegraf-devs/ppa 2>&1
lxc exec $container --env DEBIAN_FRONTEND=noninteractive -- apt-get update -y
lxc exec $container --env DEBIAN_FRONTEND=noninteractive -- apt-get upgrade -y
lxc exec $container --env DEBIAN_FRONTEND=noninteractive -- apt-get autoremove -y
lxc exec $container --env DEBIAN_FRONTEND=noninteractive -- apt-get -q install -y $PACKAGES $2
lxc exec $container --env DEBIAN_FRONTEND=noninteractive -- apt-get -q install -d -y $DOWNLOAD_PACKAGES
lxc stop $container
lxc image delete $alias || true
lxc publish $container --alias $alias description="$series juju dev image ($(date +%Y%m%d))"
lxc delete $container -f
}
start xenial
start trusty
sleep 30 # wait for network and cloud init
run xenial "$XENIAL_PACKAGES"
run trusty "$TRUSTY_PACKAGES"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment