From 3411e072ca8d5c4a34267287ded4a2ad03bfb36d Mon Sep 17 00:00:00 2001 From: cryptk <421501+cryptk@users.noreply.github.com> Date: Tue, 23 Apr 2024 11:43:00 -0500 Subject: [PATCH] Fix cleanup sonarqube findings (#2106) * fix: update dockerignore and gitignore to exclude sonarqube work dir Signed-off-by: Chris Jowett <421501+cryptk@users.noreply.github.com> * fix: remove useless equality check Signed-off-by: Chris Jowett <421501+cryptk@users.noreply.github.com> * fix: use sonarqube Dockerfile recommendations Signed-off-by: Chris Jowett <421501+cryptk@users.noreply.github.com> --------- Signed-off-by: Chris Jowett <421501+cryptk@users.noreply.github.com> --- .dockerignore | 5 ++++- .gitignore | 3 +++ Dockerfile | 23 +++++++++++----------- core/http/endpoints/openai/assistant.go | 26 ++++++++++++------------- 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/.dockerignore b/.dockerignore index 2c394c48..ea2ea6b2 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,4 +5,7 @@ models examples/chatbot-ui/models examples/rwkv/models examples/**/models -Dockerfile* \ No newline at end of file +Dockerfile* + +# SonarQube +.scannerwork \ No newline at end of file diff --git a/.gitignore b/.gitignore index f1f860e9..9338b0c4 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,6 @@ prepare *.pb.go *pb2.py *pb2_grpc.py + +# SonarQube +.scannerwork \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 805ac3a6..4bc8b35e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ ARG BASE_IMAGE=ubuntu:22.04 ARG GRPC_BASE_IMAGE=${BASE_IMAGE} # extras or core -FROM ${BASE_IMAGE} as requirements-core +FROM ${BASE_IMAGE} AS requirements-core USER root @@ -24,7 +24,7 @@ RUN apt-get update && \ apt-get install -y ca-certificates curl python3-pip unzip && apt-get clean # Install Go -RUN curl -L -s https://go.dev/dl/go$GO_VERSION.linux-$TARGETARCH.tar.gz | tar -C /usr/local -xz +RUN curl -L -s https://go.dev/dl/go${GO_VERSION}.linux-${TARGETARCH}.tar.gz | tar -C /usr/local -xz ENV PATH $PATH:/usr/local/go/bin # Install grpc compilers @@ -80,7 +80,7 @@ RUN test -n "$TARGETARCH" \ ################################### ################################### -FROM requirements-core as requirements-extras +FROM requirements-core AS requirements-extras RUN apt install -y gpg && \ curl https://repo.anaconda.com/pkgs/misc/gpgkeys/anaconda.asc | gpg --dearmor > conda.gpg && \ @@ -105,7 +105,7 @@ RUN if [ ! -e /usr/bin/python ]; then \ ################################### ################################### -FROM ${GRPC_BASE_IMAGE} as grpc +FROM ${GRPC_BASE_IMAGE} AS grpc ARG MAKEFLAGS ARG GRPC_VERSION=v1.58.0 @@ -121,16 +121,15 @@ RUN apt-get update && \ RUN git clone --recurse-submodules --jobs 4 -b ${GRPC_VERSION} --depth 1 --shallow-submodules https://github.com/grpc/grpc -RUN cd grpc && \ - mkdir -p cmake/build && \ - cd cmake/build && \ - cmake -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF ../.. && \ +WORKDIR /build/grpc/cmake/build + +RUN cmake -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF ../.. && \ make ################################### ################################### -FROM requirements-${IMAGE_TYPE} as builder +FROM requirements-${IMAGE_TYPE} AS builder ARG GO_TAGS="stablediffusion tts" ARG GRPC_BACKENDS @@ -168,9 +167,11 @@ RUN GRPC_BACKENDS=backend-assets/grpc/stablediffusion make build COPY --from=grpc /build/grpc ./grpc/ -RUN cd /build/grpc/cmake/build && make install +WORKDIR /build/grpc/cmake/build +RUN make install # Rebuild with defaults backends +WORKDIR /build RUN make build RUN if [ ! -d "/build/sources/go-piper/piper-phonemize/pi/lib/" ]; then \ @@ -288,7 +289,7 @@ RUN mkdir -p /build/models # Define the health check command HEALTHCHECK --interval=1m --timeout=10m --retries=10 \ - CMD curl -f $HEALTHCHECK_ENDPOINT || exit 1 + CMD curl -f ${HEALTHCHECK_ENDPOINT} || exit 1 VOLUME /build/models EXPOSE 8080 diff --git a/core/http/endpoints/openai/assistant.go b/core/http/endpoints/openai/assistant.go index dceb3789..c1efd8bd 100644 --- a/core/http/endpoints/openai/assistant.go +++ b/core/http/endpoints/openai/assistant.go @@ -455,21 +455,19 @@ func DeleteAssistantFileEndpoint(cl *config.BackendConfigLoader, ml *model.Model for i, assistant := range Assistants { if assistant.ID == assistantID { for j, fileId := range assistant.FileIDs { - if fileId == fileId { - Assistants[i].FileIDs = append(Assistants[i].FileIDs[:j], Assistants[i].FileIDs[j+1:]...) + Assistants[i].FileIDs = append(Assistants[i].FileIDs[:j], Assistants[i].FileIDs[j+1:]...) - // Check if the file exists in the assistantFiles slice - for i, assistantFile := range AssistantFiles { - if assistantFile.ID == fileId { - // Remove the file from the assistantFiles slice - AssistantFiles = append(AssistantFiles[:i], AssistantFiles[i+1:]...) - utils.SaveConfig(appConfig.ConfigsDir, AssistantsFileConfigFile, AssistantFiles) - return c.Status(fiber.StatusOK).JSON(DeleteAssistantFileResponse{ - ID: fileId, - Object: "assistant.file.deleted", - Deleted: true, - }) - } + // Check if the file exists in the assistantFiles slice + for i, assistantFile := range AssistantFiles { + if assistantFile.ID == fileId { + // Remove the file from the assistantFiles slice + AssistantFiles = append(AssistantFiles[:i], AssistantFiles[i+1:]...) + utils.SaveConfig(appConfig.ConfigsDir, AssistantsFileConfigFile, AssistantFiles) + return c.Status(fiber.StatusOK).JSON(DeleteAssistantFileResponse{ + ID: fileId, + Object: "assistant.file.deleted", + Deleted: true, + }) } } }