Sunday, January 11, 2015

Set up Nova-Docker on OpenStack RDO Juno on top of Fedora 21

****************************************************************************************
UPDATE as of 01/31/2015 to get Docker && Nova-Docker working on Fedora 21
****************************************************************************************
Per https://github.com/docker/docker/issues/10280
download systemd-218-3.fc22.src.rpm && build 218-3 rpms and upgrade systemd.

First set up  packages for rpmbuild :-

 $ sudo yum install audit-libs-devel autoconf  automake cryptsetup-devel \
    dbus-devel docbook-style-xsl elfutils-devel  \
    glib2-devel  gnutls-devel  gobject-introspection-devel \
    gperf     gtk-doc intltool kmod-devel libacl-devel \
    libblkid-devel     libcap-devel libcurl-devel libgcrypt-devel \
    libidn-devel libmicrohttpd-devel libmount-devel libseccomp-devel \
    libselinux-devel libtool pam-devel python3-devel python3-lxml \
    qrencode-devel  python2-devel  xz-devel 

Second :-

 $ cd rpmbuild/SPEC
 $ rpmbuild -bb systemd.spec
 $ cd ../RPMS/x86_64

Third :-

$ yum install libgudev1-218-3.fc21.x86_64.rpm \
libgudev1-devel-218-3.fc21.x86_64.rpm \
systemd-218-3.fc21.x86_64.rpm \
systemd-compat-libs-218-3.fc21.x86_64.rpm \
systemd-debuginfo-218-3.fc21.x86_64.rpm \
systemd-devel-218-3.fc21.x86_64.rpm \
systemd-journal-gateway-218-3.fc21.x86_64.rpm \
systemd-libs-218-3.fc21.x86_64.rpm \
systemd-python-218-3.fc21.x86_64.rpm \
systemd-python3-218-3.fc21.x86_64.rpm

  View also  https://ask.openstack.org/en/question/59789/attempt-to-install-nova-docker-driver-on-fedora-21/

***************************************************************************************
  Recently Filip Krikava made a fork on github and created a Juno branch using
the latest commit +  Fix the problem when an image is not located in the local docker image registry

 Master https://github.com/stackforge/nova-docker.git is targeting latest Nova ( Kilo release ), forked branch is supposed to work for Juno , reasonably including commits after "Merge oslo.i18n". Posting bellow is supposed to test Juno Branch https://github.com/fikovnik/nova-docker.git


Quote ([2]) :-

The Docker driver is a hypervisor driver for Openstack Nova Compute. It was introduced with the Havana release, but lives out-of-tree for Icehouse and Juno. Being out-of-tree has allowed the driver to reach maturity and feature-parity faster than would be possible should it have remained in-tree. It is expected the driver will return to mainline Nova in the Kilo release.
 


*****************************************************
As of 11/12/2014 third line may be per official fork
https://github.com/stackforge/nova-docker/tree/stable/juno
# git clone https://github.com/stackforge/nova-docker *****************************************************


***************************
Initial docker setup
***************************

# yum install docker-io -y
# yum install -y python-pip git
# git clone https://github.com/fikovnik/nova-docker.git
# cd nova-docker
# git branch -v -a

   master                1ed1820 A note no firewall drivers.
  remotes/origin/HEAD   -> origin/master
  remotes/origin/juno   1a08ea5 Fix the problem when an image
            is not located in the local docker image registry.
  remotes/origin/master 1ed1820 A note no firewall drivers.
# git checkout -b juno origin/juno
# python setup.py install
# systemctl start docker
# systemctl enable docker
# chmod 660  /var/run/docker.sock
# pip install pbr
#  mkdir /etc/nova/rootwrap.d


Just after `python setup.py install` six version might drop to 1.2
in this case run `pip install --upgrade six` and 1.7.3 will be back
again.

Setup via official branch

***************************
Initial docker setup
***************************
# yum install python-pbr

# yum install docker-io -y
# yum install -y python-pip git
 
# git clone https://github.com/stackforge/nova-docker
# cd nova-docker
# git checkout stable/juno
# python setup.py install
# systemctl start docker
# systemctl enable docker
# chmod 660  /var/run/docker.sock
# pip install pbr
#  mkdir /etc/nova/rootwrap.d


**************************************************************
On Fedora 21 even running systemd 218-3 you should expect
six.__version__  to be dropped to 1.2 right after `python setup.py install`

