Docker compose and startup adjustments

This commit is contained in:
Eduardo Silva 2024-04-04 21:16:53 -03:00
parent 563ee7408e
commit a194e4f0be
8 changed files with 56 additions and 8 deletions

View file

@ -2,4 +2,4 @@
*/5 * * * * root /usr/bin/curl -s http://routerfleet:8001/cron/generate_backup_schedule/ >> /var/log/cron.log 2>&1 */5 * * * * root /usr/bin/curl -s http://routerfleet:8001/cron/generate_backup_schedule/ >> /var/log/cron.log 2>&1
* * * * * root /usr/bin/curl -s http://routerfleet:8001/cron/create_backup_tasks/ >> /var/log/cron.log 2>&1 * * * * * root /usr/bin/curl -s http://routerfleet:8001/cron/create_backup_tasks/ >> /var/log/cron.log 2>&1
* * * * * root /usr/bin/curl -s http://routerfleet:8001/cron/perform_backup_tasks/ >> /var/log/cron.log 2>&1 * * * * * root /usr/bin/curl -s http://routerfleet:8001/cron/perform_backup_tasks/ >> /var/log/cron.log 2>&1
*/10 * * * * root /usr/bin/curl -s http://routerfleet:8001/cron/housekeeping/ >> /var/log/cron.log 2>&1 */10 * * * * root /usr/bin/curl -s http://routerfleet:8001/cron/housekeeping/ >> /var/log/cron.log 2>&1

View file

@ -8,7 +8,7 @@ RUN apt-get update && apt-get install -y \
nano \ nano \
vim-nox \ vim-nox \
fping \ fping \
&& rm -rf /var/lib/apt/lists/* \ && rm -rf /var/lib/apt/lists/*
COPY requirements.txt . COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt

View file

@ -93,6 +93,9 @@ def update_and_monitor():
if __name__ == "__main__": if __name__ == "__main__":
print(f"{datetime.now()} - Monitoring container started, waiting for routerfleet container to start...")
time.sleep(30) # Wait for the routerfleet container to start
print(f"{datetime.now()} - Starting monitoring service...")
update_and_monitor() update_and_monitor()

View file

@ -1,5 +1,14 @@
version: '3'
services: services:
routerfleet-postgres:
container_name: routerfleet-postgres
image: postgres:latest
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=routerfleet
- POSTGRES_USER=routerfleet
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
routerfleet: routerfleet:
container_name: routerfleet container_name: routerfleet
restart: unless-stopped restart: unless-stopped
@ -8,10 +17,14 @@ services:
environment: environment:
- SERVER_ADDRESS=${SERVER_ADDRESS} - SERVER_ADDRESS=${SERVER_ADDRESS}
- DEBUG_MODE=${DEBUG_MODE} - DEBUG_MODE=${DEBUG_MODE}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
volumes: volumes:
- media_root:/var/lib/routerfleet/ - media_root:/var/lib/routerfleet/
- static_volume:/app_static_files/ - static_volume:/app_static_files/
command: /bin/bash /app/init.sh command: /bin/bash /app/init.sh
depends_on:
- routerfleet-postgres
routerfleet-cron: routerfleet-cron:
container_name: routerfleet-cron container_name: routerfleet-cron
@ -22,13 +35,22 @@ services:
depends_on: depends_on:
- routerfleet - routerfleet
routerfleet-monitoring:
container_name: routerfleet-monitoring
restart: unless-stopped
build:
context: ./containers/monitoring
dockerfile: Dockerfile-monitoring
depends_on:
- routerfleet
nginx: nginx:
container_name: routerfleet-nginx container_name: routerfleet-nginx
restart: unless-stopped restart: unless-stopped
image: nginx:alpine image: nginx:alpine
build: build:
context: . context: ./containers/nginx
dockerfile: Dockerfile_nginx dockerfile: Dockerfile-nginx
volumes: volumes:
- ./containers/nginx/virtualhost.conf:/etc/nginx/conf.d/routerfleet.conf - ./containers/nginx/virtualhost.conf:/etc/nginx/conf.d/routerfleet.conf
- static_volume:/static - static_volume:/static
@ -36,8 +58,11 @@ services:
ports: ports:
- "80:80" - "80:80"
- "443:443" - "443:443"
depends_on:
- routerfleet
volumes: volumes:
static_volume: static_volume:
https_cert: https_cert:
media_root: media_root:
postgres_data:

View file

@ -7,6 +7,11 @@ if [ -z "$SERVER_ADDRESS" ]; then
exit 1 exit 1
fi fi
if [ -z "$POSTGRES_PASSWORD" ]; then
echo "POSTGRES_PASSWORD environment variable is not set. Exiting."
exit 1
fi
DEBUG_VALUE="False" DEBUG_VALUE="False"
if [[ "${DEBUG_MODE,,}" == "true" ]]; then if [[ "${DEBUG_MODE,,}" == "true" ]]; then
DEBUG_VALUE="True" DEBUG_VALUE="True"
@ -17,8 +22,18 @@ DEBUG = $DEBUG_VALUE
ALLOWED_HOSTS = ['routerfleet', '$SERVER_ADDRESS'] ALLOWED_HOSTS = ['routerfleet', '$SERVER_ADDRESS']
CSRF_TRUSTED_ORIGINS = ['http://routerfleet', 'https://$SERVER_ADDRESS'] CSRF_TRUSTED_ORIGINS = ['http://routerfleet', 'https://$SERVER_ADDRESS']
SECRET_KEY = '$(openssl rand -base64 32)' SECRET_KEY = '$(openssl rand -base64 32)'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'routerfleet',
'USER': 'routerfleet',
'PASSWORD': '$POSTGRES_PASSWORD',
'HOST': 'routerfleet-postgres',
'PORT': '5432',
}
}
EOL EOL
#sed -i "/^ path('admin\/', admin.site.urls),/s/^ / # /" /app/routerfleet/urls.py sed -i "/^ path('admin\/', admin.site.urls),/s/^ / # /" /app/routerfleet/urls.py
exec "$@" exec "$@"

View file

@ -11,6 +11,7 @@ django-cleanup==8.1.0
django-crispy-forms==2.1 django-crispy-forms==2.1
idna==3.6 idna==3.6
paramiko==3.4.0 paramiko==3.4.0
psycopg2-binary==2.9.9
pycparser==2.21 pycparser==2.21
PyNaCl==1.5.0 PyNaCl==1.5.0
requests==2.31.0 requests==2.31.0

View file

@ -64,7 +64,7 @@ def view_manage_router(request):
form = RouterForm(request.POST or None, instance=router) form = RouterForm(request.POST or None, instance=router)
if form.is_valid(): if form.is_valid():
form.save() form.save()
messages.success(request, 'Router saved successfully') messages.success(request, 'Router saved successfully|It may take a few minutes until monitoring starts for this router.')
router_status, _ = RouterStatus.objects.get_or_create(router=form.instance) router_status, _ = RouterStatus.objects.get_or_create(router=form.instance)
BackupSchedule.objects.filter(router=form.instance).delete() BackupSchedule.objects.filter(router=form.instance).delete()
return redirect('router_list') return redirect('router_list')

View file

@ -40,8 +40,11 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
<a href="/router/manage_sshkey/" class="btn btn-primary">Add SSH Key</a> {% comment %}<a href="/router/manage_sshkey/" class="btn btn-primary">Add SSH Key</a>{% endcomment %}
<a href="" class="btn btn-primary disabled">Add SSH Key</a>
<p>Sorry, SSH authentication using keys is still unsupported. It will be added soon</p>
</div> </div>
</div> </div>
@ -49,4 +52,5 @@
</div> </div>
</div> </div>
</div> </div>
{% endblock %} {% endblock %}