2
from subprocess import check_call
4
from charmhelpers.core.hookenv import status_set
5
from charmhelpers.core.hookenv import config
7
from charms.reactive import set_state
8
from charms.reactive import hook
9
from charms.reactive import when
10
from charms.reactive import when_not
12
# 2 Major events are emitted from this layer.
14
# `docker.ready` is an event intended to signal other layers that need to
15
# plug into the plumbing to extend the docker daemon. Such as fire up a
16
# bootstrap docker daemon, or predependency fetch + dockeropt rendering
18
# `docker.available` means the docker daemon setup has settled and is prepared
19
# to run workloads. This is a broad state that has large implications should
20
# you decide to remove it. Production workloads can be lost if no restart flag
23
# Be sure you bind to it appropriately in your workload layer and
24
# react to the proper event.
29
''' Install the docker daemon, and supporting tooling '''
30
status_set('maintenance', 'Installing Docker and AUFS')
31
# Using getenv will return '' if CHARM_DIR is not an environment variable.
32
charm_path = os.getenv('CHARM_DIR', '')
33
install_script_path = os.path.join(charm_path, 'scripts/install_docker.sh')
34
check_call([install_script_path])
35
status_set('active', 'Docker installed, cycling for extensions')
36
set_state('docker.ready')
39
check_call(['apt-get', 'install', '-y', 'python-pip'])
40
# Pip install docker-compose.
41
check_call(['pip', 'install', '-U', 'docker-compose'])
42
# Leave a status message that Docker is installed.
44
# Make with the adding of the users to the groups
45
check_call(['usermod', '-aG', 'docker', 'ubuntu'])
49
@when_not('cgroups.modified')
50
def enable_grub_cgroups():
52
if cfg.get('enable-cgroups'):
53
check_call(['scripts/enable_grub_cgroups.sh'])
54
set_state('cgroups.modified')
58
@when_not('docker.available')
59
def signal_workloads_start():
60
''' We can assume the pre-workload bits have completed now that docker.ready
61
has been reacted to. Lets remove the predep work and continue on to being
63
status_set('active', 'Docker installed')
64
set_state('docker.available')