Then run:-

# pip install --upgrade six

Downloading/unpacking six from https://pypi.python.org/packages/3.3/s/six/six-1.9.0-py2.py3-none-any.whl#md5=9ac7e129a80f72d6fc1f0216f6e9627b
  Downloading six-1.9.0-py2.py3-none-any.whl
Installing collected packages: six
  Found existing installation: six 1.7.3
    Uninstalling six:
      Successfully uninstalled six
Successfully installed six
Cleaning up...
**************************************************************

Proceed as normal.


******************************
Update nova.conf
******************************
vi /etc/nova/nova.conf
set "compute_driver = novadocker.virt.docker.DockerDriver"

************************************************
Next, create the docker.filters file:
************************************************

vi /etc/nova/rootwrap.d/docker.filters

Insert Lines

# nova-rootwrap command filters for setting up network in the docker driver
# This file should be owned by (and only-writeable by) the root user
[Filters]
# nova/virt/docker/driver.py: 'ln', '-sf', '/var/run/netns/.*'
ln: CommandFilter, /bin/ln, root

*****************************************
Add line /etc/glance/glance-api.conf
*****************************************
container_formats=ami,ari,aki,bare,ovf,ova,docker
:wq

************************
Restart Services
************************
usermod -G docker nova
systemctl restart openstack-nova-compute
systemctl status openstack-nova-compute
systemctl restart openstack-glance-api
Following bellow is Dockerfile been used to build image for GlassFish 4.1 nova-docker container extending  phusion/baseimage and starting three daemons
at a time when launching nova-docker instance been built via image been prepared to be used by Nova-Docker driver on Juno

*******************************************************************************
Verification nova-docker driver  been  built on Fedora 21
*******************************************************************************

Build bellow is extending  phusion/baseimage to start several daemons at a time
during launching nova-docker container. It has been tested on Nova-Docker RDO
Juno on top of CentOS 7 ( view Set up GlassFish 4.1 Nova-Docker Container via phusion/baseimage on RDO Juno ). Here it is reproduced on Nova-Docker RDO Juno on top of Fedora 21 coming afterwards `packstack --allinone` Juno installation on Fedora 21,  been run pretty smoothly .

*******************************************************************************
To   bring sshd back to life  create in building folder script  01_sshd_start.sh
*******************************************************************************
#!/bin/bash

if [[ ! -e /etc/ssh/ssh_host_rsa_key ]]; then
    echo "No SSH host key available. Generating one..."
    export LC_ALL=C
    export DEBIAN_FRONTEND=noninteractive
    dpkg-reconfigure openssh-server
    echo "SSH KEYS REDONE !"
fi
/usr/sbin/sshd > log &

and insert in Dockerfile:-

ADD 01_sshd_start.sh /etc/my_init.d/

*********************************************************************************
 Following bellow is Dockerfile been used to build image for GlassFish 4.1 nova-docker container extending  phusion/baseimage and starting three daemons
at a time when launching nova-docker instance been built via image been prepared to be used by Nova-Docker driver on Juno
**********************************************************************************

 FROM phusion/baseimage

MAINTAINER Boris Derzhavets

RUN apt-get update
RUN echo 'root:root' |chpasswd
RUN sed -ri 's/^PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config

RUN apt-get update && apt-get install -y wget
RUN wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25-linux-x64.tar.gz
RUN cp  jdk-8u25-linux-x64.tar.gz /opt
RUN cd /opt; tar -zxvf jdk-8u25-linux-x64.tar.gz
ENV PATH /opt/jdk1.8.0_25/bin:$PATH


RUN apt-get update && \
    apt-get install -y wget unzip pwgen expect net-tools vim && \
    wget http://download.java.net/glassfish/4.1/release/glassfish-4.1.zip && \
    unzip glassfish-4.1.zip -d /opt && \
    rm glassfish-4.1.zip && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

ENV PATH /opt/glassfish4/bin:$PATH

