Skip to content

Commit

Permalink
Changed docker and deleted cache
Browse files Browse the repository at this point in the history
  • Loading branch information
ericantosch committed Jun 21, 2023
1 parent 8fffd40 commit f80c4f7
Show file tree
Hide file tree
Showing 51 changed files with 27 additions and 201 deletions.
1 change: 1 addition & 0 deletions webApp/Backend/init.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

python manage.py makemigrations
python manage.py makemigrations sensor
python manage.py migrate

python manage.py shell < sensor/mqtt.py &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ whitenoise
django-cors-headers
djangorestframework-simplejwt
djangorestframework-jwt
cbor2
Binary file not shown.
Binary file not shown.
Binary file removed webApp/Backend/sensor/__pycache__/admin.cpython-310.pyc
Binary file not shown.
Binary file removed webApp/Backend/sensor/__pycache__/admin.cpython-311.pyc
Binary file not shown.
Binary file removed webApp/Backend/sensor/__pycache__/apps.cpython-310.pyc
Binary file not shown.
Binary file removed webApp/Backend/sensor/__pycache__/apps.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed webApp/Backend/sensor/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
57 changes: 0 additions & 57 deletions webApp/Backend/sensor/migrations_old/0001_initial.py

This file was deleted.

This file was deleted.

20 changes: 0 additions & 20 deletions webApp/Backend/sensor/migrations_old/0004_alter_user_user_id.py

This file was deleted.

This file was deleted.

16 changes: 0 additions & 16 deletions webApp/Backend/sensor/migrations_old/0007_delete_sensor_data.py

This file was deleted.

Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion webApp/Backend/sensor/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Meta:


class User(AbstractBaseUser):
id = models.UUIDField
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
firstName = models.CharField(max_length=256)
lastName = models.CharField(max_length=256)
email = models.CharField(max_length=256, unique=True)
Expand Down
7 changes: 6 additions & 1 deletion webApp/Backend/sensor/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import paho.mqtt.client as mqtt
import json
import os
from cbor2 import loads
import base64
from django.db import IntegrityError
from sensor.models import SensorData, Container
from sensor.models import SensorData, Container




# Confiugure as needed
USERNAME="mqtest2@thingsnet"
API_KEY="NNSXS.K2TY66DR7XTMNWRGFQIC6H2MJSWDH2L4JHLKT6Q.IMEQNYYILH24PW5NSOYSEKMG6XLYKKI6G2JSEZBNJ2GGB2OYTODQ"
Expand Down Expand Up @@ -66,11 +66,16 @@ def on_connect(client, userdata, flags, rc):
# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
# Parse Byte data converted to JSON

payload = json.loads(msg.payload.decode("utf-8"))
decoded_payload = loads(payload)
file = open("mqtt.txt", "a")
file.write("Creating payload print-out\n")
file.write(str(payload))
file.write(decoded_payload)
file.write("\n")
file.close()

# print(msg.topic+" "+str(msg.payload))
print(process_message(msg))

Expand Down
2 changes: 1 addition & 1 deletion webApp/Backend/sensor/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
from rest_framework.validators import UniqueValidator
from django.contrib.auth.password_validation import validate_password
from .models import SensorData, User, Container
from .models import SensorData, Container, User


from django.contrib.auth.hashers import make_password
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed webApp/Backend/server/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file not shown.
Binary file removed webApp/Backend/server/__pycache__/wsgi.cpython-311.pyc
Binary file not shown.
21 changes: 11 additions & 10 deletions webApp/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: '3'
services:
db:
image: postgres:13
container_name: backend_db_1
restart: always
volumes:
- db-data:/var/lib/postgresql/data/
Expand All @@ -12,16 +13,16 @@ services:
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres

frontend:
build:
context: .
dockerfile: dockerfile_frontend
ports:
- "3000:3000"
depends_on:
- backend
environment:
- REACT_APP_BACKEND_URL=http://localhost:8000
# frontend:
# build:
# context: .
# dockerfile: dockerfile_frontend
# ports:
# - "3000:3000"
# depends_on:
# - backend
# environment:
# - REACT_APP_BACKEND_URL=http://localhost:8000

backend:
build:
Expand Down
4 changes: 2 additions & 2 deletions webApp/dockerfile_backend
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ FROM python:3.9-alpine

RUN mkdir -p /code
WORKDIR /code
COPY . /code
COPY ./Backend /code

RUN apk add --no-cache bash
RUN apk add --no-cache postgresql
RUN pip install --no-cache-dir -r requirements.yml

COPY init.sh /usr/local/bin/
COPY ./Backend/init.sh /usr/local/bin/

RUN chmod u+x /usr/local/bin/init.sh
ENTRYPOINT ["init.sh"]
Expand Down
15 changes: 4 additions & 11 deletions webApp/dockerfile_frontend
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
FROM node:18-alpine AS base

# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat


RUN mkdir -p /code
WORKDIR /code
COPY ./Frontend/riot_frontend /code

RUN apk add --no-cache libc6-compat

# Install dependencies based on the preferred package manager
RUN npm ci
RUN npm install
# Rebuild the source code only when needed
FROM base AS builder

COPY --from=deps ./Frontend/riot_frontend/node_modules ./node_modules
COPY ./Frontend/riot_frontend .

WORKDIR /code
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
Expand All @@ -29,7 +26,6 @@ COPY ./Frontend/riot_frontend .
RUN npm run build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /code

ENV NODE_ENV production
Expand All @@ -39,12 +35,9 @@ ENV NODE_ENV production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder ./Frontend/riot_frontend/public ./public

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /code/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /code/.next/static ./.next/static

USER nextjs

Expand Down

0 comments on commit f80c4f7

Please sign in to comment.