Add docker installation script
There are several projects that tried to install docker in different ways. This potentially lead to failure of more than one such services were enabled. This commit consolidate docker installation into a devstack plugin so that other services could depend on it. The initial script was mainly from Kuryr-libnetwork. Kuryr, Fuxi, and Zun might leverage this script to install Docker in the future. Change-Id: I97dbff2f361acc98b12ec6f40ab115c8548477a3
This commit is contained in:
parent
a115b2648a
commit
69716eb42f
|
@ -0,0 +1,20 @@
|
|||
=================
|
||||
Container Plugin
|
||||
=================
|
||||
|
||||
This plugin enables installation of container engine on Devstack. The default
|
||||
container engine is Docker.
|
||||
|
||||
======================
|
||||
Enabling in Devstack
|
||||
======================
|
||||
|
||||
1. Download DevStack
|
||||
|
||||
2. Add this repo as an external repository::
|
||||
|
||||
> cat local.conf
|
||||
[[local|localrc]]
|
||||
enable_plugin devstack-plugin-container https://github.com/openstack/devstack-plugin-container
|
||||
|
||||
3. run ``stack.sh``
|
|
@ -0,0 +1,106 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Dependencies:
|
||||
#
|
||||
# - functions
|
||||
# - ``STACK_USER`` must be defined
|
||||
# - ``ETCD_PORT`` must be defined if on swarm mode
|
||||
|
||||
# stack.sh
|
||||
# ---------
|
||||
# - install_docker
|
||||
|
||||
# Save trace setting
|
||||
_XTRACE_DOCKER=$(set +o | grep xtrace)
|
||||
set +o xtrace
|
||||
|
||||
|
||||
# Defaults
|
||||
# --------
|
||||
|
||||
DOCKER_ENGINE_SOCKET_FILE=${DOCKER_ENGINE_SOCKET_FILE:-/var/run/docker.sock}
|
||||
DOCKER_ENGINE_PORT=${DOCKER_ENGINE_PORT:-2375}
|
||||
SWARM_MODE=$(trueorfalse False SWARM_MODE)
|
||||
|
||||
|
||||
# Functions
|
||||
# ---------
|
||||
|
||||
function check_docker {
|
||||
if is_ubuntu; then
|
||||
dpkg -s docker-engine > /dev/null 2>&1 || dpkg -s docker-ce > /dev/null 2>&1
|
||||
else
|
||||
rpm -q docker-engine > /dev/null 2>&1 || rpm -q docker > /dev/null 2>&1 || rpm -q docker-ce > /dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
function install_docker {
|
||||
if [[ -z "$os_PACKAGE" ]]; then
|
||||
GetOSVersion
|
||||
fi
|
||||
|
||||
local lsb_dist=${os_VENDOR,,}
|
||||
local dist_version=${os_CODENAME}
|
||||
local arch=$(dpkg --print-architecture)
|
||||
if is_ubuntu; then
|
||||
apt_get install linux-image-extra-$(uname -r) linux-image-extra-virtual
|
||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
|
||||
sudo add-apt-repository -y \
|
||||
"deb [arch=${arch}] https://download.docker.com/linux/${lsb_dist} \
|
||||
${dist_version} \
|
||||
stable"
|
||||
REPOS_UPDATED=False apt_get_update
|
||||
apt_get install docker-ce
|
||||
elif is_fedora; then
|
||||
if [[ "$lsb_dist" = "centos" ]]; then
|
||||
sudo yum-config-manager \
|
||||
--add-repo \
|
||||
https://download.docker.com/linux/centos/docker-ce.repo
|
||||
elif [[ "$lsb_dist" = "fedora" ]]; then
|
||||
sudo dnf config-manager \
|
||||
--add-repo \
|
||||
https://download.docker.com/linux/fedora/docker-ce.repo
|
||||
fi
|
||||
yum_install docker-ce
|
||||
fi
|
||||
}
|
||||
|
||||
function configure_docker {
|
||||
# After an ./unstack it will be stopped. So it is ok if it returns exit-code == 1
|
||||
sudo systemctl stop docker.service || true
|
||||
|
||||
local cluster_store_opts=""
|
||||
if [[ "$SWARM_MODE" = "True" ]]; then
|
||||
cluster_store_opts+="\"cluster-store\": \"etcd://localhost:$ETCD_PORT\","
|
||||
fi
|
||||
local docker_config_file=/etc/docker/daemon.json
|
||||
sudo mkdir -p $(dirname ${docker_config_file})
|
||||
cat <<EOF | sudo tee $docker_config_file >/dev/null
|
||||
{
|
||||
$cluster_store_opts
|
||||
"group": "$STACK_USER",
|
||||
"hosts": [
|
||||
"unix://$DOCKER_ENGINE_SOCKET_FILE",
|
||||
"tcp://0.0.0.0:$DOCKER_ENGINE_PORT"
|
||||
]
|
||||
}
|
||||
EOF
|
||||
# NOTE(hongbin): We override ExecStart to workaround issue 22339.
|
||||
# https://github.com/docker/docker/issues/22339
|
||||
local docker_drop_in_file=/etc/systemd/system/docker.service.d/docker.conf
|
||||
sudo mkdir -p $(dirname ${docker_drop_in_file})
|
||||
cat <<EOF | sudo tee $docker_drop_in_file >/dev/null
|
||||
[Service]
|
||||
ExecStart=
|
||||
ExecStart=/usr/bin/dockerd --config-file=$docker_config_file
|
||||
EOF
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl --no-block restart docker.service
|
||||
}
|
||||
|
||||
function stop_docker {
|
||||
sudo systemctl stop docker.service || true
|
||||
}
|
||||
|
||||
# Restore xtrace
|
||||
$_XTRACE_DOCKER
|
|
@ -0,0 +1,37 @@
|
|||
# container - Devstack extras script to install container engine
|
||||
|
||||
# Save trace setting
|
||||
XTRACE=$(set +o | grep xtrace)
|
||||
set -o xtrace
|
||||
|
||||
echo_summary "container's plugin.sh was called..."
|
||||
source $DEST/devstack-plugin-container/devstack/lib/docker
|
||||
(set -o posix; set)
|
||||
|
||||
if is_service_enabled container; then
|
||||
if [[ "$1" == "stack" && "$2" == "install" ]]; then
|
||||
echo_summary "Installing container engine"
|
||||
if [[ ${CONTAINER_ENGINE} == "docker" ]]; then
|
||||
check_docker || install_docker
|
||||
fi
|
||||
elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
|
||||
echo_summary "Configuring container engine"
|
||||
if [[ ${CONTAINER_ENGINE} == "docker" ]]; then
|
||||
configure_docker
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$1" == "unstack" ]]; then
|
||||
if [[ ${CONTAINER_ENGINE} == "docker" ]]; then
|
||||
stop_docker
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$1" == "clean" ]]; then
|
||||
# nothing needed here
|
||||
:
|
||||
fi
|
||||
fi
|
||||
|
||||
# Restore xtrace
|
||||
$XTRACE
|
|
@ -0,0 +1,6 @@
|
|||
# Devstack settings
|
||||
|
||||
CONTAINER_ENGINE=${CONTAINER_ENGINE:-docker}
|
||||
|
||||
# Enable container services
|
||||
enable_service container
|
Loading…
Reference in New Issue