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

Put nginx in front of the services #63

Merged
merged 7 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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;"]
43 changes: 22 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ There are two ways to run the editor, [using docker-compose](#running-editor-usi

#### Running editor using docker-compose
To run the editor using `docker-compose`, do the following steps:
- `cd $PROJECT_ROOT`
- if on Windows, create `$PROJECT_ROOT/.env` according to [Configuration of environment variables in Windows](#configuration-of-environment-variables-in-windows)
- `cd $PROJECT_ROOT/deploy
- if on Windows, create `$PROJECT_ROOT/deploy/.env` according to [Configuration of environment variables in Windows](#configuration-of-environment-variables-in-windows)
- `docker-compose up`
- open the editor in browser at `http://localhost:3000`. The editor should be showing [example scripts from SPipes repository](https://github.com/kbss-cvut/s-pipes/doc/examples).
- open the editor in browser at `http://localhost:1235`. The editor should be showing [example scripts from SPipes repository](https://github.com/kbss-cvut/s-pipes/doc/examples).

#### Run editor using spe script

`spe` script can be used to execute the editor from a command line by specifying one or more directories from which SPipes scripts should be loaded. Internally the script uses [docker-compose.yml](https://github.com/kbss-cvut/s-pipes-editor-ui/blob/master/docker-compose.yml) file and environment variables specified in `$PROJECT_ROOT/.env.custom-script-paths`.
`spe` script can be used to execute the editor from a command line by specifying one or more directories from which SPipes scripts should be loaded. Internally the script uses [docker-compose.yml](https://github.com/kbss-cvut/s-pipes-editor-ui/blob/master/docker-compose.yml) file and environment variables specified in `$PROJECT_ROOT/deploy/.env.custom-script-paths`.

To run the editor using `spe` script, do the following steps:
- if on Windows, create `$PROJECT_ROOT/.env.custom-script-paths` according to [Configuration of environment variables in Windows](#configuration-of-environment-variables-in-windows)
- if on Windows, create `$PROJECT_ROOT/deploy/.env.custom-script-paths` according to [Configuration of environment variables in Windows](#configuration-of-environment-variables-in-windows)
- `$PROJECT_ROOT/bin/spe.$EXTENSION <paths-to-script-folders>`
- open the editor in a browser at `http://localhost:3000`. The editor should show the script from folders specified in <paths-to-script-folders> and the folder $PROJECT_ROOT/../s-pipes-modules.
- open the editor in a browser at `http://localhost:1235`. The editor should show the script from folders specified in <paths-to-script-folders> and the folder $PROJECT_ROOT/../s-pipes-modules.

Use the correct spe script extension:
- Use `spe.sh` if in bash (both linux or wsl distribution).
Expand All @@ -54,13 +54,13 @@ To make the script executable line endings should be replaced.
- `SHARED_ROOT=/mnt/c`


To override default configuration create `$PROJECT_ROOT/.env` and use following variables:
To override default configuration create `$PROJECT_ROOT/deploy/.env` and use following variables:
- `CUSTOM_SCRIPT_PATHS` -- to show different SPipes scripts (defaults to `${PROJECT_ROOT}/../s-pipes/doc/examples`).
Use separator ";" to add multiple paths. The path must be absolute and the same as in host filesystem.
- `SCRIPTRULES` -- to set up different rules to validate SPipes scripts
(defaults to `${PROJECT_ROOT}/../s-pipes-editor/src/main/resources/rules`),
- `RDF4J_SERVER_URL` -- to set up different Rdf4j server (defaults to internal docker service at `http://rdf4j:8080/rdf4j-server`).
**Note that this variable must be consistent with variable `RDF4J_PCONFIGURL`**.
- `RDF4J_SERVER_URL` -- to set up different Rdf4j server (defaults to internal docker service at `http://db-server:7200/`).
**Note that this variable must be consistent with variable `RDF4J_PCONFIGURL`**.
- `RDF4J_REPOSITORYNAME` -- to set up different Rdf4j repository name where SPipes logs from execution are created
(defaults to `s-pipes-hello-world`). **Note that this variable must be consistent with
variable `RDF4J_PCONFIGURL`**.
Expand All @@ -69,7 +69,8 @@ To override default configuration create `$PROJECT_ROOT/.env` and use following
variables `RDF4J_SERVER_URL` and `RDF4J_REPOSITORYNAME`**.
- `SPIPES_ENGINE` -- to set up different s-pipes engine (defaults to internal docker service `http://s-pipes-engine:8080/s-pipes/`),
- `SPIPES_EDITOR_REST` -- to set up different s-pipes-editor backend (defaults to internal docker service `s-pipes-editor-rest:18115`).

- `INTERNAL_HOST_PORT` -- to set the port number on which application will be accessible within the internal network (defaults to internal docker service `1235`)
- `PUBLIC_ORIGIN` -- to set the base URL or domain where the application is publicly accessible.

### Building

Expand All @@ -95,10 +96,10 @@ $ npm run dev
## Development with Docker Compose
Here is the common procedure to debug individual services of the s-pipes-editor-ui. `<service-name>` can be replaced
by one of the values `s-pipes-editor-ui`, `s-pipes-editor-rest` and `s-pipes-engine`.
1. cd to `$PROJECT_ROOT`.
2. Run `docker-compose -f docker-compose-dev.yml up` if not running already. Otherwise, run
`docker-compose -f docker-compose-dev.yml start`.
3. Stop the service which you want to develop `docker-compose -f docker-compose-dev.yml stop <service-name>`
1. cd to `$PROJECT_ROOT/deploy`.
2. Run `docker-compose up` if not running already. Otherwise, run
`docker-compose start`.
3. Stop the service which you want to develop `docker-compose stop <service-name>`
4. Start `<service-name>` in development environment
- `s-pipes-editor-ui` - run `npm run dev`
- `s-pipes-editor-rest` - start run/debug springboot configuration in IntelliJ IDEA
Expand All @@ -115,16 +116,16 @@ where <SPIPES_BACKEND_URL> denotes the URL where SPipes backend is running.
### Docker-compose

You can run editor together with backend using docker orchestration. The docker-compose is composed of 4 services and can be run via `docker-compose up`:
* [chlupnoha/s-pipes-editor-ui:latest](https://hub.docker.com/repository/docker/chlupnoha/s-pipes-editor-ui) - accessible on `http://localhost:3000`
* [chlupnoha/s-pipes-editor-rest:latest](https://hub.docker.com/repository/docker/chlupnoha/s-pipes-editor-rest) - accessible on `http://localhost:18115` with [configuration options](https://github.com/kbss-cvut/s-pipes-editor#dockerization)
* [chlupnoha/spipes-engine:latest](https://hub.docker.com/repository/docker/chlupnoha/spipes-engine) - accessible on `http://localhost:8081` with [configuration options](https://github.com/kbss-cvut/s-pipes#dockerization)
* [eclipse/rdf4j-workbench:amd64-3.5.0](https://hub.docker.com/r/eclipse/rdf4j-workbench) - accessible on `http://localhost:8080/rdf4j-workbench`
* [kbss-cvut/s-pipes-editor-ui:latest](https://ghcr.io/kbss-cvut/s-pipes-editor/s-pipes-editor-ui:latest) - accessible on `http://localhost:1235`
* [kbss-cvut/s-pipes-editor-rest:latest](https://ghcr.io/kbss-cvut/s-pipes-editor/s-pipes-editor:latest) - accessible on `http://localhost:1235/rest`
* [kbss-cvut/spipes-engine:latest](https://ghcr.io/kbss-cvut/s-pipes-engine/s-pipes-engine:latest) - accessible on `http://localhost:1235/services/s-pipes`
* [graphdb](./deploy/db-server) - accessible on `http://localhost:1235/services/db-server`

**Required manual steps:**
* s-pipes-engine
* The service does not automatically create the repository in RDF4J, so manual creation of a repository is required (after running `docker-compose up`).
* First open the RDF4J Workbench: `http://localhost:<port>/rdf4j-workbench` where `<port>` is the RDF4J service port specified in `docker-compose.yml`.
* Then follow these instructions: [Creating a Repository](https://rdf4j.org/documentation/tools/server-workbench/#:~:text=for%20the%20repository.-,Creating%20a%20Repository,-Click%20on%20%E2%80%9CNew) (For repository type use for example Native Store.)
* The service does not automatically create the repository in GraphDB, so manual creation of a repository is required (after running `docker-compose up`).
* First open the GraphDB Workbench: `http://localhost:<INTERNAL_HOST_PORT>/services/db-server/repository` where `<INTERNAL_HOST_PORT>` is the port specified in `.env`.
* Then follow these [instructions](https://graphdb.ontotext.com/documentation/10.0/creating-a-repository.html).
* The logging configuration for RDF4j is hardcoded in the image, but it could override via `_pConfigURL` param. However, it is not a convenient format to work. Also both servies must to share volume or the config has to be exposed.

* Notes
Expand Down
2 changes: 1 addition & 1 deletion bin/spe.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions bin/spe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

File renamed without changes.
9 changes: 1 addition & 8 deletions nginx.conf → deploy/.docker/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
}
4 changes: 4 additions & 0 deletions deploy/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#INTERNAL_HOST_PORT=1235
#PUBLIC_ORIGIN=http://localhost
#SPIPES_ENGINE=http://s-pipes-engine:8080/s-pipes/
#SPIPES_EDITOR_REST=s-pipes-editor-rest:18115
File renamed without changes.
82 changes: 82 additions & 0 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
version: "3.9"

services:
nginx:
image: nginx:latest
ports:
- "127.0.0.1:${INTERNAL_HOST_PORT:-1235}:80"
restart: unless-stopped
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}"
blcham marked this conversation as resolved.
Show resolved Hide resolved
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"
restart: unless-stopped
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"
restart: unless-stopped
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"
expose:
- "8080"
restart: unless-stopped
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
expose:
- "7200"
restart: unless-stopped
environment:
GDB_JAVA_OPTS: "-Dgraphdb.external-url=${PUBLIC_ORIGIN:-http://localhost:${INTERNAL_HOST_PORT:-1235}}/services/db-server"
volumes:
- ./db-server/init-config:/repo-config:ro
- db-server:/opt/graphdb/home

volumes:
data:
logs:
db-server:
35 changes: 35 additions & 0 deletions deploy/nginx/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!-- SPipes Editor Nginx reverse proxy-->
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title><!--# echo var="status" default="" --> | SPiper Editor</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--# if expr="$status = 502" -->
<meta http-equiv="refresh" content="2" />
<!--# endif -->
</head>
<style type="text/css">
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
color: #fff;
height: 100vh;
margin: 0;
background: #263238 linear-gradient(5deg, #057fa5 0%, #263238 100%);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
</style>
<body>
<!--# if expr="$status = 502" -->
<h1>The application is currently being updated</h1>
<p>You will be redirected to the new version in a few seconds.</p>
<p>If you see this message for more than a minute, something has gone wrong.</p>
<!--# else -->
<h1>Sorry, something went wrong.</h1>
<p><!--# echo var="status" default="" --></p>
<!--# endif -->
</body>
</html>
93 changes: 93 additions & 0 deletions deploy/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
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;
}

}
}
Loading
Loading