Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback nginx to serve "something went wrong" #950

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions services/simcore/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
docker-compose.deploy.yml
docker-compose.yml
dask-sidecar/**
5 changes: 5 additions & 0 deletions services/simcore/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ compose-aws: .env ${TEMP_COMPOSE}-aws ## Create docker-compose.deploy for AWS
.PHONY: compose-master
compose-master: .env ${TEMP_COMPOSE}-master ## Create docker-compose.deploy for Master

.PHONY: docker-compose.yml
docker-compose.yml: .venv .env
@$(call jinja, docker-compose.yml.j2, .env, docker-compose.yml.unlinted) && \
$(_yq) docker-compose.yml.unlinted > docker-compose.yml; \
rm docker-compose.yml.unlinted >/dev/null 2>&1;

.PHONY: ${TEMP_COMPOSE}-local
${TEMP_COMPOSE}-local: docker-compose.yml docker-compose.deploy.local.yml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"errors": ["Oops! Something went wrong. Please try again."]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
server {
listen 80;
listen [::]:80;
server_name localhost;

error_page 503 /503.json;

location / {
return 503;
}

location = /503.json {
default_type application/json;

add_header Retry-After "10" always; # https://serverfault.com/a/647552

root /usr/share/nginx/api;
}
}
72 changes: 72 additions & 0 deletions services/simcore/configs/fallback-service-nginx/web/503.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<html style="overflow: hidden; margin: 0px; padding: 0px; height: 100%; width: 100%;"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

<!-- Setup the viewport for mobile and desktop environments -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">

<!-- Configure linking of this application to the home screen of mobile devices -->
<meta name="apple-mobile-web-app-title" content="${name}">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<meta name="msapplication-tap-highlight" content="no">

<!-- Disable chrome translation requests and automatic phone number linking -->
<meta name="google" value="notranslate">

<style>
body {
padding: 0px;
margin: 0px;
width: 100%;
height: 100%;
position: fixed;
-webkit-touch-callout: none !important;
overflow: hidden;
background-color: #202020;
}

.container {
position: relative;
text-align: center;
color: white;
}
.box {
/* 50% darker than the main color bg */
opacity: .7;
padding-bottom: 20px;
padding-top: 1px;
padding-right: 40px;
padding-left: 40px;
}
.centered {
position: absolute;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
}
h2 {
font-family: "Helvetica";
font-size: 2.4em;
color: white;
text-align: center;
}
</style>

<title>Oops</title>

