Dean Troyer | 2aa2a89 | 2013-08-04 19:53:19 -0500 | [diff] [blame] | 1 | # lib/nova_plugins/docker |
| 2 | # Configure the Docker hypervisor |
| 3 | |
| 4 | # Enable with: |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 5 | # |
| 6 | # VIRT_DRIVER=docker |
Dean Troyer | 2aa2a89 | 2013-08-04 19:53:19 -0500 | [diff] [blame] | 7 | |
| 8 | # Dependencies: |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 9 | # |
| 10 | # - ``functions`` file |
| 11 | # - ``nova`` and ``glance`` configurations |
Dean Troyer | 2aa2a89 | 2013-08-04 19:53:19 -0500 | [diff] [blame] | 12 | |
| 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 |
| 20 | MY_XTRACE=$(set +o | grep xtrace) |
| 21 | set +o xtrace |
| 22 | |
| 23 | |
| 24 | # Defaults |
| 25 | # -------- |
| 26 | |
| 27 | # Set up default directories |
| 28 | DOCKER_DIR=$DEST/docker |
Dean Troyer | 2aa2a89 | 2013-08-04 19:53:19 -0500 | [diff] [blame] | 29 | |
| 30 | DOCKER_UNIX_SOCKET=/var/run/docker.sock |
| 31 | DOCKER_PID_FILE=/var/run/docker.pid |
| 32 | DOCKER_REGISTRY_PORT=${DOCKER_REGISTRY_PORT:-5042} |
| 33 | |
Eric Windisch | 97ce935 | 2014-01-31 01:40:50 -0500 | [diff] [blame^] | 34 | DOCKER_IMAGE=${DOCKER_IMAGE:-cirros:latest} |
| 35 | DOCKER_IMAGE_NAME=cirros |
Eric Windisch | 2dac885 | 2014-01-31 01:25:28 -0500 | [diff] [blame] | 36 | DOCKER_REGISTRY_IMAGE=${DOCKER_REGISTRY_IMAGE:-registry:latest} |
| 37 | DOCKER_REGISTRY_IMAGE_NAME=registry |
Dean Troyer | 2aa2a89 | 2013-08-04 19:53:19 -0500 | [diff] [blame] | 38 | DOCKER_REPOSITORY_NAME=${SERVICE_HOST}:${DOCKER_REGISTRY_PORT}/${DOCKER_IMAGE_NAME} |
| 39 | |
Dean Troyer | 2aa2a89 | 2013-08-04 19:53:19 -0500 | [diff] [blame] | 40 | DOCKER_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 |
| 47 | function 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 |
| 55 | function configure_nova_hypervisor() { |
Dean Troyer | 2aa2a89 | 2013-08-04 19:53:19 -0500 | [diff] [blame] | 56 | iniset $NOVA_CONF DEFAULT compute_driver docker.DockerDriver |
| 57 | iniset $GLANCE_API_CONF DEFAULT container_formats ami,ari,aki,bare,ovf,docker |
Dean Troyer | 2aa2a89 | 2013-08-04 19:53:19 -0500 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | # install_nova_hypervisor() - Install external components |
| 61 | function 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 Alba | 5a77d03 | 2013-10-21 16:17:30 -0700 | [diff] [blame] | 68 | if ! is_package_installed lxc-docker; then |
Dean Troyer | 2aa2a89 | 2013-08-04 19:53:19 -0500 | [diff] [blame] | 69 | 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 |
| 80 | function 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 |
| 114 | function 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: |