Microservie docker update
This commit is contained in:
@ -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"]
|
||||
@ -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
|
||||
|
||||
5
Project/requirements.txt
Normal file
5
Project/requirements.txt
Normal file
@ -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
|
||||
@ -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:
|
||||
|
||||
Reference in New Issue
Block a user