Skip to content

Commit

Permalink
[monitoring] Docker configuration added #274
Browse files Browse the repository at this point in the history
Fixes #274
  • Loading branch information
praptisharma28 committed Jun 2, 2024
1 parent d02db9c commit 43e53ab
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 21 deletions.
12 changes: 8 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ RUN pip install -U pip setuptools wheel
COPY requirements-test.txt requirements.txt /opt/openwisp/
RUN pip install -r /opt/openwisp/requirements.txt && \
pip install -r /opt/openwisp/requirements-test.txt && \
rm -rf /var/lib/apt/lists/* /root/.cache/pip/* /tmp/*
rm -rf /root/.cache/pip/* /tmp/*

# Copy project files and install the project
ADD . /opt/openwisp
COPY . /opt/openwisp
RUN pip install -U /opt/openwisp && \
rm -rf /var/lib/apt/lists/* /root/.cache/pip/* /tmp/*
rm -rf /root/.cache/pip/* /tmp/*

# Copy entrypoint script
COPY docker-entrypoint.sh /opt/openwisp/docker-entrypoint.sh
RUN chmod +x /opt/openwisp/docker-entrypoint.sh

# Set working directory
WORKDIR /opt/openwisp/tests/
Expand All @@ -35,4 +39,4 @@ ENV NAME=openwisp-monitoring \
EXPOSE 8000

# Command to run the application
CMD ["sh", "docker-entrypoint.sh"]
ENTRYPOINT ["/opt/openwisp/docker-entrypoint.sh"]
31 changes: 25 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ services:
dockerfile: Dockerfile
ports:
- "8000:8000"
- "8089:8089/udp"
- "8090:8090/udp"
- "8091:8091/udp"
- "8092:8092/udp"
depends_on:
- influxdb
- influxdb2
- redis

influxdb:
Expand All @@ -32,11 +29,33 @@ services:
INFLUXDB_USER: openwisp
INFLUXDB_USER_PASSWORD: openwisp

influxdb2:
image: influxdb:2.0-alpine
volumes:
- influxdb2-data:/var/lib/influxdb2
ports:
- "9999:9999"
environment:
DOCKER_INFLUXDB_INIT_MODE: setup
DOCKER_INFLUXDB_INIT_USERNAME: openwisp
DOCKER_INFLUXDB_INIT_PASSWORD: openwisp
DOCKER_INFLUXDB_INIT_ORG: openwisp
DOCKER_INFLUXDB_INIT_BUCKET: openwisp2
DOCKER_INFLUXDB_INIT_RETENTION: 1w
DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: my-super-secret-auth-token
INFLUXD_LOG_LEVEL: debug
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9999/health"]
interval: 30s
timeout: 10s
retries: 5

redis:
image: redis:5.0-alpine
ports:
- "6379:6379"
entrypoint: redis-server --appendonly yes
entrypoint: ["redis-server", "--appendonly", "yes"]

volumes:
influxdb-data: {}
influxdb-data:
influxdb2-data:
3 changes: 0 additions & 3 deletions openwisp_monitoring/db/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ def load_backend_module(backend_name=TIMESERIES_DB['BACKEND'], module=None):
assert 'USER' in TIMESERIES_DB, 'USER'
assert 'PASSWORD' in TIMESERIES_DB, 'PASSWORD'
assert 'NAME' in TIMESERIES_DB, 'NAME'
assert 'USER' in TIMESERIES_DB, 'USER'
assert 'PASSWORD' in TIMESERIES_DB, 'PASSWORD'
assert 'NAME' in TIMESERIES_DB, 'NAME'
assert 'HOST' in TIMESERIES_DB, 'HOST'
assert 'PORT' in TIMESERIES_DB, 'PORT'
if module:
Expand Down
17 changes: 16 additions & 1 deletion tests/docker-entrypoint.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

set -e

create_superuser() {
local username="$1"
local email="$2"
Expand All @@ -16,8 +18,21 @@ else:
EOF
}

# Run migrations
echo "Running database migrations..."
python manage.py migrate --no-input

# Create superuser if it doesn't exist
echo "Creating superuser if it doesn't exist..."
create_superuser admin [email protected] admin

# Start Celery worker and beat in the background
echo "Starting Celery worker..."
celery -A openwisp2 worker -l info &

echo "Starting Celery beat..."
celery -A openwisp2 beat -l info &
python manage.py runserver 0.0.0.0:8000

# Start the Django development server
echo "Starting Django server..."
exec python manage.py runserver 0.0.0.0:8000
15 changes: 8 additions & 7 deletions tests/openwisp2/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,23 @@
'USER': 'openwisp',
'PASSWORD': 'openwisp',
'NAME': 'openwisp2',
'HOST': os.getenv('INFLUXDB_HOST', 'localhost'),
'HOST': 'influxdb',
'PORT': '8086',
# UDP writes are disabled by default
'OPTIONS': {'udp_writes': False, 'udp_port': 8089},
}

# For InfluxDB 2.x
INFLUXDB_2x_DATABASE = {
'BACKEND': 'openwisp_monitoring.db.backends.influxdb2',
'TOKEN': 'your-influxdb-2.0-token',
'ORG': 'your-org',
'BUCKET': 'your-bucket',
'HOST': os.getenv('INFLUXDB2_HOST', 'localhost'),
'PORT': '8087',
'TOKEN': 'my-super-secret-auth-token',
'ORG': 'openwisp',
'BUCKET': 'openwisp2',
'HOST': 'influxdb2',
'PORT': '9999',
}

if os.environ.get('USE_INFLUXDB2', False):
if os.environ.get('USE_INFLUXDB2', 'False') == 'True':
TIMESERIES_DATABASE = INFLUXDB_2x_DATABASE
else:
TIMESERIES_DATABASE = INFLUXDB_1x_DATABASE
Expand Down

0 comments on commit 43e53ab

Please sign in to comment.