diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..201598f0 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Remote Attach", + "type": "debugpy", + "request": "attach", + "connect": { + "host": "localhost", + "port": 5678 + }, + "pathMappings": [ + { + "localRoot": "${workspaceFolder}", + "remoteRoot": "/var/www/cts" + } + ], + "justMyCode": true + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..13759f92 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,17 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Docker Compose Up", + "type": "shell", + "command": "docker-compose up --build", + "problemMatcher": [] + }, + { + "label": "Docker Compose Down", + "type": "shell", + "command": "docker-compose down", + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/coptic/.dockerignore b/coptic/.dockerignore new file mode 100644 index 00000000..0b1e1e7e --- /dev/null +++ b/coptic/.dockerignore @@ -0,0 +1,27 @@ +**/__pycache__ +**/.venv +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/bin +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md diff --git a/coptic/Dockerfile b/coptic/Dockerfile new file mode 100644 index 00000000..0345c4f0 --- /dev/null +++ b/coptic/Dockerfile @@ -0,0 +1,42 @@ +# Base image +FROM ubuntu:20.04 + +# Environment settings +ENV DEBIAN_FRONTEND=noninteractive + +# Install key packages +RUN apt-get update && apt-get install -y \ + apache2 \ + apache2-dev \ + chromium-browser \ + git \ + libapache2-mod-wsgi-py3 \ + default-libmysqlclient-dev \ + build-essential \ + pkg-config \ + python3-pip \ + redis-server \ + redis-tools \ + unzip \ + xvfb \ + && apt-get clean + +# Install Python dependencies +COPY coptic/requirements.txt /var/www/cts/coptic/requirements.txt +RUN pip3 install -r /var/www/cts/coptic/requirements.txt +RUN pip3 install debugpy + +# Copy application files +WORKDIR /var/www/cts/coptic +COPY ./coptic /var/www/cts/coptic +RUN mkdir -p /var/www/cts/coptic/scripts +COPY ./scripts/ /var/www/cts/coptic/scripts + +# Apache configuration +COPY ./ansible/roles/scriptorium/files/scriptorium.conf /etc/apache2/sites-available/000-default.conf + +EXPOSE 80 +# Environment variables for Django +ENV DJANGO_SETTINGS_MODULE="coptic.settings.docker" +# Command to start Apache +CMD ["python3", "-m", "debugpy", "--listen", "0.0.0.0:5678", "manage.py", "runserver", "0.0.0.0:8000"] \ No newline at end of file diff --git a/coptic/README_Docker.md b/coptic/README_Docker.md new file mode 100644 index 00000000..3975c4e5 --- /dev/null +++ b/coptic/README_Docker.md @@ -0,0 +1,9 @@ +# Developing with visual studio code + +``` +export SECRET_KEY="what you want" +export GITHUB_TOKEN="what you need" +docker compose build +docker compose up +code . +``` \ No newline at end of file diff --git a/coptic/coptic/settings/docker.py b/coptic/coptic/settings/docker.py new file mode 100644 index 00000000..3cb61a35 --- /dev/null +++ b/coptic/coptic/settings/docker.py @@ -0,0 +1,78 @@ +import os +from pathlib import Path +SECRET_KEY="what you want" # this is local development only + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent.parent + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ + + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = ['*'] + +# Application definition +INSTALLED_APPS = ( + 'grappelli', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'texts', + #'annis', + #'ingest', + 'api', + 'mod_wsgi.server' +) + +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 = 'coptic.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(BASE_DIR, '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 = 'coptic.wsgi.application' + +# Database +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': os.environ.get('MYSQL_DB', 'coptic'), + 'USER': os.environ.get('MYSQL_USER', 'coptic'), + 'PASSWORD': os.environ.get('MYSQL_PASSWORD', ''), + 'HOST': os.environ.get('MYSQL_HOST', 'db'), + 'PORT': os.environ.get('MYSQL_PORT', '3306'), + } +} + +# Static files (CSS, JavaScript, Images) +STATIC_URL = '/static/' +STATIC_ROOT = "/var/www/cts/coptic/static/" + diff --git a/coptic/requirements.txt b/coptic/requirements.txt index 751c34ca..1de7b697 100644 --- a/coptic/requirements.txt +++ b/coptic/requirements.txt @@ -1,10 +1,10 @@ requests -django -django-grappelli -beautifulsoup4 -selenium==2.45.0 -xvfbwrapper==0.2.4 -mod-wsgi==4.4.11 -celery==3.1.18 +django==2.2.13 +mysqlclient +django-grappelli==2.13.1 +beautifulsoup4==4.8.0 +selenium==3.141.0 +xvfbwrapper==0.2.9 +mod-wsgi +celery github3.py==1.3.0 -tqdm diff --git a/coptic/requirements_django_2.txt b/coptic/requirements_django_2.txt deleted file mode 100644 index 4768448e..00000000 --- a/coptic/requirements_django_2.txt +++ /dev/null @@ -1,9 +0,0 @@ -requests -django==2.2.13 -django-grappelli==2.13.1 -beautifulsoup4==4.8.0 -selenium==3.141.0 -xvfbwrapper==0.2.9 -mod-wsgi -celery==4.3.0 -github3.py==1.3.0 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..1c0e99a8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,29 @@ +services: + web: + build: + context: . + dockerfile: coptic/Dockerfile + environment: + - DJANGO_SETTINGS_MODULE=coptic.settings.docker + - MYSQL_HOST=db + - MYSQL_USER=coptic + - MYSQL_PASSWORD=your_mysql_password + - MYSQL_DB=coptic + command: ["python3", "-m", "debugpy", "--listen", "0.0.0.0:5678", "manage.py", "runserver", "0.0.0.0:8000"] + volumes: + - .:/var/www/cts + ports: + - "8000:8000" + - "5678:5678" + depends_on: + - db + db: + image: mariadb:10.2 + restart: always + environment: + MYSQL_ROOT_PASSWORD: root_password + MYSQL_DATABASE: coptic + MYSQL_USER: coptic + MYSQL_PASSWORD: your_mysql_password + ports: + - "3306:3306" \ No newline at end of file