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
This commit is contained in:
Alexey Ovchinnikov 2016-04-14 12:05:58 +03:00
parent 12eac6e6cb
commit b8ce11524a
4 changed files with 96 additions and 0 deletions

20
data/docker/Dockerfile Normal file
View File

@ -0,0 +1,20 @@
FROM phusion/baseimage:0.9.18
EXPOSE 445
EXPOSE 139
EXPOSE 135
CMD ["/sbin/my_init"]
RUN apt-get update && apt-get install -y samba smbclient
RUN mkdir /shares
RUN chmod 0777 /shares
RUN adduser --disabled-password --gecos '' master
RUN (echo pwd; echo pwd) | smbpasswd -a -s master
RUN sed -i "/\[global\]/a\ \ \ include = registry" /etc/samba/smb.conf
RUN apt-get clean
entrypoint ["/usr/sbin/smbd"]
cmd ["-F", "-S"]

71
tools/docker_builder.sh Executable file
View File

@ -0,0 +1,71 @@
#!/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

View File

@ -6,4 +6,6 @@ if [ "$IMAGE" = "generic" ]; then
tox -v -e buildimage tox -v -e buildimage
elif [ "$IMAGE" = "lxd" ]; then elif [ "$IMAGE" = "lxd" ]; then
tox -v -e buildimage-lxd tox -v -e buildimage-lxd
elif [ "$IMAGE" = "docker" ]; then
tox -v -e buildimage-docker
fi fi

View File

@ -32,6 +32,9 @@ commands = manila-image-create
deps = deps =
-r{toxinidir}/requirements.txt -r{toxinidir}/requirements.txt
[testenv:buildimage-docker]
commands = {toxinidir}/tools/docker_builder.sh
[testenv:buildimage-lxd] [testenv:buildimage-lxd]
commands = manila-image-create lxd commands = manila-image-create lxd