From 5c6ffae12ea1f503e1f032aebb73b15a338c8415 Mon Sep 17 00:00:00 2001 From: William Brown Date: Jun 14 2019 12:54:43 +0000 Subject: Ticket 50439 - Update docker integration to work out of source directory Bug Description: Docker did not function in some cases, and we had to wait for releases via rpm. Fix Description: This adds the support to build from source into the tree so that we can build and test git master. This also resolves a var/run issue in the image, as well as some other minor python cleaning such as handling sigchld to act as init. https://pagure.io/389-ds-base/issue/50439 Author: William Brown william@blackhats.net.au Review by: spichugi --- diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1905eb5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git +.gitignore +./src/cockpit/389-console/node_modules diff --git a/docker.mk b/docker.mk index 528ab2f..4f07cec 100644 --- a/docker.mk +++ b/docker.mk @@ -1,4 +1,3 @@ - -poc: - docker build -t 389-poc:latest -f docker/389ds_poc/Dockerfile . +suse: + docker build -t 389-ds-suse:master -f docker/389-ds-suse/Dockerfile . diff --git a/docker/389-ds-fedora/Dockerfile b/docker/389-ds-fedora/Dockerfile new file mode 100644 index 0000000..d61df8c --- /dev/null +++ b/docker/389-ds-fedora/Dockerfile @@ -0,0 +1,46 @@ +# --- BEGIN COPYRIGHT BLOCK --- +# Copyright (C) 2017 Red Hat, Inc. +# All rights reserved. +# +# License: GPL (version 3 or any later version). +# See LICENSE for details. +# --- END COPYRIGHT BLOCK --- + +FROM fedora:26 +MAINTAINER 389-devel@lists.fedoraproject.org +EXPOSE 389 636 +ENV container docker + +RUN mkdir -p /usr/local/src +WORKDIR /usr/local/src + +ADD ./ /usr/local/src/389-ds-base + +RUN dnf upgrade -y && \ + dnf install --setopt=strict=False -y \ + @buildsys-build rpm-build make bzip2 git rsync \ + `grep -E "^(Build)?Requires" 389-ds-base/rpm/389-ds-base.spec.in | grep -v -E '(name|MODULE)' | awk '{ print $2 }' | sed 's/%{python3_pkgversion}/3/g' | grep -v "^/" | grep -v pkgversion | sort | uniq | tr '\n' ' '` && \ + dnf clean all + + +### CHANGE THIS TO A ./configure and build that way. + +RUN cd 389-ds-base && \ + PERL_ON=0 RUST_ON=1 make -f rpm.mk rpms + +RUN dnf install -y 389-ds-base/dist/rpms/*389*.rpm && \ + dnf clean all + +# Create the example setup inf. It's valid for containers! +# Build the instance from the new installer tools. +RUN /usr/sbin/dscreate create-template > /root/ds-setup.inf && /usr/sbin/dscreate -v from-file /root/ds-setup.inf --containerised + +# Finally add the volumes, they will inherit the contents of these directories. +VOLUME /etc/dirsrv +VOLUME /var/log/dirsrv +VOLUME /var/lib/dirsrv + +# Or, run them as dirsrv +USER dirsrv +CMD ["/usr/sbin/ns-slapd", "-d", "0", "-D", "/etc/dirsrv/slapd-localhost", "-i", "/var/run/dirsrv/slapd-localhost.pid"] + diff --git a/docker/389-ds-suse/Dockerfile b/docker/389-ds-suse/Dockerfile new file mode 100644 index 0000000..a286912 --- /dev/null +++ b/docker/389-ds-suse/Dockerfile @@ -0,0 +1,78 @@ +#!BuildTag: 389-ds-container +FROM opensuse/leap:15.1 +MAINTAINER wbrown@suse.de + +EXPOSE 3389 3636 + +# RUN zypper ar -G obs://network:ldap network:ldap && \ +RUN zypper ar http://download.opensuse.org/update/leap/15.1/oss/ u && \ + zypper ar http://download.opensuse.org/distribution/leap/15.1/repo/oss/ m && \ + zypper ar http://download.opensuse.org/repositories/network:ldap/openSUSE_Leap_15.1/ "network:ldap" && \ + zypper mr -p 97 "network:ldap" && \ + zypper --gpg-auto-import-keys ref + +RUN zypper --non-interactive si --build-deps-only 389-ds && \ + zypper in -y 389-ds rust cargo rust-std && \ + zypper rm -y 389-ds + +# Install build dependencies +# RUN zypper in -C -y autoconf automake cracklib-devel cyrus-sasl-devel db-devel doxygen gcc-c++ \ +# gdb krb5-devel libcmocka-devel libevent-devel libtalloc-devel libtevent-devel libtool \ +# net-snmp-devel openldap2-devel pam-devel pkgconfig python-rpm-macros "pkgconfig(icu-i18n)" \ +# "pkgconfig(icu-uc)" "pkgconfig(libcap)" "pkgconfig(libpcre)" "pkgconfig(libsystemd)" \ +# "pkgconfig(nspr)" "pkgconfig(nss)" rsync cargo rust rust-std acl cyrus-sasl-plain db-utils \ +# bind-utils krb5 fillup shadow openldap2-devel pkgconfig "pkgconfig(nspr)" "pkgconfig(nss)" \ +# "pkgconfig(systemd)" python3-argcomplete python3-argparse-manpage python3-ldap \ +# python3-pyasn1 python3-pyasn1-modules python3-python-dateutil python3-six krb5-client \ +# mozilla-nss-tools + +# Push source code to the container +ADD ./ /usr/local/src/389-ds-base +WORKDIR /usr/local/src/389-ds-base + + +# Build and install +# Derived from rpm --eval '%configure' on opensuse. +RUN ./configure --host=x86_64-suse-linux-gnu --build=x86_64-suse-linux-gnu \ + --program-prefix= \ + --disable-dependency-tracking \ + --prefix=/usr \ + --exec-prefix=/usr \ + --bindir=/usr/bin \ + --sbindir=/usr/sbin \ + --sysconfdir=/etc \ + --datadir=/usr/share \ + --includedir=/usr/include \ + --libdir=/usr/lib64 \ + --libexecdir=/usr/lib \ + --localstatedir=/var \ + --sharedstatedir=/var/lib \ + --mandir=/usr/share/man \ + --infodir=/usr/share/info \ + --disable-dependency-tracking \ + --enable-debug \ + --enable-gcc-security --enable-autobind --enable-auto-dn-suffix --with-openldap \ + --enable-cmocka --enable-rust --disable-perl --with-pythonexec="python3" --without-systemd \ + --libexecdir=/usr/lib/dirsrv/ --prefix=/ && \ + make -j 12 && \ + make install && \ + make lib389 && \ + make lib389-install + +# Link some known static locations to point to /data +RUN mkdir -p /data/config && \ + mkdir -p /data/ssca && \ + mkdir -p /data/run && \ + mkdir -p /var/run/dirsrv && \ + ln -s /data/config /etc/dirsrv/slapd-localhost && \ + ln -s /data/ssca /etc/dirsrv/ssca && \ + ln -s /data/run /var/run/dirsrv + +# Temporal volumes for each instance + +VOLUME /data + +# Set the userup correctly. +# USER dirsrv + +CMD [ "/usr/sbin/dscontainer", "-r" ] diff --git a/docker/389ds_poc/Dockerfile b/docker/389ds_poc/Dockerfile deleted file mode 100644 index d61df8c..0000000 --- a/docker/389ds_poc/Dockerfile +++ /dev/null @@ -1,46 +0,0 @@ -# --- BEGIN COPYRIGHT BLOCK --- -# Copyright (C) 2017 Red Hat, Inc. -# All rights reserved. -# -# License: GPL (version 3 or any later version). -# See LICENSE for details. -# --- END COPYRIGHT BLOCK --- - -FROM fedora:26 -MAINTAINER 389-devel@lists.fedoraproject.org -EXPOSE 389 636 -ENV container docker - -RUN mkdir -p /usr/local/src -WORKDIR /usr/local/src - -ADD ./ /usr/local/src/389-ds-base - -RUN dnf upgrade -y && \ - dnf install --setopt=strict=False -y \ - @buildsys-build rpm-build make bzip2 git rsync \ - `grep -E "^(Build)?Requires" 389-ds-base/rpm/389-ds-base.spec.in | grep -v -E '(name|MODULE)' | awk '{ print $2 }' | sed 's/%{python3_pkgversion}/3/g' | grep -v "^/" | grep -v pkgversion | sort | uniq | tr '\n' ' '` && \ - dnf clean all - - -### CHANGE THIS TO A ./configure and build that way. - -RUN cd 389-ds-base && \ - PERL_ON=0 RUST_ON=1 make -f rpm.mk rpms - -RUN dnf install -y 389-ds-base/dist/rpms/*389*.rpm && \ - dnf clean all - -# Create the example setup inf. It's valid for containers! -# Build the instance from the new installer tools. -RUN /usr/sbin/dscreate create-template > /root/ds-setup.inf && /usr/sbin/dscreate -v from-file /root/ds-setup.inf --containerised - -# Finally add the volumes, they will inherit the contents of these directories. -VOLUME /etc/dirsrv -VOLUME /var/log/dirsrv -VOLUME /var/lib/dirsrv - -# Or, run them as dirsrv -USER dirsrv -CMD ["/usr/sbin/ns-slapd", "-d", "0", "-D", "/etc/dirsrv/slapd-localhost", "-i", "/var/run/dirsrv/slapd-localhost.pid"] - diff --git a/src/lib389/cli/dscontainer b/src/lib389/cli/dscontainer index 81195c9..83a1f79 100755 --- a/src/lib389/cli/dscontainer +++ b/src/lib389/cli/dscontainer @@ -45,6 +45,12 @@ from lib389.paths import Paths # is always available! log = setup_script_logger("container-init", True) +# Handle any dead child process signals we receive. Wait for them to terminate, or +# if they are not found, move on. +def _sigchild_handler(): + log.debug("Received SIGCHLD ...") + os.waitpid(-1, os.WNOHANG) + def begin_magic(): log.info("The 389 Directory Server Container Bootstrap") # Leave this comment here: UofA let me take this code with me provided @@ -158,8 +164,8 @@ def begin_magic(): # Create the marker to say we exist. This is also a good writable permissions # test for the volume. - with open('/data/config/container.inf', 'w'): - pass + with open('/data/config/container.inf', 'w') as f: + f.write('allocated') # TODO: All of this is contingent on the server starting *and* # ldapi working ... Perhaps these are better inside ns-slapd core @@ -206,6 +212,9 @@ def begin_magic(): # THE LETTER OF THE DAY IS C AND THE NUMBER IS 10 if __name__ == '__main__': + # Before all else, we are INIT so setup sigchild + signal.signal(signal.SIGCHLD, _sigchild_handler) + parser = argparse.ArgumentParser(allow_abbrev=True, description=""" dscontainer - this is a container entry point that will run a stateless instance of 389-ds. You should not use this unless you are developing or diff --git a/src/lib389/lib389/__init__.py b/src/lib389/lib389/__init__.py index ed1c259..1c57415 100644 --- a/src/lib389/lib389/__init__.py +++ b/src/lib389/lib389/__init__.py @@ -212,6 +212,8 @@ def pid_exists(pid): return True else: raise + # Tell the OS to reap this please ... + os.waitpid(pid, os.WNOHANG) return True def pid_from_file(pidfile):