apiVersion: v1
kind: ConfigMap
metadata:
  name: mbs-frontend-configmap
data:
  start.sh: |-
    mkdir /tmp/httpdir{,/run}
    ln -s /etc/httpd/modules /tmp/httpdir/modules
    truncate --size=0 /tmp/httpdir/accesslog /tmp/httpdir/errorlog
    tail -qf /tmp/httpdir/accesslog /tmp/httpdir/errorlog &
    ulimit -c 0
    exec httpd -f /etc/mbs-frontend/httpd.conf -DFOREGROUND -DNO_DETACH

  mbs.wsgi: |-
    import logging
    logging.basicConfig(level=logging.DEBUG)
    from module_build_service import app as application

  httpd.conf: |-
    ServerRoot "/tmp/httpdir"
    PidFile "/tmp/httpdir/httpd.pid"
    LoadModule authn_file_module modules/mod_authn_file.so
    LoadModule authn_anon_module modules/mod_authn_anon.so
    LoadModule authz_user_module modules/mod_authz_user.so
    LoadModule authz_host_module modules/mod_authz_host.so
    LoadModule include_module modules/mod_include.so
    LoadModule log_config_module modules/mod_log_config.so
    LoadModule env_module modules/mod_env.so
    LoadModule ext_filter_module modules/mod_ext_filter.so
    LoadModule expires_module modules/mod_expires.so
    LoadModule headers_module modules/mod_headers.so
    LoadModule mime_module modules/mod_mime.so
    LoadModule status_module modules/mod_status.so
    LoadModule dir_module modules/mod_dir.so
    LoadModule alias_module modules/mod_alias.so
    LoadModule rewrite_module modules/mod_rewrite.so
    LoadModule version_module modules/mod_version.so
    LoadModule wsgi_module modules/mod_wsgi_python3.so
    LoadModule authn_core_module modules/mod_authn_core.so
    LoadModule authz_core_module modules/mod_authz_core.so
    LoadModule unixd_module modules/mod_unixd.so
    LoadModule mpm_event_module modules/mod_mpm_event.so
    LoadModule ssl_module modules/mod_ssl.so
    StartServers  20
    ServerLimit   100
    MaxRequestsPerChild 2000
    MaxRequestWorkers 100
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    CustomLog /tmp/httpdir/accesslog combined
    ErrorLog /tmp/httpdir/errorlog
    LogLevel debug
    TypesConfig /etc/mime.types
    AddDefaultCharset UTF-8
    CoreDumpDirectory /tmp
    Listen 0.0.0.0:8443 https
    SSLEngine on
    SSLProtocol TLSv1.2

    WSGIDaemonProcess mbs_frontend display-name=mbs_frontend processes=2 threads=2 maximum-requests=1000 home=/tmp/httpdir
    WSGIProcessGroup mbs_frontend
    WSGIApplicationGroup %{GLOBAL}
    WSGISocketPrefix run/wsgi
    WSGIRestrictStdout Off
    WSGIRestrictSignal Off
    WSGIPythonOptimize 1

    WSGIScriptAlias / /etc/mbs-frontend/mbs.wsgi
    <Location />
      Require all granted
    </Location>

    RewriteEngine on
    RewriteRule ^(|/+)$ /module-build-service/1/module-builds/ [L,R=302]

    SSLCertificateFile /etc/servicecert/tls.crt
    SSLCertificateKeyFile /etc/servicecert/tls.key
    SSLCertificateChainFile /etc/cacert/cert
