This commit is contained in:
10
.dockerignore
Normal file
10
.dockerignore
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
*.md
|
||||||
|
LICENSE
|
||||||
|
kubeconfig-*.yaml
|
||||||
|
k8s/
|
||||||
|
.gitea/
|
||||||
|
__pycache__
|
||||||
|
*.pyc
|
||||||
|
.env
|
||||||
55
.gitea/workflows/ci.yaml
Normal file
55
.gitea/workflows/ci.yaml
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
name: CI/CD Pipeline
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: git.fpmoz.sum.ba
|
||||||
|
IMAGE_NAME: blazp04/distribuirani
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout koda
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Postavi Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Prijava na Gitea Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ secrets.REGISTRY_USER }}
|
||||||
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Generiraj tagove za image
|
||||||
|
id: meta
|
||||||
|
run: |
|
||||||
|
SHORT_SHA=$(echo "${{ gitea.sha }}" | cut -c1-7)
|
||||||
|
echo "short_sha=${SHORT_SHA}" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "tags=${REGISTRY}/${IMAGE_NAME}:${SHORT_SHA},${REGISTRY}/${IMAGE_NAME}:latest" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Build i push Docker image
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
||||||
|
cache-to: type=inline
|
||||||
|
|
||||||
|
- name: Ažuriraj image tag u deployment manifestu
|
||||||
|
run: |
|
||||||
|
SHORT_SHA=${{ steps.meta.outputs.short_sha }}
|
||||||
|
sed -i "s|image: ${REGISTRY}/${IMAGE_NAME}:.*|image: ${REGISTRY}/${IMAGE_NAME}:${SHORT_SHA}|" k8s/distribuirani/deployment.yaml
|
||||||
|
cat k8s/distribuirani/deployment.yaml
|
||||||
|
|
||||||
|
- name: Commit i push ažuriranog manifesta
|
||||||
|
run: |
|
||||||
|
git config user.name "Gitea Actions"
|
||||||
|
git config user.email "actions@git.fpmoz.sum.ba"
|
||||||
|
git add k8s/distribuirani/deployment.yaml
|
||||||
|
git diff --cached --quiet && echo "Nema promjena" || (git commit -m "ci: update image tag to ${{ steps.meta.outputs.short_sha }} [skip ci]" && git push)
|
||||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1 +1,5 @@
|
|||||||
kubeconfig-Blazp04.yaml
|
kubeconfig-*.yaml
|
||||||
|
.env
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
*.pyo
|
||||||
|
|||||||
24
Dockerfile
Normal file
24
Dockerfile
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# ---------- build stage ----------
|
||||||
|
FROM python:3.12-slim AS builder
|
||||||
|
|
||||||
|
WORKDIR /build
|
||||||
|
COPY app/requirements.txt .
|
||||||
|
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
|
||||||
|
|
||||||
|
# ---------- runtime stage ----------
|
||||||
|
FROM python:3.12-slim
|
||||||
|
|
||||||
|
LABEL maintainer="blazp04"
|
||||||
|
LABEL org.opencontainers.image.source="https://git.fpmoz.sum.ba/blazp04/distribuirani"
|
||||||
|
|
||||||
|
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
|
||||||
@@ -15,7 +15,7 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: distribuirani
|
- name: distribuirani
|
||||||
image: git.fpmoz.sum.ba/blazp04/distribuirani:1.0
|
image: git.fpmoz.sum.ba/blazp04/distribuirani:latest
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8000
|
- containerPort: 8000
|
||||||
envFrom:
|
envFrom:
|
||||||
@@ -32,6 +32,18 @@ spec:
|
|||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
name: distribuirani-secret
|
name: distribuirani-secret
|
||||||
key: API_KEY
|
key: API_KEY
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /health
|
||||||
|
port: 8000
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
periodSeconds: 10
|
||||||
|
readinessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /health
|
||||||
|
port: 8000
|
||||||
|
initialDelaySeconds: 3
|
||||||
|
periodSeconds: 5
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
memory: "64Mi"
|
memory: "64Mi"
|
||||||
|
|||||||
9
k8s/distribuirani/secret.yaml
Normal file
9
k8s/distribuirani/secret.yaml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: distribuirani-secret
|
||||||
|
namespace: student-blazp04
|
||||||
|
type: Opaque
|
||||||
|
stringData:
|
||||||
|
DB_PASSWORD: "SUPERTAJNIPASSWD"
|
||||||
|
API_KEY: "APIKEYNEKI DEMO"
|
||||||
Reference in New Issue
Block a user