add docker health status, keep python3.9: deps not updated for 3.10 yet

This commit is contained in:
Maxi Quoß
2021-10-15 00:52:25 +02:00
parent 9484e40815
commit dd2be0946c
4 changed files with 26 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
FROM python:3-slim-bullseye as base
FROM python:3.9-slim-bullseye as base
FROM base as builder
@@ -8,7 +8,7 @@ RUN apt-get update && apt-get -y install build-essential libssl-dev libffi-dev p
mkdir /install
WORKDIR /install
COPY requirements.txt .
RUN python -m pip install --prefix=/install --no-cache-dir --upgrade pip && \
RUN python -m pip install --no-cache-dir --upgrade pip && \
pip install --prefix=/install --no-cache-dir -r requirements.txt && \
rm -rf /var/lib/apt/lists/* && \
apt-get clean
@@ -19,7 +19,7 @@ COPY --from=builder /install /usr/local
COPY app /app
WORKDIR /app
RUN apt-get update && \
apt-get -y install iputils-ping nmap && \
apt-get -y install iputils-ping nmap curl && \
rm -rf /var/lib/apt/lists/*
CMD ["./run.sh"]

View File

@@ -9,5 +9,6 @@ urlpatterns = [
path("settings/scan/", views.settings_scan, name="settings_scan"),
path("settings/scan_add/", views.settings_scan_add, name="settings_scan_add"),
path("settings/custom_add/", views.settings_custom_add, name="settings_custom_add"),
path("settings/del/", views.settings_del, name="settings_del")
path("settings/del/", views.settings_del, name="settings_del"),
path("health/", views.health, name="health")
]

View File

@@ -6,7 +6,7 @@ import subprocess
from asgiref.sync import async_to_sync
from channels.layers import get_channel_layer
from django.http import HttpResponseRedirect
from django.http.response import JsonResponse
from django.http.response import HttpResponse, HttpResponseServerError, JsonResponse
from django.shortcuts import render
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt
@@ -164,3 +164,10 @@ def settings_del(request):
})})
return JsonResponse(data=data)
def health(request):
try:
Settings.objects.all()
return HttpResponse("Ok")
except Exception:
return HttpResponseServerError("db: cannot connect to database.")

View File

@@ -4,9 +4,6 @@ services:
container_name: upsnap_django
image: seriousm4x/upsnap:latest
network_mode: host
depends_on:
- upsnap_redis
- upsnap_postgres
restart: always
environment:
- DJANGO_SUPERUSER_USER=admin
@@ -21,20 +18,32 @@ services:
- POSTGRES_PASSWORD=upsnap
- PING_INTERVAL=5
- ENABLE_NOTIFICATIONS=True
healthcheck:
test: curl --fail -s http://localhost:$DJANGO_PORT/health/ || exit 1
interval: 10s
depends_on:
- upsnap_redis
- upsnap_postgres
upsnap_redis:
container_name: upsnap_redis
image: redis:6
network_mode: host
restart: always
healthcheck:
test: redis-cli ping
interval: 10s
upsnap_postgres:
container_name: upsnap_postgres
image: postgres:13-alpine
restart: always
network_mode: host
restart: always
environment:
- "POSTGRES_USER=upsnap"
- "POSTGRES_PASSWORD=upsnap"
- "POSTGRES_DB=upsnap"
healthcheck:
test: pg_isready
interval: 10s
volumes:
- upsnap_db:/var/lib/postgresql/data
volumes: