diff --git a/.gitignore b/.gitignore index eaec4cc..a882870 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,6 @@ __pycache__/ # Distribution / packaging .Python env/ -build/ develop-eggs/ dist/ downloads/ diff --git a/build/Dockerfile b/build/Dockerfile new file mode 100644 index 0000000..33aa28b --- /dev/null +++ b/build/Dockerfile @@ -0,0 +1,25 @@ +# syntax = docker/dockerfile:1.0-experimental +ARG dirac_version=v6r22p26 +FROM alexanderrichards/dirac_ui:${dirac_version} +ARG productionsystem_version=master + +RUN yum install -y git gcc cronie python3 python3-devel yum-priorities +RUN yum install -y http://repository.egi.eu/sw/production/umd/4/centos7/x86_64/updates/umd-release-4.1.3-1.el7.centos.noarch.rpm +RUN yum install -y ca-policy-egi-core fetch-crl +RUN systemctl enable fetch-crl-cron; systemctl start fetch-crl-cron +RUN fetch-crl -v +RUN python3 -m pip install --upgrade pip setuptools wheel +RUN python3 -m pip install --upgrade productionsystem@git+https://github.com/alexanderrichards/ProductionSystem.git@$productionsystem_version +RUN . /root/dirac_ui/bashrc && python -m pip install --upgrade pip setuptools wheel && python -m pip install --upgrade productionsystem@git+https://github.com/alexanderrichards/ProductionSystem.git@$productionsystem_version +RUN yum clean all + +## setup cron jobs - maybe not needed if mounting from outside. +RUN echo "@daily userdb-update.py &>> /root/log/userdb-update.log" | crontab +RUN echo -e "[userdb]\ntrusted_cas='/etc/grid-security/certificates'" > /root/.config/productionsystem/productionsystem.conf +WORKDIR /root + +COPY startup.sh /root/startup.sh + +CMD ["all"] + +ENTRYPOINT ["/root/startup.sh"] diff --git a/build/Dockerfileold b/build/Dockerfileold new file mode 100644 index 0000000..473ae71 --- /dev/null +++ b/build/Dockerfileold @@ -0,0 +1,38 @@ +# syntax = docker/dockerfile:1.0-experimental +from centos:8 +ARG dirac_version=v6r22p6 +ARG lcgtools_version=v14r1 +ARG python_version=27 +ARG productionsystem_version=master + +RUN dnf swap -y coreutils-single coreutils # Fix for wrapper coreutils +RUN dnf install -y cronie gcc git wget python2 python3 python3-devel +RUN alternatives --set python /usr/bin/python2 # Set unversioned python command to python2 for DIRAC scripts +RUN python3 -m pip install --upgrade pip setuptools wheel +RUN python3 -m pip install --upgrade productionsystem@git+https://github.com/alexanderrichards/ProductionSystem.git@$productionsystem_version +RUN dnf clean all + +# DIRAC setup +RUN mkdir -p /root/dirac_ui +WORKDIR /root/dirac_ui +RUN wget -np -O dirac-install https://raw.githubusercontent.com/DIRACGrid/DIRAC/integration/Core/scripts/dirac-install.py +RUN chmod u+x dirac-install +RUN ./dirac-install --dirac-os -r $dirac_version -i $python_version -g $lcgtools_version +RUN --mount=type=secret,id=proxy,dst=/tmp/x509up_u0 . /root/dirac_ui/bashrc && dirac-configure -F -S GridPP -C dips://dirac01.grid.hep.ph.ic.ac.uk:9135/Configuration/Server -I +# These two lines are necessary as git commands broken in DIRACOS so need to check out first then pip install else could do commented out line below +RUN git clone -b $productionsystem_version https://github.com/alexanderrichards/ProductionSystem.git +RUN . /root/dirac_ui/bashrc && python -m pip install --upgrade ProductionSystem/ +#RUN . /root/dirac_ui/bashrc && python -m pip install -v --trusted-host github.com --upgrade productionsystem@git+https://github.com/alexanderrichards/ProductionSystem.git@$productionsystem_version +RUN rm -f dirac-install + + +## setup cron jobs - maybe not needed if mounting from outside. +RUN echo "@daily userdb-update.py &>> /root/log/userdb-update.log" | crontab + +WORKDIR /root + +COPY startup.sh /root/startup.sh + +CMD ["all"] + +ENTRYPOINT ["/root/startup.sh"] diff --git a/build/build.sh b/build/build.sh new file mode 100755 index 0000000..7758e90 --- /dev/null +++ b/build/build.sh @@ -0,0 +1,4 @@ +#!/bin/bash +(. ~/dirac_ui/bashrc && dirac-proxy-init -x) +#DOCKER_BUILDKIT=1 docker build --no-cache --progress=plain --secret id=proxy,src=/tmp/x509up_u`id -u` -t alexanderrichards/productionsystem:latest . +DOCKER_BUILDKIT=1 docker build --progress=plain --secret id=proxy,src=/tmp/x509up_u`id -u` -t alexanderrichards/productionsystem:latest . diff --git a/build/startup.sh b/build/startup.sh new file mode 100755 index 0000000..1ba1da9 --- /dev/null +++ b/build/startup.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +trap "stop_daemon $1 && exit 0" SIGTERM + +function stop_daemon { + case "$1" in + dirac) + echo "*** Stopping DIRAC daemon. ***" + (. /root/dirac_ui/bashrc && dirac-daemon.py stop) + ;; + monitoring) + echo "*** Stopping monitoring daemon. ***" + monitoring-daemon.py stop + ;; + webapp) + echo "*** Stopping web app daemon. ***" + webapp-daemon.py stop + ;; + all) + stop_daemon dirac + stop_daemon monitoring + stop_daemon webapp + ;; + *) + echo "Unknown parameter: $1" + echo "Expected: {dirac|monitoring|webapp|all}" + exit 1 + esac +} + +function start_daemon { + case "$1" in + dirac) + echo "*** Starting DIRAC daemon. ***" + (. /root/dirac_ui/bashrc && dirac-daemon.py start) + ;; + monitoring) + echo "*** Starting monitoring daemon. ***" + monitoring-daemon.py start + ;; + webapp) + echo "*** Starting web app daemon. ***" + webapp-daemon.py start + ;; + all) + start_daemon dirac + start_daemon monitoring + start_daemon webapp + ;; + *) + echo "Unknown parameter: $1" + echo "Expected: {dirac|monitoring|webapp|all}" + exit 1 + esac +} + +crond +start_daemon $1 +# Allow time to receive and process SIGTERM handler +while true +do +sleep 5 +done diff --git a/scripts/dirac-daemon.py b/scripts/dirac-daemon.py index bbc5030..8d7d7c2 100755 --- a/scripts/dirac-daemon.py +++ b/scripts/dirac-daemon.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 # pylint: disable=invalid-name """Dirac daemon run script.""" # Py2/3 compatibility layer diff --git a/scripts/monitoring-daemon.py b/scripts/monitoring-daemon.py index 0a13774..49c0bd8 100755 --- a/scripts/monitoring-daemon.py +++ b/scripts/monitoring-daemon.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # pylint: disable=invalid-name """ DB monitoring daemon. diff --git a/scripts/userdb-update.py b/scripts/userdb-update.py index 86b1254..08aa725 100755 --- a/scripts/userdb-update.py +++ b/scripts/userdb-update.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # pylint: disable=invalid-name """Script to read users info from VOMS and update locat SQL table.""" # Py2/3 compatibility layer diff --git a/scripts/webapp-daemon.py b/scripts/webapp-daemon.py index fec5e13..581ee41 100755 --- a/scripts/webapp-daemon.py +++ b/scripts/webapp-daemon.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # pylint: disable=invalid-name """Script to start the Production web server.""" # Py2/3 compatibility layer