Updated docker and script files to make them more robust

This commit is contained in:
Luke Else 2024-01-04 18:59:51 +00:00
parent 79231a1f0d
commit f1065b8150
3 changed files with 18 additions and 6 deletions

View File

@ -3,4 +3,5 @@ COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip install -r requirements.txt
COPY . /app
CMD ["scripts/run.sh"]
RUN chmod +x scripts/run.sh
CMD ["sh", "scripts/run.sh"]

View File

@ -1,13 +1,18 @@
import sqlite3
import os
def create_connection(db_file):
def create_connection(path: str, filename: str):
""" create a database connection to a SQLite database """
conn = None
try:
print("Opening Database file and ensuring table integrity")
conn = sqlite3.connect(db_file)
# Make the directory for the file to go into
create_directory(path)
print("Opening Database file and ensuring table integrity")
conn = sqlite3.connect(path + filename)
print("Database file open")
# Execute creation scripts
sql = open("scripts/create_tables.sql", "r");
conn.executescript(sql.read())
@ -20,6 +25,12 @@ def create_connection(db_file):
if conn:
conn.close()
# Ensure a directory is created given a path to it
def create_directory(dir: str):
try:
os.makedirs(dir)
except FileExistsError:
pass
if __name__ == '__main__':
create_connection(r"./data/wmgzon.db")
create_connection(r"./data/", r"wmgzon.db")

View File

@ -1,4 +1,4 @@
#! /bin/sh
python ./scripts/create_database.py
python ./scripts/create_database.py
python ./app.py