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: |
| 5 | # VIRT_DRIVER=docker |
| 6 | |
| 7 | # Dependencies: |
| 8 | # ``functions`` file |
| 9 | # ``nova`` and ``glance`` configurations |
| 10 | |
| 11 | # install_nova_hypervisor - install any external requirements |
| 12 | # configure_nova_hypervisor - make configuration changes, including those to other services |
| 13 | # start_nova_hypervisor - start any external services |
| 14 | # stop_nova_hypervisor - stop any external services |
| 15 | # cleanup_nova_hypervisor - remove transient data and cache |
| 16 | |
| 17 | # Save trace setting |
| 18 | MY_XTRACE=$(set +o | grep xtrace) |
| 19 | set +o xtrace |
| 20 | |
| 21 | |
| 22 | # Defaults |
| 23 | # -------- |
| 24 | |
| 25 | # Set up default directories |
| 26 | DOCKER_DIR=$DEST/docker |
| 27 | DOCKER_REPO=${DOCKER_REPO:-https://github.com/dotcloud/openstack-docker.git} |
| 28 | DOCKER_BRANCH=${DOCKER_BRANCH:-master} |
| 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 | |
| 34 | DOCKER_IMAGE=${DOCKER_IMAGE:-http://get.docker.io/images/openstack/docker-ut.tar.gz} |
| 35 | DOCKER_IMAGE_NAME=docker-busybox |
| 36 | DOCKER_REGISTRY_IMAGE=${DOCKER_REGISTRY_IMAGE:-http://get.docker.io/images/openstack/docker-registry.tar.gz} |
| 37 | DOCKER_REGISTRY_IMAGE_NAME=docker-registry |
| 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() { |
| 56 | git_clone $DOCKER_REPO $DOCKER_DIR $DOCKER_BRANCH |
| 57 | |
| 58 | ln -snf ${DOCKER_DIR}/nova-driver $NOVA_DIR/nova/virt/docker |
| 59 | |
| 60 | iniset $NOVA_CONF DEFAULT compute_driver docker.DockerDriver |
| 61 | iniset $GLANCE_API_CONF DEFAULT container_formats ami,ari,aki,bare,ovf,docker |
| 62 | |
| 63 | sudo cp -p ${DOCKER_DIR}/nova-driver/docker.filters $NOVA_CONF_DIR/rootwrap.d |
| 64 | } |
| 65 | |
| 66 | # install_nova_hypervisor() - Install external components |
| 67 | function install_nova_hypervisor() { |
| 68 | # So far this is Ubuntu only |
| 69 | if ! is_ubuntu; then |
| 70 | die $LINENO "Docker is only supported on Ubuntu at this time" |
| 71 | fi |
| 72 | |
| 73 | # Make sure Docker is installed |
Sam Alba | 5a77d03 | 2013-10-21 16:17:30 -0700 | [diff] [blame^] | 74 | if ! is_package_installed lxc-docker; then |
Dean Troyer | 2aa2a89 | 2013-08-04 19:53:19 -0500 | [diff] [blame] | 75 | die $LINENO "Docker is not installed. Please run tools/docker/install_docker.sh" |
| 76 | fi |
| 77 | |
| 78 | local docker_pid |
| 79 | read docker_pid <$DOCKER_PID_FILE |
| 80 | if [[ -z $docker_pid ]] || ! ps -p $docker_pid | grep [d]ocker; then |
| 81 | die $LINENO "Docker not running" |
| 82 | fi |
| 83 | } |
| 84 | |
| 85 | # start_nova_hypervisor - Start any required external services |
| 86 | function start_nova_hypervisor() { |
| 87 | local docker_pid |
| 88 | read docker_pid <$DOCKER_PID_FILE |
| 89 | if [[ -z $docker_pid ]] || ! ps -p $docker_pid | grep [d]ocker; then |
| 90 | die $LINENO "Docker not running, start the daemon" |
| 91 | fi |
| 92 | |
| 93 | # Start the Docker registry container |
| 94 | docker run -d -p ${DOCKER_REGISTRY_PORT}:5000 \ |
| 95 | -e SETTINGS_FLAVOR=openstack -e OS_USERNAME=${OS_USERNAME} \ |
| 96 | -e OS_PASSWORD=${OS_PASSWORD} -e OS_TENANT_NAME=${OS_TENANT_NAME} \ |
| 97 | -e OS_GLANCE_URL="${SERVICE_PROTOCOL}://${GLANCE_HOSTPORT}" \ |
| 98 | -e OS_AUTH_URL=${OS_AUTH_URL} \ |
| 99 | $DOCKER_REGISTRY_IMAGE_NAME ./docker-registry/run.sh |
| 100 | |
| 101 | echo "Waiting for docker registry to start..." |
| 102 | DOCKER_REGISTRY=${SERVICE_HOST}:${DOCKER_REGISTRY_PORT} |
| 103 | if ! timeout $SERVICE_TIMEOUT sh -c "while ! curl -s $DOCKER_REGISTRY; do sleep 1; done"; then |
| 104 | die $LINENO "docker-registry did not start" |
| 105 | fi |
| 106 | |
| 107 | # Tag image if not already tagged |
| 108 | if ! docker images | grep $DOCKER_REPOSITORY_NAME; then |
| 109 | docker tag $DOCKER_IMAGE_NAME $DOCKER_REPOSITORY_NAME |
| 110 | fi |
| 111 | |
| 112 | # Make sure we copied the image in Glance |
| 113 | DOCKER_IMAGE=$(glance image-list | egrep " $DOCKER_IMAGE_NAME ") |
| 114 | if ! is_set DOCKER_IMAGE ; then |
| 115 | docker push $DOCKER_REPOSITORY_NAME |
| 116 | fi |
| 117 | } |
| 118 | |
| 119 | # stop_nova_hypervisor - Stop any external services |
| 120 | function stop_nova_hypervisor() { |
| 121 | # Stop the docker registry container |
| 122 | docker kill $(docker ps | grep docker-registry | cut -d' ' -f1) |
| 123 | } |
| 124 | |
| 125 | |
| 126 | # Restore xtrace |
| 127 | $MY_XTRACE |
| 128 | |
| 129 | # Local variables: |
| 130 | # mode: shell-script |
| 131 | # End: |