IHTSDO / sct-browser-frontend

HMTL & Javascript for the front end for the SNOMED CT Browser.
http://browser.ihtsdotools.org
Other
84 stars 31 forks source link

Local setup : 400 and 404 errors, cannot browse concepts #50

Closed Myu-Unix closed 4 years ago

Myu-Unix commented 4 years ago

Hello dears,

I am trying to run the sct-browser-fronted locally inside a docker-compose connected to a snowstorm 4.8.0 in the same docker-compose network.

I can access the UI just fine (after npm install, grunt) but upon trying to browse concepts I have several 400 and 404 errors.

400

404

From the sct-browser-fronted container, I can access the snowstorm just fine so network-wise it's OK

root@c8ed642444e7:/# curl http://snowstorm-front:8080/codesystems
{
  "items" : [ {
    "shortName" : "SNOMEDCT",
    "branchPath" : "MAIN",
    "dailyBuildAvailable" : false
  } ],
  "total" : 1,
  "limit" : 1,
  "offset" : 0
}

From the host, I can also confirm nginx is proxying requests to snowstorm routes correctly :

curl http://127.0.0.1/snowstorm/snomed-ct/codesystems
{
  "items" : [ {
    "shortName" : "SNOMEDCT",
    "branchPath" : "MAIN",
    "dailyBuildAvailable" : false
  } ],
  "total" : 1,
  "limit" : 1,
  "offset" : 0
}

The UI error looks like this :

ui-errior

My nginx.conf looks like this :

user  nginx;

worker_processes  2;
pid        /var/run/nginx.pid;

events {
    worker_connections  512;
}

http {
        sendfile  on;
        server_tokens  off;
        tcp_nodelay  on;
        access_log  /var/log/nginx/access.log;
        default_type  application/octet-stream;
        keepalive_timeout  65;
        error_log  /var/log/nginx/error.log;
        gzip_disable  msie6;
        gzip  on;
        server_names_hash_bucket_size  64;
        tcp_nopush  on;
        types_hash_bucket_size  64;

    server {
        include mime.types;

        set $secure off;
        if ($scheme = https) { set $secure on; }

        set $cors "";
        if ($http_origin ~* (.*\.ihtsdotools.org)) { set $cors "true"; }
        if ($http_origin ~* (.*\.ontoserver.csiro.au)) { set $cors "true"; }

        #proxy_pass directives
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        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_connect_timeout 150;
        proxy_send_timeout 100;
        proxy_read_timeout 100;
        proxy_buffers 4 32k;
        client_max_body_size 1024m;
        client_body_buffer_size 128k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;
        proxy_set_header X-Url-Scheme $scheme;
        proxy_set_header X-Forwarded-Ssl $secure;
        proxy_set_header X-Forwarded-Host $host;

        location / {
            add_header Cache-Control "private, no-cache, no-store, must-revalidate";
            add_header Expires "Sat, 01 Jan 2000 00:00:00 GMT";
            add_header Pragma no-cache;
            root /usr/share/nginx/html;
        }

        location /browser {
            alias /usr/share/nginx/html;
        }

        location /snowstorm/snomed-ct/ {
            #
            # Snowstorm running on the local host machine on port 8080.
            # Change this if using a remote server.
            # Change the branch name if you want to target a specific version or extension.
            #
        resolver 127.0.0.11;
            proxy_pass http://snowstorm-front:8080/;

        }

        location /fhir {
            if ($cors = "true") {
                add_header 'Access-Control-Allow-Origin' "$http_origin";
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE, PUT';
                add_header 'Access-Control-Allow-Credentials' 'true';
                add_header 'Access-Control-Allow-Headers' 'User-Agent,Keep-Alive,Content-Type';
            } if ($request_method = OPTIONS) { return 204; }
            rewrite ^(/fhir/.*)$ /snowstorm/snomed-ct$1;
        }

        location /ecl/ {
            proxy_pass http://snowstorm-front:8080/;
        }

    }
}

I am building the sct-browser-fronted container with

git clone https://github.com/IHTSDO/sct-browser-frontend.git
cd sct-browser-frontend
# docker/nginx.conf tweaks
npm install
grunt
docker build -t snomedstorm-browser-nginx .

And running it inside a docker-compose this way (full docker-compose ahead)

version: '3.7'

services:

  browser:
    image: snomedstorm-browser-nginx:latest
    volumes:
      - /home/laurent/dev/sct-browser-frontend/:/usr/share/nginx/html
    ports:
      - "80:80"

  snowstorm-elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.5.4
    environment:
      - "ES_JAVA_OPTS=-Xms4g -Xmx4g"
    volumes:
      - /dev/log:/dev/log
      - /vol/indexes/elasticsearch/data:/usr/share/elasticsearch/data
    ports:
      - "9200:9200"

  snowstorm-front:
    image: docker.earlytracks.be/production/snowstorm:480
    environment:
      - "ES_JAVA_OPTS=-Xms4g -Xmx4g"
    command: java -jar snowstorm.jar --elasticsearch.urls=http://snowstorm-elasticsearch:9200
    volumes:
      - /dev/log:/dev/log
      - /vol/snowstorm/data:/usr/share/elasticsearch/data
    ports:
      - "8080:8080"
    depends_on:
      - snowstorm-elasticsearch

Could you help me out to understand if I made any setup mistakes or if it's a bug ?

Any pointers much appreciated :)

Cheers !

rorydavidson commented 4 years ago

Hi @Myu-Unix , if you just go to http://snowstorm-front:8080/codesystems outside of any of the containers do you get an expected response?

Myu-Unix commented 4 years ago

Hello Rory,

No, since "snowstorm-front" is a docker-only resolvable name.

curl http://127.0.0.1:8080/codesystems works though.

rorydavidson commented 4 years ago

Not entirely sure why yours isn't working, but I expect that it will link back to a network/name lookup issue between the host and Docker containers.

This may not be right for your environment, but as a guide to help you analyze further, the following docker-compose (based on the one in the snowstorm repo) did work, using the default nginx.conf in this repository:

version: '2.1'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.5.4
    container_name: elasticsearch
    environment:
      - "ES_JAVA_OPTS=-Xms4g -Xmx4g"
    volumes:
      - ~/elastic/docker:/usr/share/elasticsearch/data
      - ~/log:/dev/log
    networks:
      elastic:
        aliases:
         - es
    healthcheck:
      test: ["CMD", "curl", "-f", "http://es:9200"]
      interval: 1s
      timeout: 1s
      retries: 60
    ports:
      - 9200:9200
    mem_reservation: 4g

  snowstorm:
    image: snomedinternational/snowstorm:latest
    container_name: snowstorm
    depends_on:
      elasticsearch:
        condition: service_healthy
    entrypoint: java -Xms2g -Xmx4g -jar snowstorm.jar --elasticsearch.urls=http://es:9200
    volumes:
        - ~/log:/dev/log
    networks:
      - elastic
    ports:
      - 8080:8080

  browser:
    image: snomedstorm-browser-nginx:latest
    volumes:
      - ~/Dev/sct-browser-frontend/:/usr/share/nginx/html
    ports:
      - "80:80"
    networks:
      - elastic

networks:
  elastic:
Myu-Unix commented 4 years ago

Hello Rory,

It worked with a docker-compose based on the one you've shared above, thanks a lot !

I guess that answers my question, I'll close the issue.

Cheers.