From 75bb1bc6129941a63241ca3e6a5795cea03bb820 Mon Sep 17 00:00:00 2001 From: andrei Date: Sat, 7 Jun 2025 20:12:40 +0500 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20k8s=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5?= =?UTF-8?q?=D1=80=D0=B6=D0=BA=D0=B0=20=D0=B8=20Dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API/.gitignore | 3 ++ API/app/Dockerfile | 18 +++++++++ API/app/infrastructure/teams_service.py | 2 +- API/k8s/helm/teamfolio-api/Chart.yaml | 5 +++ .../teamfolio-api/templates/deployment.yaml | 35 ++++++++++++++++++ .../helm/teamfolio-api/templates/ingress.yaml | 23 ++++++++++++ API/k8s/helm/teamfolio-api/templates/pvc.yaml | 29 +++++++++++++++ .../templates/secrets-example.yaml | 8 ++++ .../helm/teamfolio-api/templates/service.yaml | 11 ++++++ API/k8s/helm/teamfolio-api/values.yaml | 30 +++++++++++++++ API/req.txt | Bin 1220 -> 1212 bytes 11 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 API/.gitignore create mode 100644 API/app/Dockerfile create mode 100644 API/k8s/helm/teamfolio-api/Chart.yaml create mode 100644 API/k8s/helm/teamfolio-api/templates/deployment.yaml create mode 100644 API/k8s/helm/teamfolio-api/templates/ingress.yaml create mode 100644 API/k8s/helm/teamfolio-api/templates/pvc.yaml create mode 100644 API/k8s/helm/teamfolio-api/templates/secrets-example.yaml create mode 100644 API/k8s/helm/teamfolio-api/templates/service.yaml create mode 100644 API/k8s/helm/teamfolio-api/values.yaml diff --git a/API/.gitignore b/API/.gitignore new file mode 100644 index 0000000..84f1c5f --- /dev/null +++ b/API/.gitignore @@ -0,0 +1,3 @@ +k8s/helm/teamfolio-api/templates/secrets.yaml +.venv +*.pyc \ No newline at end of file diff --git a/API/app/Dockerfile b/API/app/Dockerfile new file mode 100644 index 0000000..be6473e --- /dev/null +++ b/API/app/Dockerfile @@ -0,0 +1,18 @@ +FROM python:3.10-slim + +RUN apt-get update && apt-get install -y \ + libpq-dev \ + libmagic1 \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +COPY req.txt . + +RUN pip install --no-cache-dir -r req.txt + +COPY . . + +EXPOSE 8000 + +CMD ["uvicorn", "app.main:app", "--host=0.0.0.0"] diff --git a/API/app/infrastructure/teams_service.py b/API/app/infrastructure/teams_service.py index 3dcfe60..ca7fe26 100644 --- a/API/app/infrastructure/teams_service.py +++ b/API/app/infrastructure/teams_service.py @@ -4,7 +4,7 @@ from typing import Optional, Any, Coroutine import aiofiles from fastapi import HTTPException, status, UploadFile -from magic import magic +import magic from sqlalchemy.ext.asyncio import AsyncSession from starlette.responses import FileResponse from werkzeug.utils import secure_filename diff --git a/API/k8s/helm/teamfolio-api/Chart.yaml b/API/k8s/helm/teamfolio-api/Chart.yaml new file mode 100644 index 0000000..17e056e --- /dev/null +++ b/API/k8s/helm/teamfolio-api/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v2 +name: teamfolio-api-app +description: Teamfolio API project +version: 0.1.0 +appVersion: "1.0" \ No newline at end of file diff --git a/API/k8s/helm/teamfolio-api/templates/deployment.yaml b/API/k8s/helm/teamfolio-api/templates/deployment.yaml new file mode 100644 index 0000000..9778621 --- /dev/null +++ b/API/k8s/helm/teamfolio-api/templates/deployment.yaml @@ -0,0 +1,35 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Chart.Name }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app: {{ .Chart.Name }} + template: + metadata: + labels: + app: {{ .Chart.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - containerPort: {{ .Values.service.port }} + env: + - name: SECRET_KEY + valueFrom: + secretKeyRef: + name: teamfolio-api-secret + key: SECRET_KEY + volumeMounts: + - name: uploads-volume + mountPath: {{ .Values.persistence.uploads.containerPath }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumes: + - name: uploads-volume + persistentVolumeClaim: + claimName: "{{ .Release.Name }}-uploads-pvc" \ No newline at end of file diff --git a/API/k8s/helm/teamfolio-api/templates/ingress.yaml b/API/k8s/helm/teamfolio-api/templates/ingress.yaml new file mode 100644 index 0000000..e017748 --- /dev/null +++ b/API/k8s/helm/teamfolio-api/templates/ingress.yaml @@ -0,0 +1,23 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: teamfolio-api-ingress + annotations: + cert-manager.io/cluster-issuer: lets-encrypt +spec: + tls: + - hosts: + - {{ .Values.ingress.domain }} + secretName: {{ .Values.ingress.secretTLSName }} + ingressClassName: public + rules: + - host: {{ .Values.ingress.domain }} + http: + paths: + - path: {{ .Values.ingress.path }} + pathType: {{ .Values.ingress.pathType }} + backend: + service: + name: {{ .Chart.Name }}-service + port: + number: {{ .Values.service.port }} diff --git a/API/k8s/helm/teamfolio-api/templates/pvc.yaml b/API/k8s/helm/teamfolio-api/templates/pvc.yaml new file mode 100644 index 0000000..515e8f0 --- /dev/null +++ b/API/k8s/helm/teamfolio-api/templates/pvc.yaml @@ -0,0 +1,29 @@ +{{- if .Values.persistence.uploads.enabled }} +apiVersion: v1 +kind: PersistentVolume +metadata: + name: {{ .Release.Name }}-uploads-pv +spec: + capacity: + storage: {{ .Values.persistence.uploads.size }} + accessModes: + - ReadWriteOnce + storageClassName: microk8s-hostpath + hostPath: + path: {{ .Values.persistence.path }}/uploads + type: DirectoryOrCreate + persistentVolumeReclaimPolicy: Retain +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ .Release.Name }}-uploads-pvc +spec: + accessModes: + - ReadWriteOnce + storageClassName: microk8s-hostpath + resources: + requests: + storage: {{ .Values.persistence.uploads.size }} + volumeName: {{ .Release.Name }}-uploads-pv +{{- end }} \ No newline at end of file diff --git a/API/k8s/helm/teamfolio-api/templates/secrets-example.yaml b/API/k8s/helm/teamfolio-api/templates/secrets-example.yaml new file mode 100644 index 0000000..004b213 --- /dev/null +++ b/API/k8s/helm/teamfolio-api/templates/secrets-example.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Secret +metadata: + name: teamfolio-api-secret +type: Opaque +data: + SECRET_KEY: + DATABASE_URL: diff --git a/API/k8s/helm/teamfolio-api/templates/service.yaml b/API/k8s/helm/teamfolio-api/templates/service.yaml new file mode 100644 index 0000000..67b1eb9 --- /dev/null +++ b/API/k8s/helm/teamfolio-api/templates/service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Chart.Name }}-service +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: {{ .Values.service.port }} + selector: + app: {{ .Chart.Name }} \ No newline at end of file diff --git a/API/k8s/helm/teamfolio-api/values.yaml b/API/k8s/helm/teamfolio-api/values.yaml new file mode 100644 index 0000000..ac8529e --- /dev/null +++ b/API/k8s/helm/teamfolio-api/values.yaml @@ -0,0 +1,30 @@ +replicaCount: 1 + +image: + repository: archi341/teamfolio-api + tag: latest + pullPolicy: Always + +service: + type: ClusterIP + port: 8000 + +resources: + limits: + memory: 512Mi + cpu: 500m + +persistence: + path: /mnt/k8s_storage/teamfolio-api + uploads: + enabled: true + size: 7Gi + containerPath: /app/uploads + +ingress: + secretTLSName: teamfolio-api-tls-secret + + domain: api.numerum.team + + path: / + pathType: Prefix \ No newline at end of file diff --git a/API/req.txt b/API/req.txt index b317c77abda1d8d3229fe3104fbd46b267ecc1b8..6025b706b7244b1b0a4b334efc3e97025ee35a69 100644 GIT binary patch delta 28 icmX@YxrcLu2s6JegDryrgC2tk5F0U=Z`Nj>$p`>hPz8qo delta 36 ocmdnPd4zL=2(!2@LlQ$KLmq=I5E?M(F_-|cA%n?gW#*ZT0FPn@=>Px# From bf4619b78acd7ddea14c26560aa95753b6da01d6 Mon Sep 17 00:00:00 2001 From: andrei Date: Sat, 7 Jun 2025 21:43:30 +0500 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80?= =?UTF-8?q?=D0=B6=D0=BA=D0=B0=20K8s=20=D0=B8=20Docker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API/.dockerignore | 4 +++ API/app/main.py | 2 +- .../teamfolio-api/templates/deployment.yaml | 5 ++++ WEB/.dockerignore | 7 ++++++ WEB/.gitignore | 2 ++ WEB/Dockerfile | 25 +++++++++++++++++++ WEB/k8s/helm/teamfolio-web/Chart.yaml | 5 ++++ .../teamfolio-web/templates/deployment.yaml | 22 ++++++++++++++++ .../helm/teamfolio-web/templates/ingress.yaml | 23 +++++++++++++++++ .../helm/teamfolio-web/templates/service.yaml | 11 ++++++++ WEB/k8s/helm/teamfolio-web/values.yaml | 23 +++++++++++++++++ WEB/src/core/config.js | 2 +- 12 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 API/.dockerignore create mode 100644 WEB/.dockerignore create mode 100644 WEB/Dockerfile create mode 100644 WEB/k8s/helm/teamfolio-web/Chart.yaml create mode 100644 WEB/k8s/helm/teamfolio-web/templates/deployment.yaml create mode 100644 WEB/k8s/helm/teamfolio-web/templates/ingress.yaml create mode 100644 WEB/k8s/helm/teamfolio-web/templates/service.yaml create mode 100644 WEB/k8s/helm/teamfolio-web/values.yaml diff --git a/API/.dockerignore b/API/.dockerignore new file mode 100644 index 0000000..329ed4e --- /dev/null +++ b/API/.dockerignore @@ -0,0 +1,4 @@ +.venv +k8s +.idea +.env \ No newline at end of file diff --git a/API/app/main.py b/API/app/main.py index 2207555..55181ac 100644 --- a/API/app/main.py +++ b/API/app/main.py @@ -22,7 +22,7 @@ def start_app(): api_app.add_middleware( CORSMiddleware, - allow_origins=["http://localhost:5173"], + allow_origins=["https://api.numerum.team", "https://numerum.team", "http://localhost:5173"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], diff --git a/API/k8s/helm/teamfolio-api/templates/deployment.yaml b/API/k8s/helm/teamfolio-api/templates/deployment.yaml index 9778621..381a9b1 100644 --- a/API/k8s/helm/teamfolio-api/templates/deployment.yaml +++ b/API/k8s/helm/teamfolio-api/templates/deployment.yaml @@ -24,6 +24,11 @@ spec: secretKeyRef: name: teamfolio-api-secret key: SECRET_KEY + - name: DATABASE_URL + valueFrom: + secretKeyRef: + name: teamfolio-api-secret + key: DATABASE_URL volumeMounts: - name: uploads-volume mountPath: {{ .Values.persistence.uploads.containerPath }} diff --git a/WEB/.dockerignore b/WEB/.dockerignore new file mode 100644 index 0000000..593eedb --- /dev/null +++ b/WEB/.dockerignore @@ -0,0 +1,7 @@ +node_modules +npm-debug.log +build +.dockerignore +.git +k8s +.env \ No newline at end of file diff --git a/WEB/.gitignore b/WEB/.gitignore index 7211af5..f088a92 100644 --- a/WEB/.gitignore +++ b/WEB/.gitignore @@ -23,3 +23,5 @@ dist-ssr *.sln *.sw? */.vscode/* + +.env diff --git a/WEB/Dockerfile b/WEB/Dockerfile new file mode 100644 index 0000000..da3a794 --- /dev/null +++ b/WEB/Dockerfile @@ -0,0 +1,25 @@ +FROM node:20-alpine AS builder + +WORKDIR /app + +COPY package.json package-lock.json ./ + +RUN npm install + +COPY . . + +ARG VITE_BASE_URL +ENV VITE_BASE_URL=https://api.numerum.team +RUN npm run build + +FROM node:20-alpine + +WORKDIR /app + +RUN npm install -g serve + +COPY --from=builder /app/dist /app + +EXPOSE 3000 + +CMD ["serve", "-s", ".", "-l", "3000"] \ No newline at end of file diff --git a/WEB/k8s/helm/teamfolio-web/Chart.yaml b/WEB/k8s/helm/teamfolio-web/Chart.yaml new file mode 100644 index 0000000..81bc2f7 --- /dev/null +++ b/WEB/k8s/helm/teamfolio-web/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v2 +name: teamfolio-web-app +description: teamfolio WEB project +version: 0.1.0 +appVersion: "1.0" \ No newline at end of file diff --git a/WEB/k8s/helm/teamfolio-web/templates/deployment.yaml b/WEB/k8s/helm/teamfolio-web/templates/deployment.yaml new file mode 100644 index 0000000..3f5bd9c --- /dev/null +++ b/WEB/k8s/helm/teamfolio-web/templates/deployment.yaml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Chart.Name }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app: {{ .Chart.Name }} + template: + metadata: + labels: + app: {{ .Chart.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - containerPort: {{ .Values.service.port }} + resources: + {{- toYaml .Values.resources | nindent 12 }} \ No newline at end of file diff --git a/WEB/k8s/helm/teamfolio-web/templates/ingress.yaml b/WEB/k8s/helm/teamfolio-web/templates/ingress.yaml new file mode 100644 index 0000000..da2c7ec --- /dev/null +++ b/WEB/k8s/helm/teamfolio-web/templates/ingress.yaml @@ -0,0 +1,23 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: visus-api-ingress + annotations: + cert-manager.io/cluster-issuer: lets-encrypt +spec: + tls: + - hosts: + - {{ .Values.ingress.domain }} + secretName: {{ .Values.ingress.secretTLSName }} + ingressClassName: public + rules: + - host: {{ .Values.ingress.domain }} + http: + paths: + - path: {{ .Values.ingress.path }} + pathType: {{ .Values.ingress.pathType }} + backend: + service: + name: {{ .Chart.Name }}-service + port: + number: {{ .Values.service.port }} diff --git a/WEB/k8s/helm/teamfolio-web/templates/service.yaml b/WEB/k8s/helm/teamfolio-web/templates/service.yaml new file mode 100644 index 0000000..67b1eb9 --- /dev/null +++ b/WEB/k8s/helm/teamfolio-web/templates/service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Chart.Name }}-service +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: {{ .Values.service.port }} + selector: + app: {{ .Chart.Name }} \ No newline at end of file diff --git a/WEB/k8s/helm/teamfolio-web/values.yaml b/WEB/k8s/helm/teamfolio-web/values.yaml new file mode 100644 index 0000000..89944d8 --- /dev/null +++ b/WEB/k8s/helm/teamfolio-web/values.yaml @@ -0,0 +1,23 @@ +replicaCount: 1 + +image: + repository: archi341/teamfolio-web + tag: latest + pullPolicy: Always + +service: + type: ClusterIP + port: 3000 + +resources: + limits: + memory: 512Mi + cpu: 500m + +ingress: + secretTLSName: teamfolio-web-tls-secret + + domain: numerum.team + + path: / + pathType: Prefix diff --git a/WEB/src/core/config.js b/WEB/src/core/config.js index fb32220..965cb9f 100644 --- a/WEB/src/core/config.js +++ b/WEB/src/core/config.js @@ -1,5 +1,5 @@ const CONFIG = { - BASE_URL: "http://127.0.0.1:8000", + BASE_URL: import.meta.env.VITE_BASE_URL || "http://127.0.0.1:8000", }; export default CONFIG;