From d44ae5501ff36cc52a98abc6c73d0bc8a1e4adfc Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Mon, 2 Nov 2020 17:25:58 +0100 Subject: [PATCH 1/2] Put an nginx reverse-proxy in front of the voila server to give us more flexibility in how we present the endpoint. --- .gitlab-ci.yml | 12 +++++++ README.md | 13 +++++++ app-config/docker-compose.yml | 13 +++++++ app-config/nginx/index.html | 3 ++ app-config/nginx/nginx.conf | 65 +++++++++++++++++++++++++++++++++++ app.sh | 3 +- 6 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 app-config/docker-compose.yml create mode 100644 app-config/nginx/index.html create mode 100644 app-config/nginx/nginx.conf diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b87c5097..7f4f0bfb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -25,3 +25,15 @@ trigger_build_on_openshift: - if: '$OPENSHIFT_BUILD_WEBHOOK_SECRET' script: - curl -X POST -k https://openshift.cern.ch:443/apis/build.openshift.io/v1/namespaces/cara/buildconfigs/cara-app/webhooks/${OPENSHIFT_BUILD_WEBHOOK_SECRET}/generic + + +deploy_to_test: + stage: deploy + rules: + - if: '$CI_MERGE_REQUEST_EVENT_TYPE == "detached"' + when: never + - if: '$OPENSHIFT_TEST_BUILD_WEBHOOK_SECRET' + when: manual + allow_failure: true + script: + - curl -X POST -k https://openshift-dev.cern.ch:443/apis/build.openshift.io/v1/namespaces/test-cara/buildconfigs/test-cara/webhooks/${OPENSHIFT_TEST_BUILD_WEBHOOK_SECRET}/generic diff --git a/README.md b/README.md index 0ba6d354..2c7cd501 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,19 @@ ## Development guide +### Building the docker image for local execution + +**Simulate the docker build that takes place on openshift with:** + +``` +s2i build file://$(pwd) --copy --context-dir=app-config/nginx/ centos/nginx-112-centos7 cara-nginx-app +s2i build file://$(pwd) --copy --context-dir=./ centos/python-36-centos7 cara-voila-app +cd app-config +docker-compose up +``` + +Then visit localhost:8080. + ### Setting up the application The https://cern.ch/cara application is running on CERN's OpenShift platform. In order to set it up for the first time, we followed the documentation at https://cern.service-now.com/service-portal?id=kb_article&n=KB0004498. In particular we: diff --git a/app-config/docker-compose.yml b/app-config/docker-compose.yml new file mode 100644 index 00000000..675b6829 --- /dev/null +++ b/app-config/docker-compose.yml @@ -0,0 +1,13 @@ +version: "3.8" +services: + cara-app: + image: cara-voila-app + # ports: + # - "8080:8081" + links: + - cara-router + cara-router: + image: cara-nginx-app + ports: + - "8080:8080" + diff --git a/app-config/nginx/index.html b/app-config/nginx/index.html new file mode 100644 index 00000000..264c7af2 --- /dev/null +++ b/app-config/nginx/index.html @@ -0,0 +1,3 @@ +

+Welcome! Please see the expert application. +

diff --git a/app-config/nginx/nginx.conf b/app-config/nginx/nginx.conf new file mode 100644 index 00000000..660f5616 --- /dev/null +++ b/app-config/nginx/nginx.conf @@ -0,0 +1,65 @@ +worker_processes auto; +error_log /var/log/nginx/error.log; +pid /run/nginx.pid; + +include /usr/share/nginx/modules/*.conf; + +events { + worker_connections 1024; +} + +http { + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + server { + listen 8080 default_server; + listen [::]:8080 default_server; + server_name _; + root /opt/app-root/src; + + # Load configuration files for the default server block. + include /opt/app-root/etc/nginx.default.d/*.conf; + + large_client_header_buffers 4 16k; + + location / { + } + + error_page 404 /404.html; + location = /40x.html { + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + } + + location /voila-server/ { + proxy_pass http://cara-app:8080/voila-server/; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_read_timeout 86400; + } + rewrite ^/expert-app$ /voila-server/voila/render/cara.ipynb last; + # Before implementing the nginx router we could access /voila/render/cara.ipynb. + # Redirect this (and all other) URLs to the new scheme. + rewrite ^/voila/(.*)$ /voila-server/voila/$1 redirect; + } +} \ No newline at end of file diff --git a/app.sh b/app.sh index ad938b68..e23f5afe 100755 --- a/app.sh +++ b/app.sh @@ -1 +1,2 @@ -voila app/ --port=8080 +voila app/ --port=8080 --no-browser --base_url=/voila-server/ --Voila.tornado_settings="{'allow_origin': '*'}" + From ffa2e53994a3562cacfcd8c075d568aa504dc919 Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Tue, 3 Nov 2020 12:38:38 +0100 Subject: [PATCH 2/2] Prepare the repository for having a separate calculator app. --- app-config/docker-compose.yml | 2 -- app-config/nginx/404.html | 1 + app-config/nginx/calculator-static | 1 + app-config/nginx/nginx.conf | 8 ++++++++ cara/apps/__init__.py | 4 ++++ cara/apps/calculator/__init__.py | 0 cara/apps/calculator/static/form.html | 0 cara/{apps.py => apps/expert.py} | 0 8 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 app-config/nginx/404.html create mode 120000 app-config/nginx/calculator-static create mode 100644 cara/apps/__init__.py create mode 100644 cara/apps/calculator/__init__.py create mode 100644 cara/apps/calculator/static/form.html rename cara/{apps.py => apps/expert.py} (100%) diff --git a/app-config/docker-compose.yml b/app-config/docker-compose.yml index 675b6829..917660ea 100644 --- a/app-config/docker-compose.yml +++ b/app-config/docker-compose.yml @@ -2,8 +2,6 @@ version: "3.8" services: cara-app: image: cara-voila-app - # ports: - # - "8080:8081" links: - cara-router cara-router: diff --git a/app-config/nginx/404.html b/app-config/nginx/404.html new file mode 100644 index 00000000..2000eebc --- /dev/null +++ b/app-config/nginx/404.html @@ -0,0 +1 @@ +Page not found! diff --git a/app-config/nginx/calculator-static b/app-config/nginx/calculator-static new file mode 120000 index 00000000..5605de12 --- /dev/null +++ b/app-config/nginx/calculator-static @@ -0,0 +1 @@ +../../cara/apps/calculator/static \ No newline at end of file diff --git a/app-config/nginx/nginx.conf b/app-config/nginx/nginx.conf index 660f5616..b32341d5 100644 --- a/app-config/nginx/nginx.conf +++ b/app-config/nginx/nginx.conf @@ -46,6 +46,8 @@ http { } location /voila-server/ { + # cara-app is the name of the voila server in each of docker-compose, + # test-cara.web.cern.ch and cara.web.cern.ch. proxy_pass http://cara-app:8080/voila-server/; proxy_set_header Host $host; @@ -58,6 +60,12 @@ http { proxy_read_timeout 86400; } rewrite ^/expert-app$ /voila-server/voila/render/cara.ipynb last; + + # Give the static content of the calculator app a sensible name which is + # consistent with the static directory of the calculator webserver used + # for development. + rewrite ^/calculator/static/(.*)$ /calculator-static/$1 last; + # Before implementing the nginx router we could access /voila/render/cara.ipynb. # Redirect this (and all other) URLs to the new scheme. rewrite ^/voila/(.*)$ /voila-server/voila/$1 redirect; diff --git a/cara/apps/__init__.py b/cara/apps/__init__.py new file mode 100644 index 00000000..da903ca1 --- /dev/null +++ b/cara/apps/__init__.py @@ -0,0 +1,4 @@ +from .expert import ExpertApplication + + +__all__ = ['ExpertApplication'] diff --git a/cara/apps/calculator/__init__.py b/cara/apps/calculator/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cara/apps/calculator/static/form.html b/cara/apps/calculator/static/form.html new file mode 100644 index 00000000..e69de29b diff --git a/cara/apps.py b/cara/apps/expert.py similarity index 100% rename from cara/apps.py rename to cara/apps/expert.py