Skip to content

Commit 922648d

Browse files
[feature] Add Docker support for development and testing #741
Added Docker support to streamline development and testing workflows Closes #741
1 parent 0840c44 commit 922648d

4 files changed

Lines changed: 146 additions & 4 deletions

File tree

Dockerfile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# NOTE: This Docker image is for development purposes only.
2+
3+
FROM python:3.12-slim-bookworm
4+
5+
# System dependencies from the developer installation guide
6+
RUN apt-get update && \
7+
apt-get install -y --no-install-recommends \
8+
xmlsec1 \
9+
gettext \
10+
fping \
11+
gdal-bin \
12+
libproj-dev \
13+
libgeos-dev \
14+
libspatialite-dev \
15+
spatialite-bin \
16+
libsqlite3-mod-spatialite \
17+
sqlite3 \
18+
libsqlite3-dev \
19+
zlib1g-dev \
20+
libjpeg-dev \
21+
openssl \
22+
libssl-dev \
23+
libglib2.0-0 \
24+
libcairo2 \
25+
libpango-1.0-0 \
26+
libpangocairo-1.0-0 \
27+
libgdk-pixbuf-2.0-0 \
28+
shared-mime-info \
29+
&& rm -rf /var/lib/apt/lists/*
30+
31+
WORKDIR /opt/openwisp
32+
33+
# Install test requirements first so this layer is cached separately
34+
# from the source code copy below.
35+
COPY requirements-test.txt .
36+
RUN pip install --no-cache-dir -r requirements-test.txt
37+
38+
# Copy source and install the package with all optional extras
39+
COPY . .
40+
RUN pip install --no-cache-dir -e ".[saml,openvpn_status]"
41+
42+
ENV PYTHONUNBUFFERED=1 \
43+
REDIS_HOST=redis \
44+
INFLUXDB_HOST=influxdb
45+
46+
EXPOSE 8000
47+
CMD ["bash", "docker-entrypoint.sh"]

docker-compose.yml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3"
2-
31
services:
42
influxdb:
53
image: influxdb:1.8-alpine
@@ -11,12 +9,36 @@ services:
119
INFLUXDB_DB: openwisp2
1210
INFLUXDB_USER: openwisp
1311
INFLUXDB_USER_PASSWORD: openwisp
12+
networks:
13+
- openwisp
1414

1515
redis:
1616
image: redis:alpine
1717
ports:
1818
- "6379:6379"
19-
entrypoint: redis-server --appendonly yes
19+
command: redis-server --appendonly yes
20+
networks:
21+
- openwisp
22+
23+
radius:
24+
build:
25+
context: .
26+
dockerfile: Dockerfile
27+
image: openwisp-radius-dev
28+
working_dir: /opt/openwisp/tests
29+
ports:
30+
- "8000:8000"
31+
volumes:
32+
- .:/opt/openwisp/
33+
depends_on:
34+
- redis
35+
- influxdb
36+
networks:
37+
- openwisp
2038

2139
volumes:
22-
influxdb-data: {}
40+
influxdb-data:
41+
42+
networks:
43+
openwisp:
44+
driver: bridge

docs/developer/installation.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,56 @@ Run quality assurance tests with:
115115
116116
./run-qa-checks
117117
118+
.. _radius_dev_docker:
119+
120+
Install and Run on Docker
121+
-------------------------
122+
123+
.. warning::
124+
125+
This Docker image is for development purposes only.
126+
127+
For the official OpenWISP Docker images, see: :doc:`docker-openwisp
128+
</docker/index>`.
129+
130+
Ensure `Docker <https://docs.docker.com/get-docker/>`_ and
131+
`Docker Compose <https://docs.docker.com/compose/install/>`_ are installed
132+
on your system.
133+
134+
Fork and clone the forked repository:
135+
136+
.. code-block:: shell
137+
138+
git clone git://github.com/<your_fork>/openwisp-radius
139+
140+
Navigate into the cloned repository:
141+
142+
.. code-block:: shell
143+
144+
cd openwisp-radius/
145+
146+
Build the development image:
147+
148+
.. code-block:: shell
149+
150+
docker compose build
151+
152+
Start all services (Redis, InfluxDB, and the development server):
153+
154+
.. code-block:: shell
155+
156+
docker compose up
157+
158+
The development server will be available at ``http://127.0.0.1:8000/``.
159+
The admin interface is at ``http://127.0.0.1:8000/admin/`` with credentials
160+
``admin`` / ``admin``.
161+
162+
To run the test suite inside the container:
163+
164+
.. code-block:: shell
165+
166+
docker compose run --rm radius bash -c "cd /opt/openwisp && ./runtests"
167+
118168
Alternative Sources
119169
-------------------
120170

tests/docker-entrypoint.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
create_superuser() {
6+
local username="$1"
7+
local email="$2"
8+
local password="$3"
9+
cat <<EOF | python manage.py shell
10+
from django.contrib.auth import get_user_model
11+
12+
User = get_user_model()
13+
14+
if not User.objects.filter(username="$username").exists():
15+
User.objects.create_superuser("$username", "$email", "$password")
16+
else:
17+
print('User "{}" exists already, not created'.format("$username"))
18+
EOF
19+
}
20+
21+
python manage.py migrate --no-input
22+
create_superuser admin admin@example.com admin
23+
exec python manage.py runserver 0.0.0.0:8000

0 commit comments

Comments
 (0)