From d7ec2883ee1c3c70a5dc5df9c84f6fa5bbf9446e Mon Sep 17 00:00:00 2001 From: Miki Date: Fri, 31 Jan 2025 18:02:56 +0100 Subject: [PATCH] feat: add docker files --- docker-compose.yml | 21 +++++++++++++++++++++ src/ign-api/Dockerfile | 22 ++++++++++++++++++++++ src/ign-api/crontab | 1 + src/ign-api/requirements.txt | 7 ++++--- src/ign-api/run-worker.sh | 5 +++++ 5 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 docker-compose.yml create mode 100644 src/ign-api/Dockerfile create mode 100644 src/ign-api/crontab create mode 100755 src/ign-api/run-worker.sh diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ac0cef2 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +version: '3.8' + +services: + api: + build: ./src/ign-api + container_name: api + environment: + - REDISTOGO_URL=redis://redis:6379/0 + ports: + - "8000:8000" + depends_on: + - redis + redis: + image: redis:latest + container_name: redis + ports: + - "6379:6379" + +networks: + default: + driver: bridge \ No newline at end of file diff --git a/src/ign-api/Dockerfile b/src/ign-api/Dockerfile new file mode 100644 index 0000000..d5e59ad --- /dev/null +++ b/src/ign-api/Dockerfile @@ -0,0 +1,22 @@ +FROM python:3.9-slim + +RUN apt-get update && apt-get install -y cron + +WORKDIR /app + +COPY requirements.txt requirements.txt +RUN pip install --no-cache-dir -r requirements.txt +RUN pip install gunicorn + +COPY . . +RUN chmod +x /app/run-worker.sh + +COPY crontab /etc/cron.d/my-cron-job +RUN chmod 0644 /etc/cron.d/my-cron-job +RUN crontab /etc/cron.d/my-cron-job + +RUN touch /var/log/cron.log + +EXPOSE 8000 + +CMD cron && /app/run-worker.sh && tail -f /var/log/cron.log & /usr/local/bin/gunicorn --env REDISTOGO_URL=redis://redis:6379/ --workers 3 -m 007 -b 0.0.0.0:8000 wsgi:app diff --git a/src/ign-api/crontab b/src/ign-api/crontab new file mode 100644 index 0000000..a976da6 --- /dev/null +++ b/src/ign-api/crontab @@ -0,0 +1 @@ +5 */6 * * * ubuntu . /usr/bin/bash /app/run-worker.sh diff --git a/src/ign-api/requirements.txt b/src/ign-api/requirements.txt index 31ea140..7003ad4 100755 --- a/src/ign-api/requirements.txt +++ b/src/ign-api/requirements.txt @@ -1,15 +1,16 @@ Pillow==10.3.0 -flask==1.1.2 +Flask==3.1.0 flask_cors==3.0.8 image-go-nord==1.2.0 gunicorn==20.0.4 rq==1.8.0 pytest==6.0.2 -itsdangerous==2.0.1 -Werkzeug==2.0.3 +itsdangerous==2.2.0 +Werkzeug==3.1.3 ffmpeg-python==0.2.0 numpy==1.24.4 torch==2.2.2 torch-vision==0.1.6.dev0 torchvision==0.17.2 scikit-image==0.19.2 +Jinja2==3.1.2 \ No newline at end of file diff --git a/src/ign-api/run-worker.sh b/src/ign-api/run-worker.sh new file mode 100755 index 0000000..736761d --- /dev/null +++ b/src/ign-api/run-worker.sh @@ -0,0 +1,5 @@ +#!/bin/bash +for i in {1..3} +do +python ./worker.py 2>&1 & +done \ No newline at end of file