From 87dc1e6a8fb365a2f46d1d1815465bbfa9a9fc44 Mon Sep 17 00:00:00 2001 From: teticio Date: Thu, 26 Aug 2021 10:14:11 +0100 Subject: [PATCH] added ffmpeg to docker, improvements --- .env.development | 2 +- backend/deejai.py | 3 +- backend/main.py | 9 +++--- build_docker.sh | 3 ++ helm-chart/deejai/templates/deployment.yaml | 22 +++++++++++---- helm-chart/deejai/values.yaml | 31 ++++++++++++++------- helm-chart/images/Dockerfile | 14 ++++------ install_helm_chart.sh | 4 +++ src/components/RemovableTrack.js | 4 --- 9 files changed, 58 insertions(+), 34 deletions(-) create mode 100755 build_docker.sh create mode 100755 install_helm_chart.sh diff --git a/.env.development b/.env.development index 3fd1789..d4ffd51 100644 --- a/.env.development +++ b/.env.development @@ -1 +1 @@ -REACT_APP_API_URL='http://localhost:8000/api/v1' +REACT_APP_API_URL='http://localhost:8001/api/v1' diff --git a/backend/deejai.py b/backend/deejai.py index beed488..41dfec6 100644 --- a/backend/deejai.py +++ b/backend/deejai.py @@ -5,6 +5,7 @@ import random import shutil import librosa +import logging import requests import numpy as np from io import BytesIO @@ -229,7 +230,7 @@ def _get_similar_vec(): ] return ids except Exception as e: - print(e) + logging.error(e) if os.path.exists(f'./{playlist_id}.mp3'): os.remove(f'./{playlist_id}.mp3') return [] diff --git a/backend/main.py b/backend/main.py index cfe4f96..2317f39 100644 --- a/backend/main.py +++ b/backend/main.py @@ -42,6 +42,7 @@ def get_db(): "https://deej-ai.online", "http://localhost:8000", "http://localhost:3000", + "http://127.0.0.1:8080", ] app.add_middleware( @@ -79,8 +80,8 @@ async def spotify_callback(code: str, state: Optional[str] = '/'): headers = { 'Authorization': 'Basic ' + - b64encode(f'{credentials.client_id}:{credentials.client_secret}' - .encode('utf-8')).decode('utf-8') + b64encode(f'{credentials.client_id}:{credentials.client_secret}'. + encode('utf-8')).decode('utf-8') } async with aiohttp.ClientSession() as session: try: @@ -108,8 +109,8 @@ async def spotify_refresh_token(refresh_token: str): headers = { 'Authorization': 'Basic ' + - b64encode(f'{credentials.client_id}:{credentials.client_secret}' - .encode('utf-8')).decode('utf-8') + b64encode(f'{credentials.client_id}:{credentials.client_secret}'. + encode('utf-8')).decode('utf-8') } async with aiohttp.ClientSession() as session: try: diff --git a/build_docker.sh b/build_docker.sh new file mode 100755 index 0000000..9d85dbf --- /dev/null +++ b/build_docker.sh @@ -0,0 +1,3 @@ +#!/bin/sh +eval $(minikube -p minikube docker-env) +docker build . -f helm-chart/images/Dockerfile -t deejai diff --git a/helm-chart/deejai/templates/deployment.yaml b/helm-chart/deejai/templates/deployment.yaml index b398da4..d082bdc 100644 --- a/helm-chart/deejai/templates/deployment.yaml +++ b/helm-chart/deejai/templates/deployment.yaml @@ -35,17 +35,27 @@ spec: imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - name: http - containerPort: 3000 + containerPort: 80 protocol: TCP + {{- if .Values.deployment.livenessProbe.enabled }} livenessProbe: httpGet: - path: / - port: http - initialDelaySeconds: 300 + path: {{ .Values.deployment.livenessProbe.path }} + port: {{ .Values.deployment.livenessProbe.port }} + initialDelaySeconds: {{ .Values.deployment.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.deployment.livenessProbe.periodSeconds }} + timeoutSeconds: {{ .Values.deployment.livenessProbe.timeoutSeconds }} + failureThreshold: {{ .Values.deployment.livenessProbe.failureThreshold }} {{- end }} + {{- if .Values.deployment.readinessProbe.enabled }} readinessProbe: httpGet: - path: / - port: http + path: {{ .Values.deployment.readinessProbe.path }} + port: {{ .Values.deployment.readinessProbe.port }} + initialDelaySeconds: {{ .Values.deployment.readinessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.deployment.readinessProbe.periodSeconds }} + timeoutSeconds: {{ .Values.deployment.readinessProbe.timeoutSeconds }} + failureThreshold: {{ .Values.deployment.readinessProbe.failureThreshold }} + {{- end }} resources: {{- toYaml .Values.resources | nindent 12 }} {{- with .Values.nodeSelector }} diff --git a/helm-chart/deejai/values.yaml b/helm-chart/deejai/values.yaml index c1f3150..aa656bb 100644 --- a/helm-chart/deejai/values.yaml +++ b/helm-chart/deejai/values.yaml @@ -6,7 +6,7 @@ replicaCount: 1 image: repository: deejai - pullPolicy: Never + pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. tag: "" @@ -21,7 +21,7 @@ serviceAccount: annotations: {} # The name of the service account to use. # If not set and create is true, a name is generated using the fullname template - name: "deejai" + name: "" podAnnotations: {} @@ -37,8 +37,8 @@ securityContext: {} # runAsUser: 1000 service: - type: NodePort - port: 3000 + type: ClusterIP + port: 80 ingress: enabled: false @@ -82,9 +82,20 @@ tolerations: [] affinity: {} -# eval $(minikube -p minikube docker-env) -# docker build . -f helm-chart/images/Dockerfile -t deejai -# helm install deejai helm-chart/deejai --values helm-chart/deejai/values.yaml -# export POD_NAME=$(kubectl get pods -l "app.kubernetes.io/name=deejai,app.kubernetes.io/instance=deejai" -o jsonpath="{.items[0].metadata.name}") -# kubectl port-forward $POD_NAME 3000:3000 -# helm upgrade deejai helm-chart/deejai --values helm-chart/deejai/values.yaml \ No newline at end of file +deployment: + readinessProbe: + enabled: false + path: /healthz + port: http + initialDelaySeconds: 0 + periodSeconds: 5 + failureThreshold: 1000 # we rely on the liveness probe to resolve issues if needed + timeoutSeconds: 3 + livenessProbe: + enabled: false + path: /healthz + port: http + initialDelaySeconds: 10 + periodSeconds: 5 + failureThreshold: 3 + timeoutSeconds: 10 diff --git a/helm-chart/images/Dockerfile b/helm-chart/images/Dockerfile index 4f10132..119e09d 100644 --- a/helm-chart/images/Dockerfile +++ b/helm-chart/images/Dockerfile @@ -2,17 +2,15 @@ FROM python:3.8 COPY . /deej-ai.online-app WORKDIR "/deej-ai.online-app" RUN apt update -RUN apt install libsndfile1 nodejs npm -y +RUN apt install ffmpeg libsndfile-dev nodejs npm -y RUN npm install --global yarn RUN rm -rf node_modules deejai.db RUN yarn install RUN pip install -r requirements-lock.txt -RUN sed -i 's@https://deej-ai.online@http://localhost:3000@g' .env.production -RUN sed -i 's@https://deej-ai.online@http://localhost:3000@g' backend/credentials.py +RUN sed -i 's|\(http\)[^/]*/[^/]*/[^/]*/|http://localhost:8080/|g' .env.production +RUN sed -i 's|\(http\)[^/]*/[^/]*/[^/]*/|http://localhost:8080/|g' backend/credentials.py RUN yarn build -ENV APP_URL http://localhost:3000 +ENV APP_URL http://localhost:8080 ENV CUDA_VISIBLE_DEVICES "" -CMD ["uvicorn", "backend.main:app", "--reload", "--port=3000"] - -# docker build . -f helm-chart/images/Dockerfile -t deejai -# docker run --rm --network="host" deejai \ No newline at end of file +CMD ["uvicorn", "backend.main:app", "--reload", "--port=80"] +EXPOSE 80 diff --git a/install_helm_chart.sh b/install_helm_chart.sh new file mode 100755 index 0000000..1173310 --- /dev/null +++ b/install_helm_chart.sh @@ -0,0 +1,4 @@ +#!/bin/sh +helm uninstall deejai -n deejai +kubectl create namespace deejai +helm install deejai helm-chart/deejai -n deejai --values helm-chart/deejai/values.yaml diff --git a/src/components/RemovableTrack.js b/src/components/RemovableTrack.js index 4171c66..cc63567 100644 --- a/src/components/RemovableTrack.js +++ b/src/components/RemovableTrack.js @@ -1,17 +1,13 @@ -import { useState } from "react"; import { FaTimes } from "react-icons/fa"; import { HorizontalSpacer } from "../lib"; import Track from "./Track"; export default function RemovableTrack({ track_id, uuid, onRemove = f => f }) { - const [loaded, setLoaded] = useState(false); - return ( <> setLoaded(true)} >