From 2a443815b0b658fea59e839c7436ed423c1397f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniele=20Vigan=C3=B2?= Date: Tue, 16 Jun 2020 22:48:58 +0200 Subject: [PATCH] Cleanup --- docker/django/production.py.sample | 9 ++++---- docker/docker-compose.edge.yml | 21 +++++++++-------- docker/docker-compose.prod.yml | 6 ++--- docker/docker-compose.yml | 20 ++++++---------- docker/mqtt/docker-compose.rabbitmq.yml | 18 +++++++++++++++ docker/mqtt/docker-compose.vernemq.yml | 14 +++++++++++ docker/{ => mqtt}/rabbitmq/enabled_plugins | 0 freedcs/freedcs/production.py.sample | 27 ---------------------- freedcs/freedcs/settings.py | 2 +- freedcs/telemetry/views.py | 4 ++-- 10 files changed, 61 insertions(+), 60 deletions(-) create mode 100644 docker/mqtt/docker-compose.rabbitmq.yml create mode 100644 docker/mqtt/docker-compose.vernemq.yml rename docker/{ => mqtt}/rabbitmq/enabled_plugins (100%) delete mode 100644 freedcs/freedcs/production.py.sample diff --git a/docker/django/production.py.sample b/docker/django/production.py.sample index 0fee18e..6a5dd09 100644 --- a/docker/django/production.py.sample +++ b/docker/django/production.py.sample @@ -6,7 +6,7 @@ from freedcs import settings SECRET_KEY = 'i4z%50+4b4ek(l0#!w2-r1hpo%&r6tk7p$p_-(=6d!c9n=g5m&' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False ALLOWED_HOSTS = ['*'] @@ -21,9 +21,10 @@ DATABASES = { } } -MQTT_BROKER = { - 'HOST': 'rabbitmq', - 'PORT': 1883, +REST_FRAMEWORK = { + 'DEFAULT_RENDERER_CLASSES': ( + 'rest_framework.renderers.JSONRenderer', + ) } SKIP_WHITELIST = True diff --git a/docker/docker-compose.edge.yml b/docker/docker-compose.edge.yml index 2f25281..7c028c3 100644 --- a/docker/docker-compose.edge.yml +++ b/docker/docker-compose.edge.yml @@ -1,12 +1,13 @@ version: "3.7" -edge-host: - <<: *service_default - image: docker:dind - privileged: true - environment: - DOCKER_TLS_CERTDIR: - # networks: - # - net - ports: - - "127.0.0.1:22375:2375" +services: + edge-host: + <<: *service_default + image: docker:dind + privileged: true + environment: + DOCKER_TLS_CERTDIR: + # networks: + # - net + ports: + - "127.0.0.1:22375:2375" diff --git a/docker/docker-compose.prod.yml b/docker/docker-compose.prod.yml index 984e518..ad8060b 100644 --- a/docker/docker-compose.prod.yml +++ b/docker/docker-compose.prod.yml @@ -8,13 +8,13 @@ services: freedcs: volumes: - - "./django/production.py.sample:/srv/freedcs/freedcs/production.py" + - "./django/production.py.sample:/srv/app/freedcs/freedcs/production.py" command: ["gunicorn", "-b", "0.0.0.0:8000", "freedcs.wsgi:application"] data-migration: volumes: - - "./django/production.py.sample:/srv/freedcs/freedcs/production.py" + - "./django/production.py.sample:/srv/app/freedcs/freedcs/production.py" mqtt-to-db: volumes: - - "./django/production.py.sample:/srv/freedcs/freedcs/production.py" + - "./django/production.py.sample:/srv/app/freedcs/freedcs/production.py" diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index f4c483b..83938a2 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -32,22 +32,16 @@ services: networks: - net - rabbitmq: + broker: <<: *service_default - image: rabbitmq:3-management-alpine - # environment: # we use unauth access atm - # RABBITMQ_DEFAULT_VHOST: "freedcs" - # RABBITMQ_DEFAULT_USER: "freedcs" - # RABBITMQ_DEFAULT_PASS: "password" - volumes: - - ./rabbitmq/enabled_plugins:/etc/rabbitmq/enabled_plugins + image: eclipse-mosquitto networks: - net ports: - "1883:1883" - - "15672:15672" ingress: + <<: *service_default image: traefik:v2.2 command: --api.insecure=true --providers.docker ports: @@ -66,7 +60,7 @@ services: dockerfile: ./docker/django/Dockerfile image: daniviga/freedcs volumes: - - "../freedcs:/srv/freedcs" + - "../freedcs:/srv/app/freedcs" command: ["python3", "manage.py", "runserver", "0.0.0.0:8000"] networks: - net @@ -80,7 +74,7 @@ services: data-migration: image: daniviga/freedcs volumes: - - "../freedcs:/srv/freedcs" + - "../freedcs:/srv/app/freedcs" command: ["python3", "manage.py", "migrate", "--noinput"] networks: - net @@ -89,11 +83,11 @@ services: <<: *service_default image: daniviga/freedcs volumes: - - "../freedcs:/srv/freedcs" + - "../freedcs:/srv/app/freedcs" command: ["python3", "manage.py", "mqtt-to-db"] networks: - net depends_on: - data-migration - timescale - - rabbitmq + - broker diff --git a/docker/mqtt/docker-compose.rabbitmq.yml b/docker/mqtt/docker-compose.rabbitmq.yml new file mode 100644 index 0000000..f3f23aa --- /dev/null +++ b/docker/mqtt/docker-compose.rabbitmq.yml @@ -0,0 +1,18 @@ +version: "3.7" + +services: + broker: + image: rabbitmq:3-management-alpine + # environment: # we use unauth access atm + # RABBITMQ_DEFAULT_VHOST: "freedcs" + # RABBITMQ_DEFAULT_USER: "freedcs" + # RABBITMQ_DEFAULT_PASS: "password" + volumes: + - ./mqtt/rabbitmq/enabled_plugins:/etc/rabbitmq/enabled_plugins + networks: + - net + ports: + - "1883:1883" + - "15672:15672" + init: true + restart: always diff --git a/docker/mqtt/docker-compose.vernemq.yml b/docker/mqtt/docker-compose.vernemq.yml new file mode 100644 index 0000000..5bcb16e --- /dev/null +++ b/docker/mqtt/docker-compose.vernemq.yml @@ -0,0 +1,14 @@ +version: "3.7" + +services: + broker: + image: vernemq/vernemq + environment: + DOCKER_VERNEMQ_ALLOW_ANONYMOUS: "on" + DOCKER_VERNEMQ_ACCEPT_EULA: "yes" + networks: + - net + ports: + - "1883:1883" + init: true + restart: always diff --git a/docker/rabbitmq/enabled_plugins b/docker/mqtt/rabbitmq/enabled_plugins similarity index 100% rename from docker/rabbitmq/enabled_plugins rename to docker/mqtt/rabbitmq/enabled_plugins diff --git a/freedcs/freedcs/production.py.sample b/freedcs/freedcs/production.py.sample deleted file mode 100644 index 3e1fedf..0000000 --- a/freedcs/freedcs/production.py.sample +++ /dev/null @@ -1,27 +0,0 @@ -from freedcs import settings - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'i4z%50+4b4ek(l0#!w2-r1hpo%&r6tk7p$p_-(=6d!c9n=g5m&' - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = ['*'] - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'freedcs', - 'USER': 'freedcs', - 'PASSWORD': 'password', - 'HOST': 'timescale', - 'PORT': '5432', - } -} - -MQTT_BROKER = { - 'HOST': 'rabbitmq', - 'PORT': '1883', -} - -SKIP_WHITELIST = True diff --git a/freedcs/freedcs/settings.py b/freedcs/freedcs/settings.py index 0f94a53..cc69dc4 100644 --- a/freedcs/freedcs/settings.py +++ b/freedcs/freedcs/settings.py @@ -129,7 +129,7 @@ STATIC_URL = '/static/' SKIP_WHITELIST = True MQTT_BROKER = { - 'HOST': 'rabbitmq', + 'HOST': 'broker', 'PORT': '1883', } diff --git a/freedcs/telemetry/views.py b/freedcs/telemetry/views.py index f8a6999..afdb139 100644 --- a/freedcs/telemetry/views.py +++ b/freedcs/telemetry/views.py @@ -42,8 +42,8 @@ class TelemetryLatest(ModelViewSet): def retrieve(self, request, device=None): queryset = Telemetry.objects.filter( - device__serial=device).order_by('-time')[0] + device__serial=device).order_by('-time') if not queryset: raise Http404 - serializer = TelemetrySerializer(queryset) + serializer = TelemetrySerializer(queryset[0]) return Response(serializer.data)