From 8cbe6073e10564dec06a3077da095b3ce799164e Mon Sep 17 00:00:00 2001 From: Vyacheslav Tykhonov <4tikhonov@gmail.com> Date: Fri, 5 Mar 2021 11:51:02 +0100 Subject: [PATCH 1/7] Dockerfile and Docker Compose spec, start-server.sh script to start up Node.js and Django --- Dockerfile | 24 ++++++++++++++++++++++++ docker-compose.yml | 20 ++++++++++++++++++++ start-server.sh | 7 +++++++ 3 files changed, 51 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 start-server.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..180bc04 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM alpine:3.10 +MAINTAINER Vyacheslav Tykhonov +RUN apk update && apk add --no-cache freetype && apk add python3 && apk add python3-dev && apk add py3-pip +RUN apk --update add libxml2-dev libxslt-dev libffi-dev gcc musl-dev libgcc openssl-dev curl +RUN apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev +RUN apk add --update nodejs npm +RUN apk add bash gcc gfortran python python-dev py-pip build-base wget freetype-dev libpng-dev openblas-dev +RUN pip3 install --upgrade pip +RUN pip3 install cython +RUN pip3 install matplotlib +COPY . /semantic-bot +RUN pip3 install pybind11==2.2.4 +WORKDIR /semantic-bot +RUN pip3 install -r requirements.txt +RUN apk add npm +RUN npm install -g yarn +ENV WORKDIR=/semantic-bot +RUN npm i +ENV DJANGO_SETTINGS_MODULE=chatbot_app.settings +ENV PYTHONPATH=$PYTHONPATH:$WORKDIR +ENV DATADIR=$WORKDIR/data_dumps +ENTRYPOINT ["bash"] +EXPOSE 8000 +EXPOSE 8001 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b844d72 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +version: '3.7' +services: + ontology: + build: ./ + container_name: ontology + privileged: true + environment: + - "WORKDIR=/semantic-bot" + - "PYTHONPATH=/semantic-bot" + - "LANG=en" + ports: + - "8000:8000" + volumes: + - ./data_dumps:/semantic-bot/data_dumps + - ./chat:/semantic-bot/chat + - ./chatbot_app/settings.py:/semantic-bot/chatbot_app/settings.py + - ./start-server.sh:/semantic-bot/start-server.sh + - ./assets:/semantic-bot/static_files + - ./webpack.watch.config.js:/semantic-bot/webpack.watch.config.js + command: '/semantic-bot/start-server.sh' diff --git a/start-server.sh b/start-server.sh new file mode 100644 index 0000000..7e5f64d --- /dev/null +++ b/start-server.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +cd /semantic-bot +yarn run watch & +/usr/bin/python3 manage.py migrate +/usr/bin/python3 manage.py collectstatic +/usr/bin/python3 manage.py runserver 0:8000 From 749c70d1338d06b5fa3546910725da4e5f546cb6 Mon Sep 17 00:00:00 2001 From: Vyacheslav Tykhonov <4tikhonov@gmail.com> Date: Fri, 5 Mar 2021 11:52:25 +0100 Subject: [PATCH 2/7] Docker should ignore data folder --- .dockerignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..95be657 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +data_dumps/ + From 7103ef16cbe2deca249e8935e949be749ab42532 Mon Sep 17 00:00:00 2001 From: Vyacheslav Tykhonov <4tikhonov@gmail.com> Date: Fri, 5 Mar 2021 13:12:57 +0100 Subject: [PATCH 3/7] Demo settings added to show case Semantic Web running from Docker --- demo/settings.py | 171 +++++++++++++++++++++++++++++++++++ demo/start-server.sh | 8 ++ demo/webpack.watch.config.js | 17 ++++ 3 files changed, 196 insertions(+) create mode 100644 demo/settings.py create mode 100644 demo/start-server.sh create mode 100644 demo/webpack.watch.config.js diff --git a/demo/settings.py b/demo/settings.py new file mode 100644 index 0000000..c3bb40b --- /dev/null +++ b/demo/settings.py @@ -0,0 +1,171 @@ +""" + +Django settings for chatbot_app project. + +Generated by 'django-admin startproject' using Django 1.11.9. + +For more information on this file, see +https://docs.djangoproject.com/en/1.11/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.11/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +#BASE_DIR = "/semantic-bot/" + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = False +DEBUG = True + +ALLOWED_HOSTS = ["*"] +SECRET_KEY = 'change-me' +#ALLOWED_HOSTS = ["0.0.0.0","127.0.0.1","localhost"] + +# To be defined in your local_settings +DATA_API_KEY = None +MAPPING_SERIALIZER = 'YARRRML' + +# If True, all URIs (classes and properties) are used only if available (returns http code 200) +CHECK_URI_AVAILABILITY = False + +# Set the minimal score for an URI to be used by the chatbot (see _custom_scoring function in utils/lov_ods_api) +MINIMAL_CHATBOT_SCORE = 700 + +# Set the number of records to retrieve +RECORD_NUMBER = 10 + +# Application definition + +INSTALLED_APPS = [ + # 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'chat', + 'webpack_loader' +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + # 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware' +] + +ROOT_URLCONF = 'chatbot_app.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(BASE_DIR, "chat/templates")], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'chatbot_app.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.11/ref/settings/#databases + +DATABASES = {} + + +# Password validation +# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'formatters': { + 'simple': { + 'format': '[%(asctime)s] [%(levelname)s] [%(module)s] %(message)s' + } + }, + 'handlers': { + 'chatbot_results': { + 'level': 'INFO', + 'class': 'logging.FileHandler', + 'filename': 'logs/chatbot_results.log', + 'formatter': 'simple' + } + }, + 'loggers': { + 'results_logger': { + 'handlers': ['chatbot_results'], + 'level': 'INFO', + 'propagate': False, + } + }, +} + +# Internationalization +# https://docs.djangoproject.com/en/1.11/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + +try: + from .local_settings import * +except ImportError: + pass + +STATICFILES_DIRS = ( + os.path.join(BASE_DIR, 'assets'), +) +#STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static_files')] + +#STATIC_ROOT = os.path.join(BASE_DIR, 'assets') +#STATIC_ROOT = '/semantic-bot/assets' +STATIC_URL = '/static/' +#STATIC_URL = 'http://dataverse.org.ua:8080/static/' +print(STATICFILES_DIRS) + +WEBPACK_LOADER = { + 'DEFAULT': { + 'BUNDLE_DIR_NAME': 'bundles/', + 'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'), + } +} diff --git a/demo/start-server.sh b/demo/start-server.sh new file mode 100644 index 0000000..892ee86 --- /dev/null +++ b/demo/start-server.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +cd /semantic-bot +yarn run watch & +#/usr/bin/python3 manage.py migrate +#/usr/bin/python3 manage.py collectstatic +/usr/bin/python3 manage.py runserver 0.0.0.0:80 +#yarn run watch & diff --git a/demo/webpack.watch.config.js b/demo/webpack.watch.config.js new file mode 100644 index 0000000..0e7d4f2 --- /dev/null +++ b/demo/webpack.watch.config.js @@ -0,0 +1,17 @@ +var baseConfig = require('./webpack.config.js'); +var merge = require('webpack-merge'); +var webpack = require('webpack'); + +module.exports = merge(baseConfig, { + entry: [ + 'webpack-dev-server/client?', + 'webpack/hot/only-dev-server' + ], + output: { + publicPath: '/static/bundles/', + }, + plugins: [ + new webpack.HotModuleReplacementPlugin(), + new webpack.NoEmitOnErrorsPlugin(), + ], +}); From 4a171ab7a0c6500aed983cacae0f857b771d340d Mon Sep 17 00:00:00 2001 From: Vyacheslav Tykhonov <4tikhonov@gmail.com> Date: Fri, 5 Mar 2021 13:13:26 +0100 Subject: [PATCH 4/7] Docker compose settings for Django and Node.js --- docker-compose.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index b844d72..cb679a3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,12 +9,12 @@ services: - "PYTHONPATH=/semantic-bot" - "LANG=en" ports: - - "8000:8000" + - "8080:80" + - "8081:8081" volumes: - ./data_dumps:/semantic-bot/data_dumps - ./chat:/semantic-bot/chat - - ./chatbot_app/settings.py:/semantic-bot/chatbot_app/settings.py - - ./start-server.sh:/semantic-bot/start-server.sh - - ./assets:/semantic-bot/static_files - - ./webpack.watch.config.js:/semantic-bot/webpack.watch.config.js + - ./demo/settings.py:/semantic-bot/chatbot_app/settings.py + - ./demo/start-server.sh:/semantic-bot/start-server.sh + - ./demo/webpack.watch.config.js:/semantic-bot/webpack.watch.config.js command: '/semantic-bot/start-server.sh' From 76fb65204a0e1f9759f9b760cdeb76e458ea5bde Mon Sep 17 00:00:00 2001 From: Vyacheslav Tykhonov <4tikhonov@gmail.com> Date: Fri, 5 Mar 2021 13:18:12 +0100 Subject: [PATCH 5/7] Docker instructions added to README --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index f59ea8b..c29b5c7 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,11 @@ SECRET_KEY = "" If you get errors, proceed to the manual installation. +## Docker +Build image: `docker build -t semantic-bot .` +Run container: `docker-compose up` +Open your browser: http://0.0.0.0:8080 + ## Manual installation install python dependencies with pip From 2a9b6c7ad0c72aeecc5399136e5638b34b35e79c Mon Sep 17 00:00:00 2001 From: Vyacheslav Tykhonov <4tikhonov@gmail.com> Date: Fri, 5 Mar 2021 13:23:15 +0100 Subject: [PATCH 6/7] Warning about demo mode --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c29b5c7..36fee06 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,12 @@ If you get errors, proceed to the manual installation. ## Docker Build image: `docker build -t semantic-bot .` + Run container: `docker-compose up` -Open your browser: http://0.0.0.0:8080 + +Open application in your browser: http://0.0.0.0:8080 + +Warning: Docker container is running in the demonstration mode with configuration files in `demo` folder. ## Manual installation From deb727de7244f2b39351595f4d245f745cd5c015 Mon Sep 17 00:00:00 2001 From: Vyacheslav Tykhonov <4tikhonov@gmail.com> Date: Fri, 5 Mar 2021 13:25:48 +0100 Subject: [PATCH 7/7] Set container name to 'semantic-bot' --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index cb679a3..e795ea6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3.7' services: ontology: build: ./ - container_name: ontology + container_name: semantic-bot privileged: true environment: - "WORKDIR=/semantic-bot"