From 11afc7a4ac2e7871f8d77bf70894b95096137202 Mon Sep 17 00:00:00 2001 From: Fabio Scotto di Santolo Date: Tue, 10 Jun 2025 21:42:42 +0200 Subject: [PATCH] import code --- Dockerfile | 12 +++++++ app.py | 68 +++++++++++++++++++++++++++++++++++++++ requirements.txt | 2 ++ task-definition-rev1.json | 48 +++++++++++++++++++++++++++ 4 files changed, 130 insertions(+) create mode 100755 Dockerfile create mode 100755 app.py create mode 100755 requirements.txt create mode 100644 task-definition-rev1.json diff --git a/Dockerfile b/Dockerfile new file mode 100755 index 0000000..52cfefc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.11-slim + +WORKDIR /app + +COPY requirements.txt . +COPY app.py . + +RUN pip install --no-cache-dir -r requirements.txt + +EXPOSE 5000 + +CMD ["python", "app.py"] diff --git a/app.py b/app.py new file mode 100755 index 0000000..23a5cb6 --- /dev/null +++ b/app.py @@ -0,0 +1,68 @@ +from flask import Flask, jsonify, request, Blueprint +from flasgger import Swagger +import logging + +app = Flask(__name__) +swagger = Swagger(app) + +# Configura il logging +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + +# Crea un blueprint per l'API v1 +api_v1 = Blueprint('api_v1', __name__) + +@api_v1.route('/greet', methods=['GET']) +def greet(): + """ + Greet a user by name. + --- + tags: + - Greeting + parameters: + - name: name + in: query + type: string + required: false + default: World + description: The name to greet. + responses: + 200: + description: A greeting message + schema: + type: object + properties: + message: + type: string + example: Hello, World! + """ + name = request.args.get('name', 'World') + message = f'Hello, {name}!' + logger.info(f"[v1] Greeting requested for name: {name}") + return jsonify({'message': message}) + +# Aggiungi endpoint di health check +@app.route('/health', methods=['GET']) +def health_check(): + """ + Health check endpoint. + --- + tags: + - Health + responses: + 200: + description: Service is healthy + schema: + type: object + properties: + status: + type: string + example: OK + """ + return jsonify({'status': 'OK'}), 200 + +# Registra il blueprint sotto /api/v1 +app.register_blueprint(api_v1, url_prefix='/api/v1') + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=5000) diff --git a/requirements.txt b/requirements.txt new file mode 100755 index 0000000..5d45016 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +flask +flasgger diff --git a/task-definition-rev1.json b/task-definition-rev1.json new file mode 100644 index 0000000..d231d99 --- /dev/null +++ b/task-definition-rev1.json @@ -0,0 +1,48 @@ +{ + "family": "pygreeting", + "containerDefinitions": [ + { + "name": "pygreeting", + "image": "public.ecr.aws/t5q0y5r5/pygreeting:latest", + "cpu": 0, + "portMappings": [ + { + "name": "pygreeting-5000-tcp", + "containerPort": 5000, + "hostPort": 5000, + "protocol": "tcp", + "appProtocol": "http" + } + ], + "essential": true, + "environment": [], + "environmentFiles": [], + "mountPoints": [], + "volumesFrom": [], + "ulimits": [], + "healthCheck": { + "command": [ + "CMD-SHELL", + "curl --location 'localhost:5000/health' || exit 1" + ], + "interval": 30, + "timeout": 5, + "retries": 3 + }, + "systemControls": [] + } + ], + "volumes": [], + "placementConstraints": [], + "networkMode": "awsvpc", + "requiresCompatibilities": [ + "FARGATE" + ], + "cpu": "1024", + "memory": "3072", + "runtimePlatform": { + "cpuArchitecture": "X86_64", + "operatingSystemFamily": "LINUX" + }, + "enableFaultInjection": false +}