From 8e91a4a6a182857bef56bc00763e671ff95c9eda Mon Sep 17 00:00:00 2001 From: mukeshs Date: Tue, 21 Oct 2025 10:10:45 +0530 Subject: [PATCH] Microservie docker update --- Project/Dockerfile | 33 +++++++++++++++++++++++++++++++++ Project/microservice.py | 3 ++- Project/requirements.txt | 5 +++++ docker-compose.yml | 29 +++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 Project/requirements.txt diff --git a/Project/Dockerfile b/Project/Dockerfile index e69de29..66062bf 100644 --- a/Project/Dockerfile +++ b/Project/Dockerfile @@ -0,0 +1,33 @@ +# Use Python 3.11 slim image +FROM python:3.11-slim + +# Set working directory +WORKDIR /app + +# Set environment variables +ENV PYTHONUNBUFFERED=1 +ENV PYTHONDONTWRITEBYTECODE=1 + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + gcc \ + && rm -rf /var/lib/apt/lists/* + +# Copy requirements file +COPY requirements.txt . + +# Install Python dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Copy application code +COPY microservice.py . + +# Expose port 5001 +EXPOSE 5001 + +# Health check +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD python -c "import requests; requests.get('http://localhost:5001/', timeout=5)" + +# Run the application with gunicorn +CMD ["gunicorn", "--bind", "0.0.0.0:5001", "--workers", "2", "--timeout", "120", "--access-logfile", "-", "--error-logfile", "-", "microservice:app"] \ No newline at end of file diff --git a/Project/microservice.py b/Project/microservice.py index eaba3bc..f517b96 100644 --- a/Project/microservice.py +++ b/Project/microservice.py @@ -15,7 +15,8 @@ CORS(app, ) # Configuration - point to your main backend -MAIN_BACKEND_URL = "http://127.0.0.1:5000" # Change this to your main backend URL +MAIN_BACKEND_URL = "http://127.0.0.1:5000" +MAIN_BACKEND_URL = "https://iotbackend.rootxwire.com" # Change this to your main backend URL # Add OPTIONS handler for preflight requests @app.before_request diff --git a/Project/requirements.txt b/Project/requirements.txt new file mode 100644 index 0000000..31173a1 --- /dev/null +++ b/Project/requirements.txt @@ -0,0 +1,5 @@ +Flask==3.0.0 +flask-cors==4.0.0 +requests==2.31.0 +gunicorn==21.2.0 +Werkzeug==3.0.1 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 025d42e..e104328 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -48,6 +48,34 @@ services: echo '🚀 Starting Gunicorn server...' && gunicorn --bind 0.0.0.0:5000 --workers 2 --timeout 120 run:app " + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:5000/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s + + microservice: + build: + context: ./Microservice + dockerfile: Dockerfile + container_name: vending-microservice + ports: + - "8088:5001" + volumes: + - ./Microservice:/app + networks: + - vending-network + environment: + - MAIN_BACKEND_URL=https://iotbackend.rootxwire.com + - FLASK_ENV=production + restart: always + healthcheck: + test: ["CMD", "python", "-c", "import requests; requests.get('http://localhost:5001/', timeout=5)"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 10s frontend: build: @@ -60,6 +88,7 @@ services: - vending-network depends_on: - backend + - microservice restart: always networks: