Skip to content

Commit

Permalink
Merge pull request #221 from kit-data-manager/reverse-proxy
Browse files Browse the repository at this point in the history
Reverse proxy
  • Loading branch information
FelixFrizzy authored Oct 17, 2024
2 parents e1f1ea0 + 33ab501 commit a3cc6b2
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ EVOKS_MAIL=
FUSEKI_PASSWORD=
POSTGRES_USER=
POSTGRES_PASSWORD=
# example evoks_url for reverse-proxy: /evoks
EVOKS_URL=
# all following only needed for development:
POSTGRES_PORT=
FUSEKI_DEV_PORT=
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ media
*.bak

evoks/theme/static_src/core
evoks/theme/static/admin
evoks/theme/static/guardian



# If you are using PyCharm #
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ This software is only for internal vocabulary development purposes. It is *not r
The main way to install EVOKS and its depending services is to build and run the docker images locally using docker compose.
## Prerequisites
* Unix-based system (e.g. Linux, MacOS, Windows using WSL (untested))
* Installation of
* Installation of most recent versions of
* [git](https://git-scm.com/)
* [Docker](https://www.docker.com/)
* [Docker](https://www.docker.com/) (at least docker compose version v2.27.1 needed)

## Installation procedure:

Expand Down
18 changes: 11 additions & 7 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
services:
proxy:
container_name: evokstest_proxy
restart: "no"

postgres:
container_name: evokstest_postgres
restart: no
restart: "no"

web:
container_name: evokstest_testrunner
command: >
entrypoint: >
sh -c "set -e &&
cd ./evoks &&
python manage.py migrate &&
coverage run manage.py test -v 3 tests/model/ tests/migration/ tests/skosmos/ tests/fuseki/ tests/views/ tests/evoks &&
coverage report &&
coverage xml"
restart: no
restart: "no"

fuseki-dev:
container_name: evokstest_fuseki-dev
restart: no
restart: "no"

fuseki-live:
container_name: evokstest_fuseki-live
restart: no
restart: "no"

skosmos-dev:
container_name: evokstest_skosmos-dev
restart: no
restart: "no"

skosmos-live:
container_name: evokstest_skosmos-live
restart: no
restart: "no"
37 changes: 33 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
services:
proxy:
build:
context: ./proxy
container_name: evoks_${INSTANCE_NAME:-defaultinstance}_proxy
ports:
- 9000:80
depends_on:
- web
restart: always
networks:
- frontnet
volumes:
- ./evoks/theme/static:/app/evoks/static
- static-skosmos-dev:/app/skosmos-dev/static
- static-skosmos-live:/app/skosmos-live/static
environment:
- EVOKS_URL=${EVOKS_URL:-}

postgres:
container_name: evoks_${INSTANCE_NAME:-defaultinstance}_postgres
image: postgres
Expand Down Expand Up @@ -55,9 +73,11 @@ services:
context: "."
# caution, don't change this port since it is the one used within the container
# to change port, use the "ports:" section
command: >
sh -c "python ./evoks/manage.py migrate &&
python ./evoks/manage.py runserver 0.0.0.0:8000"
# command: >
# sh -c "python ./evoks/manage.py migrate &&
# python ./evoks/manage.py runserver 0.0.0.0:8000"
entrypoint: >
sh -c "python ./evoks/manage.py migrate && python ./evoks/manage.py collectstatic --noinput --verbosity 0 && gunicorn evoks.wsgi:application --bind 0.0.0.0:8000 --chdir evoks --log-level debug"
ports:
- "${EVOKS_PORT:-8000}:8000"
depends_on:
Expand All @@ -77,12 +97,13 @@ services:
- postgres
- fuseki-dev
- fuseki-live
- frontnet
volumes:
- .:/code
- ./skosmos-dev/config.ttl:/code/skosmos-dev/config.ttl
- ./skosmos-live/config.ttl:/code/skosmos-live/config.ttl
- fuseki-dev-backup:/code/fuseki-dev/backup
- fuseki-live-backup:/code/fuseki-live/backup
- fuseki-live-backup:/code/fuseki-live/backup
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:8000 || exit 1"]
Expand Down Expand Up @@ -149,8 +170,10 @@ services:
- fuseki-dev
networks:
- fuseki-dev
- frontnet
volumes:
- ./skosmos-dev/config.ttl:/var/www/html/config.ttl
- static-skosmos-dev:/var/www/html/resource
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:80 || exit 1"]
Expand All @@ -171,8 +194,10 @@ services:
- fuseki-live
networks:
- fuseki-live
- frontnet
volumes:
- ./skosmos-live/config.ttl:/var/www/html/config.ttl
- static-skosmos-live:/var/www/html/resource
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:80 || exit 1"]
Expand All @@ -188,6 +213,8 @@ networks:
driver: bridge
fuseki-live:
driver: bridge
frontnet:
driver: bridge
volumes:
postgres:
fuseki:
Expand All @@ -197,3 +224,5 @@ volumes:
fuseki-live-data:
fuseki-live-config:
fuseki-live-backup:
static-skosmos-dev:
static-skosmos-live:
6 changes: 3 additions & 3 deletions evoks/evoks/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_env(key, fallback):
SECRET_KEY = 'django-insecure-_91@mjc8g-&q_f9io$jmicovci2bilh#)ud3$^iqhj1wnccr%t'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = False


# set to False to disable Browser-sync
Expand Down Expand Up @@ -155,7 +155,7 @@ def get_env(key, fallback):
]

WSGI_APPLICATION = 'evoks.wsgi.application'

FORCE_SCRIPT_NAME = get_env('EVOKS_URL', '/')

# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
Expand Down Expand Up @@ -215,7 +215,7 @@ def get_env(key, fallback):
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = "/static/"
STATIC_URL = "{}/static/".format(get_env('EVOKS_URL', ''))
STATIC_ROOT = BASE_DIR / "theme/static"

# Default primary key field type
Expand Down
5 changes: 5 additions & 0 deletions proxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM nginx:1.13-alpine
COPY proxy-template.conf /etc/nginx/conf.d/default.conf.template
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
7 changes: 7 additions & 0 deletions proxy/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

# Substitute environment variables in the Nginx template
envsubst '\$EVOKS_URL' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf

# Start Nginx
nginx -g 'daemon off;'
93 changes: 93 additions & 0 deletions proxy/proxy-template.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
server {
listen 80;
listen [::]:80;
server_name localhost;
absolute_redirect off;

location ${EVOKS_URL}/ {
proxy_pass http://web:8000/;
proxy_redirect http://web:8000/ http://$host/;
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;

# Increase timeouts because evoks is sometimes slow
proxy_connect_timeout 10s;
proxy_send_timeout 10s;
proxy_read_timeout 10s;

# # increase buffers / disable buffers
# proxy_buffering off;
# proxy_buffer_size 128k;
# proxy_buffers 4 256k;
# proxy_busy_buffers_size 256k;
# proxy_max_temp_file_size 0;

# Handle large request bodies
client_max_body_size 50M;

# static files of evoks
location ${EVOKS_URL}/static/ {
include /etc/nginx/mime.types;
alias /app/evoks/static/;
}

}


location /skosmos-dev/ {
proxy_pass http://skosmos-dev:80/;
proxy_redirect http://skosmos-dev:80/ http://$host/skosmos-dev/;
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;

# Increase timeouts because skosmos is sometimes slow
proxy_connect_timeout 10s;
proxy_send_timeout 10s;
proxy_read_timeout 10s;
# Handle large request bodies
client_max_body_size 50M;

# static files of skosmos-dev
location /skosmos-dev/static/ {
include /etc/nginx/mime.types;
alias /app/skosmos-dev/static/;
}

}


location /skosmos-live/ {
proxy_pass http://skosmos-live:80/;
proxy_redirect http://skosmos-live:80/ http://$host/skosmos-live/;
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;

# Increase timeouts because skosmos is sometimes slow
proxy_connect_timeout 10s;
proxy_send_timeout 10s;
proxy_read_timeout 10s;
# Handle large request bodies
client_max_body_size 50M;

# static files of skosmos-live
location /skosmos-live/static/ {
include /etc/nginx/mime.types;
alias /app/skosmos-live/static/;
}

}








}
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ langcodes
coverage
requests
unidecode
gunicorn
environs==7.3.1
1 change: 1 addition & 0 deletions skosmos-dev/config.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

:config a skosmos:Configuration ;
skosmos:baseHref "http://localhost:9000/skosmos-dev/" ;
skosmos:customCss "resource/css/stylesheet.css" ;
skosmos:feedbackAddress "" ;
skosmos:feedbackEnvelopeSender "" ;
Expand Down
3 changes: 2 additions & 1 deletion skosmos-live/config.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

:config a skosmos:Configuration ;
skosmos:customCss "resource/css/stylesheet.css" ;
skosmos:customCss "resource/css/stylesheet.css" ;
skosmos:baseHref "http://localhost:9000/skosmos-live/" ;
skosmos:feedbackAddress "" ;
skosmos:feedbackEnvelopeSender "" ;
skosmos:feedbackSender "" ;
Expand Down

0 comments on commit a3cc6b2

Please sign in to comment.