Merge pull request #68 from edgd1er/req

move requirements from Dockerfile to txt file. #67
This commit is contained in:
simonmicro 2022-05-30 00:22:14 +02:00 committed by GitHub
commit 1435c86fe4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 39 deletions

View file

@ -12,27 +12,21 @@ ENV HWID RANDOM
ENV LOGLEVEL INFO
ENV LOGFILE STDOUT
ENV LOGSIZE ""
ENV TYPE MINIMAL
COPY ./py-kms /home/py-kms
COPY docker/requirements_minimal.txt /home/py-kms/requirements.txt
RUN apk add --no-cache --update \
bash \
git \
py3-argparse \
py3-flask \
py3-pygments \
python3-tkinter \
sqlite-libs \
bash \
python3 \
py3-pip \
tzdata \
python3-tkinter \
ca-certificates \
shadow \
tzdata \
netcat-openbsd \
build-base python3-dev \
&& pip3 install --no-cache-dir peewee tzlocal pytz wheel dnspython \
&& apk del git build-base python3-dev \
&& addgroup power_users \
&& pip3 install --no-cache-dir -r /home/py-kms/requirements.txt \
&& adduser -S py-kms -G users -s /bin/bash \
&& usermod -a -G power_users py-kms \
&& chown py-kms:users /home/py-kms \
# Fix undefined timezone, in case the user did not mount the /etc/localtime
&& ln -sf /usr/share/zoneinfo/UTC /etc/localtime

View file

@ -17,31 +17,21 @@ ENV LOGSIZE ""
ENV TZ America/Chicago
COPY py-kms /home/py-kms/
COPY docker/requirements.txt /home/py-kms/
RUN apk add --no-cache --update \
bash \
git \
python3 \
py3-argparse \
py3-flask \
py3-pygments \
py3-pip \
python3-tkinter \
sqlite-libs \
py3-pip \
build-base python3-dev \
ca-certificates \
tzdata \
shadow \
netcat-openbsd \
&& git clone --branch master --depth 1 https://github.com/coleifer/sqlite-web.git /tmp/sqlite_web \
&& mv /tmp/sqlite_web/sqlite_web /home/ \
&& rm -rf /tmp/sqlite_web \
&& pip3 install --no-cache-dir peewee tzlocal pytz pysqlite3 wheel dnspython \
&& apk del git build-base python3-dev \
&& pip3 install --no-cache-dir -r /home/py-kms/requirements.txt \
#&& apk del git build-base python3-dev \
&& mkdir /db/ \
&& addgroup power_users \
&& adduser -S py-kms -G users -s /bin/bash \
&& usermod -a -G power_users py-kms \
&& chown py-kms:users /home/py-kms \
# Fix undefined timezone, in case the user did not mount the /etc/localtime
&& ln -sf /usr/share/zoneinfo/UTC /etc/localtime

View file

@ -9,6 +9,7 @@ import pwd
import subprocess
import sys
import signal
import time
PYTHON3 = '/usr/bin/python3'
dbPath = os.path.join(os.sep, 'home', 'py-kms', 'db') # Do not include the database file name, as we must correct the folder permissions (the db file is recursively reachable)
@ -26,8 +27,11 @@ loggersrv.addHandler(streamhandler)
def change_uid_grp():
if os.geteuid() != 0:
loggersrv.info(f'not root user, cannot change uid/gid.')
return None
user_db_entries = pwd.getpwnam("py-kms")
user_grp_db_entries = grp.getgrnam("power_users")
user_grp_db_entries = grp.getgrnam("users")
uid = int(user_db_entries.pw_uid)
gid = int(user_grp_db_entries.gr_gid)
new_gid = int(os.getenv('GID', str(gid)))
@ -62,17 +66,15 @@ def change_uid_grp():
def change_tz():
tz = os.getenv('TZ', 'etc/UTC')
# TZ is not symlinked and defined TZ exists
if tz not in os.readlink('/etc/localtime') and os.path.isfile('/usr/share/zoneinfo/' + tz):
if tz not in os.readlink('/etc/localtime') and os.path.isfile('/usr/share/zoneinfo/' + tz) and hasattr(time, 'tzset'):
loggersrv.info("Setting timzeone to %s" % tz )
os.remove('/etc/localtime')
os.symlink(os.path.join('/usr/share/zoneinfo/', tz), '/etc/localtime')
f = open("/etc/timezone", "w")
f.write(tz)
f.close()
# time.tzet() should be called on Unix, but doesn't exist on Windows.
time.tzset()
# Main
if (__name__ == "__main__"):
loggersrv.info("Log level: %s" % log_level)
loggersrv.debug("user id: %s" % os.getuid())
change_tz()
childProcess = subprocess.Popen(PYTHON3 + " -u /usr/bin/start.py", preexec_fn=change_uid_grp(), shell=True)
def shutdown(signum, frame):

5
docker/requirements.txt Normal file
View file

@ -0,0 +1,5 @@
Flask==2.1.2
Pygments==2.12.0
dnspython==2.2.1
tzlocal==4.2
sqlite-web==0.4.0

View file

@ -0,0 +1,4 @@
Flask==2.1.2
Pygments==2.12.0
dnspython==2.2.1
tzlocal==4.2

View file

@ -21,9 +21,9 @@ argumentVariableMapping = {
}
sqliteWebPath = '/home/sqlite_web/sqlite_web.py'
enableSQLITE = os.path.isfile(sqliteWebPath) and os.environ.get('SQLITE', 'false').lower() == 'true'
enableSQLITE = os.environ.get('SQLITE', 'false').lower() == 'true' and os.environ.get('TYPE') != 'MINIMAL'
dbPath = os.path.join(os.sep, 'home', 'py-kms', 'db', 'pykms_database.db')
log_level_bootstrap = log_level = os.getenv('LOGLEVEL', 'INFO')
log_level_bootstrap = log_level = os.environ.get('LOGLEVEL', 'INFO')
if log_level_bootstrap == "MININFO":
log_level_bootstrap = "INFO"
log_file = os.environ.get('LOGFILE', 'STDOUT')
@ -57,7 +57,7 @@ def start_kms():
command.append(os.environ.get(env))
if len(listen_ip) > 1:
command.append("connect")
for i in range(1,len(listen_ip)):
for i in range(1, len(listen_ip)):
command.append("-n")
command.append(listen_ip[i] + "," + listen_port)
@ -74,7 +74,7 @@ def start_kms():
if enableSQLITE:
time.sleep(5) # The server may take a while to start
start_kms_client()
sqlite_cmd = [PYTHON3, '-u', '/home/sqlite_web/sqlite_web.py', '-H', listen_ip[0], '--read-only', '-x',
sqlite_cmd = ['sqlite_web', '-H', listen_ip[0], '--read-only', '-x',
dbPath, '-p', sqlite_port]
loggersrv.debug("sqlite_cmd: %s" % (" ".join(str(x) for x in sqlite_cmd).strip()))
@ -103,4 +103,5 @@ if (__name__ == "__main__"):
datefmt='%a, %d %b %Y %H:%M:%S')
streamhandler.setFormatter(formatter)
loggersrv.addHandler(streamhandler)
loggersrv.debug("user id: %s" % os.getuid())
start_kms()