1
0
mirror of https://github.com/daniviga/bite.git synced 2024-11-26 14:56:13 +01:00

Project maintenance

This commit is contained in:
Daniele Viganò 2021-03-19 10:11:55 +01:00
parent cacc397162
commit e2203d0266
Signed by: dani
GPG Key ID: DB49AFC03C40EE02
20 changed files with 41 additions and 230 deletions

View File

@ -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 from django.db import migrations, models
import uuid
class Migration(migrations.Migration): class Migration(migrations.Migration):
@ -14,20 +16,25 @@ class Migration(migrations.Migration):
migrations.CreateModel( migrations.CreateModel(
name='Device', name='Device',
fields=[ fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('serial', models.CharField(max_length=128, unique=True, validators=[api.models.device_validation])),
('serial', models.CharField(max_length=128, unique=True)), ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('creation_time', models.DateTimeField(auto_now_add=True)), ('creation_time', models.DateTimeField(auto_now_add=True)),
('updated_time', models.DateTimeField(auto_now=True)), ('updated_time', models.DateTimeField(auto_now=True)),
], ],
options={
'ordering': ['updated_time', 'serial'],
},
), ),
migrations.CreateModel( migrations.CreateModel(
name='WhiteList', name='WhiteList',
fields=[ fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('serial', models.CharField(max_length=128, primary_key=True, serialize=False)),
('serial', models.CharField(max_length=128, unique=True)),
('creation_time', models.DateTimeField(auto_now_add=True)), ('creation_time', models.DateTimeField(auto_now_add=True)),
('updated_time', models.DateTimeField(auto_now=True)), ('updated_time', models.DateTimeField(auto_now=True)),
('is_published', models.BooleanField(default=True)), ('is_published', models.BooleanField(default=True)),
], ],
options={
'ordering': ['serial', 'updated_time'],
},
), ),
] ]

View File

@ -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']},
),
]

View File

@ -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]),
),
]

View File

@ -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),
),
]

View File

@ -37,7 +37,7 @@ def device_validation(value):
class WhiteList(models.Model): 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) creation_time = models.DateTimeField(auto_now_add=True)
updated_time = models.DateTimeField(auto_now=True) updated_time = models.DateTimeField(auto_now=True)
is_published = models.BooleanField(default=True) is_published = models.BooleanField(default=True)
@ -52,7 +52,7 @@ class WhiteList(models.Model):
class Device(models.Model): class Device(models.Model):
serial = models.CharField(max_length=128, unique=True, serial = models.CharField(max_length=128, unique=True,
validators=[device_validation]) validators=[device_validation])
uuid = models.UUIDField(unique=True, default=uuid.uuid4, uuid = models.UUIDField(primary_key=True, default=uuid.uuid4,
editable=False) editable=False)
creation_time = models.DateTimeField(auto_now_add=True) creation_time = models.DateTimeField(auto_now_add=True)
updated_time = models.DateTimeField(auto_now=True) updated_time = models.DateTimeField(auto_now=True)

View File

@ -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 from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
import telemetry.models
class Migration(migrations.Migration): class Migration(migrations.Migration):
@ -17,10 +18,16 @@ class Migration(migrations.Migration):
migrations.CreateModel( migrations.CreateModel(
name='Telemetry', name='Telemetry',
fields=[ fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.AutoField(primary_key=True, serialize=False)),
('time', models.DateTimeField(auto_now_add=True)), ('time', models.DateTimeField(auto_now_add=True, db_index=True)),
('payload', django.contrib.postgres.fields.jsonb.JSONField()), ('transport', models.CharField(choices=[('http', 'http'), ('mqtt', 'mqtt')], default='http', max_length=4)),
('device', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Device')), ('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'],
},
), ),
] ]

View File

@ -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']},
),
]

View File

@ -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),
),
]

View File

@ -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');"),
]

View File

@ -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)]),
),
]

View File

@ -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'},
),
]

View File

@ -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),
),
]

View File

@ -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]),
),
]

View File

@ -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]),
),
]

View File

@ -30,8 +30,9 @@ def telemetry_validation(value):
class Telemetry(models.Model): class Telemetry(models.Model):
id = models.AutoField(primary_key=True)
device = models.ForeignKey(Device, on_delete=models.CASCADE) 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, transport = models.CharField(max_length=4,
choices=[('http', 'http'), ('mqtt', 'mqtt')], choices=[('http', 'http'), ('mqtt', 'mqtt')],
default='http') default='http')

View File

@ -17,20 +17,20 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
FROM python:3.8-alpine AS builder FROM python:3.9-alpine AS builder
RUN apk update && apk add gcc musl-dev postgresql-dev \ RUN apk update && apk add gcc musl-dev postgresql-dev \
&& pip install psycopg2-binary && pip install psycopg2-binary
# --- # ---
FROM python:3.8-alpine FROM python:3.9-alpine
ENV PYTHONUNBUFFERED 1 ENV PYTHONUNBUFFERED 1
ENV DJANGO_SETTINGS_MODULE "bite.settings" ENV DJANGO_SETTINGS_MODULE "bite.settings"
RUN apk update && apk add --no-cache postgresql-libs \ 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- \ && 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 | 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 COPY --chown=1000:1000 requirements.txt /srv/app/bite/requirements.txt
RUN pip3 install --no-cache-dir -r /srv/app/bite/requirements.txt RUN pip3 install --no-cache-dir -r /srv/app/bite/requirements.txt

View File

@ -40,6 +40,10 @@ services:
volumes: volumes:
- ../bite:/srv/app/bite - ../bite:/srv/app/bite
static-files:
volumes:
- ../bite:/srv/app/bite
mqtt-to-db: mqtt-to-db:
volumes: volumes:
- ../bite:/srv/app/bite - ../bite:/srv/app/bite

View File

@ -54,7 +54,7 @@ services:
broker: broker:
<<: *service_default <<: *service_default
image: eclipse-mosquitto image: eclipse-mosquitto:1.6
volumes: volumes:
- "./mqtt/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf" - "./mqtt/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf"
networks: networks:
@ -65,6 +65,8 @@ services:
ingress: ingress:
<<: *service_default <<: *service_default
image: nginx:stable-alpine image: nginx:stable-alpine
environment:
NGINX_ENTRYPOINT_QUIET_LOGS: 1
ports: ports:
- "${CUSTOM_DOCKER_IP:-0.0.0.0}:80:80" - "${CUSTOM_DOCKER_IP:-0.0.0.0}:80:80"
networks: networks:

View File

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
FROM alpine:3.9 FROM alpine:3.12
RUN apk update && apk add chrony && \ RUN apk update && apk add chrony && \
chown -R chrony:chrony /var/lib/chrony chown -R chrony:chrony /var/lib/chrony

View File

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
FROM python:3.8-alpine FROM python:3.9-alpine
RUN pip3 install urllib3 paho-mqtt RUN pip3 install urllib3 paho-mqtt
COPY ./device_simulator.py /opt/bite/device_simulator.py COPY ./device_simulator.py /opt/bite/device_simulator.py