zadaca
This commit is contained in:
18
Dockerfile
Normal file
18
Dockerfile
Normal file
@@ -0,0 +1,18 @@
|
||||
FROM python:3.12-slim AS builder
|
||||
|
||||
WORKDIR /builder
|
||||
COPY app/requirements.txt .
|
||||
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
|
||||
|
||||
FROM python:3.12-slim
|
||||
RUN adduser --disabled-password --no-create-home appuser
|
||||
WORKDIR /app
|
||||
COPY --from=builder /install /usr/local
|
||||
COPY app/ .
|
||||
|
||||
USER appuser
|
||||
EXPOSE 8000
|
||||
|
||||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
|
||||
|
||||
123
app/main.py
Normal file
123
app/main.py
Normal file
@@ -0,0 +1,123 @@
|
||||
import os
|
||||
import datetime
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import HTMLResponse
|
||||
|
||||
app = FastAPI(title="Distribuirani Sustavi - FPMOZ")
|
||||
|
||||
SERVICE_NAME = os.getenv("SERVICE_NAME", "distribuirani-service")
|
||||
LOG_LEVEL = os.getenv("LOG_LEVEL", "info")
|
||||
WELCOME_MSG = os.getenv("WELCOME_MSG", "Pozdrav iz FPMOZ k3s clustera!")
|
||||
|
||||
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
def root():
|
||||
return f"""<!DOCTYPE html>
|
||||
<html lang="hr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{SERVICE_NAME}</title>
|
||||
<style>
|
||||
* {{ margin: 0; padding: 0; box-sizing: border-box; }}
|
||||
body {{
|
||||
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
|
||||
background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
|
||||
color: #e0e0e0;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}}
|
||||
.container {{
|
||||
text-align: center;
|
||||
padding: 3rem;
|
||||
background: rgba(255,255,255,0.05);
|
||||
border-radius: 20px;
|
||||
backdrop-filter: blur(10px);
|
||||
border: 1px solid rgba(255,255,255,0.1);
|
||||
max-width: 600px;
|
||||
box-shadow: 0 8px 32px rgba(0,0,0,0.3);
|
||||
}}
|
||||
h1 {{
|
||||
font-size: 2.2rem;
|
||||
background: linear-gradient(90deg, #00d2ff, #3a7bd5);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
margin-bottom: 1rem;
|
||||
}}
|
||||
.welcome {{
|
||||
font-size: 1.3rem;
|
||||
color: #a0d8ef;
|
||||
margin-bottom: 2rem;
|
||||
}}
|
||||
.info {{
|
||||
display: grid;
|
||||
gap: 0.8rem;
|
||||
text-align: left;
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 1.5rem;
|
||||
border-radius: 12px;
|
||||
}}
|
||||
.info-row {{
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 0.4rem 0;
|
||||
border-bottom: 1px solid rgba(255,255,255,0.05);
|
||||
}}
|
||||
.label {{ color: #888; }}
|
||||
.value {{ color: #00d2ff; font-weight: 600; }}
|
||||
.badge {{
|
||||
display: inline-block;
|
||||
margin-top: 1.5rem;
|
||||
padding: 0.5rem 1.2rem;
|
||||
background: linear-gradient(90deg, #00d2ff, #3a7bd5);
|
||||
border-radius: 20px;
|
||||
font-size: 0.85rem;
|
||||
color: #fff;
|
||||
font-weight: 600;
|
||||
}}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Distribuirani Sustavi</h1>
|
||||
<p class="welcome">{WELCOME_MSG}</p>
|
||||
<div class="info">
|
||||
<div class="info-row">
|
||||
<span class="label">Servis</span>
|
||||
<span class="value">{SERVICE_NAME}</span>
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<span class="label">Hostname</span>
|
||||
<span class="value">{os.getenv("HOSTNAME", "local")}</span>
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<span class="label">Log Level</span>
|
||||
<span class="value">{LOG_LEVEL}</span>
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<span class="label">Vrijeme</span>
|
||||
<span class="value">{datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")}</span>
|
||||
</div>
|
||||
</div>
|
||||
<span class="badge">FPMOZ K3s Cluster • GitOps CI/CD</span>
|
||||
</div>
|
||||
</body>
|
||||
</html>"""
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
def health():
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
@app.get("/info")
|
||||
def info():
|
||||
return {
|
||||
"service": SERVICE_NAME,
|
||||
"hostname": os.getenv("HOSTNAME", "local"),
|
||||
"log_level": LOG_LEVEL,
|
||||
"welcome": WELCOME_MSG,
|
||||
"timestamp": datetime.datetime.now(datetime.timezone.utc).isoformat(),
|
||||
}
|
||||
2
app/requirements.txt
Normal file
2
app/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
fastapi==0.115.6
|
||||
uvicorn[standard]==0.34.0
|
||||
9
k8s/configmap.yaml
Normal file
9
k8s/configmap.yaml
Normal file
@@ -0,0 +1,9 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: zadaca-config
|
||||
namespace: student-blazp04
|
||||
data:
|
||||
SERVICE_NAME: "distribuirani-service"
|
||||
LOG_LEVEL: "info"
|
||||
WELCOME_MSG: "Zadaca 1"
|
||||
37
k8s/deployment.yaml
Normal file
37
k8s/deployment.yaml
Normal file
@@ -0,0 +1,37 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: zadaca-deployment
|
||||
namespace: student-blazp04
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: zadaca
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: zadaca
|
||||
spec:
|
||||
containers:
|
||||
- name: zadaca
|
||||
image: git.fpmoz.sum.ba/blazp04/zadaca:latest
|
||||
ports:
|
||||
- containerPort: 8000
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: zadaca-config
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 8000
|
||||
initialDelaySeconds: 3
|
||||
periodSeconds: 5
|
||||
resources:
|
||||
requests:
|
||||
memory: "64Mi"
|
||||
cpu: "50m"
|
||||
limits:
|
||||
memory: "128Mi"
|
||||
cpu: "200m"
|
||||
19
k8s/ingress.yaml
Normal file
19
k8s/ingress.yaml
Normal file
@@ -0,0 +1,19 @@
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: zadaca-ingress
|
||||
namespace: student-blazp04
|
||||
annotations:
|
||||
traefik.ingress.kubernetes.io/router.entrypoints: web
|
||||
spec:
|
||||
rules:
|
||||
- host: blazp04-zadaca.argocd.fpmoz.sum.ba
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: zadaca-service
|
||||
port:
|
||||
number: 80
|
||||
13
k8s/service.yaml
Normal file
13
k8s/service.yaml
Normal file
@@ -0,0 +1,13 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: zadaca-service
|
||||
namespace: student-blazp04
|
||||
spec:
|
||||
selector:
|
||||
app: zadaca
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 8000
|
||||
protocol: TCP
|
||||
type: ClusterIP
|
||||
Reference in New Issue
Block a user