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

Update to Trac 1.6 and Python 3.8 #157

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 5 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,20 @@ jobs:
uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.7'
python-version: '3.8'
- run: pip install "tinycss2>=1.2.0"
- run: python noshadows.py --tests

tracdjangoplugin:
runs-on: ubuntu-latest
container:
image: python:2.7.18-buster
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.8'
felixxm marked this conversation as resolved.
Show resolved Hide resolved
- name: Install requirements
run: python -m pip install -r requirements.txt
- name: Install backport of unittest.mock
run: python -m pip install mock
- name: Run tests
run: python -m django test tracdjangoplugin.tests
env:
Expand Down
5 changes: 2 additions & 3 deletions DjangoPlugin/tracdjangoplugin/plugins.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from urlparse import urlparse
from urllib.parse import urlparse

from trac.core import Component, implements
from trac.web.chrome import INavigationContributor
from trac.web.api import IRequestFilter, IRequestHandler, RequestDone
from trac.web.auth import LoginModule
from trac.wiki.web_ui import WikiModule
from trac.util import Markup
from trac.util.html import tag
from tracext.github import GitHubBrowser

Expand Down Expand Up @@ -82,7 +81,7 @@ def get_navigation_items(self, req):
(
"mainnav",
"custom_reports",
Markup('<a href="%s">Reports</a>' % req.href.wiki("Reports")),
tag.a("Reports", href=req.href.wiki("Reports")),
),
]

Expand Down
5 changes: 1 addition & 4 deletions DjangoPlugin/tracdjangoplugin/tests.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from functools import partial

try:
from unittest.mock import Mock
except ImportError:
from mock import Mock
from unittest.mock import Mock

from django.core.signals import request_finished, request_started
from django.contrib.auth.forms import AuthenticationForm
Expand Down
98 changes: 49 additions & 49 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
# The official python:2.7 image no longer receives automatic rebuilds (it's
# a year old as of October, 2021), so use the latest LTS release of Ubuntu
# that includes Python 2.7 instead.
FROM ubuntu:20.04

# Install packages needed to run your application (not build deps).
RUN set -x \
&& RUN_DEPS=" \
ca-certificates \
git \
libpq5 \
make \
postgresql-client \
python2.7 \
" \
&& apt-get update && apt-get install -y --no-install-recommends $RUN_DEPS \
# pull official base image
FROM python:3.8-slim-bullseye

# set work directory
WORKDIR /code

