Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: group RUN's, conditionalize starting of services #18

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
69 changes: 26 additions & 43 deletions CentOS/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,35 @@ FROM centos:latest
MAINTAINER Humble Chirammal [email protected]

ENV container docker
VOLUME [ "/sys/fs/cgroup", "/etc/glusterfs", "/var/lib/glusterd", "/var/log/glusterfs", "/var/lib/heketi" ]
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

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); \
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 wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm; rpm -ivh epel-release-latest-7.noarch.rpm; rm epel-release-latest-7.noarch.rpm;

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

# Backing up gluster config as it overlaps when bind mounting.
RUN 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;

# Adding script to move the glusterfs config file to location
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
RUN systemctl enable ntpd.service
RUN systemctl enable rpcbind.service
RUN systemctl enable glusterd.service
RUN 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
RUN yum --setopt=tsflags=nodocs -y install centos-release-gluster epel-release && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add yum --setopt=tsflags=nodocs -y update ? @humblec what do you think will we need this?

Copy link
Author

@ibotty ibotty Sep 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT there is no consensus re yum update within Dockerfiles. (See e.g. this discussion). I tend not to include them if the base image gets updated regularly. I rely on my build triggers in that case. Note that if the image is not updated, you still have to make sure to rebuild the image. And how should you know you'll have to do that :/.

The advantage of not using yum update is reproducibility.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. So we will depend on the image rebuilds and trigger accordingly. BTW link"this discussion" points to 404 page.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never get the github issue links right. corrected above.

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 && \
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done) && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure but doesn't this wipe the service files of gluster too, since its done after installation of the packages.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, yes. It wipes the annotation that they are to be started (if they start automatically). The unit files themselves don't reside there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we copy our service file here thought everyone will be doing the same.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that one does not get deleted. Only the unit links in xxx.wants get deleted. Maybe I am missing things.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah my bad did not notice the "xxx.wants" there. Thanks

rm -f /lib/systemd/system/multi-user.target.wants/* && \
rm -f /etc/systemd/system/*.wants/* && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the way && is used instead of ; .

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/* && \
sed -i '/Defaults requiretty/c\#Defaults requiretty' /etc/sudoers && \
sed -i '/Port 22/c\Port 2222' /etc/ssh/sshd_config && \
for dir in /etc/glusterfs /var/lib/glusterd /var/log/glusterfs; do \
mkdir -p ${dir}_bkp && \
cp -r $dir/* ${dir}_bkp ; \
done && \
chmod 644 /etc/systemd/system/gluster-setup.service && \
chmod 500 /usr/sbin/gluster-setup.sh && \
systemctl disable nfs-server.service && \
systemctl enable glusterd.service gluster-setup.service && \
echo 'root:password' | chpasswd

CMD ["/usr/sbin/init"]
17 changes: 17 additions & 0 deletions CentOS/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
This dockerfile can be used to build a CentOS Gluster Container.


## Automounting bricks

If you volume-mount an `fstab(5)` file, the container will mount all bricks in that file.
Specify the name with environment variable `FSTAB`.

A deprecated way is volume mounting /var/lib/heketi/fstab without setting `FSTAB` to that file.


## Enabling additional services

By default, only glusterd will be enabled. To enable other services, set the following env variables to `yes`.

* `ENABLE_NTPD`
* `ENABLE_SSHD`
* `ENABLE_RPCBIND`
88 changes: 45 additions & 43 deletions CentOS/gluster-setup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash -e

###
# Description: Script to move the glusterfs initial setup to bind mounted directories of Atomic Host.
Expand All @@ -12,58 +12,60 @@
# cases as published by the Free Software Foundation.
###

DIRS_TO_RESTORE="/etc/glusterfs /var/log/glusterfs /var/lib/glusterd"
FSTAB=${FSTAB-/var/lib/heketi/fstab}
ENABLE_NTPD="${ENABLE_NTPD-yes}"
ENABLE_SSHD="${ENABLE_SSHD-no}"
ENABLE_RPCBIND="${ENABLE_RPCBIND-yes}"

err() {
echo -ne $* 1>&2
}

enable_start_unit_if_env() {
local unit="$1"
local env_var="$1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be $2, let me know if I am wrong.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course!

case ${env_var,,} in
yes|y|true|t)
echo "Enable and start $unit"
systemctl enable $unit
systemctl start $unit
;;
esac
}

main () {
if test "$(ls /var/lib/heketi/fstab)"
if [ -f "$FSTAB" ]
then
mount -a --fstab /var/lib/heketi/fstab
if [ $? -eq 1 ]
then
echo "mount failed"
exit 1
fi
echo "Mount Successful"
if ! mount -a --fstab "$FSTAB"
then
err "mount failed"
exit 1
fi
echo "Mount Successful"
else
echo "heketi-fstab not found"
echo "fstab file $FSTAB not found"
fi
DIR_1="/etc/glusterfs"
DIR_2="/var/log/glusterfs"
DIR_3="/var/lib/glusterd"
var=0
for i in $DIR_1 $DIR_2 $DIR_3

for dir in $DIRS_TO_RESTORE
do
if test "$(ls $i)"
if test "$(ls $dir)"
then
echo "$i is not empty"
var=$((var+1))
echo "$dir is not empty"
else
if ! cp -r ${dir}_bkp/* $dir
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel we should copy only if all the directory in the list are empty. Say if they miss a volume -v /var/lib/glusterd:/var/lib/glusterd:z, In this case it will copy the default options and start the container which is not IMO is persisting the state of container. I feel It should fail in these cases and let the user notified that failed due to this directory.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree.

then
err "Failed to copy $dir"
exit 1
fi
fi
done

if [ $var -eq 3 ]
then
exit 1
fi

cp -r /etc/glusterfs_bkp/* /etc/glusterfs
if [ $? -eq 1 ]
then
echo "Failed to copy $DIR_1"
exit 1
fi

cp -r /var/log/glusterfs_bkp/* /var/log/glusterfs
if [ $? -eq 1 ]
then
echo "Failed to copy $DIR_2"
exit 1
fi
enable_start_unit_if_env rpcbind.service "$ENABLE_RPCBIND"
enable_start_unit_if_env ntpd.service "$ENABLE_NTPD"
enable_start_unit_if_env sshd.service "$ENABLE_SSHD"

cp -r /var/lib/glusterd_bkp/* /var/lib/glusterd
if [ $? -eq 1 ]
then
echo "Failed to copy $DIR_3"
exit 1
fi

echo "Script Ran Successfully"
}

main