ADD 01_sshd_start.sh  /etc/my_init.d
ADD run.sh /etc/my_init.d/
ADD database.sh  /etc/my_init.d/
ADD change_admin_password.sh /change_admin_password.sh
ADD change_admin_password_func.sh /change_admin_password_func.sh
ADD enable_secure_admin.sh /enable_secure_admin.sh
RUN chmod +x /*.sh /etc/my_init.d/*.sh

# 4848 (administration), 8080 (HTTP listener), 8181 (HTTPS listener), 9009 (JPDA debug port)
EXPOSE 22  4848 8080 8181 9009

CMD ["/sbin/my_init"]


********************************************************************************
I had to update database.sh script as follows to make nova-docker container
starting  on RDO Juno on top of Fedora 21 ( view http://lxer.com/module/newswire/view/209277/index.html ).
********************************************************************************
# cat database.sh

#!/bin/bash

set -e
asadmin start-database --dbhost 127.0.0.1 --terse=true > log &

echo "Derby database started !"

the important  change is binding dbhost to 127.0.0.1 , which  is not required for loading docker container. Nova-Docker Driver ( http://www.linux.com/community/blogs/133-general-linux/799569-running-nova-docker-on-openstack-rdo-juno-centos-7 ) seems to be more picky about --dbhost  key value of Derby Database

*********************
Build image
*********************

[root@junolxc docker-glassfish41]# ls -l
total 44
-rw-r--r--. 1 root root   217 Jan  7 00:27 change_admin_password_func.sh
-rw-r--r--. 1 root root   833 Jan  7 00:27 change_admin_password.sh
-rw-r--r--. 1 root root   473 Jan  7 00:27 circle.yml
-rw-r--r--. 1 root root    44 Jan  7 00:27 database.sh
-rw-r--r--. 1 root root  1287 Jan  7 00:27 Dockerfile
-rw-r--r--. 1 root root   167 Jan  7 00:27 enable_secure_admin.sh
-rw-r--r--. 1 root root 11323 Jan  7 00:27 LICENSE
-rw-r--r--. 1 root root  2123 Jan  7 00:27 README.md
-rw-r--r--. 1 root root   354 Jan  7 00:27 run.sh

[root@junolxc docker-glassfish41]# docker build -t derby/docker-glassfish41 .

*************************
Upload image to glance
*************************

# . keystonerc_admin
# docker save derby/docker-glassfish41:latest | glance image-create --is-public=True   --container-format=docker --disk-format=raw --name derby/docker-glassfish41:latest

**********************
Launch instance
**********************
# .  keystonerc_demo
# nova boot --image "derby/docker-glassfish41:latest" --flavor m1.small --key-name  oskey57    --nic net-id=demo_network-id DerbyGlassfish41


 

 

  

 
 

[root@fedora21 docker-glassfish41(keystone_admin)]# docker logs 4eb390cf155d
*** Running /etc/my_init.d/00_regen_ssh_host_keys.sh...
No SSH host key available. Generating one...
Creating SSH2 RSA key; this may take some time ...
Creating SSH2 DSA key; this may take some time ...
Creating SSH2 ECDSA key; this may take some time ...
Creating SSH2 ED25519 key; this may take some time ...
invoke-rc.d: policy-rc.d denied execution of restart.
*** Running /etc/my_init.d/database.sh...
Derby database started !
*** Running /etc/my_init.d/run.sh...
Bad Network Configuration.  DNS can not resolve the hostname:
java.net.UnknownHostException: instance-0000000d: instance-0000000d: unknown error
Waiting for domain1 to start ...........
Successfully started the domain : domain1
domain  Location: /opt/glassfish4/glassfish/domains/domain1
Log File: /opt/glassfish4/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.
=> Modifying password of admin to random in Glassfish
spawn asadmin --user admin change-admin-password
Enter the admin password>
Enter the new admin password>
Enter the new admin password again>
Command change-admin-password executed successfully.
=> Enabling secure admin login
spawn asadmin enable-secure-admin
Enter admin user name>  admin
Enter admin password for user "admin">
You must restart all running servers for the change in secure admin to take effect.
Command enable-secure-admin executed successfully.
=> Done!
========================================================================
You can now connect to this Glassfish server using:

     admin:H5V0x7fVKKWu

Please remember to change the above password as soon as possible!
========================================================================
=> Restarting Glassfish server
Waiting for the domain to stop .
Command stop-domain executed successfully.
=> Starting and running Glassfish server
=> Debug mode is set to: false
Bad Network Configuration.  DNS can not resolve the hostname:
java.net.UnknownHostException: instance-0000000d: instance-0000000d: unknown error