# set environment varibles
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# getting postgres from PGDG (https://wiki.postgresql.org/wiki/Apt)
# gnupg is required to run apt.postgresql.org.sh
RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends \
git \
gnupg \
postgresql-common \
&& /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y\
&& apt-get install --assume-yes --no-install-recommends postgresql-client-14\
&& apt-get purge --assume-yes --auto-remove gnupg\
&& rm -rf /var/lib/apt/lists/*

# Copy requirements
ADD requirements.txt /requirements.txt
ADD DjangoPlugin /DjangoPlugin

# Install build deps, then run `pip install`, then remove unneeded build deps all in a single step.
# Correct the path to your production requirements file, if needed.
# For installing a python2.7-compatible pip: https://stackoverflow.com/a/54335642/166053
# Since we are using the system Python, also isolate the code in its own virtualenv.
RUN set -x \
&& BUILD_DEPS=" \
build-essential \
libpq-dev \
python2.7-dev \
wget \
" \
&& apt-get update && apt-get install -y --no-install-recommends $BUILD_DEPS \
&& wget -q -O /tmp/get-pip.py https://bootstrap.pypa.io/pip/2.7/get-pip.py \
&& python2.7 /tmp/get-pip.py \
&& rm /tmp/get-pip.py \
&& python2.7 -m pip install virtualenv \
&& virtualenv /venv \
&& /venv/bin/python -m pip install --no-cache-dir -r /requirements.txt \
\
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $BUILD_DEPS \
# install deb packages
RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends \
make \
&& rm -rf /var/lib/apt/lists/*

# Copy application code
RUN mkdir /code/
WORKDIR /code/
ADD . /code/
# install python dependencies
COPY ./requirements.txt ./requirements.txt
COPY ./DjangoPlugin ./DjangoPlugin

RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends \
g++ \
gcc \
libc6-dev \
libpq-dev \
&& python3 -m pip install --no-cache-dir -r requirements.txt \
&& apt-get purge --assume-yes --auto-remove \
gcc \
libc6-dev \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*

COPY ./docker-entrypoint.sh ./docker-entrypoint.sh
COPY ./Makefile ./Makefile
COPY ./scss ./scss
COPY ./trac-env ./trac-env
RUN make compile-scss
RUN rm -r ./scss

RUN PATH=/venv/bin:${PATH} make compile-scss

VOLUME /code/trac-env/files/

# gunicorn or tracd will listen on this port
EXPOSE 9000

ENV DJANGO_SETTINGS_MODULE=tracdjangoplugin.settings TRAC_ENV=/code/trac-env/

ENTRYPOINT ["/code/docker-entrypoint.sh"]
ENTRYPOINT ["./docker-entrypoint.sh"]

# Start gunicorn
CMD ["/venv/bin/gunicorn", "tracdjangoplugin.wsgi:application", "--bind", "0.0.0.0:9000", "--workers", "8", "--max-requests", "1000"]
CMD ["gunicorn", "tracdjangoplugin.wsgi:application", "--bind", "0.0.0.0:9000", "--workers", "8", "--max-requests", "1000"]
11 changes: 10 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,23 @@ Using Docker

* Install Docker
* ``pip install docker-compose``
* Create a ``secrets.json`` file at the root of the repository (next to `Dockerfile`), containing
something like::

{
"secret_key": "xyz",
"db_host": "localhost",
"db_password": "secret"
}

* ``docker-compose up --build``
* Follow instructions above to create/load the DB, grant permissions, create the
config, etc. For example::

docker-compose up --build
export DATABASE_URL=postgres://code.djangoproject:secret@db/code.djangoproject
docker-compose exec -T db psql $DATABASE_URL < ../djangoproject.com/tracdb/trac.sql
docker-compose exec trac /venv/bin/trac-admin /code/trac-env/ permission add anonymous TRAC_ADMIN
docker-compose exec trac trac-admin /code/trac-env/ permission add anonymous TRAC_ADMIN

Using Podman
------------
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ services:
build:
context: ./
dockerfile: Dockerfile
command: ["/venv/bin/tracd", "--port", "9000", "-s", "trac-env"]
command: ["gunicorn", "--bind", "0:9000", "--reload", "tracdjangoplugin.wsgi"]
environment:
- TRAC_INI_database=postgres://code.djangoproject:secret@db/code.djangoproject
- SECRETS_FILE=/code/secrets.json
volumes:
- ./:/code/
ports:
Expand Down
4 changes: 2 additions & 2 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ set -e
# database = postgres://...

for var in "${!TRAC_INI_@}"; do
sed -i "s;^${var:9} = .*;${var:9} = ${!var};" trac-env/conf/trac.ini
sed -i "s;^${var:9} = .*;${var:9} = ${!var};" /code/trac-env/conf/trac.ini
done

if [ "x$TRAC_COLLECT_STATIC" = 'xon' ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the future -- perhaps we could use a similar trick to allow upgrade to be run more easily, when it is needed? (Not now.)

# Collect trac static files to be served by nginx
/venv/bin/trac-admin ./trac-env/ deploy ./static/
trac-admin /code/trac-env/ deploy ./static/
fi

exec "$@"
19 changes: 7 additions & 12 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
# spam-filter doesn't work without babel (but somehow doesn't list it in its requirements)
Trac[pygments, babel]==1.4.4
Trac[pygments, babel]==1.6.0
dnspython==1.15
spambayes == 1.1b1
psycopg2==2.7.6.1 --no-binary=psycopg2
docutils==0.14
psycopg2==2.9.9 --no-binary=psycopg2
Django==1.11.29
libsass==0.17.0
Genshi==0.7.7 # still required by some plugins
libsass==0.23.0

# Trac plugins
https://trac.edgewall.org/browser/plugins/1.4/spam-filter?format=zip
# TracXMLRPC from PyPI does not (yet) have a 1.2.0 release (compatible with Trac 1.4)
https://trac.edgewall.org/browser/plugins/trunk/spam-filter?rev=17752&format=zip
# TracXMLRPC from PyPI does not (yet) have a 1.2.0 release (compatible with Trac >=1.4)
https://trac-hacks.org/browser/xmlrpcplugin/trunk?rev=18591&format=zip

oauthlib==2.1.0
requests==2.20.1
requests-oauthlib==1.0.0
Comment on lines -16 to -18
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these 3 packages required even without bumping to the Trac 1.6?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're required for the "log in with github" functionality provided by trac-github.I was able to remove the lines from the requirements here because I'm using the [oauth] extra of trac-github[oauth] which install them automatically.

We could make this change to our requirements file already without updating Trac, yes, but it doesn't (shouldn't?) have any effect in practice because the dependencies are installed anyway. It only serves to reduce the size of the requirements file.

trac-github==2.3
# No pypi release compatible with trac 1.6 yet
trac-github[oauth] @ git+https://github.com/bmispelon/trac-github.git@trac-1.6-py3

gunicorn==19.10.0
sentry-sdk==1.11.0
Expand Down
Loading