#141 OpenShift
Merged 4 years ago by lholecek. Opened 4 years ago by frantisekz.

file added
+2
@@ -0,0 +1,2 @@ 

+ UPGRADE_PIP_TO_LATEST=1

+ APP_CONFIG=/opt/app-root/src/gunicorn.cfg

file modified
+55 -8
@@ -1,10 +1,57 @@ 

- FROM fedoraqa/flask-base:24

+ # This will produce an image to be used in Openshift

+ # Build should be triggered from repo root like:

+ # docker build -f openshift/Dockerfile \

+ #              --tag <IMAGE_TAG>

  

- COPY . /usr/src/resultsdb

- WORKDIR /usr/src/resultsdb

- EXPOSE 5001

- ENV DEV true

- RUN pip install -r requirements.txt &&\

-     python run_cli.py init_db

+ FROM registry.fedoraproject.org/fedora:33

+ 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=""

+ 

+ USER root

+ COPY ./resultsdb.spec /opt/app-root/src/resultsdb/resultsdb.spec

+ 

+ # install dependencies defined in RPM spec file

+ RUN dnf -y install findutils rpm-build python3-pip python3-mod_wsgi httpd python3-psycopg2 python3-stomppy \

+     && rpm --query --requires --specfile /opt/app-root/src/resultsdb/resultsdb.spec | xargs -d '\n' dnf -y install

+ 

+ COPY . /opt/app-root/src/resultsdb/

+ # install using --no-deps option to ensure nothing comes from PyPi

+ RUN pip3 install --no-deps /opt/app-root/src/resultsdb

+ 

+ # fix apache config for container use

+ RUN sed -i 's#^WSGISocketPrefix .*#WSGISocketPrefix /tmp/wsgi#' /opt/app-root/src/resultsdb/conf/resultsdb.conf

  

- CMD ["python", "runapp.py"]

+ # config files

+ RUN install -d /usr/share/resultsdb/conf \

+     && install -p -m 0644 /opt/app-root/src/resultsdb/conf/resultsdb.conf /usr/share/resultsdb/conf/ \

+     && install -p -m 0644 /opt/app-root/src/resultsdb/conf/resultsdb.wsgi /usr/share/resultsdb/ \

+     && install -d /etc/resultsdb \

+     && install -p -m 0644 /opt/app-root/src/resultsdb/conf/resultsdb.conf /etc/httpd/conf.d/

+ 

+ # alembic

+ RUN install -p -m 0644 /opt/app-root/src/resultsdb/alembic.ini /usr/share/resultsdb/alembic.ini

+ RUN cp -a /opt/app-root/src/resultsdb/resultsdb/alembic /usr/share/resultsdb/alembic

+ RUN chmod -R 0755 /usr/share/resultsdb/alembic

+ 

+ # clean up

+ RUN rm -rf /opt/app-root/src/resultsdb \

+     && dnf -y autoremove findutils rpm-build \

+     && dnf clean all

+ 

+ # EXPOSE 5001/tcp

+ EXPOSE 5001

+ CMD ["mod_wsgi-express-3", "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" \

+ ]

+ USER 1001:0

file added
+5
@@ -0,0 +1,5 @@ 

+ import logging

+ import sys

+ 

+ gunicorn_logger = logging.getLogger('gunicorn.error')

+ gunicorn_logger.addHandler(logging.StreamHandler(sys.stdout))

file modified
+3
@@ -21,4 +21,7 @@ 

  # Test suite requirements

  pytest >= 2.4.2

  pytest-cov >= 1.6

+ 

+ # s2i requirements

  psycopg2

+ gunicorn

file modified
+12 -1
@@ -19,6 +19,7 @@ 

  #   Ralph Bean <rbean@redhat.com>

  

  from resultsdb import proxy

+ from . import config

  

  import flask

  from flask import Flask
@@ -67,11 +68,18 @@ 

  

  flask.jsonify = jsonify_with_jsonp

  

+ # Checks for env variable OPENSHIFT_PROD to trigger OpenShift codepath on init

