blob: 2e5b510c41aaa28813ccf042d2b758d39a14cb74 [file] [log] [blame]
Dean Troyer2aa2a892013-08-04 19:53:19 -05001#!/usr/bin/env bash
2
3# **install_docker.sh** - Do the initial Docker installation and configuration
4
5# install_docker.sh
6#
7# Install docker package and images
8# * downloads a base busybox image and a glance registry image if necessary
9# * install the images in Docker's image cache
10
11
12# Keep track of the current directory
13SCRIPT_DIR=$(cd $(dirname "$0") && pwd)
14TOP_DIR=$(cd $SCRIPT_DIR/../..; pwd)
15
16# Import common functions
17source $TOP_DIR/functions
18
19# Load local configuration
20source $TOP_DIR/stackrc
21
22FILES=$TOP_DIR/files
23
24# Get our defaults
25source $TOP_DIR/lib/nova_plugins/hypervisor-docker
26
27SERVICE_TIMEOUT=${SERVICE_TIMEOUT:-60}
28
29
30# Install Docker Service
31# ======================
32
33# Stop the auto-repo updates and do it when required here
34NO_UPDATE_REPOS=True
35
36# Set up home repo
37curl https://get.docker.io/gpg | sudo apt-key add -
38install_package python-software-properties && \
39 sudo sh -c "echo deb $DOCKER_APT_REPO docker main > /etc/apt/sources.list.d/docker.list"
40apt_get update
Sam Alba5a77d032013-10-21 16:17:30 -070041install_package --force-yes lxc-docker socat
Dean Troyer2aa2a892013-08-04 19:53:19 -050042
43# Start the daemon - restart just in case the package ever auto-starts...
44restart_service docker
45
46echo "Waiting for docker daemon to start..."
47DOCKER_GROUP=$(groups | cut -d' ' -f1)
48CONFIGURE_CMD="while ! /bin/echo -e 'GET /v1.3/version HTTP/1.0\n\n' | socat - unix-connect:$DOCKER_UNIX_SOCKET | grep -q '200 OK'; do
49 # Set the right group on docker unix socket before retrying
50 sudo chgrp $DOCKER_GROUP $DOCKER_UNIX_SOCKET
51 sudo chmod g+rw $DOCKER_UNIX_SOCKET
52 sleep 1
53done"
54if ! timeout $SERVICE_TIMEOUT sh -c "$CONFIGURE_CMD"; then
55 die $LINENO "docker did not start"
56fi
57
58
59# Get Docker image
60if [[ ! -r $FILES/docker-ut.tar.gz ]]; then
61 (cd $FILES; curl -OR $DOCKER_IMAGE)
62fi
63if [[ ! -r $FILES/docker-ut.tar.gz ]]; then
64 die $LINENO "Docker image unavailable"
65fi
66docker import - $DOCKER_IMAGE_NAME <$FILES/docker-ut.tar.gz
67
68# Get Docker registry image
69if [[ ! -r $FILES/docker-registry.tar.gz ]]; then
70 (cd $FILES; curl -OR $DOCKER_REGISTRY_IMAGE)
71fi
72if [[ ! -r $FILES/docker-registry.tar.gz ]]; then
73 die $LINENO "Docker registry image unavailable"
74fi
75docker import - $DOCKER_REGISTRY_IMAGE_NAME <$FILES/docker-registry.tar.gz