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 |
| 29 | DOCKER_REPO=${DOCKER_REPO:-https://github.com/dotcloud/openstack-docker.git} |
| 30 | DOCKER_BRANCH=${DOCKER_BRANCH:-master} |
| 31 | |
| 32 | DOCKER_UNIX_SOCKET=/var/run/docker.sock |
| 33 | DOCKER_PID_FILE=/var/run/docker.pid |
| 34 | DOCKER_REGISTRY_PORT=${DOCKER_REGISTRY_PORT:-5042} |
| 35 | |
| 36 | DOCKER_IMAGE=${DOCKER_IMAGE:-http://get.docker.io/images/openstack/docker-ut.tar.gz} |
| 37 | DOCKER_IMAGE_NAME=docker-busybox |
| 38 | DOCKER_REGISTRY_IMAGE=${DOCKER_REGISTRY_IMAGE:-http://get.docker.io/images/openstack/docker-registry.tar.gz} |
| 39 | DOCKER_REGISTRY_IMAGE_NAME=docker-registry |
| 40 | DOCKER_REPOSITORY_NAME=${SERVICE_HOST}:${DOCKER_REGISTRY_PORT}/${DOCKER_IMAGE_NAME} |
| 41 | |
| 42 | DOCKER_PACKAGE_VERSION=${DOCKER_PACKAGE_VERSION:-0.6.1} |
| 43 | DOCKER_APT_REPO=${DOCKER_APT_REPO:-https://get.docker.io/ubuntu} |
| 44 | |
| 45 | |
| 46 | # Entry Points |
| 47 | # ------------ |
| 48 | |
| 49 | # clean_nova_hypervisor - Clean up an installation |
| 50 | function cleanup_nova_hypervisor() { |
| 51 | stop_service docker |
| 52 | |
| 53 | # Clean out work area |
| 54 | sudo rm -rf /var/lib/docker |
| 55 | } |
| 56 | |
| 57 | # configure_nova_hypervisor - Set config files, create data dirs, etc |
| 58 | function configure_nova_hypervisor() { |
| 59 | git_clone $DOCKER_REPO $DOCKER_DIR $DOCKER_BRANCH |
| 60 | |
| 61 | ln -snf ${DOCKER_DIR}/nova-driver $NOVA_DIR/nova/virt/docker |
| 62 | |
| 63 | iniset $NOVA_CONF DEFAULT compute_driver docker.DockerDriver |
| 64 | iniset $GLANCE_API_CONF DEFAULT container_formats ami,ari,aki,bare,ovf,docker |
| 65 | |
| 66 | sudo cp -p ${DOCKER_DIR}/nova-driver/docker.filters $NOVA_CONF_DIR/rootwrap.d |
| 67 | } |
| 68 | |
| 69 | # install_nova_hypervisor() - Install external components |
| 70 | function install_nova_hypervisor() { |
| 71 | # So far this is Ubuntu only |
| 72 | if ! is_ubuntu; then |
| 73 | die $LINENO "Docker is only supported on Ubuntu at this time" |
| 74 | fi |
| 75 | |
| 76 | # Make sure Docker is installed |
Min Li | fdc9ae8 | 2013-10-09 15:45:41 -0400 | [diff] [blame] | 77 | if ! is_package_installed lxc-docker-${DOCKER_PACKAGE_VERSION}; then |
Dean Troyer | 2aa2a89 | 2013-08-04 19:53:19 -0500 | [diff] [blame] | 78 | die $LINENO "Docker is not installed. Please run tools/docker/install_docker.sh" |
| 79 | fi |
| 80 | |
| 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" |
| 85 | fi |
| 86 | } |
| 87 | |
| 88 | # start_nova_hypervisor - Start any required external services |
| 89 | function start_nova_hypervisor() { |
| 90 | local docker_pid |
| 91 | read docker_pid <$DOCKER_PID_FILE |
| 92 | if [[ -z $docker_pid ]] || ! ps -p $docker_pid | grep [d]ocker; then |
| 93 | die $LINENO "Docker not running, start the daemon" |
| 94 | fi |
| 95 | |
| 96 | # Start the Docker registry container |
| 97 | docker run -d -p ${DOCKER_REGISTRY_PORT}:5000 \ |
| 98 | -e SETTINGS_FLAVOR=openstack -e OS_USERNAME=${OS_USERNAME} \ |
| 99 | -e OS_PASSWORD=${OS_PASSWORD} -e OS_TENANT_NAME=${OS_TENANT_NAME} \ |
| 100 | -e OS_GLANCE_URL="${SERVICE_PROTOCOL}://${GLANCE_HOSTPORT}" \ |
| 101 | -e OS_AUTH_URL=${OS_AUTH_URL} \ |
| 102 | $DOCKER_REGISTRY_IMAGE_NAME ./docker-registry/run.sh |
| 103 | |
| 104 | echo "Waiting for docker registry to start..." |
| 105 | DOCKER_REGISTRY=${SERVICE_HOST}:${DOCKER_REGISTRY_PORT} |
| 106 | if ! timeout $SERVICE_TIMEOUT sh -c "while ! curl -s $DOCKER_REGISTRY; do sleep 1; done"; then |
| 107 | die $LINENO "docker-registry did not start" |
| 108 | fi |
| 109 | |
| 110 | # Tag image if not already tagged |
| 111 | if ! docker images | grep $DOCKER_REPOSITORY_NAME; then |
| 112 | docker tag $DOCKER_IMAGE_NAME $DOCKER_REPOSITORY_NAME |
| 113 | fi |
| 114 | |
| 115 | # Make sure we copied the image in Glance |
| 116 | DOCKER_IMAGE=$(glance image-list | egrep " $DOCKER_IMAGE_NAME ") |
| 117 | if ! is_set DOCKER_IMAGE ; then |
| 118 | docker push $DOCKER_REPOSITORY_NAME |
| 119 | fi |
| 120 | } |
| 121 | |
| 122 | # stop_nova_hypervisor - Stop any external services |
| 123 | function stop_nova_hypervisor() { |
| 124 | # Stop the docker registry container |
| 125 | docker kill $(docker ps | grep docker-registry | cut -d' ' -f1) |
| 126 | } |
| 127 | |
| 128 | |
| 129 | # Restore xtrace |
| 130 | $MY_XTRACE |
| 131 | |
| 132 | # Local variables: |
| 133 | # mode: shell-script |
| 134 | # End: |