From 5d4172daa49805ea834e33417805362262722f43 Mon Sep 17 00:00:00 2001 From: hakimlutfi46 Date: Sun, 3 May 2026 23:28:01 +0700 Subject: [PATCH] feat: add api deployment setup --- Dockerfile | 31 +++++++++++++++++++++++++++++++ docker-compose.yml | 20 ++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b89f75d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM python:3.10-slim + +# Set working directory +WORKDIR /app + +# Install dependencies sistem untuk OpenCV & Build tools +RUN apt-get update && apt-get install -y \ + build-essential \ + libgl1 \ + libglib2.0-0 \ + && rm -rf /var/lib/apt/lists/* + +# Copy requirements +COPY requirements.txt . + +# Install python libraries +RUN pip install --no-cache-dir --upgrade pip && \ + pip install --no-cache-dir -r requirements.txt \ + && pip install --no-cache-dir gunicorn # Tambahkan gunicorn + +# Copy seluruh file project +COPY . . + +# Pastikan folder storage tersedia dengan permission yang benar +RUN mkdir -p storage/face_datasets storage/face_models storage/temp + +# Buka port (di Flask script kamu pakai 5000, tapi di docker kita arahkan ke 8000 agar konsisten dengan compose) +EXPOSE 8000 + +# Jalankan menggunakan Gunicorn (4 worker biasanya cukup untuk Ryzen 5600G) +CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "4", "app:app"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..73865b1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +services: + api-hrismp-ml: + build: . + container_name: api_hrismp_face + restart: unless-stopped + ports: + - "8002:8000" + environment: + - FLASK_ML_API_KEY=dev-api-key-mpg-hris + volumes: + - .:/app + - hrismp_storage:/app/storage + networks: + - hrismp-network + +volumes: + hrismp_storage: +networks: + hrismp-network: + driver: bridge