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

Integrate changes from the CEOI #23

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
868f53f
Recognize math mode in markdown
birka0 Aug 7, 2023
84d2b1e
requirements.txt: Remove most of explicit version pins
gollux Jun 14, 2024
a9fb285
Package version constraints
gollux Jun 14, 2024
37ef9a3
Django upgrade: Automatic fixes using django-upgrade
gollux Jun 14, 2024
2956b50
Django upgrade: request.user.is_authenticated is no longer a method
gollux Jun 29, 2024
d5a1336
Django upgrade: request.is_ajax() no longer exists
gollux Jun 14, 2024
3dbeaa5
.gitignore: Add static and Vim swap files
gollux Jun 14, 2024
8e96926
Django upgrade: reverse
gollux Jun 14, 2024
3e9e32d
Django upgrade: utc
gollux Jun 14, 2024
02f79c5
Django upgrade: static
gollux Jun 14, 2024
563a844
Django upgrade: NullBooleanField
gollux Jun 14, 2024
7ef8c2a
Django upgrade: A new name of the DB engine
gollux Jul 1, 2024
b0e80a7
Pass is_editor to templates
gollux Jun 15, 2024
6ec779d
release_task_url moved to editor.html where it is used
gollux Jun 15, 2024
61ce99b
Avoid asking for id of a non-existent next_version
gollux Jun 15, 2024
1cfcdf6
Simplify URL routing to use path instead of re_path
gollux Jun 15, 2024
49851a8
Upgrade pyppeteer
gollux Jun 15, 2024
1357636
Admin: Do not escape HTML link in user admin
gollux Jun 15, 2024
4149237
requirements: inotify (for gunicorn --reload)
gollux Jun 17, 2024
f7b3382
Update constraints.txt
gollux Jun 17, 2024
d36b350
Add XForwardedForMiddleware
gollux Jun 17, 2024
7e87bb0
Update constraints.txt
gollux Jun 17, 2024
c1fccc1
Print job queue: For pending jobs, show worker taking care of them
gollux Jun 17, 2024
d4fd8ec
Remove unused import
gollux Jun 17, 2024
66d9908
Info line for drafts mentions that they are drafts
gollux Jun 17, 2024
3ba56c6
Breaking of edit locks is available to regular users
gollux Jun 17, 2024
8219f05
Reform handling of tokens in the editor
gollux Jun 17, 2024
323cb15
Staff no longer needs to break users' edit locks
gollux Jun 17, 2024
316f241
Add management command for export of translations
gollux Jun 27, 2024
0d00ca8
Nginx: X-Real-IP is no longer needed
gollux Jul 1, 2024
11f58b2
Requirements: Prefer binary version of psycopg2
gollux Jul 1, 2024
206241b
Settings: Make more configurable via environment
gollux Jul 1, 2024
2212651
Docker: Refactor app container building
gollux Jul 1, 2024
efa187a
Docker: Propagate settings via environment
gollux Jul 1, 2024
10cc198
Docker: Use TRANS_TIME_ZONE in the entry point script
gollux Jul 1, 2024
0898008
Docker: Start gunicorn in --reload (debugging) or --preload (producti…
gollux Jul 1, 2024
3522aa1
Docker: Update volumes in compose files
gollux Jul 1, 2024
4c98555
Nginx: Static files moved to /opt/app/{media,static}/
gollux Jul 1, 2024
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: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,9 @@ TAGS

# Emacs config files
*.el

# Generated static files
static

# Vim swap files
.*.swp
30 changes: 17 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
FROM ubuntu:focal
FROM debian:bookworm

RUN echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections

RUN apt-get update -qq && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
python3 python3-pip python3-setuptools \
RUN sed -i '/^Components:/s/main/main non-free contrib/' /etc/apt/sources.list.d/debian.sources

RUN apt update -qq && \
DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends \
python3 python3-pip python3-setuptools python3-venv \
libfontconfig wkhtmltopdf xvfb libpq-dev ttf-mscorefonts-installer fonts-noto \
chromium-chromedriver libxcomposite1 libxdamage1 libxtst6 libnss3 libcups2 libxss1 libxrandr2 libasound2 \
libpangocairo-1.0-0 libatk1.0-0 libatk-bridge2.0-0 libgtk-3-0 libx11-xcb1 && \
pip3 install -U pip
libxcomposite1 libxdamage1 libxtst6 libnss3 libcups2 libxss1 libxrandr2 libasound2 \
libpangocairo-1.0-0 libatk1.0-0 libatk-bridge2.0-0 libgtk-3-0 libx11-xcb1 \
tzdata

COPY binaries/cpdf/cpdf /usr/local/bin/
RUN chmod +x /usr/local/bin/cpdf

COPY trans/static/fonts/ /usr/local/share/fonts/
RUN python3 -m venv /opt/translate/venv

COPY requirements.txt /root/requirements.txt
RUN pip3 install -r /root/requirements.txt
COPY requirements.txt constraints.txt /opt/translate/
RUN /opt/translate/venv/bin/pip3 install -r /opt/translate/requirements.txt -c /opt/translate/constraints.txt

RUN python3 -c 'import pyppeteer.command; pyppeteer.command.install()'
RUN /opt/translate/venv/bin/python3 -c 'import pyppeteer.command; pyppeteer.command.install()'

COPY trans/static/fonts/ /usr/local/share/fonts/

COPY docker-entrypoint.sh /root/docker-entrypoint.sh
RUN chmod +x /root/docker-entrypoint.sh

COPY . /usr/src/app
WORKDIR /usr/src/app
COPY . /opt/translate/app

WORKDIR /opt/translate/app
ENTRYPOINT ["/root/docker-entrypoint.sh"]
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ At this point, the app will be running at `http://localhost:9000/`. You may opti
* You can get access to the system logs by running `docker-compose logs`. To follow the logs from now on, run `docker-compose logs -f --tail=0`.
* To stop the app, run `docker-compose stop`.

To use docker in development settings, add `--reload` option to the execution line of gunicorn in `docker-entrypoint.sh` file. Then run docker by `docker-compose up --build`.

License
-------
This software is distributed under the MIT license,
Expand Down
20 changes: 11 additions & 9 deletions Translation/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
SECRET_KEY = os.environ['SECRET_KEY']

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

ALLOWED_HOSTS = ['*']
USE_X_FORWARDED_HOST = True
DEBUG = int(os.environ.get('TRANS_DEBUG', '0')) > 0

PYPPETEER_PDF_OPTIONS = {
'margin': {
Expand Down Expand Up @@ -60,6 +57,7 @@
WSGI_APPLICATION = 'ws4redis.django_runserver.application'

MIDDLEWARE = [
'xff.middleware.XForwardedForMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
Expand Down Expand Up @@ -98,7 +96,7 @@

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ['DB_NAME'],
'USER': os.environ['DB_USER'],
'PASSWORD': os.environ['DB_PASSWORD'],
Expand All @@ -110,7 +108,7 @@
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://%s:6379/%s" % (os.environ['REDIS_HOST'], os.environ['REDIS_DB']),
"LOCATION": "redis://%s:%s/%s" % (os.environ['REDIS_HOST'], os.environ.get('REDIS_PORT', '6379'), os.environ['REDIS_DB']),
'TIMEOUT': None,
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
Expand Down Expand Up @@ -200,8 +198,7 @@

LANGUAGE_CODE = 'en-us'

# TODO: change this to your time zone
TIME_ZONE = 'UTC'
TIME_ZONE = os.environ.get('TRANS_TIME_ZONE', 'UTC')

USE_I18N = True
USE_L10N = True
Expand All @@ -213,4 +210,9 @@
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
HOST_URL = 'http://127.0.0.1:9000/'

HOST_URL = os.environ.get('TRANS_URL', 'http://127.0.0.1:9000/')

ALLOWED_HOSTS = ['*']
USE_X_FORWARDED_HOST = True
CSRF_TRUSTED_ORIGINS = [HOST_URL + '*']
25 changes: 5 additions & 20 deletions Translation/urls.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
"""IOI_Translate URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.10/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.urls import include, path, re_path
from django.contrib import admin

from trans.views.user import FirstPage

urlpatterns = [
url(r'^admin/login/$', FirstPage.as_view()),
url(r'^admin/', admin.site.urls),
url(r'^queue/', include('print_job_queue.urls')),
url(r'^' , include('trans.urls')),
path('admin/login/', FirstPage.as_view()),
path('admin/', admin.site.urls),
path('queue/', include('print_job_queue.urls')),
path('' , include('trans.urls')),
]
67 changes: 67 additions & 0 deletions constraints.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
appdirs==1.4.4
asgiref==3.8.1
asttokens==2.4.1
async-timeout==4.0.3
boto3==1.7.67
botocore==1.10.84
certifi==2024.6.2
charset-normalizer==3.3.2
decorator==5.1.1
diff-match-patch==20230430
Django==5.0.6
django-import-export==4.0.8
django-redis==5.4.0
django-storages==1.14.3
django-upgrade==1.18.0
django-websocket-redis==0.6.0
django-xff==1.4.0
docutils==0.21.2
et-xmlfile==1.1.0
executing==2.0.1
gevent==24.2.1
greenlet==3.0.3
gunicorn==22.0.0
idna==3.7
importlib_metadata==7.1.0
inotify==0.2.10
ipython==8.25.0
jedi==0.19.1
jmespath==0.10.0
Markdown==3.6
matplotlib-inline==0.1.7
mistune==0.7.1
moratab==0.5.2
nose==1.3.7
openpyxl==3.1.4
packaging==24.1
parso==0.8.4
pexpect==4.9.0
prompt_toolkit==3.0.47
psycopg2==2.9.9
ptyprocess==0.7.0
pure-eval==0.2.2
pyee==11.1.0
Pygments==2.18.0
pyppeteer==2.0.0
python-dateutil==2.9.0.post0
python-markdown-math==0.8
pytz==2024.1
raven==6.10.0
redis==5.0.6
requests==2.32.3
s3transfer==0.1.13
six==1.14.0
sqlparse==0.5.0
stack-data==0.6.3
tablib==3.5.0
tokenize-rt==5.2.0
tqdm==4.66.4
traitlets==5.14.3
typing_extensions==4.12.2
urllib3==1.26.18
wcwidth==0.2.13
websocket-client==1.8.0
websockets==10.4
zipp==3.19.2
zope.event==5.0
zope.interface==6.4.post2
15 changes: 10 additions & 5 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ services:
ports:
- 9001:8000 # Debugging
volumes:
- .:/usr/src/app/ # Debugging
- ioi_static:/usr/src/app/static/
- ioi_media:/usr/src/app/media/
- .:/opt/translate/app/ # Debugging
- ioi_static:/opt/translate/app/static/
- ioi_media:/opt/translate/app/media/
- ioi_logs:/opt/translate/app/logs/
depends_on:
- postgres
- redis
Expand All @@ -27,6 +28,9 @@ services:
LOG_HANDLERS: 'file,stderr'
TRANS_LOG_HANDLERS: 'trans,stderr'
PRINT_JOB_QUEUE_LOG_HANDLERS: 'print_job_queue,stderr'
TRANS_URL: 'http://127.0.0.1:9001/'
TRANS_DEBUG: 1
TRANS_TIME_ZONE: 'UTC'


nginx:
Expand All @@ -37,8 +41,8 @@ services:
depends_on:
- app
volumes:
- ioi_static:/usr/src/app/static/:ro
- ioi_media:/usr/src/app/media/:ro
- ioi_static:/opt/translate/app/static/:ro
- ioi_media:/opt/translate/app/media/:ro

postgres:
restart: always
Expand All @@ -58,3 +62,4 @@ volumes:
ioi_pgdata:
ioi_static:
ioi_media:
ioi_logs:
13 changes: 9 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ services:
restart: always
build: ./
volumes:
- ioi_static:/usr/src/app/static/
- ioi_media:/usr/src/app/media/
- ioi_static:/opt/translate/app/static/
- ioi_media:/opt/translate/app/media/
- ioi_logs:/opt/translate/app/logs/
depends_on:
- postgres
- redis
Expand All @@ -22,6 +23,9 @@ services:
REDIS_DB: 1
GUNICORN_WORKERS: 2
LOG_HANDLERS: 'file,stderr'
TRANS_URL: 'http://127.0.0.1:9000/'
TRANS_DEBUG: 0
TRANS_TIME_ZONE: 'UTC'


nginx:
Expand All @@ -32,8 +36,8 @@ services:
depends_on:
- app
volumes:
- ioi_static:/usr/src/app/static/:ro
- ioi_media:/usr/src/app/media/:ro
- ioi_static:/opt/translate/app/static/:ro
- ioi_media:/opt/translate/app/media/:ro

postgres:
restart: always
Expand All @@ -53,3 +57,4 @@ volumes:
ioi_pgdata:
ioi_static:
ioi_media:
ioi_lots:
24 changes: 14 additions & 10 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#!/usr/bin/env bash

cd /usr/src/app
. /opt/translate/venv/bin/activate
cd /opt/translate/app

export DJANGO_SETTINGS_MODULE=Translation.settings
export LANG=C.UTF-8

export DEBIAN_FRONTEND=noninteractive
apt-get install -y tzdata

# TODO: change this to your time zone
ln -fs /usr/share/zoneinfo/UTC /etc/localtime
ln -fs /usr/share/zoneinfo/${TRANS_TIME_ZONE:-UTC} /etc/localtime

dpkg-reconfigure --frontend noninteractive tzdata
dpkg-reconfigure --frontend noninteractive tzdata

fc-cache

Expand All @@ -29,9 +27,15 @@ if [[ $# -eq 0 ]]; then
python3 manage.py migrate

echo "Starting Gunicorn"

# For using docker in development settings, add `--reload` option below to the execution line of gunicorn
exec /usr/local/bin/gunicorn Translation.wsgi:application -w "${GUNICORN_WORKERS:-1}" -b :9000

if [ ! -v GUNICORN_OPTIONS ] ; then
if [ "${TRANS_DEBUG:-0}" = 1 ] ; then
GUNICORN_OPTIONS=--reload
else
GUNICORN_OPTIONS=--preload
fi
fi
exec gunicorn Translation.wsgi:application -w "${GUNICORN_WORKERS:-1}" -b :9000 $GUNICORN_OPTIONS
fi

exec "$@"
5 changes: 2 additions & 3 deletions nginx/conf.d/ioi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ server {
gzip_types text/plain application/x-javascript text/xml text/css application/xml;

location /static {
alias /usr/src/app/static;
alias /opt/translate/app/static;
}

location /media {
alias /usr/src/app/media;
alias /opt/translate/app/media;
}

location / {
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_read_timeout 3600;
client_max_body_size 100M;
Expand Down
6 changes: 1 addition & 5 deletions print_job_queue/templates/base_queue.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,13 @@
table#in-progress-tbl tbody td:nth-child(2) {
text-align: center;
}
/* Action */
/* The guard isn't actually necessary. Added for clarity. */
{% if worker_name %}
/* Action or worker handling the request */
table#in-progress-tbl thead th:nth-child(4) {
width: 150px;
}
table#in-progress-tbl tbody td:nth-child(4) {
text-align: center;
}
{% endif %}

table#pending-tbl {
width: {% if worker_name %}300px{% else %}150px{% endif %};
Expand Down Expand Up @@ -153,4 +150,3 @@

</body>
</html>

Loading