blob: cdd9317761f0868d4463723b58ce5ef3e4f723a2 [file] [log] [blame]
Dean Troyer2aa2a892013-08-04 19:53:19 -05001# lib/nova_plugins/docker
2# Configure the Docker hypervisor
3
4# Enable with:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01005#
6# VIRT_DRIVER=docker
Dean Troyer2aa2a892013-08-04 19:53:19 -05007
8# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01009#
10# - ``functions`` file
11# - ``nova`` and ``glance`` configurations
Dean Troyer2aa2a892013-08-04 19:53:19 -050012
13# install_nova_hypervisor - install any external requirements
14# configure_nova_hypervisor - make configuration changes, including those to other services
15# start_nova_hypervisor - start any external services
16# stop_nova_hypervisor - stop any external services
17# cleanup_nova_hypervisor - remove transient data and cache
18
19# Save trace setting
20MY_XTRACE=$(set +o | grep xtrace)
21set +o xtrace
22
23
24# Defaults
25# --------
26
27# Set up default directories
28DOCKER_DIR=$DEST/docker
Dean Troyer2aa2a892013-08-04 19:53:19 -050029
30DOCKER_UNIX_SOCKET=/var/run/docker.sock
31DOCKER_PID_FILE=/var/run/docker.pid
32DOCKER_REGISTRY_PORT=${DOCKER_REGISTRY_PORT:-5042}
33
Eric Windisch97ce9352014-01-31 01:40:50 -050034DOCKER_IMAGE=${DOCKER_IMAGE:-cirros:latest}
35DOCKER_IMAGE_NAME=cirros
Eric Windisch2dac8852014-01-31 01:25:28 -050036DOCKER_REGISTRY_IMAGE=${DOCKER_REGISTRY_IMAGE:-registry:latest}
37DOCKER_REGISTRY_IMAGE_NAME=registry
Dean Troyer2aa2a892013-08-04 19:53:19 -050038DOCKER_REPOSITORY_NAME=${SERVICE_HOST}:${DOCKER_REGISTRY_PORT}/${DOCKER_IMAGE_NAME}
39
Dean Troyer2aa2a892013-08-04 19:53:19 -050040DOCKER_APT_REPO=${DOCKER_APT_REPO:-https://get.docker.io/ubuntu}
41
42
43# Entry Points
44# ------------
45
46# clean_nova_hypervisor - Clean up an installation
47function cleanup_nova_hypervisor() {
48 stop_service docker
49
50 # Clean out work area
51 sudo rm -rf /var/lib/docker
52}
53
54# configure_nova_hypervisor - Set config files, create data dirs, etc
55function configure_nova_hypervisor() {
Dean Troyer2aa2a892013-08-04 19:53:19 -050056 iniset $NOVA_CONF DEFAULT compute_driver docker.DockerDriver
57 iniset $GLANCE_API_CONF DEFAULT container_formats ami,ari,aki,bare,ovf,docker
Dean Troyer2aa2a892013-08-04 19:53:19 -050058}
59
60# install_nova_hypervisor() - Install external components
61function install_nova_hypervisor() {
62 # So far this is Ubuntu only
63 if ! is_ubuntu; then
64 die $LINENO "Docker is only supported on Ubuntu at this time"
65 fi
66
67 # Make sure Docker is installed
Sam Alba5a77d032013-10-21 16:17:30 -070068 if ! is_package_installed lxc-docker; then
Dean Troyer2aa2a892013-08-04 19:53:19 -050069 die $LINENO "Docker is not installed. Please run tools/docker/install_docker.sh"
70 fi
71
72 local docker_pid
73 read docker_pid <$DOCKER_PID_FILE
74 if [[ -z $docker_pid ]] || ! ps -p $docker_pid | grep [d]ocker; then
75 die $LINENO "Docker not running"
76 fi
77}
78
79# start_nova_hypervisor - Start any required external services
80function start_nova_hypervisor() {
81 local docker_pid
82 read docker_pid <$DOCKER_PID_FILE
83 if [[ -z $docker_pid ]] || ! ps -p $docker_pid | grep [d]ocker; then
84 die $LINENO "Docker not running, start the daemon"
85 fi
86
87 # Start the Docker registry container
88 docker run -d -p ${DOCKER_REGISTRY_PORT}:5000 \
89 -e SETTINGS_FLAVOR=openstack -e OS_USERNAME=${OS_USERNAME} \
90 -e OS_PASSWORD=${OS_PASSWORD} -e OS_TENANT_NAME=${OS_TENANT_NAME} \
91 -e OS_GLANCE_URL="${SERVICE_PROTOCOL}://${GLANCE_HOSTPORT}" \
92 -e OS_AUTH_URL=${OS_AUTH_URL} \
93 $DOCKER_REGISTRY_IMAGE_NAME ./docker-registry/run.sh
94
95 echo "Waiting for docker registry to start..."
96 DOCKER_REGISTRY=${SERVICE_HOST}:${DOCKER_REGISTRY_PORT}
97 if ! timeout $SERVICE_TIMEOUT sh -c "while ! curl -s $DOCKER_REGISTRY; do sleep 1; done"; then
98 die $LINENO "docker-registry did not start"
99 fi
100
101 # Tag image if not already tagged
102 if ! docker images | grep $DOCKER_REPOSITORY_NAME; then
103 docker tag $DOCKER_IMAGE_NAME $DOCKER_REPOSITORY_NAME
104 fi
105
106 # Make sure we copied the image in Glance
107 DOCKER_IMAGE=$(glance image-list | egrep " $DOCKER_IMAGE_NAME ")
108 if ! is_set DOCKER_IMAGE ; then
109 docker push $DOCKER_REPOSITORY_NAME
110 fi
111}
112
113# stop_nova_hypervisor - Stop any external services
114function stop_nova_hypervisor() {
115 # Stop the docker registry container
116 docker kill $(docker ps | grep docker-registry | cut -d' ' -f1)
117}
118
119
120# Restore xtrace
121$MY_XTRACE
122
123# Local variables:
124# mode: shell-script
125# End: