Skip to content

Commit 43e53ab

Browse files
[monitoring] Docker configuration added #274
Fixes #274
1 parent d02db9c commit 43e53ab

File tree

5 files changed

+57
-21
lines changed

5 files changed

+57
-21
lines changed

Dockerfile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ RUN pip install -U pip setuptools wheel
1414
COPY requirements-test.txt requirements.txt /opt/openwisp/
1515
RUN pip install -r /opt/openwisp/requirements.txt && \
1616
pip install -r /opt/openwisp/requirements-test.txt && \
17-
rm -rf /var/lib/apt/lists/* /root/.cache/pip/* /tmp/*
17+
rm -rf /root/.cache/pip/* /tmp/*
1818

1919
# Copy project files and install the project
20-
ADD . /opt/openwisp
20+
COPY . /opt/openwisp
2121
RUN pip install -U /opt/openwisp && \
22-
rm -rf /var/lib/apt/lists/* /root/.cache/pip/* /tmp/*
22+
rm -rf /root/.cache/pip/* /tmp/*
23+
24+
# Copy entrypoint script
25+
COPY docker-entrypoint.sh /opt/openwisp/docker-entrypoint.sh
26+
RUN chmod +x /opt/openwisp/docker-entrypoint.sh
2327

2428
# Set working directory
2529
WORKDIR /opt/openwisp/tests/
@@ -35,4 +39,4 @@ ENV NAME=openwisp-monitoring \
3539
EXPOSE 8000
3640

3741
# Command to run the application
38-
CMD ["sh", "docker-entrypoint.sh"]
42+
ENTRYPOINT ["/opt/openwisp/docker-entrypoint.sh"]

docker-compose.yml

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ services:
88
dockerfile: Dockerfile
99
ports:
1010
- "8000:8000"
11-
- "8089:8089/udp"
12-
- "8090:8090/udp"
13-
- "8091:8091/udp"
14-
- "8092:8092/udp"
1511
depends_on:
1612
- influxdb
13+
- influxdb2
1714
- redis
1815

1916
influxdb:
@@ -32,11 +29,33 @@ services:
3229
INFLUXDB_USER: openwisp
3330
INFLUXDB_USER_PASSWORD: openwisp
3431

32+
influxdb2:
33+
image: influxdb:2.0-alpine
34+
volumes:
35+
- influxdb2-data:/var/lib/influxdb2
36+
ports:
37+
- "9999:9999"
38+
environment:
39+
DOCKER_INFLUXDB_INIT_MODE: setup
40+
DOCKER_INFLUXDB_INIT_USERNAME: openwisp
41+
DOCKER_INFLUXDB_INIT_PASSWORD: openwisp
42+
DOCKER_INFLUXDB_INIT_ORG: openwisp
43+
DOCKER_INFLUXDB_INIT_BUCKET: openwisp2
44+
DOCKER_INFLUXDB_INIT_RETENTION: 1w
45+
DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: my-super-secret-auth-token
46+
INFLUXD_LOG_LEVEL: debug
47+
healthcheck:
48+
test: ["CMD", "curl", "-f", "http://localhost:9999/health"]
49+
interval: 30s
50+
timeout: 10s
51+
retries: 5
52+
3553
redis:
3654
image: redis:5.0-alpine
3755
ports:
3856
- "6379:6379"
39-
entrypoint: redis-server --appendonly yes
57+
entrypoint: ["redis-server", "--appendonly", "yes"]
4058

4159
volumes:
42-
influxdb-data: {}
60+
influxdb-data:
61+
influxdb2-data:

openwisp_monitoring/db/backends/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ def load_backend_module(backend_name=TIMESERIES_DB['BACKEND'], module=None):
4040
assert 'USER' in TIMESERIES_DB, 'USER'
4141
assert 'PASSWORD' in TIMESERIES_DB, 'PASSWORD'
4242
assert 'NAME' in TIMESERIES_DB, 'NAME'
43-
assert 'USER' in TIMESERIES_DB, 'USER'
44-
assert 'PASSWORD' in TIMESERIES_DB, 'PASSWORD'
45-
assert 'NAME' in TIMESERIES_DB, 'NAME'
4643
assert 'HOST' in TIMESERIES_DB, 'HOST'
4744
assert 'PORT' in TIMESERIES_DB, 'PORT'
4845
if module:

tests/docker-entrypoint.sh

100644100755
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
set -e
4+
35
create_superuser() {
46
local username="$1"
57
local email="$2"
@@ -16,8 +18,21 @@ else:
1618
EOF
1719
}
1820

21+
# Run migrations
22+
echo "Running database migrations..."
1923
python manage.py migrate --no-input
24+
25+
# Create superuser if it doesn't exist
26+
echo "Creating superuser if it doesn't exist..."
2027
create_superuser admin [email protected] admin
28+
29+
# Start Celery worker and beat in the background
30+
echo "Starting Celery worker..."
2131
celery -A openwisp2 worker -l info &
32+
33+
echo "Starting Celery beat..."
2234
celery -A openwisp2 beat -l info &
23-
python manage.py runserver 0.0.0.0:8000
35+
36+
# Start the Django development server
37+
echo "Starting Django server..."
38+
exec python manage.py runserver 0.0.0.0:8000

tests/openwisp2/settings.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,23 @@
2626
'USER': 'openwisp',
2727
'PASSWORD': 'openwisp',
2828
'NAME': 'openwisp2',
29-
'HOST': os.getenv('INFLUXDB_HOST', 'localhost'),
29+
'HOST': 'influxdb',
3030
'PORT': '8086',
3131
# UDP writes are disabled by default
3232
'OPTIONS': {'udp_writes': False, 'udp_port': 8089},
3333
}
3434

35+
# For InfluxDB 2.x
3536
INFLUXDB_2x_DATABASE = {
3637
'BACKEND': 'openwisp_monitoring.db.backends.influxdb2',
37-
'TOKEN': 'your-influxdb-2.0-token',
38-
'ORG': 'your-org',
39-
'BUCKET': 'your-bucket',
40-
'HOST': os.getenv('INFLUXDB2_HOST', 'localhost'),
41-
'PORT': '8087',
38+
'TOKEN': 'my-super-secret-auth-token',
39+
'ORG': 'openwisp',
40+
'BUCKET': 'openwisp2',
41+
'HOST': 'influxdb2',
42+
'PORT': '9999',
4243
}
4344

44-
if os.environ.get('USE_INFLUXDB2', False):
45+
if os.environ.get('USE_INFLUXDB2', 'False') == 'True':
4546
TIMESERIES_DATABASE = INFLUXDB_2x_DATABASE
4647
else:
4748
TIMESERIES_DATABASE = INFLUXDB_1x_DATABASE

0 commit comments

Comments
 (0)