Erste Anpassungen für Dockercontainer

This commit is contained in:
Alexander Malzkuhn 2025-06-02 11:32:41 +02:00
parent e7acbce08c
commit e54a210d69
8 changed files with 62 additions and 16 deletions

23
Dockerfile Normal file
View File

@ -0,0 +1,23 @@
FROM debian:latest
RUN apt update && apt upgrade -y
RUN apt install python3 python3-pip python3.11-venv locales -y
RUN mkdir /app
RUN mkdir /.venv
RUN mkdir /backup
RUN python3 -m venv /.venv
RUN /.venv/bin/pip install nicegui
RUN /.venv/bin/pip install segno
RUN /.venv/bin/pip install python-dateutil
RUN sed -i '/de_DE.UTF-8/s/^# //g' /etc/locale.gen && \
locale-gen
ENV LANG de_DE.UTF-8
ENV LANGUAGE de_DE:de
ENV LC_ALL de_DE.UTF-8
COPY main.py /app/main.py
COPY favicon.svg /app/favicon.svg
COPY lib /app/lib/
EXPOSE 8090
ENTRYPOINT ["/.venv/bin/python", "/app/main.py", "--docker"]
#ENTRYPOINT exec /app/.venv/bin/python /app/main.py --docker

10
docker-compose.yml Normal file
View File

@ -0,0 +1,10 @@
services:
test:
image: test:0
restart: always
ports:
- 8090:8090
volumes:
- /home/alexander/Dokumente/Python/Zeiterfassung:/app
- /home/alexander/Dokumente/Python/Zeiterfassung/users-docker:/users
- /home/alexander/Dokumente/Python/Zeiterfassung/backup:/backup

View File

@ -1,7 +1,6 @@
from datetime import datetime
import dateutil.easter
from PIL.SpiderImagePlugin import isInt
from dateutil.easter import *
from nicegui import ui, app, events
@ -45,6 +44,9 @@ def page_admin():
updates_available = ValueBinder()
updates_available.value = False
is_docker = ValueBinder
print(docker)
with ui.tabs() as tabs:
time_overview = ui.tab('Zeitdaten')
@ -1468,7 +1470,10 @@ Dies kann nicht rückgängig gemacht werden!''')
except ValueError:
button_string = date_string
ui.markdown(button_string)
ui.markdown(f'{round(size/1_000_000,2)} MB')
if size > 1_000_000:
ui.markdown(f'{round(size/1_000_000,2)} MB')
else:
ui.markdown(f'{round(size / 1_000, 2)} kB')
ui.markdown(version)
ui.button(icon='download', on_click=lambda file=date_string: ui.download.file(
os.path.join(scriptpath, backupfolder, f'{file}.zip'))).tooltip(
@ -1529,7 +1534,7 @@ Dies kann nicht rückgängig gemacht werden!''')
for file in files:
add = os.path.join(root, file)
target.write(add)
target.write(usersettingsfilename)
target.write(os.path.join(scriptpath, usersettingsfilename), arcname=usersettingsfilename)
target.writestr("app_version.txt", data=app_version)
backup_list.refresh()
n.dismiss()

View File

@ -6,9 +6,12 @@ from pathlib import Path
import hashlib
app_title = "Zeiterfassung"
app_version = ("0.0.0")
app_version = "0.0.0"
docker = False
# Standardpfade
scriptpath = str(Path(os.path.dirname(os.path.abspath(__file__))).parent.absolute())
userfolder = "users"
backupfolder = str(os.path.join(scriptpath, "backup"))

View File

@ -14,25 +14,28 @@ import shutil
import re
from lib.definitions import userfolder, scriptpath, usersettingsfilename, photofilename, status_in, status_out, \
standard_adminsettings, standard_usersettings, va_file
standard_adminsettings, standard_usersettings, va_file, docker
# Benutzerklasse
class user:
def __init__(self, name):
self.userfolder = os.path.join(scriptpath, userfolder, name)
if not scriptpath == "/app":
self.userfolder = os.path.join(scriptpath, userfolder, name)
else:
self.userfolder = os.path.join("/users", name)
self.settingsfile = os.path.join(self.userfolder, usersettingsfilename)
self.photofile = os.path.join(self.userfolder, photofilename)
# Stammdaten einlesen
try:
with open(self.settingsfile) as json_file:
#try:
with open(self.settingsfile) as json_file:
data = json.load(json_file)
except:
print("Fehler beim Erstellen des Datenarrays.")
#Hier muss noch Fehlerbehandlungcode hin
print(data)
#except:
# print("Fehler beim Erstellen des Datenarrays.")
# #TODO Hier muss noch Fehlerbehandlungcode hin
self.password = data["password"]
self.workhours = data["workhours"]
@ -534,6 +537,7 @@ def new_user(username: str):
def load_adminsettings():
# Settingsdatei einlesen
settings_filename = os.path.join(scriptpath, usersettingsfilename)
print(settings_filename)
if not os.path.exists(settings_filename):
print("Keine Einstellungsdatei gefunden. Lege Standarddatei an.")
with open(settings_filename, 'w') as json_file:

View File

@ -73,6 +73,7 @@
"2030-10-30": "Reformationstag",
"2030-12-25": "1. Weihnachtsfeiertag",
"2030-12-26": "2. Weihnachtsfeiertag",
"2025-06-11": "Testeintrag"
"2025-06-11": "Testeintrag",
"2025-05-31": "Testeintrag"
}
}

View File

@ -1,5 +1,6 @@
{
"archived": 0,
"archived": 1,
"total_hours": 0,
"absence": {}
"absence": {},
"overtime": -406441
}

View File

@ -15,7 +15,6 @@ import argparse
from lib.web_ui import hash_password
class Commandline_Header:
message_string = f"{app_title} {app_version}"
underline = ""