From e2203d02667db85ee792fdaf404727917c4598d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniele=20Vigan=C3=B2?= Date: Fri, 19 Mar 2021 10:11:55 +0100 Subject: [PATCH] Project maintenance --- bite/api/migrations/0001_initial.py | 17 ++++++++---- .../api/migrations/0002_auto_20200601_1523.py | 21 --------------- .../api/migrations/0003_auto_20200602_2128.py | 19 -------------- bite/api/migrations/0004_device_uuid.py | 19 -------------- bite/api/models.py | 4 +-- bite/telemetry/migrations/0001_initial.py | 19 +++++++++----- .../migrations/0002_auto_20200601_1557.py | 17 ------------ .../migrations/0003_auto_20200602_2131.py | 26 ------------------- .../migrations/0004_auto_20200602_2132.py | 15 ----------- .../migrations/0005_telemetry_clock.py | 19 -------------- .../migrations/0006_auto_20200603_1317.py | 17 ------------ .../migrations/0007_telemetry_transport.py | 18 ------------- .../migrations/0008_auto_20200619_1627.py | 20 -------------- .../migrations/0009_auto_20200823_1340.py | 19 -------------- bite/telemetry/models.py | 3 ++- docker/django/Dockerfile | 6 ++--- docker/docker-compose.dev.yml | 4 +++ docker/docker-compose.yml | 4 ++- docker/ntpd/Dockerfile | 2 +- docker/simulator/Dockerfile | 2 +- 20 files changed, 41 insertions(+), 230 deletions(-) delete mode 100644 bite/api/migrations/0002_auto_20200601_1523.py delete mode 100644 bite/api/migrations/0003_auto_20200602_2128.py delete mode 100644 bite/api/migrations/0004_device_uuid.py delete mode 100644 bite/telemetry/migrations/0002_auto_20200601_1557.py delete mode 100644 bite/telemetry/migrations/0003_auto_20200602_2131.py delete mode 100644 bite/telemetry/migrations/0004_auto_20200602_2132.py delete mode 100644 bite/telemetry/migrations/0005_telemetry_clock.py delete mode 100644 bite/telemetry/migrations/0006_auto_20200603_1317.py delete mode 100644 bite/telemetry/migrations/0007_telemetry_transport.py delete mode 100644 bite/telemetry/migrations/0008_auto_20200619_1627.py delete mode 100644 bite/telemetry/migrations/0009_auto_20200823_1340.py diff --git a/bite/api/migrations/0001_initial.py b/bite/api/migrations/0001_initial.py index 4282a77..0276db1 100644 --- a/bite/api/migrations/0001_initial.py +++ b/bite/api/migrations/0001_initial.py @@ -1,6 +1,8 @@ -# Generated by Django 3.0.6 on 2020-06-01 14:13 +# Generated by Django 3.1.3 on 2021-03-19 08:08 +import api.models from django.db import migrations, models +import uuid class Migration(migrations.Migration): @@ -14,20 +16,25 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Device', fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('serial', models.CharField(max_length=128, unique=True)), + ('serial', models.CharField(max_length=128, unique=True, validators=[api.models.device_validation])), + ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), ('creation_time', models.DateTimeField(auto_now_add=True)), ('updated_time', models.DateTimeField(auto_now=True)), ], + options={ + 'ordering': ['updated_time', 'serial'], + }, ), migrations.CreateModel( name='WhiteList', fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('serial', models.CharField(max_length=128, unique=True)), + ('serial', models.CharField(max_length=128, primary_key=True, serialize=False)), ('creation_time', models.DateTimeField(auto_now_add=True)), ('updated_time', models.DateTimeField(auto_now=True)), ('is_published', models.BooleanField(default=True)), ], + options={ + 'ordering': ['serial', 'updated_time'], + }, ), ] diff --git a/bite/api/migrations/0002_auto_20200601_1523.py b/bite/api/migrations/0002_auto_20200601_1523.py deleted file mode 100644 index 2d77c86..0000000 --- a/bite/api/migrations/0002_auto_20200601_1523.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 3.0.6 on 2020-06-01 15:23 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0001_initial'), - ] - - operations = [ - migrations.AlterModelOptions( - name='device', - options={'ordering': ['updated_time', 'serial']}, - ), - migrations.AlterModelOptions( - name='whitelist', - options={'ordering': ['serial', 'updated_time']}, - ), - ] diff --git a/bite/api/migrations/0003_auto_20200602_2128.py b/bite/api/migrations/0003_auto_20200602_2128.py deleted file mode 100644 index b01d214..0000000 --- a/bite/api/migrations/0003_auto_20200602_2128.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 3.0.6 on 2020-06-02 21:28 - -import api.models -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0002_auto_20200601_1523'), - ] - - operations = [ - migrations.AlterField( - model_name='device', - name='serial', - field=models.CharField(max_length=128, unique=True, validators=[api.models.device_validation]), - ), - ] diff --git a/bite/api/migrations/0004_device_uuid.py b/bite/api/migrations/0004_device_uuid.py deleted file mode 100644 index e627420..0000000 --- a/bite/api/migrations/0004_device_uuid.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 3.0.6 on 2020-06-05 09:19 - -from django.db import migrations, models -import uuid - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0003_auto_20200602_2128'), - ] - - operations = [ - migrations.AddField( - model_name='device', - name='uuid', - field=models.UUIDField(default=uuid.uuid4, editable=False, unique=True), - ), - ] diff --git a/bite/api/models.py b/bite/api/models.py index 7c2863c..b53e0c2 100644 --- a/bite/api/models.py +++ b/bite/api/models.py @@ -37,7 +37,7 @@ def device_validation(value): class WhiteList(models.Model): - serial = models.CharField(max_length=128, unique=True) + serial = models.CharField(primary_key=True, max_length=128) creation_time = models.DateTimeField(auto_now_add=True) updated_time = models.DateTimeField(auto_now=True) is_published = models.BooleanField(default=True) @@ -52,7 +52,7 @@ class WhiteList(models.Model): class Device(models.Model): serial = models.CharField(max_length=128, unique=True, validators=[device_validation]) - uuid = models.UUIDField(unique=True, default=uuid.uuid4, + uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) creation_time = models.DateTimeField(auto_now_add=True) updated_time = models.DateTimeField(auto_now=True) diff --git a/bite/telemetry/migrations/0001_initial.py b/bite/telemetry/migrations/0001_initial.py index 924cb81..8ff1ba3 100644 --- a/bite/telemetry/migrations/0001_initial.py +++ b/bite/telemetry/migrations/0001_initial.py @@ -1,8 +1,9 @@ -# Generated by Django 3.0.6 on 2020-06-01 14:45 +# Generated by Django 3.1.3 on 2021-03-19 08:08 -import django.contrib.postgres.fields.jsonb +import django.core.validators from django.db import migrations, models import django.db.models.deletion +import telemetry.models class Migration(migrations.Migration): @@ -17,10 +18,16 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Telemetry', fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('time', models.DateTimeField(auto_now_add=True)), - ('payload', django.contrib.postgres.fields.jsonb.JSONField()), - ('device', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Device')), + ('id', models.AutoField(primary_key=True, serialize=False)), + ('time', models.DateTimeField(auto_now_add=True, db_index=True)), + ('transport', models.CharField(choices=[('http', 'http'), ('mqtt', 'mqtt')], default='http', max_length=4)), + ('clock', models.IntegerField(null=True, validators=[django.core.validators.MinValueValidator(0)])), + ('payload', models.JSONField(validators=[telemetry.models.telemetry_validation])), + ('device', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.device')), ], + options={ + 'verbose_name_plural': 'Telemetry', + 'ordering': ['-time', 'device'], + }, ), ] diff --git a/bite/telemetry/migrations/0002_auto_20200601_1557.py b/bite/telemetry/migrations/0002_auto_20200601_1557.py deleted file mode 100644 index b6f83d2..0000000 --- a/bite/telemetry/migrations/0002_auto_20200601_1557.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.0.6 on 2020-06-01 15:57 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('telemetry', '0001_initial'), - ] - - operations = [ - migrations.AlterModelOptions( - name='telemetry', - options={'ordering': ['time', 'device']}, - ), - ] diff --git a/bite/telemetry/migrations/0003_auto_20200602_2131.py b/bite/telemetry/migrations/0003_auto_20200602_2131.py deleted file mode 100644 index b48039b..0000000 --- a/bite/telemetry/migrations/0003_auto_20200602_2131.py +++ /dev/null @@ -1,26 +0,0 @@ -# Generated by Django 3.0.6 on 2020-06-02 21:31 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('telemetry', '0002_auto_20200601_1557'), - ] - - operations = [ - migrations.AlterModelOptions( - name='telemetry', - options={'ordering': ['time', 'device'], 'verbose_name_plural': 'Telemetry'}, - ), - migrations.RemoveField( - model_name='telemetry', - name='id', - ), - migrations.AlterField( - model_name='telemetry', - name='time', - field=models.DateTimeField(auto_now_add=True, primary_key=True, serialize=False), - ), - ] diff --git a/bite/telemetry/migrations/0004_auto_20200602_2132.py b/bite/telemetry/migrations/0004_auto_20200602_2132.py deleted file mode 100644 index 94f40bd..0000000 --- a/bite/telemetry/migrations/0004_auto_20200602_2132.py +++ /dev/null @@ -1,15 +0,0 @@ -# Generated by Django 3.0.6 on 2020-06-02 21:32 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('telemetry', '0003_auto_20200602_2131'), - ] - - operations = [ - migrations.RunSQL( - "SELECT create_hypertable('telemetry_telemetry', 'time');"), - ] diff --git a/bite/telemetry/migrations/0005_telemetry_clock.py b/bite/telemetry/migrations/0005_telemetry_clock.py deleted file mode 100644 index 476e345..0000000 --- a/bite/telemetry/migrations/0005_telemetry_clock.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 3.0.6 on 2020-06-03 13:08 - -import django.core.validators -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('telemetry', '0004_auto_20200602_2132'), - ] - - operations = [ - migrations.AddField( - model_name='telemetry', - name='clock', - field=models.IntegerField(null=True, validators=[django.core.validators.MinValueValidator(0)]), - ), - ] diff --git a/bite/telemetry/migrations/0006_auto_20200603_1317.py b/bite/telemetry/migrations/0006_auto_20200603_1317.py deleted file mode 100644 index 6ca695a..0000000 --- a/bite/telemetry/migrations/0006_auto_20200603_1317.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 3.0.6 on 2020-06-03 13:17 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('telemetry', '0005_telemetry_clock'), - ] - - operations = [ - migrations.AlterModelOptions( - name='telemetry', - options={'ordering': ['-time', 'device'], 'verbose_name_plural': 'Telemetry'}, - ), - ] diff --git a/bite/telemetry/migrations/0007_telemetry_transport.py b/bite/telemetry/migrations/0007_telemetry_transport.py deleted file mode 100644 index 29395d8..0000000 --- a/bite/telemetry/migrations/0007_telemetry_transport.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 3.0.6 on 2020-06-08 20:07 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('telemetry', '0006_auto_20200603_1317'), - ] - - operations = [ - migrations.AddField( - model_name='telemetry', - name='transport', - field=models.CharField(choices=[('http', 'http'), ('mqtt', 'mqtt')], default='http', max_length=4), - ), - ] diff --git a/bite/telemetry/migrations/0008_auto_20200619_1627.py b/bite/telemetry/migrations/0008_auto_20200619_1627.py deleted file mode 100644 index 799aa39..0000000 --- a/bite/telemetry/migrations/0008_auto_20200619_1627.py +++ /dev/null @@ -1,20 +0,0 @@ -# Generated by Django 3.0.7 on 2020-06-19 16:27 - -import django.contrib.postgres.fields.jsonb -from django.db import migrations -import telemetry.models - - -class Migration(migrations.Migration): - - dependencies = [ - ('telemetry', '0007_telemetry_transport'), - ] - - operations = [ - migrations.AlterField( - model_name='telemetry', - name='payload', - field=django.contrib.postgres.fields.jsonb.JSONField(validators=[telemetry.models.telemetry_validation]), - ), - ] diff --git a/bite/telemetry/migrations/0009_auto_20200823_1340.py b/bite/telemetry/migrations/0009_auto_20200823_1340.py deleted file mode 100644 index 9558f8c..0000000 --- a/bite/telemetry/migrations/0009_auto_20200823_1340.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 3.1 on 2020-08-23 13:40 - -from django.db import migrations, models -import telemetry.models - - -class Migration(migrations.Migration): - - dependencies = [ - ('telemetry', '0008_auto_20200619_1627'), - ] - - operations = [ - migrations.AlterField( - model_name='telemetry', - name='payload', - field=models.JSONField(validators=[telemetry.models.telemetry_validation]), - ), - ] diff --git a/bite/telemetry/models.py b/bite/telemetry/models.py index 1e37c06..2854df9 100644 --- a/bite/telemetry/models.py +++ b/bite/telemetry/models.py @@ -30,8 +30,9 @@ def telemetry_validation(value): class Telemetry(models.Model): + id = models.AutoField(primary_key=True) device = models.ForeignKey(Device, on_delete=models.CASCADE) - time = models.DateTimeField(primary_key=True, auto_now_add=True) + time = models.DateTimeField(db_index=True, auto_now_add=True) transport = models.CharField(max_length=4, choices=[('http', 'http'), ('mqtt', 'mqtt')], default='http') diff --git a/docker/django/Dockerfile b/docker/django/Dockerfile index 7cd9284..8e14657 100644 --- a/docker/django/Dockerfile +++ b/docker/django/Dockerfile @@ -17,20 +17,20 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -FROM python:3.8-alpine AS builder +FROM python:3.9-alpine AS builder RUN apk update && apk add gcc musl-dev postgresql-dev \ && pip install psycopg2-binary # --- -FROM python:3.8-alpine +FROM python:3.9-alpine ENV PYTHONUNBUFFERED 1 ENV DJANGO_SETTINGS_MODULE "bite.settings" RUN apk update && apk add --no-cache postgresql-libs \ && wget https://github.com/jwilder/dockerize/releases/download/v0.6.1/dockerize-alpine-linux-amd64-v0.6.1.tar.gz -qO- \ | tar -xz -C /usr/local/bin -COPY --from=builder /usr/local/lib/python3.8/site-packages/ /usr/local/lib/python3.8/site-packages/ +COPY --from=builder /usr/local/lib/python3.9/site-packages/ /usr/local/lib/python3.9/site-packages/ COPY --chown=1000:1000 requirements.txt /srv/app/bite/requirements.txt RUN pip3 install --no-cache-dir -r /srv/app/bite/requirements.txt diff --git a/docker/docker-compose.dev.yml b/docker/docker-compose.dev.yml index dcca815..0230502 100644 --- a/docker/docker-compose.dev.yml +++ b/docker/docker-compose.dev.yml @@ -40,6 +40,10 @@ services: volumes: - ../bite:/srv/app/bite + static-files: + volumes: + - ../bite:/srv/app/bite + mqtt-to-db: volumes: - ../bite:/srv/app/bite diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 6e994f5..eac862f 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -54,7 +54,7 @@ services: broker: <<: *service_default - image: eclipse-mosquitto + image: eclipse-mosquitto:1.6 volumes: - "./mqtt/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf" networks: @@ -65,6 +65,8 @@ services: ingress: <<: *service_default image: nginx:stable-alpine + environment: + NGINX_ENTRYPOINT_QUIET_LOGS: 1 ports: - "${CUSTOM_DOCKER_IP:-0.0.0.0}:80:80" networks: diff --git a/docker/ntpd/Dockerfile b/docker/ntpd/Dockerfile index eea5209..c2c2850 100644 --- a/docker/ntpd/Dockerfile +++ b/docker/ntpd/Dockerfile @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -FROM alpine:3.9 +FROM alpine:3.12 RUN apk update && apk add chrony && \ chown -R chrony:chrony /var/lib/chrony diff --git a/docker/simulator/Dockerfile b/docker/simulator/Dockerfile index 971f342..6a59f02 100644 --- a/docker/simulator/Dockerfile +++ b/docker/simulator/Dockerfile @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -FROM python:3.8-alpine +FROM python:3.9-alpine RUN pip3 install urllib3 paho-mqtt COPY ./device_simulator.py /opt/bite/device_simulator.py