Skip to content

Commit

Permalink
Merge branch 'feature/CO2_expert' into 'master'
Browse files Browse the repository at this point in the history
CO2 Expert App

See merge request caimira/caimira!424
  • Loading branch information
andrejhenriques committed Mar 29, 2023
2 parents 6998f93 + 29a14bb commit c963034
Show file tree
Hide file tree
Showing 25 changed files with 1,104 additions and 197 deletions.
10 changes: 5 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ auth-service-image_builder:
DOCKER_CONTEXT_DIRECTORY: app-config/auth-service


caimira-webservice-image_builder:
calculator-app-image_builder:
extends:
- .image_builder
variables:
IMAGE_NAME: caimira-webservice
DOCKERFILE_DIRECTORY: app-config/caimira-webservice
IMAGE_NAME: calculator-app
DOCKERFILE_DIRECTORY: app-config/calculator-app
DOCKER_CONTEXT_DIRECTORY: ""


Expand Down Expand Up @@ -159,11 +159,11 @@ link_auth-service_with_gitlab_registry:
variables:
IMAGE_NAME: auth-service

link_caimira-webservice_with_gitlab_registry:
link_calculator-app_with_gitlab_registry:
extends:
- .link_docker_images_with_gitlab_registry
variables:
IMAGE_NAME: caimira-webservice
IMAGE_NAME: calculator-app

link_calculator_with_gitlab_registry:
extends:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pytest ./caimira

```
s2i build file://$(pwd) --copy --keep-symlinks --context-dir ./app-config/nginx/ centos/nginx-112-centos7 caimira-nginx-app
docker build . -f ./app-config/caimira-webservice/Dockerfile -t caimira-webservice
docker build . -f ./app-config/calculator-app/Dockerfile -t calculator-app
docker build ./app-config/auth-service -t auth-service
```

