mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-03-31 06:24:06 -04:00
docker env vars, remove notifications from backend
This commit is contained in:
@@ -18,8 +18,6 @@ COPY app/frontend/package*.json ./
|
||||
COPY app/frontend/src ./src
|
||||
COPY app/frontend/public ./public
|
||||
COPY app/frontend/rollup.config.js ./
|
||||
RUN npm install
|
||||
RUN npm run build
|
||||
|
||||
FROM base
|
||||
WORKDIR /app
|
||||
|
||||
@@ -151,9 +151,9 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/4.0/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = os.getenv("DJANGO_LANGUAGE_CODE")
|
||||
LANGUAGE_CODE = os.getenv("DJANGO_LANGUAGE_CODE", "en")
|
||||
|
||||
TIME_ZONE = os.getenv("DJANGO_TIME_ZONE")
|
||||
TIME_ZONE = os.getenv("DJANGO_TIME_ZONE", "UTC")
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
|
||||
@@ -1,26 +1,32 @@
|
||||
import os
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.management.utils import get_random_secret_key
|
||||
from django_celery_beat.models import IntervalSchedule, PeriodicTask
|
||||
|
||||
from wol.models import Settings, Websocket
|
||||
from django_celery_beat.models import PeriodicTask, IntervalSchedule
|
||||
|
||||
|
||||
# create superuser
|
||||
if os.getenv("DJANGO_SUPERUSER_USER") and os.getenv("DJANGO_SUPERUSER_PASSWORD"):
|
||||
if not User.objects.filter(username=os.getenv("DJANGO_SUPERUSER_USER")).exists():
|
||||
User.objects.create_superuser(os.getenv("DJANGO_SUPERUSER_USER"), password=os.getenv("DJANGO_SUPERUSER_PASSWORD"))
|
||||
else:
|
||||
print('Django user exists')
|
||||
|
||||
# create django secret key
|
||||
if not os.getenv("DJANGO_SUPERUSER_PASSWORD"):
|
||||
os.environ["DJANGO_SECRET_KEY"] = get_random_secret_key()
|
||||
|
||||
# reset visitors
|
||||
[i.delete() for i in Websocket.objects.all()]
|
||||
Websocket.objects.create(visitors=0)
|
||||
|
||||
# notifications
|
||||
if not os.getenv("PING_INTERVAL"):
|
||||
os.environ["PING_INTERVAL"] = 5
|
||||
Settings.objects.update_or_create(
|
||||
id=1,
|
||||
defaults={
|
||||
"enable_notifications": os.getenv("ENABLE_NOTIFICATIONS"),
|
||||
"interval": os.getenv("PING_INTERVAL")
|
||||
}
|
||||
)
|
||||
|
||||
@@ -17,7 +17,7 @@ class PortAdmin(admin.ModelAdmin):
|
||||
list_filter = ["number", "name"]
|
||||
|
||||
class SettingsAdmin(admin.ModelAdmin):
|
||||
list_display = ["enable_notifications", "sort_by", "scan_address", "interval"]
|
||||
list_display = ["sort_by", "scan_address", "interval"]
|
||||
|
||||
|
||||
admin.site.register(Device, DeviceAdmin)
|
||||
|
||||
@@ -221,7 +221,6 @@ class WSConsumer(AsyncWebsocketConsumer):
|
||||
def get_settings(self):
|
||||
conf = Settings.objects.get(id=1)
|
||||
data = {
|
||||
"notifications": conf.enable_notifications,
|
||||
"discovery": conf.scan_address,
|
||||
"interval": conf.interval,
|
||||
"scan_network": []
|
||||
@@ -235,7 +234,6 @@ class WSConsumer(AsyncWebsocketConsumer):
|
||||
Settings.objects.update_or_create(
|
||||
id=1,
|
||||
defaults={
|
||||
"enable_notifications": data["notifications"],
|
||||
"scan_address": data["discovery"],
|
||||
"interval": data["interval"]
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ class Websocket(models.Model):
|
||||
visitors = models.PositiveSmallIntegerField(blank=False, null=False, default=0)
|
||||
|
||||
class Settings(models.Model):
|
||||
enable_notifications = models.BooleanField(default=True)
|
||||
sort_by = models.SlugField(default="name")
|
||||
scan_address = models.GenericIPAddressField(null=True, blank=True)
|
||||
interval = models.PositiveSmallIntegerField(null=True, blank=True)
|
||||
|
||||
58
app/frontend/package-lock.json
generated
58
app/frontend/package-lock.json
generated
@@ -9,7 +9,9 @@
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-free": "^6.0.0",
|
||||
"@rollup/plugin-replace": "^4.0.0",
|
||||
"bootstrap": "^5.1.3",
|
||||
"dotenv": "^16.0.0",
|
||||
"node-sass": "^7.0.1",
|
||||
"postcss": "^8.4.6",
|
||||
"sirv-cli": "^2.0.0",
|
||||
@@ -185,11 +187,22 @@
|
||||
"rollup": "^1.20.0||^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@rollup/plugin-replace": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@rollup/plugin-replace/-/plugin-replace-4.0.0.tgz",
|
||||
"integrity": "sha512-+rumQFiaNac9y64OHtkHGmdjm7us9bo1PlbgQfdihQtuNxzjpaB064HbRnewUOggLQxVCCyINfStkgmBeQpv1g==",
|
||||
"dependencies": {
|
||||
"@rollup/pluginutils": "^3.1.0",
|
||||
"magic-string": "^0.25.7"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"rollup": "^1.20.0 || ^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@rollup/pluginutils": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz",
|
||||
"integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/estree": "0.0.39",
|
||||
"estree-walker": "^1.0.1",
|
||||
@@ -205,8 +218,7 @@
|
||||
"node_modules/@rollup/pluginutils/node_modules/estree-walker": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz",
|
||||
"integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==",
|
||||
"dev": true
|
||||
"integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg=="
|
||||
},
|
||||
"node_modules/@tootallnate/once": {
|
||||
"version": "1.1.2",
|
||||
@@ -219,8 +231,7 @@
|
||||
"node_modules/@types/estree": {
|
||||
"version": "0.0.39",
|
||||
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz",
|
||||
"integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==",
|
||||
"dev": true
|
||||
"integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw=="
|
||||
},
|
||||
"node_modules/@types/fs-extra": {
|
||||
"version": "8.1.2",
|
||||
@@ -843,6 +854,14 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "16.0.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.0.tgz",
|
||||
"integrity": "sha512-qD9WU0MPM4SWLPJy/r2Be+2WgQj8plChsyrCNQzW/0WjvcJQiKQJ9mH3ZgB3fxbUUxgc/11ZJ0Fi5KiimWGz2Q==",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/ecc-jsbn": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz",
|
||||
@@ -1041,7 +1060,6 @@
|
||||
"version": "2.3.2",
|
||||
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
|
||||
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -2337,7 +2355,6 @@
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
|
||||
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=8.6"
|
||||
},
|
||||
@@ -2646,7 +2663,6 @@
|
||||
"version": "2.67.2",
|
||||
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.67.2.tgz",
|
||||
"integrity": "sha512-hoEiBWwZtf1QdK3jZIq59L0FJj4Fiv4RplCO4pvCRC86qsoFurWB4hKQIjoRf3WvJmk5UZ9b0y5ton+62fC7Tw==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"rollup": "dist/bin/rollup"
|
||||
},
|
||||
@@ -3757,11 +3773,19 @@
|
||||
"resolve": "^1.19.0"
|
||||
}
|
||||
},
|
||||
"@rollup/plugin-replace": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@rollup/plugin-replace/-/plugin-replace-4.0.0.tgz",
|
||||
"integrity": "sha512-+rumQFiaNac9y64OHtkHGmdjm7us9bo1PlbgQfdihQtuNxzjpaB064HbRnewUOggLQxVCCyINfStkgmBeQpv1g==",
|
||||
"requires": {
|
||||
"@rollup/pluginutils": "^3.1.0",
|
||||
"magic-string": "^0.25.7"
|
||||
}
|
||||
},
|
||||
"@rollup/pluginutils": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz",
|
||||
"integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/estree": "0.0.39",
|
||||
"estree-walker": "^1.0.1",
|
||||
@@ -3771,8 +3795,7 @@
|
||||
"estree-walker": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz",
|
||||
"integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==",
|
||||
"dev": true
|
||||
"integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg=="
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -3784,8 +3807,7 @@
|
||||
"@types/estree": {
|
||||
"version": "0.0.39",
|
||||
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz",
|
||||
"integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==",
|
||||
"dev": true
|
||||
"integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw=="
|
||||
},
|
||||
"@types/fs-extra": {
|
||||
"version": "8.1.2",
|
||||
@@ -4270,6 +4292,11 @@
|
||||
"path-type": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"dotenv": {
|
||||
"version": "16.0.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.0.tgz",
|
||||
"integrity": "sha512-qD9WU0MPM4SWLPJy/r2Be+2WgQj8plChsyrCNQzW/0WjvcJQiKQJ9mH3ZgB3fxbUUxgc/11ZJ0Fi5KiimWGz2Q=="
|
||||
},
|
||||
"ecc-jsbn": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz",
|
||||
@@ -4435,7 +4462,6 @@
|
||||
"version": "2.3.2",
|
||||
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
|
||||
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"function-bind": {
|
||||
@@ -5417,8 +5443,7 @@
|
||||
"picomatch": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
|
||||
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
|
||||
"dev": true
|
||||
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA=="
|
||||
},
|
||||
"postcss": {
|
||||
"version": "8.4.6",
|
||||
@@ -5639,7 +5664,6 @@
|
||||
"version": "2.67.2",
|
||||
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.67.2.tgz",
|
||||
"integrity": "sha512-hoEiBWwZtf1QdK3jZIq59L0FJj4Fiv4RplCO4pvCRC86qsoFurWB4hKQIjoRf3WvJmk5UZ9b0y5ton+62fC7Tw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"fsevents": "~2.3.2"
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-free": "^6.0.0",
|
||||
"@rollup/plugin-replace": "^4.0.0",
|
||||
"bootstrap": "^5.1.3",
|
||||
"dotenv": "^16.0.0",
|
||||
"node-sass": "^7.0.1",
|
||||
"postcss": "^8.4.6",
|
||||
"sirv-cli": "^2.0.0",
|
||||
|
||||
@@ -6,6 +6,10 @@ import { terser } from 'rollup-plugin-terser';
|
||||
import css from 'rollup-plugin-css-only';
|
||||
import preprocess from 'svelte-preprocess';
|
||||
import copy from 'rollup-plugin-copy';
|
||||
import dotenv from "dotenv";
|
||||
import replace from '@rollup/plugin-replace';
|
||||
|
||||
dotenv.config()
|
||||
|
||||
const production = !process.env.ROLLUP_WATCH;
|
||||
|
||||
@@ -44,7 +48,11 @@ export default {
|
||||
// enable run-time checks when not in production
|
||||
dev: !production,
|
||||
},
|
||||
preprocess: preprocess()
|
||||
preprocess: preprocess(),
|
||||
}),
|
||||
replace({
|
||||
BACKEND_PORT: JSON.stringify(process.env.BACKEND_PORT),
|
||||
preventAssignment: true
|
||||
}),
|
||||
// we'll extract any component CSS out into
|
||||
// a separate file - better for performance
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
} from 'svelte/store';
|
||||
|
||||
const messageStore = writable('');
|
||||
const socket = new WebSocket("ws://" + location.hostname + ":8000/wol/");
|
||||
const socket = new WebSocket(`ws://${location.hostname}:${BACKEND_PORT}/wol/`);
|
||||
|
||||
// Connection opened
|
||||
socket.addEventListener('open', function (event) {
|
||||
|
||||
@@ -26,8 +26,10 @@ python3 manage.py collectstatic --noinput
|
||||
python3 manage.py shell < setup.py
|
||||
python3 -m celery -A backend worker &
|
||||
python3 -m celery -A backend beat &
|
||||
python3 -m gunicorn --bind 0.0.0.0:"$DJANGO_PORT" --workers 4 backend.asgi:application -k uvicorn.workers.UvicornWorker &
|
||||
python3 -m gunicorn --bind 0.0.0.0:"${BACKEND_PORT}" --workers 4 backend.asgi:application -k uvicorn.workers.UvicornWorker &
|
||||
|
||||
# start frontend
|
||||
cd /app/frontend/ || exit
|
||||
npm start
|
||||
npm install
|
||||
npm run build
|
||||
PORT=$FRONTEND_PORT npm start
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
version: "3"
|
||||
services:
|
||||
upsnap_django:
|
||||
container_name: upsnap_django
|
||||
app:
|
||||
container_name: upsnap_app
|
||||
#image: seriousm4x/upsnap:latest
|
||||
build: .
|
||||
network_mode: host
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- DJANGO_SUPERUSER_USER=admin
|
||||
- DJANGO_SUPERUSER_PASSWORD=admin
|
||||
- DJANGO_SECRET_KEY=secret
|
||||
- DJANGO_DEBUG=True
|
||||
- DJANGO_LANGUAGE_CODE=de
|
||||
- DJANGO_TIME_ZONE=Europe/Berlin
|
||||
- DJANGO_PORT=8000
|
||||
- REDIS_HOST=127.0.0.1
|
||||
- REDIS_PORT=6379
|
||||
- DB_TYPE=sqlite
|
||||
- PING_INTERVAL=5
|
||||
- ENABLE_NOTIFICATIONS=True
|
||||
- FRONTEND_PORT=8000
|
||||
- BACKEND_PORT=8001
|
||||
- DB_TYPE=sqlite # required
|
||||
- REDIS_HOST=127.0.0.1 # required (make sure to use the same ip as below)
|
||||
- REDIS_PORT=6379 # required (make sure to use the same port as below)
|
||||
- PING_INTERVAL=5 # optional (default: 5 seconds)
|
||||
- DJANGO_SUPERUSER_USER=admin # optional (default: backend login disabled)
|
||||
- DJANGO_SUPERUSER_PASSWORD=admin # optional (default: backend login disabled)
|
||||
- DJANGO_SECRET_KEY=secret # optional (default: randomly generated)
|
||||
- DJANGO_DEBUG=True # optional (default: False)
|
||||
- DJANGO_LANGUAGE_CODE=de # optional (default: en)
|
||||
- DJANGO_TIME_ZONE=Europe/Berlin # optional (default: UTC)
|
||||
depends_on:
|
||||
- upsnap_redis
|
||||
upsnap_redis:
|
||||
redis:
|
||||
container_name: upsnap_redis
|
||||
image: redis:alpine
|
||||
ports:
|
||||
|
||||
Reference in New Issue
Block a user