diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8273d3c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +# Dockerfile +FROM python:3.12-slim + +WORKDIR /app + +# Kopiraj requirements PRIJE koda — cache trick! +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +ENV APP_VERSION=dev +EXPOSE 8000 + +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/gitea/workflows/ci.yml b/gitea/workflows/ci.yml new file mode 100644 index 0000000..e69de29 diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml new file mode 100644 index 0000000..c3960bf --- /dev/null +++ b/k8s/deployment.yaml @@ -0,0 +1,29 @@ +# k8s/deployment.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: hello-cicd + namespace: student-marijanela218 +spec: + replicas: 1 + selector: + matchLabels: + app: hello-cicd + template: + metadata: + labels: + app: hello-cicd + spec: + imagePullSecrets: + - name: gitea-creds + containers: + - name: hello-cicd + image: git.fpmoz.sum.ba/Marijanela218/hello-cicd:latest + ports: + - containerPort: 8000 + env: + - name: APP_VERSION + value: "latest" + resources: + requests: {cpu: 50m, memory: 64Mi} + limits: {cpu: 200m, memory: 128Mi} diff --git a/k8s/service.yml b/k8s/service.yml new file mode 100644 index 0000000..03f0022 --- /dev/null +++ b/k8s/service.yml @@ -0,0 +1,14 @@ +# k8s/service.yaml +apiVersion: v1 +kind: Service +metadata: + name: hello-cicd-svc + namespace: student-marijanela218 +spec: + selector: + app: hello-cicd + ports: + - port: 80 + targetPort: 8000 + type: NodePort + diff --git a/main.py b/main.py new file mode 100644 index 0000000..22c44f4 --- /dev/null +++ b/main.py @@ -0,0 +1,18 @@ +# main.py +from fastapi import FastAPI +import os, datetime + +app = FastAPI() + +@app.get("/health") +def health(): + return { + "status": "ok", + "version": os.getenv("APP_VERSION", "dev"), + "timestamp": datetime.datetime.utcnow().isoformat() + } + +@app.get("/") +def root(): + return {"poruka": "Zdravo s k3s!", "host": os.uname().nodename} + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6d4d13b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +fastapi==0.115.0 +uvicorn==0.32.0