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 b317c77..6025b70 100644 Binary files a/API/req.txt and b/API/req.txt differ