Expand Down
1 change: 1 addition & 0 deletions app-config/caimira-public-docker-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ COPY ./app-config/caimira-public-docker-image/run_caimira.sh /opt/caimira/start.
# In the best case this will be a no-op.
RUN cd /opt/caimira/src/ && /opt/caimira/app/bin/pip install -r /opt/caimira/src/requirements.txt
RUN /opt/caimira/app/bin/jupyter trust /opt/caimira/src/caimira/apps/expert/*.ipynb
RUN /opt/caimira/app/bin/jupyter trust /opt/caimira/src/caimira/apps/expert_co2/*.ipynb
COPY ./app-config/caimira-public-docker-image/nginx.conf /opt/caimira/nginx.conf

EXPOSE 8080
Expand Down
6 changes: 6 additions & 0 deletions app-config/caimira-public-docker-image/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ http {
rewrite ^/expert-app$ /voila-server/ last;
rewrite ^/(files/static)/(.*)$ /voila-server/voila/$1/$2 last;

location /co2-voila-server/ {
proxy_pass http://localhost:8083/co2-voila-server/;
}
rewrite ^/co2-app$ /voila-server/ last;
rewrite ^/(files/static)/(.*)$ /voila-server/voila/$1/$2 last;

location / {
proxy_pass http://localhost:8081;
}
Expand Down
5 changes: 5 additions & 0 deletions app-config/caimira-public-docker-image/run_caimira.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ cd /opt/caimira/src/caimira
--Voila.tornado_settings 'allow_origin=*' \
>> /var/log/expert-app.log 2>&1 &

/opt/caimira/app/bin/python -m voila /opt/caimira/src/caimira/apps/expert_co2/caimira.ipynb \
--port=8083 --no-browser --base_url=/co2-voila-server/ \
--Voila.tornado_settings 'allow_origin=*' \
>> /var/log/co2-app.log 2>&1 &

# Run the calculator in the foreground.
/opt/caimira/app/bin/python -m caimira.apps.calculator --port 8081 --no-debug
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM registry.cern.ch/docker.io/condaforge/mambaforge as conda
RUN mamba create --yes -p /opt/app python=3.9
COPY . /opt/app-source
RUN cd /opt/app-source && conda run -p /opt/app python -m pip install -r ./requirements.txt .[app]
COPY app-config/caimira-webservice/app.sh /opt/app/bin/caimira-app.sh
COPY app-config/calculator-app/app.sh /opt/app/bin/calculator-app.sh
RUN cd /opt/app \
&& find -name '*.a' -delete \
&& rm -rf /opt/app/conda-meta \
Expand Down Expand Up @@ -32,5 +32,5 @@ WORKDIR /scratch
RUN CAIMIRA_INIT_FILE=$(/opt/app/bin/python -c "import caimira; print(caimira.__file__)") \
&& ln -s $(dirname ${CAIMIRA_INIT_FILE}) /scratch/caimira
CMD [ \
"caimira-app.sh" \
"calculator-app.sh" \
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [[ "$APP_NAME" == "caimira-webservice" ]]; then
if [[ "$APP_NAME" == "calculator-app" ]]; then
args=("$@")
if [ "$DEBUG" != "true" ] && [[ ! "${args[@]}" =~ "--no-debug" ]]; then
args+=("--no-debug")
Expand All @@ -26,6 +26,9 @@ if [[ "$APP_NAME" == "caimira-webservice" ]]; then
elif [[ "$APP_NAME" == "caimira-voila" ]]; then
echo "Starting the voila service"
voila caimira/apps/expert/ --port=8080 --no-browser --base_url=/voila-server/ --tornado_settings 'allow_origin=*'
elif [[ "$APP_NAME" == "caimira-co2-voila" ]]; then
echo "Starting the CO2 voila service"
voila caimira/apps/expert_co2/ --port=8080 --no-browser --base_url=/co2-voila-server/ --tornado_settings 'allow_origin=*'
else
echo "No APP_NAME specified"
exit 1
Expand Down
30 changes: 19 additions & 11 deletions app-config/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
version: "3.8"
services:
caimira-app:
image: caimira-webservice
expert-app:
image: calculator-app
environment:
- APP_NAME=caimira-voila
user: ${CURRENT_UID:?"Please run as follows 'CURRENT_UID=$(id -u):$(id -g) docker-compose up'"}

caimira-webservice:
image: caimira-webservice
expert-co2-app:
image: calculator-app
environment:
- APP_NAME=caimira-co2-voila
user: ${CURRENT_UID:?"Please run as follows 'CURRENT_UID=$(id -u):$(id -g) docker-compose up'"}

calculator-app:
image: calculator-app
environment:
- COOKIE_SECRET
- APP_NAME=caimira-webservice
- APP_NAME=calculator-app
- APPLICATION_ROOT=/
- CAIMIRA_CALCULATOR_PREFIX=/calculator-cern
- CAIMIRA_THEME=caimira/apps/templates/cern
user: ${CURRENT_UID}

caimira-calculator-open:
image: caimira-webservice
calculator-open-app:
image: calculator-app
environment:
- COOKIE_SECRET
- APP_NAME=caimira-webservice
- APP_NAME=calculator-app
- APPLICATION_ROOT=/
- CAIMIRA_CALCULATOR_PREFIX=/calculator-open
user: ${CURRENT_UID}
Expand All @@ -40,11 +46,13 @@ services:
ports:
- "8080:8080"
depends_on:
caimira-webservice:
calculator-app:
condition: service_started
calculator-open-app:
condition: service_started
caimira-calculator-open:
expert-app:
condition: service_started
caimira-app:
expert-co2-app:
condition: service_started
auth-service:
condition: service_started
Expand Down
33 changes: 26 additions & 7 deletions app-config/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ http {
# Pass the request on to the webservice. Most likely the URI won't
# exist so we get a 404 from that service instead (good as the 404
# pages are consistent).
proxy_pass http://caimira-webservice:8080/$request_uri;
proxy_pass http://calculator-app:8080/$request_uri;
}

location /voila-server/ {
Expand All @@ -81,9 +81,9 @@ http {
error_page 401 = @error401;
error_page 404 = @proxy_404_error_handler;

# caimira-app is the name of the voila server in each of docker-compose,
# expert-app is the name of the voila server in each of docker-compose,
# caimira-test.web.cern.ch and caimira.web.cern.ch.
proxy_pass http://caimira-app:8080/voila-server/;
proxy_pass http://expert-app:8080/voila-server/;
}
rewrite ^/expert-app$ /voila-server/voila/render/caimira.ipynb last;
rewrite ^/(files/static)/(.*)$ /voila-server/voila/$1/$2 last;
Expand All @@ -93,9 +93,28 @@ http {
absolute_redirect off;
rewrite ^/voila/(.*)$ /voila-server/voila/$1 redirect;

location /co2-voila-server/ {
proxy_intercept_errors on;

# Anything under voila-server or co2-app is authenticated.
auth_request /auth/probe;
error_page 401 = @error401;
error_page 404 = @proxy_404_error_handler;

# expert-co2-app is the name of the voila server in each of docker-compose,
# caimira-test.web.cern.ch and caimira.web.cern.ch.
proxy_pass http://expert-co2-app:8080/co2-voila-server/;
}
rewrite ^/co2-app$ /co2-voila-server/voila/render/caimira.ipynb last;
rewrite ^/(files/static)/(.*)$ /co2-voila-server/voila/$1/$2 last;

# Before implementing the nginx router we could access /voila/render/caimira.ipynb.
# Redirect this (and all other) URLs to the new scheme.
rewrite ^/voila/(.*)$ /co2-voila-server/voila/$1 redirect;

location / {
# By default we have no authentication.
proxy_pass http://caimira-webservice:8080;
proxy_pass http://calculator-app:8080;
}

location /calculator {
Expand All @@ -107,14 +126,14 @@ http {
auth_request /auth/probe;
error_page 401 = @error401;

# caimira-webservice is the name of the tornado server (for the calculator)
# calculator-app is the name of the tornado server (for the calculator)
# in each of docker-compose, caimira-test.web.cern.ch and caimira.web.cern.ch.
proxy_pass http://caimira-webservice:8080/calculator-cern;
proxy_pass http://calculator-app:8080/calculator-cern;
}

location /calculator-open {
# Public open calculator
proxy_pass http://caimira-calculator-open:8080/calculator-open;
proxy_pass http://calculator-open-app:8080/calculator-open;
}
}
}
Loading

0 comments on commit c963034

Please sign in to comment.