From 067633f8023fcf5477923e29665cab21f635c127 Mon Sep 17 00:00:00 2001 From: Hunor Csomortáni Date: Jun 14 2018 10:32:41 +0000 Subject: [PATCH 1/6] Build OpenShift container image on Fedora 28 This will sync the container image to be used in OpenShift deployements with WaiverDB and Greenwave. mod_wsgi-express is provided by mod_wsgi in the Fedora repos now, so remove installing it from PyPi and use dnf instead. Signed-off-by: Hunor Csomortáni --- diff --git a/openshift/Dockerfile b/openshift/Dockerfile index 1d1e281..d20e46d 100644 --- a/openshift/Dockerfile +++ b/openshift/Dockerfile @@ -2,7 +2,7 @@ # Build should be triggered from repo root like: # docker build -f openshift/Dockerfile --tag 172.30.1.1:5000/myproject/resultsdb:latest --build-arg resultsdb_rpm=resultsdb-2.0.2-1.fc25.noarch.rpm . -FROM registry.fedoraproject.org/f27/httpd:latest +FROM fedora:28 LABEL \ name="ResultsDB application" \ vendor="ResultsDB developers" \ @@ -15,21 +15,14 @@ USER 0 ARG resultsdb_rpm COPY $resultsdb_rpm /tmp -RUN yum -y update \ - && yum -y install --setopt=tsflags=nodocs \ +RUN dnf -y update \ + && dnf -y install --setopt=tsflags=nodocs \ python-psycopg2 \ - httpd-devel \ - python-devel \ - gcc \ - python2-pip \ + httpd \ + mod_wsgi \ /tmp/$(basename $resultsdb_rpm) \ - && yum clean all \ + && dnf clean all \ && rm -f /tmp/$(basename $resultsdb_rpm) - -# This is installed from pypi, in order to get -# mod_wsgi-express. -RUN pip install mod_wsgi - COPY openshift/run_app.sh /usr/bin/run_app RUN chmod 770 /usr/bin/run_app From 794a08c2d3c2cecee84f6e8ba072bd877e02d3f1 Mon Sep 17 00:00:00 2001 From: Hunor Csomortáni Date: Jun 14 2018 10:41:58 +0000 Subject: [PATCH 2/6] Allow resultsdb_rpm build arg to be a URL Signed-off-by: Hunor Csomortáni --- diff --git a/openshift/Dockerfile b/openshift/Dockerfile index d20e46d..578d718 100644 --- a/openshift/Dockerfile +++ b/openshift/Dockerfile @@ -1,6 +1,8 @@ # This will produce an image to be used in Openshift # Build should be triggered from repo root like: -# docker build -f openshift/Dockerfile --tag 172.30.1.1:5000/myproject/resultsdb:latest --build-arg resultsdb_rpm=resultsdb-2.0.2-1.fc25.noarch.rpm . +# docker build -f openshift/Dockerfile \ +# --tag \ +# --build-arg resultsdb_rpm= ./ FROM fedora:28 LABEL \ @@ -11,9 +13,10 @@ LABEL \ USER 0 -# The caller should build a resultsdb RPM package using and then pass it in this arg. +# The caller should build a resultsdb RPM package used and then pass it in this arg. +# Accept both a URL or a local path relative to the build context. ARG resultsdb_rpm -COPY $resultsdb_rpm /tmp +ADD $resultsdb_rpm /tmp RUN dnf -y update \ && dnf -y install --setopt=tsflags=nodocs \ From fef28616a7df5f4cb5e42c5d8e949772e7640b67 Mon Sep 17 00:00:00 2001 From: Hunor Csomortáni Date: Jun 14 2018 10:45:35 +0000 Subject: [PATCH 3/6] Remove USER directives Follow OpenShift guidelines [0], and adjust the group ownership of the start-up script, instead of manipulating the user ID. [0] Signed-off-by: Hunor Csomortáni --- diff --git a/openshift/Dockerfile b/openshift/Dockerfile index 578d718..78d27af 100644 --- a/openshift/Dockerfile +++ b/openshift/Dockerfile @@ -11,8 +11,6 @@ LABEL \ license="GPLv2+" \ build-date="" -USER 0 - # The caller should build a resultsdb RPM package used and then pass it in this arg. # Accept both a URL or a local path relative to the build context. ARG resultsdb_rpm @@ -27,8 +25,8 @@ RUN dnf -y update \ && dnf clean all \ && rm -f /tmp/$(basename $resultsdb_rpm) COPY openshift/run_app.sh /usr/bin/run_app -RUN chmod 770 /usr/bin/run_app +RUN chgrp 0 /usr/bin/run_app && \ + chmod g=u /usr/bin/run_app -USER 1001 EXPOSE 5001 ENTRYPOINT run_app From bcf05c3f49a0d5a278b0efd757673ec0a7e8a185 Mon Sep 17 00:00:00 2001 From: Hunor Csomortáni Date: Jun 14 2018 11:54:32 +0000 Subject: [PATCH 4/6] Document usage of the OpenShift container image Add description and usage labels, and define expectations for volume mounts. Signed-off-by: Hunor Csomortáni --- diff --git a/openshift/Dockerfile b/openshift/Dockerfile index 78d27af..0bd7f9f 100644 --- a/openshift/Dockerfile +++ b/openshift/Dockerfile @@ -9,6 +9,8 @@ LABEL \ name="ResultsDB application" \ vendor="ResultsDB developers" \ license="GPLv2+" \ + description="ResultsDB is a results store engine for, but not limited to, Fedora QA tools." \ + usage="https://pagure.io/taskotron/resultsdb/blob/develop/f/openshift/README.md" \ build-date="" # The caller should build a resultsdb RPM package used and then pass it in this arg. @@ -28,5 +30,6 @@ COPY openshift/run_app.sh /usr/bin/run_app RUN chgrp 0 /usr/bin/run_app && \ chmod g=u /usr/bin/run_app -EXPOSE 5001 +EXPOSE 5001/tcp +VOLUME ["/etc/resultsdb", "/etc/httpd/conf.d"] ENTRYPOINT run_app diff --git a/openshift/README.md b/openshift/README.md new file mode 100644 index 0000000..6819eab --- /dev/null +++ b/openshift/README.md @@ -0,0 +1,61 @@ +Building the container image +============================ + +Building the container image requires the ResultsDB rpm to be provided as a +build argument: + +```bash +$ docker build -f openshift/Dockerfile \ + --tag \ + --build-arg resultsdb_rpm= ./ +``` + +`IMAGE_TAG` is the tag to be applied on the image built. + +`RESULTSDB_RPM` is either the URL of the ResultsDB rpm, or the relative path of +that rpm *within* the build context. + + +Using the container image +========================= + +The container image has port `5001/tcp` marked as exposed, but the port to be +used by ResultsDB can be changed in the configuration with the `RUN_PORT` +configuration option. + +There are two volumes expected to be mounted, holding configuration for +ResultsDB and httpd: + +1. The volume mounted at `/etc/resultsdb` should have `settings.py`, holding + ResultsDB configuration. For an example, see `settings.py` in + `resultsdb-test-template.yaml`, or `conf/settings.py.example` + for a full list of configuration options. + +2. The volume mounted at `/etc/httpd/conf.d` should have `resultsdb.conf`, + holding httpd configuration to be used by `mod_wsgi-express`. For an + example, see `resultsdb.conf` in `resultsdb-test-template.yaml`. + + +Deploying to OpenShift +====================== + +`resultsdb-test-template.yaml` defines the +[template](https://docs.openshift.org/latest/dev_guide/templates.html) to +deploy ResultsDB and a PostgreSQL database to OpenShift. + +For the full list of template parameters see: + +```bash +$ oc process -f openshift/resultsdb-test-template.yaml --parameters +``` + +For creating the environment run: + +```bash +$ oc process -f openshift/resultsdb-test-template.yaml \ + -p TEST_ID= \ + -p RESULTSDB_IMAGE= | oc apply -f - +``` + +Use the `-p` option of `oc process` to override default values of the template +parameters. From da9d0866dc4e4a56b760aaebbf0c37215d879061 Mon Sep 17 00:00:00 2001 From: Hunor Csomortáni Date: Jun 26 2018 07:42:37 +0000 Subject: [PATCH 5/6] Add pre-deployment hook Using pre-deployment hooks to initialise the database is safer and the right way to go. See: https://pagure.io/waiverdb/issue/121 In order handle timeouts due to the database service not being available as the hook is executed, `resultsdb init_db` is being re-triggered for up to 10 minutes, until succeeds. Signed-off-by: Hunor Csomortáni --- diff --git a/openshift/resultsdb-test-template.yaml b/openshift/resultsdb-test-template.yaml index 250e856..cda18c1 100644 --- a/openshift/resultsdb-test-template.yaml +++ b/openshift/resultsdb-test-template.yaml @@ -162,9 +162,6 @@ objects: labels: environment: "test-${TEST_ID}" app: resultsdb - annotations: - service.alpha.openshift.io/dependencies: |- - [{"name": "resultsdb-test-${TEST_ID}-database", "kind": "Service"}] spec: selector: app: resultsdb @@ -197,9 +194,6 @@ objects: labels: environment: "test-${TEST_ID}" app: resultsdb - annotations: - service.alpha.openshift.io/dependencies: |- - [{"name": "resultsdb-test-${TEST_ID}-database", "kind": "Service"}] spec: selector: app: resultsdb @@ -284,6 +278,31 @@ objects: app: resultsdb environment: "test-${TEST_ID}" service: internal-api + strategy: + type: Rolling + rollingParams: + pre: + failurePolicy: Abort + execNewPod: + containerName: api + command: + - /bin/sh + - -i + - -c + - | + # try for 10 minutes (600 seconds) + e=$(( $(date +%s) + 600 )) + i=0 + while [ $(date +%s) -lt $e ]; do + echo 'TRY #'$((++i)) + if resultsdb init_db ; then + exit 0 + fi + done + exit 1 + volumes: + - config-volume + - httpd-config-volume template: metadata: labels: From c22f6b035ab6bce39db6caa228a3ec8b7a0e12a5 Mon Sep 17 00:00:00 2001 From: Hunor Csomortáni Date: Jun 26 2018 07:42:37 +0000 Subject: [PATCH 6/6] Modify container entrypoint As the database initialisation is triggered as a pre-deployement hook, there is no need for the run_app script anymore. This also tries to follow recommendations for ENTRYPOINT and CMD usage, and use CMD as a way to define default arguments for the ENTRYPOINT. Signed-off-by: Hunor Csomortáni --- diff --git a/openshift/Dockerfile b/openshift/Dockerfile index 0bd7f9f..cd5eddc 100644 --- a/openshift/Dockerfile +++ b/openshift/Dockerfile @@ -26,10 +26,16 @@ RUN dnf -y update \ /tmp/$(basename $resultsdb_rpm) \ && dnf clean all \ && rm -f /tmp/$(basename $resultsdb_rpm) -COPY openshift/run_app.sh /usr/bin/run_app -RUN chgrp 0 /usr/bin/run_app && \ - chmod g=u /usr/bin/run_app EXPOSE 5001/tcp VOLUME ["/etc/resultsdb", "/etc/httpd/conf.d"] -ENTRYPOINT run_app +ENTRYPOINT ["mod_wsgi-express", "start-server", "/usr/share/resultsdb/resultsdb.wsgi"] +CMD [\ + "--user", "apache", "--group", "apache", \ + "--port", "5001", "--threads", "5", \ + "--include-file", "/etc/httpd/conf.d/resultsdb.conf", \ + "--log-level", "info", \ + "--log-to-terminal", \ + "--access-log", \ + "--startup-log" \ +] diff --git a/openshift/run_app.sh b/openshift/run_app.sh deleted file mode 100755 index 404a2f5..0000000 --- a/openshift/run_app.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -set -x -set -e - -# initialize db (in a non-destructive manner) -env resultsdb init_db - -exec mod_wsgi-express start-server /usr/share/resultsdb/resultsdb.wsgi \ - --user apache --group apache \ - --port 5001 --threads 5 \ - --include-file /etc/httpd/conf.d/resultsdb.conf \ - --log-level info \ - --log-to-terminal \ - --access-log \ - --startup-log