manila-image-elements/tools/docker_builder.sh
Alexey Ovchinnikov b8ce11524a Add tox job for building Docker image
Add new job 'buildimage-docker' which produces a compressed
image from which a Docker container can be started. This
container is designed to run Samba.

Change-Id: I499fa1850d3ad197cab5f742bfca1a9f074e9a8b
2016-04-15 15:09:07 +03:00

72 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
MANILA_DOCKER_CONTAINER_NAME=${MANILA_DOCKER_CONTAINER_NAME:-"manila-docker-container"}
MANILA_DOCKER_CONTAINER_IMAGE_NAME=${MANILA_DOCKER_CONTAINER_IMAGE_NAME:-"$MANILA_DOCKER_CONTAINER_NAME.tar"}
if [ -e /etc/os-release ]; then
platform=$(cat /etc/os-release | awk -F= '/^ID=/ {print tolower($2);}')
# remove eventual quotes around ID=...
platform=$(echo $platform | sed -e 's,^",,;s,"$,,')
elif [ -e /etc/system-release ]; then
case "$(head -1 /etc/system-release)" in
"Red Hat Enterprise Linux Server"*)
platform=rhel
;;
"CentOS"*)
platform=centos
;;
*)
echo -e "Unknown value in /etc/system-release. Impossible to build images.\nAborting"
exit 2
;;
esac
else
echo -e "Unknown host OS. Impossible to build images.\nAborting"
exit 2
fi
is_docker_installed() {
package_name="docker"
if [ "$platform" = 'ubuntu' ]; then
dpkg -s "docker.io" &> /dev/null
else
# centos, fedora, opensuse, or rhel
if ! rpm -q "$package_name" &> /dev/null; then
rpm -q "$(rpm -q --whatprovides "$package_name")"
fi
fi
}
if ! is_docker_installed; then
echo "Docker is not found. Installing it."
case "$platform" in
"ubuntu")
sudo apt-get update
sudo apt-get install -y apparmor lxc cgroup-lite
sudo apt-get install -y docker.io
;;
"opensuse")
sudo zypper --non-interactive --gpg-auto-import-keys in docker
;;
"fedora" | "rhel" | "centos")
if [ ${platform} = "centos" ]; then
# install EPEL repo, in order to install argparse
sudo rpm -Uvh --force http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
fi
sudo yum install docker -y
;;
*)
echo -e "Unknown platform '$platform' for installing packages.\nAborting"
exit 2
;;
esac
else
echo "Docker is found."
fi
echo "Starting building a container."
sudo docker build -t $MANILA_DOCKER_CONTAINER_NAME data/docker
sudo docker save -o $MANILA_DOCKER_CONTAINER_IMAGE_NAME $MANILA_DOCKER_CONTAINER_NAME
sudo gzip -v --force $MANILA_DOCKER_CONTAINER_IMAGE_NAME