<noscript>
<meta http-equiv="refresh" content="0; url=nojs.html"/>
</noscript>
<body>
<div class="container"></div>
<div class="centered">
<div class="box">
<h2>
Oops! Something went wrong.<br>Please try again.
</h2>
</div>
</div>
</section>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
server {
listen 80;
listen [::]:80;
server_name localhost;

error_page 503 /503.html;

location / {
return 503;
}

location = /503.html {
default_type text/html;

add_header Retry-After "10" always; # https://serverfault.com/a/647552

root /usr/share/nginx/html;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ services:
agent:
networks:
- monitored
{%- raw %}
hostname: "{{.Node.Hostname}}-{{.Service.Name}}"
{%- endraw %}
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
Expand Down Expand Up @@ -270,9 +272,10 @@ services:
<<: *webserver_resources
extra_hosts: []


wb-db-event-listener:
{%- raw %}
hostname: "{{.Service.Name}}"
{%- endraw %}
environment:
- WEBSERVER_LOGLEVEL=${WEBSERVER_LOGLEVEL}
networks:
Expand Down Expand Up @@ -311,7 +314,9 @@ services:
- default
- interactive_services_subnet
- monitored
{%- raw %}
hostname: "{{.Service.Name}}"
{%- endraw %}
deploy:
update_config:
parallelism: 2
Expand Down Expand Up @@ -538,7 +543,9 @@ services:
cpus: '0.1'

efs-guardian:
{%- raw %}
hostname: "{{.Service.Name}}"
{% endraw %}
networks:
- monitored
deploy:
Expand Down Expand Up @@ -644,7 +651,9 @@ services:
networks:
- monitored
- public
{%- raw %}
hostname: "{{.Service.Name}}"
{% endraw %}
deploy:
# NOTE: https://github.com/ITISFoundation/osparc-simcore/pull/4286
# NOTE: this MUSTN'T change, or weird things might happen
Expand Down Expand Up @@ -768,6 +777,7 @@ services:
reservations:
memory: 128M
cpus: '0.1'

traefik_api:
# NOTE: this is a trick to allow to access the internal traefik REST API
# A comment
Expand Down Expand Up @@ -813,6 +823,7 @@ services:
reservations:
memory: 8M
cpus: '0.1'

whoami:
image: "containous/whoami:v1.5.0"
networks:
Expand Down Expand Up @@ -851,6 +862,7 @@ services:
reservations:
memory: 8M
cpus: '0.1'

payments:
deploy:
placement:
Expand Down Expand Up @@ -894,9 +906,82 @@ services:
- traefik.http.routers.${PREFIX_STACK_NAME}_dynamic_scheduler.tls=true
- traefik.http.routers.${PREFIX_STACK_NAME}_dynamic_scheduler.middlewares=ops_gzip@swarm, ops_auth@swarm

fallback-service-web:
image: nginx:1.25.1
configs:
- source: {{ SWARM_STACK_NAME }}_web_html
target: /usr/share/nginx/html/503.html
- source: {{ SWARM_STACK_NAME }}_web_nginx_config
target: /etc/nginx/conf.d/default.conf
networks:
- public
- monitored
deploy:
placement:
constraints:
- node.labels.simcore==true
update_config:
order: start-first
labels:
- io.simcore.zone=${TRAEFIK_SIMCORE_ZONE}
- traefik.enable=true

# webserver
- traefik.http.routers.${PREFIX_STACK_NAME}_fallback_html.priority=1
- traefik.http.routers.${PREFIX_STACK_NAME}_fallback_html.rule=(Path(`/`) || Path(`/v0`) || Path(`/socket.io/`) || Path(`/static-frontend-data.json`) || PathRegexp(`^/study/(?P<study_uuid>\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b)`) || Path(`/view`) || Path(`/#/view`) || Path(`/#/error`) || PathPrefix(`/v0/`))
- traefik.http.services.${PREFIX_STACK_NAME}_fallback_html.loadbalancer.server.port=80
- traefik.http.routers.${PREFIX_STACK_NAME}_fallback_html.entrypoints=http

fallback-service-api:
image: nginx:1.25.1
configs:
- source: {{ SWARM_STACK_NAME }}_api_json
target: /usr/share/nginx/api/503.json
- source: {{ SWARM_STACK_NAME }}_api_nginx_config
target: /etc/nginx/conf.d/default.conf
networks:
- public
- monitored
deploy:
placement:
constraints:
- node.labels.simcore==true
update_config:
order: start-first
labels:
- io.simcore.zone=${TRAEFIK_SIMCORE_ZONE}
- traefik.enable=true
# api-server
- traefik.http.routers.${PREFIX_STACK_NAME}_fallback_api.priority=1
- traefik.http.routers.${PREFIX_STACK_NAME}_fallback_api.rule=Path(`/`) || Path(`/v0`) || PathPrefix(`/v0/`) || Path(`/api/v0/openapi.json`)
- traefik.http.services.${PREFIX_STACK_NAME}_fallback_api.loadbalancer.server.port=80
- traefik.http.routers.${PREFIX_STACK_NAME}_fallback_api.entrypoints=simcore_api
- traefik.http.routers.${PREFIX_STACK_NAME}_fallback_api.service=${PREFIX_STACK_NAME}_fallback_api
# invitations
- traefik.http.routers.${PREFIX_STACK_NAME}_fallback_invitations_api.priority=1
- traefik.http.routers.${PREFIX_STACK_NAME}_fallback_invitations_api.rule=(${DEPLOYMENT_FQDNS_CAPTURE_INVITATIONS})
- traefik.http.routers.${PREFIX_STACK_NAME}_fallback_invitations_api.entrypoints=http
- traefik.http.services.${PREFIX_STACK_NAME}_fallback_invitations_api.loadbalancer.server.port=80
- traefik.http.routers.${PREFIX_STACK_NAME}_fallback_invitations_api.service=${PREFIX_STACK_NAME}_fallback_invitations_api

configs:
{{ SWARM_STACK_NAME }}_web_html:
file: ./configs/fallback-service-nginx/web/503.html
name: {{ SWARM_STACK_NAME }}_web_html_{{ "./configs/fallback-service-nginx/web/503.html" | sha256file | substring(0,10) }}
{{ SWARM_STACK_NAME }}_api_json:
file: ./configs/fallback-service-nginx/api/503.json
name: {{ SWARM_STACK_NAME }}_api_json_{{ "./configs/fallback-service-nginx/api/503.json" | sha256file | substring(0,10) }}
{{ SWARM_STACK_NAME }}_web_nginx_config:
file: ./configs/fallback-service-nginx/web/default.conf
name: {{ SWARM_STACK_NAME }}_web_nginx_config_{{ "./configs/fallback-service-nginx/web/default.conf" | sha256file | substring(0,10) }}
{{ SWARM_STACK_NAME }}_api_nginx_config:
file: ./configs/fallback-service-nginx/api/default.conf
name: {{ SWARM_STACK_NAME }}_api_nginx_config_{{ "./configs/fallback-service-nginx/api/default.conf" | sha256file | substring(0,10) }}

volumes:
rabbit_data:
name: ${SWARM_STACK_NAME}_rabbit_data

networks:
public:
external: true
Expand Down
Loading