diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fe0b486 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +# Use an official Python runtime as a parent image +FROM python:3.10 + +# Set the working directory in the container to /app +WORKDIR /app + +# Copy the current directory contents into the container at /app +COPY . /app + +# Install any needed packages specified in requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +# Make port 80 available to the world outside this container +EXPOSE 8000 diff --git a/config.py b/config.py index 793c60e..d7ebd39 100644 --- a/config.py +++ b/config.py @@ -1,7 +1,7 @@ class DefaultConfig: DEBUG = False TESTING = False - DATABASE_URI = "users.db" + DATABASE_URI = "./database/users.db" SECRET_KEY = SECURITY_PASSWORD_SALT='default' CONFIRMATATION_EMAIL_ADD=None @@ -11,7 +11,7 @@ class Config(DefaultConfig): class ProductionConfig(Config): SECRET_KEY = '\xacI4\x077\x16?Q\xb4")\xdb\x066\x95\x11i\x0b\x0c&\xb6rP\'' SECURITY_PASSWORD_SALT = '>\xe3\x9bz\xfd\xbc[\xe22\xcfK\xca\x88!\xd8\xd5,\xd0\x95\x0c\x02\xad\xfa\x9d' - DATABASE_URI = '/home/site/wwwroot/users.db' # For azure app services. The content under wwwroot is durable, unless you delete your app service. + DATABASE_URI = './users.db' # For azure app services. The content under wwwroot is durable, unless you delete your app service. class DevelopmentConfig(Config): CONFIRMATATION_EMAIL_ADD= "struebin.patrick@gmail.com" diff --git a/database/users.initialized copy.db b/database/users.initialized copy.db new file mode 100644 index 0000000..62948a1 Binary files /dev/null and b/database/users.initialized copy.db differ diff --git a/db.py b/db.py index 318cdd8..71abc67 100644 --- a/db.py +++ b/db.py @@ -41,4 +41,24 @@ def init_db_command(): def init_app(app): app.teardown_appcontext(close_db) - app.cli.add_command(init_db_command) \ No newline at end of file + app.cli.add_command(init_db_command) + + +if __name__ == "__main__": + import csv + from datetime import datetime + # Connect to the SQLite database + conn = sqlite3.connect('users.db') + c = conn.cursor() + + # Load data from CSV file + with open('users.db.backup.txt', 'r') as csvfile: + reader = csv.reader(csvfile, delimiter='|') + for row in reader: + username, email, password, confirmed, confirmation_date = row[1:] #drop first col + c.execute("INSERT INTO user (username, email, password, confirmed, confirmation_date) VALUES (?, ?, ?, ?, ?)", + (username.strip(), email.strip(), password, int(confirmed), datetime.strptime(confirmation_date, '%Y-%m-%d %H:%M:%S.%f'))) + + # Commit the changes and close the connection + conn.commit() + conn.close() \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..10d2d72 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,14 @@ +services: + app: + build: . + ports: + - "8000:8000" + network_mode: host + + volumes: + - sqlite-database:/app/database + working_dir: /app + command: sh ./run_production_server.sh + +volumes: + sqlite-database: \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 17397f4..9ffe0e9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,19 @@ -flask -msal +blinker==1.8.2 +certifi==2024.6.2 +cffi==1.16.0 +charset-normalizer==3.3.2 +click==8.1.7 +cryptography==42.0.8 +Flask==3.0.3 +gunicorn==22.0.0 +idna==3.7 +itsdangerous==2.2.0 +Jinja2==3.1.4 +MarkupSafe==2.1.5 +msal==1.29.0 +packaging==24.1 +pycparser==2.22 +PyJWT==2.8.0 +requests==2.32.3 +urllib3==2.2.2 +Werkzeug==3.0.3 diff --git a/run_production_server.sh b/run_production_server.sh new file mode 100644 index 0000000..b254ff7 --- /dev/null +++ b/run_production_server.sh @@ -0,0 +1,4 @@ +export FLASK_ENV=production +export CONFIG=config.ProductionConfig +# equivalent to 'from hello import app' +gunicorn 'app:app' \ No newline at end of file diff --git a/users.db.backup.txt b/users.db.backup.txt index 4ae3cb4..54b4a71 100644 --- a/users.db.backup.txt +++ b/users.db.backup.txt @@ -1,8 +1,6 @@ 1|Patrick Strübin|struebin.patrick@gmail.com|pbkdf2:sha256:260000$0XKR2y8Bl5VBJEwi$b466bf14019ea83125ae2b1a13303f04547950311cf5908eb3a64c1b4849513d|1|2022-06-17 09:29:35.589533 -2|Kalle|khstruebin@web.de|pbkdf2:sha256:260000$GHcPS6QHUlSOibT6$4fccef0949cdc64f75c5a609539fd5227ff7b0a53412c6a78bdf2a974a2c0be6|1|2022-06-17 09:39:34.305725 3|Simone|s.m.profus@gmail.com|pbkdf2:sha256:260000$Ze0EmkSUbr9LSIv6$3ef454b54f776c016cccaad4f13f84998807d26234c218bce375ac4f386f1d30|1|2022-06-17 10:46:08.137068 4|Simone|simone.profus@propedal.at|pbkdf2:sha256:260000$67dmLjjR1BoNwbuf$f707d073fbd34ecdee4f4f72f24d69f22880df226cb158cfef45e41402009797|1|2022-09-04 17:28:28.245465 -5|Patrick |test@bla.at|pbkdf2:sha256:260000$0r3sjIV5Or8kcBTh$44b2baf22350bebd561d6abcec7bca75aa76d72cfb66cf21d520252c0b506dcd|0| 6|Isabella M|qallen2000@yahoo.fr|pbkdf2:sha256:260000$t93QBWdWmjhdZbGr$f6a92cf8853ca4176d7e425188359587400c9a526743df1ce267400b9fca252a|1|2022-09-14 20:54:34.740235 7|Jesús|jvaz19@hotmail.com|pbkdf2:sha256:260000$6P0XDHrDo1EfVVf6$d98078ee68c4978d5274b3594b42896465fcce878f14d7262d4f9975bdd00ccd|1|2022-09-27 11:55:57.044266 9|Maximilian Zahler|damaxl48@gmail.com|pbkdf2:sha256:260000$OO3CektTREvvlXHH$7fde8ba2f46179138dee4d7ebef941d30794a50c7a5b199823dedc87751a0dd1|1|2022-09-18 19:34:22.328920