From 2c21665d0ef19adaf78464c0e3c1dc5a304d7f07 Mon Sep 17 00:00:00 2001 From: Linh Ha Date: Fri, 23 Oct 2026 08:07:44 +0000 Subject: [PATCH] Initial demo service for AISP Gitea CI --- .dockerignore | 2 ++ Dockerfile | 14 ++++++++++++++ README.md | 13 +++++++++++++ app.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 app.py diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..35cdaf3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.git +README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4550b16 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +# The AISP build gateway only allows base images from approved mirrors, written with the +# full host (docker.io/..., harbor.vts-ai.space/...). +FROM docker.io/library/python:3.12-slim + +WORKDIR /app +COPY app.py . + +# AISP enforces PodSecurity "restricted": run as a non-root UID on a port above 1024. +USER 10001 +ENV PORT=8080 \ + APP_MESSAGE="Hello from AISP" +EXPOSE 8080 + +CMD ["python", "-u", "app.py"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..79af8c0 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# aisp-ci-demo + +Service mẫu để thử luồng Gitea CI của AISP: kết nối repository → scan Dockerfile → build → +Release → deploy. + +- `GET /` trả JSON gồm `version`, `message` (từ biến `APP_MESSAGE`) và hostname của Pod. +- `GET /healthz` dùng cho readiness check. +- Lắng nghe cổng `8080`, chạy non-root (UID 10001). + +Thử thay đổi: sửa `VERSION` trong `app.py`, commit và push, rồi build lại trên console để thấy +phiên bản mới sau khi deploy. + +Chạy local: `docker build -t aisp-ci-demo . && docker run --rm -p 8080:8080 aisp-ci-demo` diff --git a/app.py b/app.py new file mode 100644 index 0000000..4c61997 --- /dev/null +++ b/app.py @@ -0,0 +1,42 @@ +"""Minimal HTTP service for testing AISP's Gitea -> build -> release -> deploy flow.""" +import json +import os +import socket +from datetime import datetime, timezone +from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer + +VERSION = "v1" +STARTED_AT = datetime.now(timezone.utc).isoformat() + + +class Handler(BaseHTTPRequestHandler): + def _send(self, status, body): + data = json.dumps(body).encode() + self.send_response(status) + self.send_header("Content-Type", "application/json") + self.send_header("Content-Length", str(len(data))) + self.end_headers() + self.wfile.write(data) + + def do_GET(self): + if self.path == "/healthz": + self._send(200, {"status": "ok"}) + elif self.path == "/": + self._send(200, { + "service": "aisp-ci-demo", + "version": VERSION, + "message": os.environ.get("APP_MESSAGE", "Hello from AISP"), + "hostname": socket.gethostname(), + "startedAt": STARTED_AT, + }) + else: + self._send(404, {"error": "not found"}) + + def log_message(self, fmt, *args): + print(f"{self.address_string()} {fmt % args}", flush=True) + + +if __name__ == "__main__": + port = int(os.environ.get("PORT", "8080")) + print(f"aisp-ci-demo {VERSION} listening on :{port}", flush=True) + ThreadingHTTPServer(("0.0.0.0", port), Handler).serve_forever()