From fb968853b52b0b5f04d14e762cac9a1c7df06ff5 Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Sun, 28 Jan 2024 01:20:50 +0100 Subject: [PATCH] container, podman pod --- Dockerfile | 19 +++++++++++++++++++ podman-commands | 8 ++++++++ requirements.txt | 3 ++- src/aliexpress.py | 2 +- src/app.py | 14 ++++++++++++-- src/main.py | 2 +- 6 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 Dockerfile create mode 100644 podman-commands diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1e52e2f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM python:bookworm + +COPY requirements.txt / + +RUN pip3 install --upgrade pip + +RUN pip3 install -r /requirements.txt + + + +COPY ./src /app + +WORKDIR /app + + + +EXPOSE 8080 + +CMD ["gunicorn","--config", "gunicorn_config.py", "app:app"] diff --git a/podman-commands b/podman-commands new file mode 100644 index 0000000..58e64d4 --- /dev/null +++ b/podman-commands @@ -0,0 +1,8 @@ +podman build --tag alipricetrack:1.0.0 -f ./Dockerfile + + +podman pod create --name aliexpress -p 8080:8080 + +podman run -d --pod=aliexpress -e POSTGRES_DB="aliexpress" -e POSTGRES_USER="postgres" -e POSTGRES_PASSWORD="postgres" -v /home/fire/Downloads/db:/var/lib/postgresql/data --name ali-db docker.io/postgres + +podman run -d --pod=aliexpress --name ali-app alipricetrack:1.0.0 diff --git a/requirements.txt b/requirements.txt index e23d7be..dcfdbc7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ Flask gunicorn -psycopg2 +psycopg2-binary requests +pyyaml diff --git a/src/aliexpress.py b/src/aliexpress.py index 8d17620..646bf52 100644 --- a/src/aliexpress.py +++ b/src/aliexpress.py @@ -34,7 +34,7 @@ def check_items(settings_items): magnifier_image_regex = re.compile(r'') session = requests.Session() - cookies_file_path = './cookies.json' + cookies_file_path = os.path.dirname(os.path.realpath(__file__))+'/cookies.json' cookies = load_cookies_from_file(cookies_file_path) session.cookies.update(cookies) diff --git a/src/app.py b/src/app.py index 3218165..14886ae 100644 --- a/src/app.py +++ b/src/app.py @@ -11,8 +11,18 @@ def get_conf(): settings = yaml.safe_load(conf_file) return settings -@app.route('/') -def hello_world(): +@app.route('/init') +def init_db(): + print("init") + settings = get_conf() + initialize(settings["db"]) + return 'Hello, World!' + +@app.route('/update') +def update_hist(): + print("update") + settings = get_conf() + fill_db(settings["db"], check_items(settings["item"])) return 'Hello, World!' @app.route('/datahistory',methods = ['POST', 'GET']) diff --git a/src/main.py b/src/main.py index ef4384c..f41c9b8 100644 --- a/src/main.py +++ b/src/main.py @@ -17,5 +17,5 @@ if __name__ == '__main__': # initialize(settings["db"]) fill_db(settings["db"], check_items(settings["item"])) - export_csv(settings["db"]) + # export_csv(settings["db"])