+ # The main difference is that settings will be queried from env (check config.openshift_config())

+ # Possible values are:

+ # "1" - OpenShift production deployment

+ # "0" - OpenShift testing deployment

+ openshift = os.getenv('OPENSHIFT_PROD')

+ 

  # Load default config, then override that with a config file

  if os.getenv('DEV') == 'true':

      default_config_obj = 'resultsdb.config.DevelopmentConfig'

      default_config_file = os.getcwd() + '/conf/settings.py'

- elif os.getenv('TEST') == 'true':

+ elif os.getenv('TEST') == 'true' or openshift == "0":

      default_config_obj = 'resultsdb.config.TestingConfig'

      default_config_file = os.getcwd() + '/conf/settings.py'

  else:
@@ -80,6 +88,9 @@ 

  

  app.config.from_object(default_config_obj)

  

+ if openshift:

+     config.openshift_config(app.config, openshift)

+ 

  config_file = os.environ.get('RESULTSDB_CONFIG', default_config_file)

  

  if os.path.exists(config_file):

file modified
+34
@@ -17,7 +17,9 @@ 

  # Authors:

  #   Josef Skladanka <jskladan@redhat.com>

  #   Ralph Bean <rbean@redhat.com>

+ 

  import os

+ import sys

  

  

  class Config(object):
@@ -116,3 +118,35 @@ 

      ADDITIONAL_RESULT_OUTCOMES = ('AMAZING',)

      MESSAGE_BUS_PLUGIN = 'dummy'

      MESSAGE_BUS_KWARGS = {}

+ 

+ 

+ def openshift_config(config_object, openshift_production):

+     # First, get db details from env

+     try:

+         config_object["SQLALCHEMY_DATABASE_URI"] = "postgresql+psycopg2://%s:%s@%s:%s/%s" % (

+             os.environ["POSTGRESQL_USER"],

+             os.environ["POSTGRESQL_PASSWORD"],

+             os.environ["POSTGRESQL_SERVICE_HOST"],

+             os.environ["POSTGRESQL_SERVICE_PORT"],

+             os.environ["POSTGRESQL_DATABASE"]

+         )

+         config_object["SECRET_KEY"] = os.environ["SECRET_KEY"]

+     except KeyError:

+         print("OpenShift mode enabled but required values couldn't be fetched. "

+               "Check, if you have these variables defined in you env: "

+               "(POSTGRESQL_[USER, PASSWORD, DATABASE, SERVICE_HOST, SERVICE_PORT], "

+               "SECRET_KEY)", file=sys.stderr)

+         sys.exit(1)

+ 

+     # Nuke out messaging, we don't support this in OpenShift mode

+     # Inject settings.py and disable OpenShift mode if you need this

+     config_object["MESSAGE_BUS_PLUGIN"] = 'dummy'

+     config_object["MESSAGE_BUS_KWARGS"] = {}

+ 

+     if os.getenv("MESSAGE_BUS_PLUGIN") or os.getenv("MESSAGE_BUS_KWARGS"):

+         print("It appears you've tried to set up messaging in OpenShift mode.")

+         print("This is not supported, you need to inject setting.py and disable "

+               "OpenShift mode if you need messaging.")

+ 

+     # Danger zone, keep this False out in the wild, always

+     config_object["SHOW_DB_URI"] = False

file added
+1
@@ -0,0 +1,1 @@ 

+ from resultsdb import app as application

no initial comment

Since Dockerhub is now rate-limited now [1], it's better to use registry.fedoraproject.org/fedora:32.

[1] https://www.docker.com/increase-rate-limit

This requires a comment. Where is this variable coming from and what are the possible values? From the code below it seems that it's assumed to be either "0" or empty/unset.

Why not fedora:33? So we don't have to upgrade it very soon.

PEP8: E302 2 blank lines needed

this line seems too long

rebased onto b1b34ae

4 years ago

Feedback should be addressed, PR rebased on top of develop.

Pull-Request has been merged by lholecek

4 years ago