Dockerfile: update to support WSGI Elixir

* Build bsddb in a separate stage to avoid using system packages in venv
* Update Docker Apache config to support WSGI
This commit is contained in:
Franciszek Stachura 2024-08-16 23:01:48 +02:00
parent 9e18f26aeb
commit 6e01f3b023
3 changed files with 51 additions and 25 deletions

View file

@ -1,24 +1,26 @@
<Directory /usr/local/elixir/http/>
Options +ExecCGI
<Directory /usr/local/elixir/>
AllowOverride None
Require all denied
<FilesMatch "wsgi.py">
Require all granted
</FilesMatch>
</Directory>
<Directory /usr/local/elixir/static/>
AllowOverride None
Require all granted
SetEnv PYTHONIOENCODING utf-8
SetEnv LXR_PROJ_DIR /srv/elixir-data
</Directory>
<Directory /usr/local/elixir/api/>
SetHandler wsgi-script
Require all granted
SetEnv PYTHONIOENCODING utf-8
SetEnv LXR_PROJ_DIR /srv/elixir-data
</Directory>
AddHandler cgi-script .py
<VirtualHost *:80>
ServerName MY_LOCAL_IP
DocumentRoot /usr/local/elixir/http
WSGIScriptAlias /api /usr/local/elixir/api/api.py
DocumentRoot /usr/local/elixir/
SetEnv LXR_PROJ_DIR /srv/elixir-data/
# NOTE: it's recommended to set processes value to the number of available cores
WSGIDaemonProcess Elixir processes=4 display-name=%{GROUP} home=/usr/local/elixir/ python-home=/usr/local/elixir/venv/
WSGIProcessGroup Elixir
WSGIScriptAliasMatch "^/(?!static/)" /usr/local/elixir/wsgi.py/$1
AllowEncodedSlashes On
RewriteEngine on
RewriteRule "^/$" "/linux/latest/source" [R]
RewriteRule "^/(?!api|acp).*/(source|ident|search)" "/web.py" [PT]
RewriteRule "^/acp" "/autocomplete.py" [PT]
</VirtualHost>

View file

@ -1,3 +1,20 @@
FROM debian:bookworm AS build
RUN \
apt-get update && \
apt-get --no-install-recommends -y install \
python3 \
python3-pip \
python3-dev \
libdb-dev \
build-essential
WORKDIR /build/
# TODO switch to berkeleydb
# NOTE wheel version MUST be sycnhronized with requirements.txt
RUN pip wheel bsddb3==6.2.9
FROM debian:bookworm
RUN \
@ -5,12 +22,9 @@ RUN \
apt-get --no-install-recommends -y install \
python3 \
python3-pip \
python3-falcon \
python3-jinja2 \
python3-bsddb3 \
python3-pytest \
python3-pygments \
python3-venv \
universal-ctags \
libdb5.3 \
perl \
git \
apache2 \
@ -21,13 +35,20 @@ RUN \
COPY . /usr/local/elixir/
WORKDIR /usr/local/elixir/
COPY --from=build /build/bsddb3-6.2.9-*.whl /tmp/build/
RUN python3 -m venv venv && \
. ./venv/bin/activate && \
pip install /tmp/build/bsddb3-6.2.9-*.whl && \
pip install -r requirements.txt
RUN mkdir -p /srv/elixir-data/
# apache elixir config, see elixir README
# make apache less stricter about cgitb spam headers
COPY ./docker/000-default.conf /etc/apache2/sites-available/000-default.conf
RUN a2enmod cgi rewrite
RUN a2enmod rewrite
EXPOSE 80

View file

@ -4,5 +4,8 @@ Pygments==2.11.2
# appears in a release (NOTE: it's not in 3.1.3).
Falcon @ git+https://github.com/falconry/falcon.git@cbca63dc7739720eab856f48b32f9e782438be7a
pytest==7.2.1
# TODO use debian package for now
#bsddb3==6.2.9
# NOTE binary wheels of bsddb3 are not distributed - on Debian this may
# require installing build-essentials, python3-dev and libdb-dev
# NOTE keep in sync with wheel version in the Dockerfile
bsddb3==6.2.9