commit e2232beb15fde4e7c3e0f2679fe4fc3a26a55082 Author: DinkoGalic Date: Mon Jun 8 14:50:30 2026 +0200 init: FastAPI priprema-za-kolokvij + k8s manifesti (monorepo) diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..dd3b7cc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +__pycache__/ +*.pyc +.env +.git/ +*.md +k8s/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c065996 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.12-slim + +WORKDIR /app + +# Kopiraj ovisnosti PRVO — ako se ne mijenjaju, pip install se preskace (cache hit) +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Kopiraj kod NAKON instalacije +COPY app/ ./app/ + +EXPOSE 8000 + +# OBAVEZNO: --host 0.0.0.0 da Ingress moze pristupiti containeru +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/app/main.py b/app/main.py new file mode 100644 index 0000000..90bc7b1 --- /dev/null +++ b/app/main.py @@ -0,0 +1,11 @@ +from fastapi import FastAPI + +app = FastAPI() + +@app.get("/") +def root(): + return {"message": "Hello, World!", autor: "Dinko Galić"} + +@app.get("/health") +def health(): + return {"status": "ok"} diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml new file mode 100644 index 0000000..073c0cd --- /dev/null +++ b/k8s/deployment.yaml @@ -0,0 +1,27 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: priprema-za-kolokvij + namespace: student-dinkoglc +spec: + replicas: 1 + selector: + matchLabels: + app: priprema-za-kolokvij + template: + metadata: + labels: + app: priprema-za-kolokvij + spec: + containers: + - name: priprema-za-kolokvij + image: git.fpmoz.sum.ba/dinkoglc/priprema-za-kolokvij:1.0 + ports: + - containerPort: 8000 + resources: + requests: + memory: "64Mi" + cpu: "50m" + limits: + memory: "128Mi" + cpu: "200m" diff --git a/k8s/ingress.yaml b/k8s/ingress.yaml new file mode 100644 index 0000000..ed75ea5 --- /dev/null +++ b/k8s/ingress.yaml @@ -0,0 +1,18 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: priprema-ingress + namespace: student-dinkoglc +spec: + ingressClassName: traefik + rules: + - host: VAŠ_KORISNIK.argocd.fpmoz.sum.ba + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: priprema-svc # mora odgovarati service.yaml + port: + number: 80 # port Servicea (ne containera!) diff --git a/k8s/service.yaml b/k8s/service.yaml new file mode 100644 index 0000000..99c572f --- /dev/null +++ b/k8s/service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: priprema-svc + namespace: student-dinkoglc +spec: + selector: + app: priprema-za-kolokvij # spaja Service s Podovima koji imaju ovaj label + ports: + - port: 80 # port koji Service eksponira (Ingress ce slati ovdje) + targetPort: 8000 # port containera (uvicorn slusa na 8000) + protocol: TCP + type: ClusterIP # samo unutar K8s clustera — Ingress rjesava vanjski pristup diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c83aa69 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +fastapi==0.111.0 +uvicorn[standard]==0.29.0