diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..88f5090 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,32 @@ +sudo: true + +addons: + apt: + sources: + - sourceline: 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse' + packages: + - shellcheck + +services: + - docker + +before_install: +- sudo apt-get update +- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-engine +- docker build -t gluster/client ./gluster-client/ +- docker run -it --name client gluster/client rpm -qa | grep gluster +- docker build -t gluster/centos ./CentOS/ +- docker run -d --name gcentos --privileged gluster/centos +- sleep 10 +- docker exec -it gcentos systemctl is-active glusterd +- docker build -t gluster/fedora ./Fedora/ +- docker run -d --name gfedora --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro gluster/fedora +- sleep 10 +- docker exec -it gfedora systemctl is-active glusterd +- docker build -t gluster/swift ./gluster-object/CentOS/docker-gluster-swift/ +- docker run -d --name swift --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro -e GLUSTER_VOLUMES=vol gluster/swift +- sleep 10 +- docker exec -it swift systemctl is-active swift-object + +script: +- make test diff --git a/CentOS/Dockerfile b/CentOS/Dockerfile index 7c0d448..db7a578 100644 --- a/CentOS/Dockerfile +++ b/CentOS/Dockerfile @@ -1,65 +1,51 @@ -FROM centos:latest +FROM centos:7 MAINTAINER Humble Chirammal hchiramm@redhat.com Mohamed Ashiq Liyazudeen mliyazud@redhat.com ENV container docker -RUN yum --setopt=tsflags=nodocs -y update; yum clean all; - -RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \ +LABEL architecture="x86_64" \ + name="gluster/gluster-centos" \ + version="3.10" \ + vendor="Red Hat, Inc" \ + summary="This image has a running glusterfs service ( CentOS 7 + Gluster 3.10)" \ + io.k8s.display-name="Gluster 3.10 based on CentOS 7" \ + io.k8s.description="Gluster Image is based on CentOS Image which is a scalable network filesystem. Using common off-the-shelf hardware, you can create large, distributed storage solutions for media streaming, data analysis, and other data- and bandwidth-intensive tasks." \ + description="Gluster Image is based on CentOS Image which is a scalable network filesystem. Using common off-the-shelf hardware, you can create large, distributed storage solutions for media streaming, data analysis, and other data- and bandwidth-intensive tasks." \ + io.openshift.tags="gluster,glusterfs,glusterfs-centos" + +RUN yum --setopt=tsflags=nodocs -y update; yum install -y centos-release-gluster; yum clean all; \ +(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \ rm -f /lib/systemd/system/multi-user.target.wants/*;\ rm -f /etc/systemd/system/*.wants/*;\ rm -f /lib/systemd/system/local-fs.target.wants/*; \ rm -f /lib/systemd/system/sockets.target.wants/*udev*; \ rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \ rm -f /lib/systemd/system/basic.target.wants/*;\ -rm -f /lib/systemd/system/anaconda.target.wants/*; - -RUN yum --setopt=tsflags=nodocs -y install wget nfs-utils attr iputils iproute centos-release-gluster - -RUN yum --setopt=tsflags=nodocs -y install openssh-server openssh-clients ntp rsync tar cronie sudo xfsprogs glusterfs glusterfs-server glusterfs-geo-replication;yum clean all; - -RUN sed -i '/Defaults requiretty/c\#Defaults requiretty' /etc/sudoers - -# Changing the port of sshd to avoid conflicting with host sshd -RUN sed -i '/Port 22/c\Port 2222' /etc/ssh/sshd_config - -# Fixing RPC port conflict issue -RUN sed -i 's/Requires\=rpcbind\.service//g' /usr/lib/systemd/system/glusterd.service - -RUN sed -i 's/rpcbind\.service/gluster-setup\.service/g' /usr/lib/systemd/system/glusterd.service - -# Fix for the separate /var on host issue -RUN sed -i 's/ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}=="1", ENV{SYSTEMD_READY}="0"/ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}=="1", GOTO="systemd_end"/g' /usr/lib/udev/rules.d/99-systemd.rules - -# Backing up gluster config as it overlaps when bind mounting. -RUN mkdir -p /etc/glusterfs_bkp /var/lib/glusterd_bkp /var/log/glusterfs_bkp;\ +rm -f /lib/systemd/system/anaconda.target.wants/*;\ +yum --setopt=tsflags=nodocs -y install wget nfs-utils attr iputils iproute openssh-server openssh-clients ntp rsync tar cronie sudo xfsprogs glusterfs glusterfs-server glusterfs-geo-replication;yum clean all; \ +sed -i '/Defaults requiretty/c\#Defaults requiretty' /etc/sudoers; \ +sed -i '/Port 22/c\Port 2222' /etc/ssh/sshd_config; \ +sed -i 's/Requires\=rpcbind\.service//g' /usr/lib/systemd/system/glusterd.service; \ +sed -i 's/rpcbind\.service/gluster-setup\.service/g' /usr/lib/systemd/system/glusterd.service; \ +sed -i 's/ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}=="1", ENV{SYSTEMD_READY}="0"/ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}=="1", GOTO="systemd_end"/g' /usr/lib/udev/rules.d/99-systemd.rules; \ +mkdir -p /etc/glusterfs_bkp /var/lib/glusterd_bkp /var/log/glusterfs_bkp;\ cp -r /etc/glusterfs/* /etc/glusterfs_bkp;\ cp -r /var/lib/glusterd/* /var/lib/glusterd_bkp;\ -cp -r /var/log/glusterfs/* /var/log/glusterfs_bkp; +cp -r /var/log/glusterfs/* /var/log/glusterfs_bkp; \ +sed -i.save -e "s#udev_sync = 1#udev_sync = 0#" -e "s#udev_rules = 1#udev_rules = 0#" -e "s#use_lvmetad = 1#use_lvmetad = 0#" /etc/lvm/lvm.conf; -# Configure LVM to create LVs and snapshots -RUN sed -i.save -e "s#udev_sync = 1#udev_sync = 0#" \ - -e "s#udev_rules = 1#udev_rules = 0#" \ - -e "s#use_lvmetad = 1#use_lvmetad = 0#" /etc/lvm/lvm.conf - -# Adding script to move the glusterfs config file to location +VOLUME [ "/sys/fs/cgroup" ] ADD gluster-setup.service /etc/systemd/system/gluster-setup.service -RUN chmod 644 /etc/systemd/system/gluster-setup.service - -# Adding script to move the glusterfs config file to location ADD gluster-setup.sh /usr/sbin/gluster-setup.sh -RUN chmod 500 /usr/sbin/gluster-setup.sh - -#RUN echo 'root:password' | chpasswd -VOLUME [ "/sys/fs/cgroup" ] -RUN systemctl disable nfs-server.service -# stops getty from consuming all the memory -RUN systemctl mask getty.target -RUN systemctl enable ntpd.service -RUN systemctl enable glusterd.service -RUN systemctl enable gluster-setup.service +RUN chmod 644 /etc/systemd/system/gluster-setup.service; \ +chmod 500 /usr/sbin/gluster-setup.sh; \ +systemctl disable nfs-server.service; \ +systemctl mask getty.target; \ +systemctl enable ntpd.service; \ +systemctl enable glusterd.service; \ +systemctl enable gluster-setup.service; EXPOSE 2222 111 245 443 24007 2049 8080 6010 6011 6012 38465 38466 38468 38469 49152 49153 49154 49156 49157 49158 49159 49160 49161 49162 diff --git a/Fedora/Dockerfile b/Fedora/Dockerfile index 370417f..fc3f722 100644 --- a/Fedora/Dockerfile +++ b/Fedora/Dockerfile @@ -1,12 +1,22 @@ FROM fedora -MAINTAINER Humble Chirammal hchiramm@redhat.com +MAINTAINER Humble Chirammal hchiramm@redhat.com Mohamed Ashiq Liyazudeen mliyazud@redhat.com ENV container docker -RUN yum -y update && yum clean all +LABEL architecture="x86_64" \ + name="gluster/gluster-fedora" \ + version="3.10" \ + vendor="Red Hat, Inc" \ + summary="This image has a running glusterfs service ( Fedora + Gluster 3.10)" \ + io.k8s.display-name="Gluster 3.10 based on Fedora" \ + io.k8s.description="Gluster Image is based on Fedora Image which is a scalable network filesystem. Using common off-the-shelf hardware, you can create large, distributed storage solutions for media streaming, data analysis, and other data- and bandwidth-intensive tasks." \ + description="Gluster Image is based on fedora Image which is a scalable network filesystem. Using common off-the-shelf hardware, you can create large, distributed storage solutions for media streaming, data analysis, and other data- and bandwidth-intensive tasks." \ + io.openshift.tags="gluster,glusterfs,gluster-fedora" -RUN yum -y install systemd; yum clean all; \ + +RUN yum -y update;\ +yum -y install systemd; \ (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \ rm -f /lib/systemd/system/multi-user.target.wants/*;\ rm -f /etc/systemd/system/*.wants/*;\ @@ -14,17 +24,15 @@ rm -f /lib/systemd/system/local-fs.target.wants/*; \ rm -f /lib/systemd/system/sockets.target.wants/*udev*; \ rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \ rm -f /lib/systemd/system/basic.target.wants/*;\ -rm -f /lib/systemd/system/anaconda.target.wants/*; - -RUN yum --setopt=tsflags=nodocs -y install wget nfs-utils iputils iproute attr glusterfs glusterfs-server glusterfs-geo-replication openssh-server; yum clean all +rm -f /lib/systemd/system/anaconda.target.wants/*; \ +yum --setopt=tsflags=nodocs -y install wget nfs-utils iputils iproute attr glusterfs glusterfs-server glusterfs-geo-replication openssh-server; yum clean all;\ +systemctl disable nfs-server.service;\ +systemctl enable rpcbind.service;\ +systemctl enable glusterd.service; -RUN echo 'root:password' | chpasswd VOLUME [ "/sys/fs/cgroup" ] EXPOSE 22 111 245 443 24007 2049 8080 6010 6011 6012 38465 38466 38468 38469 49152 49153 49154 49156 49157 49158 49159 49160 49161 49162 49163 -RUN systemctl disable nfs-server.service -RUN systemctl enable rpcbind.service -RUN systemctl enable glusterd.service CMD ["/usr/sbin/init"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2526438 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +test: + $(MAKE) -C tests test diff --git a/README.md b/README.md index 5920382..68eee5c 100644 --- a/README.md +++ b/README.md @@ -1,84 +1,80 @@ -This repo contains dockerfiles (CentOS, Fedora, Red Hat) for GlusterFS containers namely server, client and object. +This repo contains dockerfiles (CentOS and Fedora) for GlusterFS containers namely server, client and object. ## Gluster Server Docker container: -Although Setting up a glusterfs environment is a pretty simple and straight forward procedure, Gluster community do maintain docker images for gluster both in Fedora and CentOS in the docker hub for the ease of users. This blog is intented to walk the user through the steps of running GlusterFS with the help of docker. -The community maintains docker images of GlusterFS release in both Fedora and CentOS distributions. The following are the steps to build the GlusterFS docker images that we maintain: +Although Setting up a glusterfs environment is a pretty simple and straight forward procedure, Gluster community do maintain docker images of gluster both Fedora and CentOS as base image in the docker hub for the ease of users. The community maintains docker images of GlusterFS release in both Fedora and CentOS distributions. + +The following are the steps to run the GlusterFS docker images that we maintain: + To pull the docker image from the docker hub run the following command: ### Fedora: ~~~ $ docker pull gluster/gluster-fedora - ~~~ ### CentOS: ~~~ $ docker pull gluster/gluster-centos - ~~~ -This will fetch and build the docker image for you from the docker hub. -Alternatively, one could build the image from the Dockerfile directly. For this, one should pull the Gluster-Fedora Dockerfile from the source repository and build the image using that. For getting the source, One can make use of git: + +This will pull the glusterfs docker image from the docker hub. +Alternatively, one could build the image from the Dockerfile directly. For this, clone the gluster-containers source repository and build the image using Dockerfiles in the repository. For getting the source, One can make use of git: ~~~ $ git clone git@github.com:gluster/gluster-containers.git ~~~ -This repository consists of Dockerfiles for GlusterFS built in both CentOS and Fedora distributions. Once you clone the repository, to build the image, run the following commands: +This repository consists of Dockerfiles for GlusterFS to build on both CentOS and Fedora distributions. Once you clone the repository, to build the image, run the following commands: + For Fedora, ~~~ $ docker build -t gluster-fedora docker/Fedora/Dockerfile - ~~~ For CentOS, ~~~ $ docker build -t gluster-centos docker/CentOS/Dockerfile ~~~ -This command will build the docker image from the Dockerfile you just cloned and will be assigned the name gluster-fedora or gluster-centos respectively. ‘-t’ option is used to give a name to the image we are about the build. +This command will build the docker image from the Dockerfile and will be assigned the name gluster-fedora or gluster-centos respectively. ‘-t’ option is used to give a name to the image we built. -Once the image is built in either of the above two steps, we can now run the container with gluster daemon running. +Once the image is built in either of the above two steps, now we can run the container with gluster daemon running. -Before this, ensure the following directories are created in the system from where docker is launched: - - /etc/glusterfs +Before this, ensure the following directories are created on the host where docker is running: + - /etc/glusterfs - /var/lib/glusterd - /var/log/glusterfs Also, ensure they are empty to avoid any conflicts. Now run the following command: ~~~ - $ docker run -v /etc/glusterfs:/etc/glusterfs:z -v /var/lib/glusterd:/var/lib/glusterd:z -v /var/log/glusterfs:/var/log/glusterfs:z -v /sys/fs/cgroup:/sys/fs/cgroup:ro -d --privileged=true --net=host -v /dev/:/dev gluster/gluster-centos ~~~ ( is either gluster-fedora or gluster-centos as per the configurations so far) Where: - +~~~ --net=host ( Optional: This option brings maximum network throughput for your storage container) --privileged=true ( If you are exposing the `/dev/` tree of host to the container to create bricks from the container) - - +~~~ Bind mounting of following directories enables: - +~~~ `/var/lib/glusterd` : To make gluster metadata persistent in the host. `/var/log/glusterfs` : To make gluster logs persistent in the host. `/etc/glusterfs` : To make gluster configuration persistent in the host. +~~~ - - - -Systemd has been installed and is running in the container we maintain. +Systemd has been installed and is running in the container we maintain. Once issued, this will boot up the Fedora or CentOS system and you have a container started with glusterd running in it. ##### Verify the container is running successfully: ~~~ - $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES @@ -115,7 +111,6 @@ root 159 0.0 0.0 112992 2224 pts/0 S+ 06:22 0:00 grep --color=auto glusterd Number of Peers: 0 -bash-4.3# gluster --version - ~~~ That’s it! @@ -127,7 +122,6 @@ Additional Ref# https://goo.gl/3031Mm ### To pull gluster-object: ~~~ $ docker pull gluster/gluster-object - ~~~ ### To run gluster-object container: @@ -149,8 +143,7 @@ GLUSTER_VOLUMES='tv1' Where tv1 is the volume name. ~~~ -$ docker run -d --privileged -v /sys/fs/cgroup/:/sys/fs/cgroup/:ro -p 8080:8080 -v /mnt/gluster-object:/mnt/gluster-object gluster/gluster-object - +$ docker run -d --privileged -v /sys/fs/cgroup/:/sys/fs/cgroup/:ro -p 8080:8080 -v /mnt/gluster-object:/mnt/gluster-object gluster/gluster-object ~~~ Now, We can get/put objects into the gluster volume, using the gluster-object Docker container. diff --git a/gluster-client/Dockerfile b/gluster-client/Dockerfile index 9b1d1d9..9f28b4e 100644 --- a/gluster-client/Dockerfile +++ b/gluster-client/Dockerfile @@ -1,8 +1,22 @@ -FROM fedora -MAINTAINER Humble Devassy Chirammal -LABEL Name="glusterfs-client" +FROM fedora + +MAINTAINER Humble Devassy Chirammal + +LABEL architecture="x86_64" \ + name="gluster/glusterfs-client" \ + version="3.10" \ + vendor="Red Hat, Inc" \ + summary="This image has a running glusterfs service ( Fedora + Gluster 3.10 client)" \ + io.k8s.display-name="Gluster 3.10 client based on Fedora" \ + io.k8s.description="Gluster Client Image is based on Fedora Image which is used to mount a glusterfs volume." \ + description="Gluster Client Image is based on Fedora Image which is used to mount a glusterfs volume." \ + io.openshift.tags="gluster,glusterfs,glusterfs-client" + ENV container docker -RUN dnf --setopt=tsflags=nodocs -y update; dnf clean all; dnf --setopt=tsflags=nodocs -y install wget nfs-utils attr iputils iproute; -RUN sed -i "s/LANG/\#LANG/g" /etc/locale.conf -RUN dnf install -y glusterfs-fuse; dnf clean all; + +RUN dnf --setopt=tsflags=nodocs -y update; dnf --setopt=tsflags=nodocs -y install wget nfs-utils attr iputils iproute; \ +sed -i "s/LANG/\#LANG/g" /etc/locale.conf;\ +dnf install -y glusterfs-fuse;\ +dnf clean all; + CMD ["/bin/bash"] diff --git a/gluster-object/CentOS/docker-gluster-swift/Dockerfile b/gluster-object/CentOS/docker-gluster-swift/Dockerfile index 65599ec..d0c6955 100644 --- a/gluster-object/CentOS/docker-gluster-swift/Dockerfile +++ b/gluster-object/CentOS/docker-gluster-swift/Dockerfile @@ -9,6 +9,16 @@ MAINTAINER Prashanth Pai # Install gluster-swift dependencies. To be removed when RPMs become available. # Clean downloaded packages and index +LABEL architecture="x86_64" \ + name="gluster/gluster-swift" \ + version="kilo" \ + vendor="Red Hat, Inc" \ + summary="This image has a running gluster-swift service ( centos 7 + gluster-swift)" \ + io.k8s.display-name="gluster-swift based on centos 7" \ + io.k8s.description="gluster-swift image is based on centos image which enables files and directories created on GlusterFS to be accessed as objects via the Swift and S3 API." \ + description="gluster-swift image is based on centos image which enables files and directories created on GlusterFS to be accessed as objects via the Swift and S3 API." \ + io.openshift.tags="gluster,glusterfs,gluster-swift" + RUN yum -v --setopt=tsflags=nodocs -y update && \ yum -v --setopt=tsflags=nodocs -y install \ centos-release-openstack-kilo \ @@ -32,7 +42,8 @@ RUN yum -v --setopt=tsflags=nodocs -y update && \ RUN git clone git://review.gluster.org/gluster-swift /tmp/gluster-swift && \ cd /tmp/gluster-swift && \ python setup.py install && \ - cd - + cd - && \ + rm -rf /tmp/gluster-swift # Gluster volumes will be mounted *under* this directory. VOLUME /mnt/gluster-object @@ -43,6 +54,7 @@ COPY swift-proxy.service /lib/systemd/system/ COPY swift-account.service /lib/systemd/system/ COPY swift-container.service /lib/systemd/system/ COPY swift-object.service /lib/systemd/system/ +COPY swift-adduser.service /lib/systemd/system/ # Replace openstack swift conf files with local gluster-swift ones COPY etc/swift/* /etc/swift/ @@ -51,6 +63,9 @@ COPY etc/swift/* /etc/swift/ COPY update_gluster_vol.sh /usr/local/bin/update_gluster_vol.sh RUN chmod +x /usr/local/bin/update_gluster_vol.sh +COPY gluster-swift-add-user /usr/local/bin/gluster-swift-add-user +RUN chmod +x /usr/local/bin/gluster-swift-add-user + # volumes to be exposed as object storage is present in swift-volumes file COPY etc/sysconfig/swift-volumes /etc/sysconfig/swift-volumes @@ -60,12 +75,13 @@ EXPOSE 8080 RUN echo 'root:password' | chpasswd VOLUME [ "/sys/fs/cgroup" ] -RUN systemctl enable swift-gen-builders.service -RUN systemctl enable memcached.service -RUN systemctl enable swift-proxy.service -RUN systemctl enable swift-account.service -RUN systemctl enable swift-container.service -RUN systemctl enable swift-object.service +RUN systemctl enable swift-gen-builders.service;\ + systemctl enable memcached.service;\ + systemctl enable swift-proxy.service;\ + systemctl enable swift-account.service;\ + systemctl enable swift-container.service;\ + systemctl enable swift-object.service;\ + systemctl enable swift-adduser.service; ENTRYPOINT ["/usr/local/bin/update_gluster_vol.sh"] CMD ["/usr/sbin/init"] diff --git a/gluster-object/CentOS/docker-gluster-swift/README.md b/gluster-object/CentOS/docker-gluster-swift/README.md index 41e966d..0148fae 100644 --- a/gluster-object/CentOS/docker-gluster-swift/README.md +++ b/gluster-object/CentOS/docker-gluster-swift/README.md @@ -30,7 +30,7 @@ Where tv1 is the volume name. **Example:** ```bash -# docker run -d --privileged -v /sys/fs/cgroup/:/sys/fs/cgroup/:ro -p 8080:8080 -v /mnt/gluster-object:/mnt/gluster-object -e GLUSTER_VOLUMES="tv1" gluster-swift +# docker run -d --privileged -v /sys/fs/cgroup/:/sys/fs/cgroup/:ro -p 8080:8080 -v /mnt/gluster-object:/mnt/gluster-object -e GLUSTER_VOLUMES="tv1" -e GLUSTER_USER="admin" -e GLUSTER_PASSWORD="redhat" gluster-swift ``` If you have selinux set to enforced on the host machine, refer to the diff --git a/gluster-object/CentOS/docker-gluster-swift/etc/swift/proxy-server.conf b/gluster-object/CentOS/docker-gluster-swift/etc/swift/proxy-server.conf index 979b735..8e6ecc5 100644 --- a/gluster-object/CentOS/docker-gluster-swift/etc/swift/proxy-server.conf +++ b/gluster-object/CentOS/docker-gluster-swift/etc/swift/proxy-server.conf @@ -5,7 +5,7 @@ user = root workers = 1 [pipeline:main] -pipeline = catch_errors gatekeeper healthcheck proxy-logging cache bulk ratelimit swift3 staticweb slo dlo proxy-logging proxy-server +pipeline = catch_errors gatekeeper healthcheck proxy-logging cache bulk ratelimit swift3 gswauth staticweb slo dlo proxy-logging proxy-server [app:proxy-server] use = egg:gluster_swift#proxy @@ -97,3 +97,10 @@ user_test5_tester5 = testing5 service [filter:swift3] use = egg:swift3#swift3 + +[filter:gswauth] +use = egg:gluster_swift#gswauth +set log_name = gswauth +super_admin_key = gswauthkey +metadata_volume = gsmetadata +s3_support = on diff --git a/gluster-object/CentOS/docker-gluster-swift/etc/sysconfig/swift-volumes b/gluster-object/CentOS/docker-gluster-swift/etc/sysconfig/swift-volumes index 8b49f07..3aeb7ec 100644 --- a/gluster-object/CentOS/docker-gluster-swift/etc/sysconfig/swift-volumes +++ b/gluster-object/CentOS/docker-gluster-swift/etc/sysconfig/swift-volumes @@ -1,2 +1,4 @@ # Set Gluster volumes to be used by gluster-object service GLUSTER_VOLUMES="tv1" +GLUSTER_USER="admin" +GLUSTER_PASSWORD="redhat" diff --git a/gluster-object/CentOS/docker-gluster-swift/gluster-swift-add-user b/gluster-object/CentOS/docker-gluster-swift/gluster-swift-add-user new file mode 100755 index 0000000..59eb1b2 --- /dev/null +++ b/gluster-object/CentOS/docker-gluster-swift/gluster-swift-add-user @@ -0,0 +1,13 @@ +#!/bin/bash +if [ "$#" -lt 3 ]; then + echo "Incorrect args. invoke gluster-swift-add-user $GLUSTER_USER $GLUSTER_PASSWORD $GLUSTER_VOLUMES" + exit 1 +else + GLUSTER_USER=$1 + GLUSTER_PASSWORD=$2 + GLUSTER_VOLUMES=$(echo $3 | cut -d" " -f1) + sleep 5 + gswauth-prep -A http://0.0.0.0:8080/auth -K gswauthkey + gswauth-add-account -K gswauthkey $GLUSTER_VOLUMES + gswauth-add-user -K gswauthkey -a $GLUSTER_VOLUMES $GLUSTER_USER $GLUSTER_PASSWORD +fi diff --git a/gluster-object/CentOS/docker-gluster-swift/swift-adduser.service b/gluster-object/CentOS/docker-gluster-swift/swift-adduser.service new file mode 100644 index 0000000..ee4c8d7 --- /dev/null +++ b/gluster-object/CentOS/docker-gluster-swift/swift-adduser.service @@ -0,0 +1,11 @@ +[Unit] +Description=Swift Add User +After=swift-object.service + +[Service] +Type=oneshot +EnvironmentFile=-/etc/sysconfig/swift-volumes +ExecStart=/usr/local/bin/gluster-swift-add-user $GLUSTER_USER $GLUSTER_PASSWORD $GLUSTER_VOLUMES + +[Install] +WantedBy=multi-user.target diff --git a/gluster-object/CentOS/docker-gluster-swift/swift-gen-builders.service b/gluster-object/CentOS/docker-gluster-swift/swift-gen-builders.service index ab30a7c..efafca5 100644 --- a/gluster-object/CentOS/docker-gluster-swift/swift-gen-builders.service +++ b/gluster-object/CentOS/docker-gluster-swift/swift-gen-builders.service @@ -5,7 +5,7 @@ Before=memcached.service [Service] Type=oneshot EnvironmentFile=-/etc/sysconfig/swift-volumes -ExecStart=/usr/bin/gluster-swift-gen-builders $GLUSTER_VOLUMES +ExecStart=/usr/bin/gluster-swift-gen-builders $GLUSTER_VOLUMES gsmetadata [Install] WantedBy=multi-user.target diff --git a/gluster-object/CentOS/docker-gluster-swift/update_gluster_vol.sh b/gluster-object/CentOS/docker-gluster-swift/update_gluster_vol.sh index dfb891d..9e9c60e 100644 --- a/gluster-object/CentOS/docker-gluster-swift/update_gluster_vol.sh +++ b/gluster-object/CentOS/docker-gluster-swift/update_gluster_vol.sh @@ -1,12 +1,14 @@ #!/bin/bash # To update gluster volume name in swift-volumes, used by swift-gen-builders.service -if [ -z "$GLUSTER_VOLUMES" ]; then - echo "You need to set GLUSTER_VOLUMES env variable" +if [[ -z "$GLUSTER_VOLUMES" || -z "$GLUSTER_USER" || -z "$GLUSTER_PASSWORD" ]]; then + echo "You need to set GLUSTER_VOLUMES, GLUSTER_USER, GLUSTER_PASSWORD env variable" exit 1 else echo "GLUSTER_VOLUMES env variable is set. Update in swift-volumes" sed -i.bak '/^GLUSTER_VOLUMES=/s/=.*/='\""$GLUSTER_VOLUMES"\"'/' /etc/sysconfig/swift-volumes + sed -i.bak '/^GLUSTER_USER=/s/=.*/='\""$GLUSTER_USER"\"'/' /etc/sysconfig/swift-volumes + sed -i.bak '/^GLUSTER_PASSWORD=/s/=.*/='\""$GLUSTER_PASSWORD"\"'/' /etc/sysconfig/swift-volumes fi # Hand off to CMD diff --git a/tests/Dockerfiletest/Dockerfile_faulty b/tests/Dockerfiletest/Dockerfile_faulty new file mode 100644 index 0000000..b538995 --- /dev/null +++ b/tests/Dockerfiletest/Dockerfile_faulty @@ -0,0 +1,10 @@ + +MAINTAINER Humble Chirammal hchiramm@redhat.com Mohamed Ashiq Liyazudeen mliyazud@redhat.com + +LABEL Name="faulty" + +RUNCMD 'echo "fail"' + +EXPOSE 3333 + +CMD ["/usr/sbin/init"] diff --git a/tests/Dockerfiletest/Makefile b/tests/Dockerfiletest/Makefile new file mode 100644 index 0000000..13cf414 --- /dev/null +++ b/tests/Dockerfiletest/Makefile @@ -0,0 +1,2 @@ +test: + ./run.sh diff --git a/tests/Dockerfiletest/run_mask.sh b/tests/Dockerfiletest/run_mask.sh new file mode 100755 index 0000000..b82b810 --- /dev/null +++ b/tests/Dockerfiletest/run_mask.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +SCRIPT_DIR=$(cd $(dirname $0); pwd) + +echo "running tests in ${SCRIPT_DIR}" + +for test in ${SCRIPT_DIR}/test_*.sh ; do + $test + if [ $? -ne 0 ]; then + exit 1 + fi +done diff --git a/tests/Dockerfiletest/test_gluster_dockerfile.sh b/tests/Dockerfiletest/test_gluster_dockerfile.sh new file mode 100755 index 0000000..fc52d44 --- /dev/null +++ b/tests/Dockerfiletest/test_gluster_dockerfile.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +SCRIPT_DIR=$(cd $(dirname ${0}); pwd) +TESTS_DIR="${SCRIPT_DIR}/.." +INC_DIR="${TESTS_DIR}/common" +BASE_DIR="${SCRIPT_DIR}/../.." +FAULTY_DOCKERFILE="${SCRIPT_DIR}/Dockerfile_faulty" + +source "${INC_DIR}/subunit.sh" + +check_dockerfilelint_invalid() { + local file="${1}" + check_dockerfilelint ${file} + if [[ "x$?" == "x0" ]]; then + echo "ERROR: parsing invalid Dockerfile succeeded" + return 1 + fi + + return 0 +} + +check_dockerfilelint() { + local file="${1}" + if ! which dockerfile_lint ; then + echo "dockerfile_lint not found: skipping..." + return 0 + fi + + dockerfile_lint -p -f ${file} +} + +failed=0 + + testit "check invalid Dockerfile" \ + check_dockerfilelint_invalid ${FAULTY_DOCKERFILE} \ + || ((failed++)) + + for Dockerfile in $(find ${BASE_DIR} -name "Dockerfile") ; do + testit "check Dockerfile_lint $(basename ${Dockerfile})" \ + check_dockerfilelint ${Dockerfile} \ + || ((failed++)) + done + + +testok $0 ${failed} diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..13cf414 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,2 @@ +test: + ./run.sh diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..2d825d4 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,35 @@ +# Testsuite + +This directory contains tests for gluster-containers. +These are tests that do not test the full stack end-to-end +but are syntax-checks or unit-tests. + +## Prerequisites + +The Dockerfile lint tests require the 'dockerfile_lint' program. +Install it with + +* `dnf install npm`, or +* `apt-get install npm` + +* `npm install dockerfile_lint` + +Ref: https://github.com/projectatomic/dockerfile_lint + +The test uses ShellCheck. +Install with + +* `dnf install ShellCheck`, or +* `apt-get install shellcheck` + +## Travis CI +* dockerfile_lint has dependency problem, hence disabling it. +* Builds the docker image and does a basic test. +* Tests the shell script. + +## TODOs + +* Write more tests +* Write full functional tests to be run in vms. + (like the atomic vagrant environment) + diff --git a/tests/common/subunit.sh b/tests/common/subunit.sh new file mode 100755 index 0000000..71aba94 --- /dev/null +++ b/tests/common/subunit.sh @@ -0,0 +1,113 @@ +# +# subunit.sh: shell functions to report test status via the subunit protocol. +# Copyright (C) 2006 Robert Collins +# Copyright (C) 2008 Jelmer Vernooij +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +timestamp() { + # mark the start time. With Gnu date, you get nanoseconds from %N + # (here truncated to microseconds with %6N), but not on BSDs, + # Solaris, etc, which will apparently leave either %N or N at the end. + date -u +'time: %Y-%m-%d %H:%M:%S.%6NZ' | sed 's/\..*NZ$/.000000Z/' +} + +subunit_start_test () { + # emit the current protocol start-marker for test $1 + timestamp + echo "test: $1" +} + + +subunit_pass_test () { + # emit the current protocol test passed marker for test $1 + timestamp + echo "success: $1" +} + +# This is just a hack as we have some broken scripts +# which use "exit $failed", without initializing failed. +failed=0 + +subunit_fail_test () { + # emit the current protocol fail-marker for test $1, and emit stdin as + # the error text. + # we use stdin because the failure message can be arbitrarily long, and this + # makes it convenient to write in scripts (using <&1` + status=$? + if [ x$status = x0 ]; then + subunit_pass_test "$name" + else + echo "$output" | subunit_fail_test "$name" + fi + return $status +} + +testit_expect_failure () { + name="$1" + shift + cmdline="$*" + subunit_start_test "$name" + output=`$cmdline 2>&1` + status=$? + if [ x$status = x0 ]; then + echo "$output" | subunit_fail_test "$name" + else + subunit_pass_test "$name" + fi + return $status +} + +testok () { + name=`basename $1` + failed=$2 + + exit $failed +} diff --git a/tests/run.sh b/tests/run.sh new file mode 100755 index 0000000..baf6a48 --- /dev/null +++ b/tests/run.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +SCRIPT_DIR=$(cd $(dirname $0); pwd) + +for testdir in ${SCRIPT_DIR}/*; do + if [[ ! -d ${testdir} ]]; then + continue + fi + + if [[ ! -x ${testdir}/run.sh ]]; then + continue + fi + + pushd ${testdir} + ./run.sh + rc=$? + popd + + if [[ ${rc} -ne 0 ]]; then + exit 1 + fi +done diff --git a/tests/shelltest/Makefile b/tests/shelltest/Makefile new file mode 100644 index 0000000..13cf414 --- /dev/null +++ b/tests/shelltest/Makefile @@ -0,0 +1,2 @@ +test: + ./run.sh diff --git a/tests/shelltest/run.sh b/tests/shelltest/run.sh new file mode 100755 index 0000000..b82b810 --- /dev/null +++ b/tests/shelltest/run.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +SCRIPT_DIR=$(cd $(dirname $0); pwd) + +echo "running tests in ${SCRIPT_DIR}" + +for test in ${SCRIPT_DIR}/test_*.sh ; do + $test + if [ $? -ne 0 ]; then + exit 1 + fi +done diff --git a/tests/shelltest/test_gluster_container_basic.sh b/tests/shelltest/test_gluster_container_basic.sh new file mode 100755 index 0000000..8d139ca --- /dev/null +++ b/tests/shelltest/test_gluster_container_basic.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +SCRIPT_DIR=$(cd $(dirname ${0}); pwd) +TESTS_DIR="${SCRIPT_DIR}/.." +INC_DIR="${TESTS_DIR}/common" +BASE_DIR="${SCRIPT_DIR}/../.." + +GK_DEPLOY="${DEPLOY_DIR}/" + +source "${INC_DIR}/subunit.sh" + + +test_syntax() { + local file="${1}" + bash -n ${file} +} + +test_shellcheck() { + local file="${1}" + if ! which shellcheck ; then + echo "ShellCheck not found: skipping..." + return 0 + fi + + shellcheck -s bash -e SC2181 ${file} +} + +failed=0 + +testit "test script syntax ${BASE_DIR}/CentOS/gluster-setup.sh" \ + test_syntax ${BASE_DIR}/CentOS/gluster-setup.sh \ + || ((failed++)) + +testit "test shellcheck ${BASE_DIR}/CentOS/gluster-setup.sh" \ + test_shellcheck ${BASE_DIR}/CentOS/gluster-setup.sh \ + || ((failed++)) + +testit "test script syntax ${BASE_DIR}/gluster-object/CentOS/docker-gluster-swift/update_gluster_vol.sh" \ + test_syntax ${BASE_DIR}/gluster-object/CentOS/docker-gluster-swift/update_gluster_vol.sh \ + || ((failed++)) + +testit "test shellcheck ${BASE_DIR}/gluster-object/CentOS/docker-gluster-swift/update_gluster_vol.sh" \ + test_shellcheck ${BASE_DIR}/gluster-object/CentOS/docker-gluster-swift/update_gluster_vol.sh \ + || ((failed++)) + + +testok $0 ${failed}