From e507646aa849d6cddcb1a7e27007bc3c4f447864 Mon Sep 17 00:00:00 2001 From: Ivan087 Date: Fri, 28 Nov 2025 11:07:38 +0800 Subject: [PATCH] Auto-generated by Trail System --- Dockerfile | 13 +++++++++++++ app.py | 21 +++++++++++++++++++++ chart/Chart.yaml | 6 ++++++ chart/templates/deployment.yaml | 24 ++++++++++++++++++++++++ chart/templates/service.yaml | 9 +++++++++ chart/values.yaml | 8 ++++++++ requirements.txt | 1 + 7 files changed, 82 insertions(+) create mode 100644 Dockerfile create mode 100644 app.py create mode 100644 chart/Chart.yaml create mode 100644 chart/templates/deployment.yaml create mode 100644 chart/templates/service.yaml create mode 100644 chart/values.yaml create mode 100644 requirements.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3dfb76a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3.9-slim as build +WORKDIR /app +COPY requirements.txt . +RUN pip install --user -r requirements.txt + +FROM python:3.9-slim +WORKDIR /app +COPY --from=build /root/.local /root/.local +COPY . . +RUN apt-get update && apt-get install -y --no-install-recommends adduser && adduser --disabled-password --gecos '' appuser && chown -R appuser /app +USER appuser +ENV PATH=/root/.local/bin:$PATH +CMD ["python", "app.py"] \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..09d4c5f --- /dev/null +++ b/app.py @@ -0,0 +1,21 @@ +from flask import Flask + +app = Flask(__name__) + +@app.route('/') +def home(): + """Handle the root endpoint, returns 'Todo List' as a string.""" + return 'Todo List' + +@app.errorhandler(404) +def not_found(e): + """Handle 404 Not Found errors with a custom message.""" + return 'Page not found', 404 + +@app.errorhandler(500) +def server_error(e): + """Handle 500 Internal Server Error with a custom message.""" + return 'Internal server error', 500 + +if __name__ == '__main__': + app.run(debug=False) \ No newline at end of file diff --git a/chart/Chart.yaml b/chart/Chart.yaml new file mode 100644 index 0000000..ddde2db --- /dev/null +++ b/chart/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: todo-app +description: A simple Flask-based Todo App hosted in a Docker container with Helm orchestration. The application exposes a single endpoint at '/' that returns 'Todo List'. Uses minimal dependencies and follows 12-factor principles for containerized deployment. +type: application +version: 0.1.0 +appVersion: "1.0.0" \ No newline at end of file diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml new file mode 100644 index 0000000..ba98019 --- /dev/null +++ b/chart/templates/deployment.yaml @@ -0,0 +1,24 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: flask-todo-app +spec: + replicas: 1 + selector: + matchLabels: + app: flask-todo-app + template: + metadata: + labels: + app: flask-todo-app + spec: + containers: + - name: flask-todo-app + image: {{ .Values.image.repository }}:{{ .Values.image.tag }} + ports: + - containerPort: 5000 + env: + - name: FLASK_APP + value: "{{ .Values.env.FLASK_APP }}" + - name: DEBUG + value: "{{ .Values.env.DEBUG }}" \ No newline at end of file diff --git a/chart/templates/service.yaml b/chart/templates/service.yaml new file mode 100644 index 0000000..5b2869d --- /dev/null +++ b/chart/templates/service.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Values.service.name }} +spec: + ports: + - port: {{ .Values.service.port }} + selector: + app: {{ .Values.app.name }} \ No newline at end of file diff --git a/chart/values.yaml b/chart/values.yaml new file mode 100644 index 0000000..0239361 --- /dev/null +++ b/chart/values.yaml @@ -0,0 +1,8 @@ +image: + repository: flask-todo-app + tag: latest +service: + port: 5000 +env: + FLASK_APP: app.py + DEBUG: "False" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2077213 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +Flask \ No newline at end of file