Commit 1a6781bc authored by Michele Del Giudice's avatar Michele Del Giudice
Browse files

Dockerfile with health

parent 2a8a23d2
FROM python:3.11-slim
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /app
# Install build deps needed for some packages (cryptography, etc.) then remove them
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential libssl-dev libffi-dev curl ca-certificates && \
rm -rf /var/lib/apt/lists/*
COPY requirements.txt ./
RUN pip install --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Copy application
COPY . /app
ENV FLASK_APP=app:create_app
EXPOSE 5000
# Healthcheck: call the Flask /health endpoint
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD curl -fS http://127.0.0.1:5000/health || exit 1
# Use gunicorn and call the factory to create the app
CMD ["gunicorn", "-b", "0.0.0.0:5000", "app:create_app()"]
...@@ -22,6 +22,10 @@ def create_app(): ...@@ -22,6 +22,10 @@ def create_app():
def bad_request(e): def bad_request(e):
return jsonify({'error': 'Bad request', 'message': str(e)}), 400 return jsonify({'error': 'Bad request', 'message': str(e)}), 400
@app.route('/health', methods=['GET'])
def health():
return jsonify({'status': 'ok'})
@app.route('/cars', methods=['GET']) @app.route('/cars', methods=['GET'])
def list_cars(): def list_cars():
cars = Car.query.all() cars = Car.query.all()
......
...@@ -4,4 +4,5 @@ PyMySQL>=1.0 ...@@ -4,4 +4,5 @@ PyMySQL>=1.0
cryptography==46.0.3 cryptography==46.0.3
Flask-Migrate>=4.0 Flask-Migrate>=4.0
pytest>=7.0 pytest>=7.0
pytest-flask>=1.2 pytest-flask>=1.2
\ No newline at end of file gunicorn>=20.0
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment