mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-04-05 08:54:03 -04:00
support postgres, mysql docker
This commit is contained in:
@@ -24,7 +24,7 @@ WORKDIR /app
|
|||||||
ENV PYTHONUNBUFFERED 1
|
ENV PYTHONUNBUFFERED 1
|
||||||
ENV DEBIAN_FRONTEND=noninteractive
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
RUN apt-get update &&\
|
RUN apt-get update &&\
|
||||||
apt-get install -y --no-install-recommends nodejs npm iputils-ping nmap &&\
|
apt-get install -y --no-install-recommends default-mysql-client nodejs npm iputils-ping nmap &&\
|
||||||
apt-get clean &&\
|
apt-get clean &&\
|
||||||
rm -rf /var/lib/{apt,dpkg,cache,log}/
|
rm -rf /var/lib/{apt,dpkg,cache,log}/
|
||||||
COPY --from=python-build /python-build/venv /app/venv
|
COPY --from=python-build /python-build/venv /app/venv
|
||||||
|
|||||||
@@ -13,27 +13,25 @@ if os.getenv("DJANGO_SUPERUSER_USER") and os.getenv("DJANGO_SUPERUSER_PASSWORD")
|
|||||||
else:
|
else:
|
||||||
print('Django user exists')
|
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
|
# reset visitors
|
||||||
[i.delete() for i in Websocket.objects.all()]
|
[i.delete() for i in Websocket.objects.all()]
|
||||||
Websocket.objects.create(visitors=0)
|
Websocket.objects.create(visitors=0)
|
||||||
|
|
||||||
# notifications
|
# notifications
|
||||||
if not os.getenv("PING_INTERVAL"):
|
if os.environ.get("PING_INTERVAL"):
|
||||||
os.environ["PING_INTERVAL"] = 5
|
ping_interval = os.environ.get("PING_INTERVAL")
|
||||||
|
else:
|
||||||
|
ping_interval = 5
|
||||||
Settings.objects.update_or_create(
|
Settings.objects.update_or_create(
|
||||||
id=1,
|
id=1,
|
||||||
defaults={
|
defaults={
|
||||||
"interval": os.getenv("PING_INTERVAL")
|
"interval": ping_interval
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# register device ping task
|
# register device ping task
|
||||||
schedule, created = IntervalSchedule.objects.get_or_create(
|
schedule, created = IntervalSchedule.objects.get_or_create(
|
||||||
every=int(os.getenv("PING_INTERVAL")),
|
every=ping_interval,
|
||||||
period=IntervalSchedule.SECONDS,
|
period=IntervalSchedule.SECONDS,
|
||||||
)
|
)
|
||||||
if created:
|
if created:
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ cd /app/backend/ || exit
|
|||||||
# wait for db and redis
|
# wait for db and redis
|
||||||
if [ "${DB_TYPE}" != "sqlite" ]; then
|
if [ "${DB_TYPE}" != "sqlite" ]; then
|
||||||
/usr/bin/env bash ./wait-for-it.sh "${DB_HOST}":"${DB_PORT}" -t 300 -s
|
/usr/bin/env bash ./wait-for-it.sh "${DB_HOST}":"${DB_PORT}" -t 300 -s
|
||||||
|
echo "sleeping 20"
|
||||||
sleep 20
|
sleep 20
|
||||||
fi
|
fi
|
||||||
/usr/bin/env bash ./wait-for-it.sh "${REDIS_HOST}":"${REDIS_PORT}" -t 300 -s
|
/usr/bin/env bash ./wait-for-it.sh "${REDIS_HOST}":"${REDIS_PORT}" -t 300 -s
|
||||||
@@ -19,6 +20,12 @@ elif [ "$PING_INTERVAL" -lt 5 ]; then
|
|||||||
PING_INTERVAL=5
|
PING_INTERVAL=5
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# create django secret key
|
||||||
|
if [ -z "$DJANGO_SECRET_KEY" ]; then
|
||||||
|
DJANGO_SECRET_KEY=$(python3 -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())')
|
||||||
|
export DJANGO_SECRET_KEY
|
||||||
|
fi
|
||||||
|
|
||||||
# init django
|
# init django
|
||||||
python3 manage.py makemigrations
|
python3 manage.py makemigrations
|
||||||
python3 manage.py migrate
|
python3 manage.py migrate
|
||||||
|
|||||||
@@ -6,23 +6,23 @@ services:
|
|||||||
network_mode: host
|
network_mode: host
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
- DJANGO_SUPERUSER_USER=admin
|
- FRONTEND_PORT=8000
|
||||||
- DJANGO_SUPERUSER_PASSWORD=admin
|
- BACKEND_PORT=8001
|
||||||
- DJANGO_SECRET_KEY=secret
|
- DB_TYPE=mysql # required
|
||||||
- DJANGO_DEBUG=False
|
- REDIS_HOST=127.0.0.1 # required (make sure to use the same ip as below)
|
||||||
- DJANGO_LANGUAGE_CODE=de
|
- REDIS_PORT=6379 # required (make sure to use the same port as below)
|
||||||
- DJANGO_TIME_ZONE=Europe/Berlin
|
|
||||||
- DJANGO_PORT=8000
|
|
||||||
- REDIS_HOST=127.0.0.1
|
|
||||||
- REDIS_PORT=6379
|
|
||||||
- DB_TYPE=mysql
|
|
||||||
- DB_HOST=127.0.0.1
|
- DB_HOST=127.0.0.1
|
||||||
- DB_PORT=3306
|
- DB_PORT=3306
|
||||||
- DB_NAME=upsnap
|
- DB_NAME=upsnap
|
||||||
- DB_USER=upsnap
|
- DB_USER=upsnap
|
||||||
- DB_PASSWORD=upsnap
|
- DB_PASSWORD=upsnap
|
||||||
- PING_INTERVAL=5
|
#- PING_INTERVAL=5 # optional (default: 5 seconds)
|
||||||
- ENABLE_NOTIFICATIONS=True
|
#- 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:
|
depends_on:
|
||||||
- upsnap_redis
|
- upsnap_redis
|
||||||
- upsnap_mysql
|
- upsnap_mysql
|
||||||
|
|||||||
@@ -6,23 +6,23 @@ services:
|
|||||||
network_mode: host
|
network_mode: host
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
- DJANGO_SUPERUSER_USER=admin
|
- FRONTEND_PORT=8000
|
||||||
- DJANGO_SUPERUSER_PASSWORD=admin
|
- BACKEND_PORT=8001
|
||||||
- DJANGO_SECRET_KEY=secret
|
- DB_TYPE=postgres # required
|
||||||
- DJANGO_DEBUG=False
|
- REDIS_HOST=127.0.0.1 # required (make sure to use the same ip as below)
|
||||||
- DJANGO_LANGUAGE_CODE=de
|
- REDIS_PORT=6379 # required (make sure to use the same port as below)
|
||||||
- DJANGO_TIME_ZONE=Europe/Berlin
|
|
||||||
- DJANGO_PORT=8000
|
|
||||||
- REDIS_HOST=127.0.0.1
|
|
||||||
- REDIS_PORT=6379
|
|
||||||
- DB_TYPE=postgres
|
|
||||||
- DB_HOST=127.0.0.1
|
- DB_HOST=127.0.0.1
|
||||||
- DB_PORT=5432
|
- DB_PORT=5432
|
||||||
- DB_NAME=upsnap
|
- DB_NAME=upsnap
|
||||||
- DB_USER=upsnap
|
- DB_USER=upsnap
|
||||||
- DB_PASSWORD=upsnap
|
- DB_PASSWORD=upsnap
|
||||||
- PING_INTERVAL=5
|
#- PING_INTERVAL=5 # optional (default: 5 seconds)
|
||||||
- ENABLE_NOTIFICATIONS=True
|
#- 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:
|
depends_on:
|
||||||
- upsnap_redis
|
- upsnap_redis
|
||||||
- upsnap_postgres
|
- upsnap_postgres
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ version: "3"
|
|||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
container_name: upsnap_app
|
container_name: upsnap_app
|
||||||
#image: seriousm4x/upsnap:latest
|
image: seriousm4x/upsnap:latest
|
||||||
build: .
|
|
||||||
network_mode: host
|
network_mode: host
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
@@ -12,13 +11,13 @@ services:
|
|||||||
- DB_TYPE=sqlite # required
|
- DB_TYPE=sqlite # required
|
||||||
- REDIS_HOST=127.0.0.1 # required (make sure to use the same ip as below)
|
- 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)
|
- REDIS_PORT=6379 # required (make sure to use the same port as below)
|
||||||
- PING_INTERVAL=5 # optional (default: 5 seconds)
|
#- PING_INTERVAL=5 # optional (default: 5 seconds)
|
||||||
- DJANGO_SUPERUSER_USER=admin # optional (default: backend login disabled)
|
#- DJANGO_SUPERUSER_USER=admin # optional (default: backend login disabled)
|
||||||
- DJANGO_SUPERUSER_PASSWORD=admin # optional (default: backend login disabled)
|
#- DJANGO_SUPERUSER_PASSWORD=admin # optional (default: backend login disabled)
|
||||||
- DJANGO_SECRET_KEY=secret # optional (default: randomly generated)
|
#- DJANGO_SECRET_KEY=secret # optional (default: randomly generated)
|
||||||
- DJANGO_DEBUG=True # optional (default: False)
|
#- DJANGO_DEBUG=True # optional (default: False)
|
||||||
- DJANGO_LANGUAGE_CODE=de # optional (default: en)
|
#- DJANGO_LANGUAGE_CODE=de # optional (default: en)
|
||||||
- DJANGO_TIME_ZONE=Europe/Berlin # optional (default: UTC)
|
#- DJANGO_TIME_ZONE=Europe/Berlin # optional (default: UTC)
|
||||||
depends_on:
|
depends_on:
|
||||||
- upsnap_redis
|
- upsnap_redis
|
||||||
redis:
|
redis:
|
||||||
|
|||||||
Reference in New Issue
Block a user