Initial demo service for AISP Gitea CI
This commit is contained in:
2
.dockerignore
Normal file
2
.dockerignore
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
.git
|
||||||
|
README.md
|
||||||
14
Dockerfile
Normal file
14
Dockerfile
Normal file
@@ -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"]
|
||||||
13
README.md
Normal file
13
README.md
Normal file
@@ -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`
|
||||||
42
app.py
Normal file
42
app.py
Normal file
@@ -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()
|
||||||
Reference in New Issue
Block a user