From bc70fce74c84f26bdf9567cceffa6613b502ae79 Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Mon, 9 Sep 2024 15:34:38 +0200 Subject: [PATCH] [#50] Implement initial nginx settings --- Dockerfile | 6 +- bin/spe.bat | 2 +- bin/spe.sh | 3 +- .../.docker/docker-entrypoint.sh | 0 nginx.conf => deploy/.docker/nginx.conf | 9 +- deploy/.env.custom-script-paths | 1 + deploy/docker-compose.yml | 78 +++++++++++++++ deploy/nginx/error.html | 35 +++++++ deploy/nginx/nginx.conf | 96 +++++++++++++++++++ 9 files changed, 216 insertions(+), 14 deletions(-) rename docker-entrypoint.sh => deploy/.docker/docker-entrypoint.sh (100%) rename nginx.conf => deploy/.docker/nginx.conf (86%) create mode 100644 deploy/.env.custom-script-paths create mode 100644 deploy/docker-compose.yml create mode 100644 deploy/nginx/error.html create mode 100644 deploy/nginx/nginx.conf diff --git a/Dockerfile b/Dockerfile index 5f47ab3..be3c432 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ WORKDIR /app # will be cached unless changes to one of those two files # are made. COPY package.json package-lock.json ./ -RUN npm install --legacy-peer-deps +RUN npm install # Copy the main application COPY ./ /app/ @@ -33,12 +33,12 @@ COPY --from=build /app/dist /var/www COPY ./public /var/www/public # Copy our custom nginx config -COPY nginx.conf /etc/nginx/nginx.conf.template +COPY deploy/.docker/nginx.conf /etc/nginx/nginx.conf.template # Expose port 80 to the Docker host, so we can access it # from the outside. EXPOSE 80 -COPY docker-entrypoint.sh / +COPY deploy/.docker/docker-entrypoint.sh / ENTRYPOINT ["/docker-entrypoint.sh"] CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/bin/spe.bat b/bin/spe.bat index 12faba7..0823472 100644 --- a/bin/spe.bat +++ b/bin/spe.bat @@ -37,7 +37,7 @@ for %%A in (%*) do ( ) ) ) -cd %PROJECT_DIR% +cd %PROJECT_DIR%/deploy echo starting s-pipes-editor-ui with scripts %CUSTOM_SCRIPT_PATHS% docker-compose --env-file=.env.custom-script-paths up :eof diff --git a/bin/spe.sh b/bin/spe.sh index 0b781ad..5176427 100755 --- a/bin/spe.sh +++ b/bin/spe.sh @@ -33,8 +33,7 @@ done - -cd $PROJECT_DIR +cd $PROJECT_DIR/deploy CUSTOM_SCRIPT_PATHS="$CUSTOM_SCRIPT_PATHS" docker-compose --env-file=.env.custom-script-paths up cd diff --git a/docker-entrypoint.sh b/deploy/.docker/docker-entrypoint.sh similarity index 100% rename from docker-entrypoint.sh rename to deploy/.docker/docker-entrypoint.sh diff --git a/nginx.conf b/deploy/.docker/nginx.conf similarity index 86% rename from nginx.conf rename to deploy/.docker/nginx.conf index 018b50a..1bc5772 100644 --- a/nginx.conf +++ b/deploy/.docker/nginx.conf @@ -65,13 +65,6 @@ try_files $uri =404; } - location /rest/ { - proxy_pass ${SERVICE_URL}/og_spipes/rest/; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header Host $host; - proxy_cache_bypass $http_upgrade; - } + } } diff --git a/deploy/.env.custom-script-paths b/deploy/.env.custom-script-paths new file mode 100644 index 0000000..da591a9 --- /dev/null +++ b/deploy/.env.custom-script-paths @@ -0,0 +1 @@ +#SHARED_ROOT=/host_mnt diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml new file mode 100644 index 0000000..c9b5531 --- /dev/null +++ b/deploy/docker-compose.yml @@ -0,0 +1,78 @@ +version: "3.9" + +services: + nginx: + image: nginx:latest + ports: + - "1235:80" + container_name: "nginx_main" + restart: always + depends_on: + - s-pipes-engine + - s-pipes-editor-rest + - db-server + - s-pipes-editor-ui + environment: + NGINX_ENVSUBST_OUTPUT_DIR: /etc/nginx + APP_ORIGIN: "${PUBLIC_ORIGIN:-http://localhost:${INTERNAL_HOST_PORT:-1235}}" + SERVICE_URL: "${SPIPES_EDITOR_REST:-http://s-pipes-editor-rest:18115}" + volumes: + - ./nginx/nginx.conf:/etc/nginx/templates/nginx.conf.template:ro + - ./nginx/error.html:/usr/share/nginx/html/error.html:ro + + s-pipes-editor-ui: + image: "ghcr.io/kbss-cvut/s-pipes-editor-ui/s-pipes-editor-ui:latest" + expose: + - "80" + depends_on: + - s-pipes-editor-rest + environment: + SERVICE_URL: "${SPIPES_EDITOR_REST:-http://s-pipes-editor-rest:18115}" + + s-pipes-editor-rest: + # <<: *s-pipes-editor-rest-dev-port + image: "ghcr.io/kbss-cvut/s-pipes-editor/s-pipes-editor:latest" + expose: + - "18115" + depends_on: + - s-pipes-engine + - db-server + environment: + SCRIPTPATHS: "${SCRIPTPATHS:-${PWD}/../../s-pipes-modules;${CUSTOM_SCRIPT_PATHS:-${PWD}/../../s-pipes/doc/examples}}" + SCRIPTRULES: "${SCRIPTRULES:-${PWD}/../../s-pipes-editor/src/main/resources/rules}" + ENGINEURL: "${SPIPES_ENGINE:-http://s-pipes-engine:8080/s-pipes}/" + RDF4J_REPOSITORYURL: "${RDF4J_SERVER_URL:-http://db-server:7200}/repositories" + RDF4J_REPOSITORYNAME: "${RDF4J_REPOSITORYNAME:-s-pipes-hello-world}" + RDF4J_PCONFIGURL: "${RDF4J_PCONFIGURL:-./s-pipes-engine/config.ttl}" + volumes: + - /tmp:/tmp + - ${SHARED_ROOT:-/home}:${SHARED_ROOT:-/home} + # - /usr/local/tomcat/temp/:/usr/local/tomcat/temp/ + + s-pipes-engine: + image: "ghcr.io/kbss-cvut/s-pipes/s-pipes-engine:latest" + # container_name: s-pipes-engine + expose: + - "8080" + depends_on: + - db-server + environment: + CONTEXTS_SCRIPTPATHS: "${SCRIPTPATHS:-${PWD}/../../s-pipes-modules;${CUSTOM_SCRIPT_PATHS:-${PWD}/../../s-pipes/doc/examples}}" + volumes: + - /tmp:/tmp + - ${SHARED_ROOT:-/home}:${SHARED_ROOT:-/home} + # - /usr/local/tomcat/temp/:/usr/local/tomcat/temp/ + + db-server: + build: + context: ./db-server + ports: + - "7200:7200" + volumes: + - ./db-server/init-config:/repo-config:ro + - db-server:/opt/graphdb/home + +volumes: + data: + logs: + db-server: diff --git a/deploy/nginx/error.html b/deploy/nginx/error.html new file mode 100644 index 0000000..d1f35ad --- /dev/null +++ b/deploy/nginx/error.html @@ -0,0 +1,35 @@ + + + + + + <!--# echo var="status" default="" --> | Record manager + + + + + + + + +

The application is currently being updated

+

You will be redirected to the new version in a few seconds.

+

If you see this message for more than a minute, something has gone wrong.

+ +

Sorry, something went wrong.

+

+ + + diff --git a/deploy/nginx/nginx.conf b/deploy/nginx/nginx.conf new file mode 100644 index 0000000..0d5a99d --- /dev/null +++ b/deploy/nginx/nginx.conf @@ -0,0 +1,96 @@ +worker_processes 1; + +events +{ + worker_connections 1024; +} + +http +{ + + client_max_body_size 100M; + + include mime.types; + default_type application/octet-stream; + + map $status $status_text + { + 400 'Bad Request'; + 401 'Unauthorized'; + 403 'Forbidden'; + 404 'Not Found'; + 405 'Method Not Allowed'; + 406 'Not Acceptable'; + 413 'Payload Too Large'; + 414 'URI Too Long'; + 431 'Request Header Fields Too Large'; + 500 'Internal Server Error'; + 501 'Not Implemented'; + 502 'Bad Gateway'; + 503 'Service Unavailable'; + 504 'Gateway Timeout'; + } + + server + { + listen 80; + server_name localhost; + error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 + 415 416 417 418 421 422 423 424 426 428 429 431 451 500 501 502 503 + 504 505 506 507 508 510 511 /error.html; + + location = /error.html { + + ssi on; + internal; + root /usr/share/nginx/html; + } + + location / { + proxy_pass http://s-pipes-editor-ui; + 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_set_header X-Forwarded-Proto $scheme; + } + + location /rest { + return 302 ${APP_ORIGIN}/rest/; + } + + location /rest/ { + proxy_pass ${SERVICE_URL}/og_spipes/rest/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } + + location = /services/db-server + { + return 302 ${APP_ORIGIN}/services/db-server/; + } + + location = /services/db-server/ + { + proxy_pass http://db-server:7200/; + } + + location = /services/s-pipes { + return 302 ${APP_ORIGIN}/services/s-pipes/; + } + + location = /services/s-pipes/ + { + proxy_pass http://s-pipes-engine:8080/; + } + + location = /health-check + { + return 200; + access_log off; + } + + } +} \ No newline at end of file