Merge remote-tracking branch 'origin/v2.2.1' into v2.2.3

This commit is contained in:
Gabriel Rodrigues 2025-02-10 17:22:38 -03:00
commit 10183f26df
12 changed files with 887 additions and 20 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
.DS_Store
# compiled output
/dist
/node_modules

37
.postgres/Dockerfile Normal file
View File

@ -0,0 +1,37 @@
FROM golang:1.23.4-alpine3.21 AS go_build
WORKDIR /build
RUN apk update \
&& apk add --no-cache \
build-base \
git
RUN git clone https://github.com/tianon/gosu.git .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-s -w" \
-o gosu
FROM postgres:16-alpine3.21 AS pgvector_build
WORKDIR /pgvector
RUN apk update \
&& apk add --no-cache \
build-base \
git \
clang \
llvm \
postgresql16-dev
RUN git clone https://github.com/pgvector/pgvector.git . \
&& make \
&& make install
FROM postgres:16-alpine3.21
COPY --from=go_build /build/gosu /usr/local/bin
COPY --from=pgvector_build /pgvector/vector.so /usr/local/lib/postgresql
COPY --from=pgvector_build /pgvector/vector.control /usr/local/share/postgresql/extension
COPY --from=pgvector_build /pgvector/sql/vector--0.8.0.sql /usr/local/share/postgresql/extension

View File

@ -17,7 +17,7 @@ COPY ./src ./src
COPY ./public ./public
COPY ./prisma ./prisma
COPY ./manager ./manager
COPY ./.env.example ./.env
COPY .env ./.env
COPY ./runWithProvider.js ./
COPY ./tsup.config.ts ./
@ -51,8 +51,10 @@ COPY --from=builder /evolution/Docker ./Docker
COPY --from=builder /evolution/runWithProvider.js ./runWithProvider.js
COPY --from=builder /evolution/tsup.config.ts ./tsup.config.ts
COPY newrelic.js .
ENV DOCKER_ENV=true
EXPOSE 8080
ENTRYPOINT ["/bin/bash", "-c", ". ./Docker/scripts/deploy_database.sh && npm run start:prod" ]
ENTRYPOINT ["/bin/bash", "-c", ". ./Docker/scripts/deploy_database.sh && npm run start:prod" ]

87
chatfluxctl Executable file
View File

@ -0,0 +1,87 @@
#!/bin/bash
if [ "$#" -lt 3 ]; then
echo "Usage: $0 <environment> <action> <service_name>"
echo "Environment: staging|production"
echo "Action: start|stop"
echo "Service: service_name|all"
exit 1
fi
ENVIRONMENT=$1
ACTION=$2
SERVICE_NAME=$3
BASE_COMPOSE=""
ENV_COMPOSE=""
DOCKER_COMPOSE_CMD="docker compose"
# Check for both yml and yaml extensions for base compose
if [ -f "docker-compose.yml" ]; then
BASE_COMPOSE="docker-compose.yml"
elif [ -f "docker-compose.yaml" ]; then
BASE_COMPOSE="docker-compose.yaml"
else
echo "Error: Base docker-compose file not found (tried .yml and .yaml)"
exit 1
fi
# Check for both yml and yaml extensions for environment compose
if [ -f "docker-compose.${ENVIRONMENT}.yml" ]; then
ENV_COMPOSE="docker-compose.${ENVIRONMENT}.yml"
elif [ -f "docker-compose.${ENVIRONMENT}.yaml" ]; then
ENV_COMPOSE="docker-compose.${ENVIRONMENT}.yaml"
else
echo "Error: Environment docker-compose file not found (tried .yml and .yaml)"
exit 1
fi
# Validate environment
if [ "$ENVIRONMENT" != "staging" ] && [ "$ENVIRONMENT" != "production" ]; then
echo "Error: Environment must be either 'staging' or 'production'"
exit 1
fi
# Validate action
if [ "$ACTION" != "start" ] && [ "$ACTION" != "stop" ]; then
echo "Error: Action must be either 'start' or 'stop'"
exit 1
fi
# Function to check if service exists in compose files
check_service() {
local service=$1
if [ "$service" != "all" ]; then
if ! $DOCKER_COMPOSE_CMD -f $BASE_COMPOSE -f $ENV_COMPOSE config --services | grep -q "^$service$"; then
echo "Error: Service '$service' not found in docker-compose files"
exit 1
fi
fi
}
# Validate service exists
check_service $SERVICE_NAME
if [ "$ACTION" == "stop" ]; then
echo "Stopping service(s): $SERVICE_NAME"
if [ "$SERVICE_NAME" == "all" ]; then
$DOCKER_COMPOSE_CMD -f $BASE_COMPOSE -f $ENV_COMPOSE down
else
$DOCKER_COMPOSE_CMD -f $BASE_COMPOSE -f $ENV_COMPOSE stop $SERVICE_NAME
$DOCKER_COMPOSE_CMD -f $BASE_COMPOSE -f $ENV_COMPOSE rm -f $SERVICE_NAME
fi
else
echo "Starting service(s): $SERVICE_NAME"
if [ "$SERVICE_NAME" == "all" ]; then
$DOCKER_COMPOSE_CMD -f $BASE_COMPOSE -f $ENV_COMPOSE up -d
else
$DOCKER_COMPOSE_CMD -f $BASE_COMPOSE -f $ENV_COMPOSE up -d $SERVICE_NAME
fi
fi
# Check service status
echo "Service status:"
if [ "$SERVICE_NAME" == "all" ]; then
$DOCKER_COMPOSE_CMD -f $BASE_COMPOSE -f $ENV_COMPOSE ps
else
$DOCKER_COMPOSE_CMD -f $BASE_COMPOSE -f $ENV_COMPOSE ps $SERVICE_NAME
fi

View File

@ -0,0 +1,11 @@
services:
api:
environment:
NODE_ENV: PROD
CHATFLUX_ENV: Production
NEW_RELIC_APP_NAME: "Production Evolution API"
LOG_LEVEL: "DEBUG"
CACHE_REDIS_ENABLED: "true"
CACHE_LOCAL_ENABLED: "false"
WEBHOOK_EVENTS_ERRORS: "true"
WEBHOOK_EVENTS_ERRORS_WEBHOOK: ${WEBHOOK_EVENTS_ERRORS_WEBHOOK}

View File

@ -0,0 +1,9 @@
services:
api:
environment:
NODE_ENV: PROD
CHATFLUX_ENV: Staging
NEW_RELIC_APP_NAME: "Staging Evolution API"
LOG_LEVEL: "DEBUG"
CACHE_REDIS_ENABLED: "true"
CACHE_LOCAL_ENABLED: "false"

View File

@ -1,24 +1,35 @@
services:
api:
container_name: evolution_api
image: atendai/evolution-api:homolog
image: ghcr.io/ai-chat-os/evolution-api:v2.2.1-redis-on
restart: always
depends_on:
- redis
- postgres
ports:
- 8080:8080
environment:
# 1- Add the Env key values pair to /etc/environment file
# 2- Run source /etc/environment
# 3- Run env |grep -i relic; to validate it being loaded.
# 4- If didn't, CTRL+d to logout
# 5- Login to the server
# 6- Run env |grep -i relic again;
CACHE_REDIS_URI: redis://redis:6379/6
NEW_RELIC_LICENSE_KEY: ${NEW_RELIC_LICENSE_KEY}
NEW_RELIC_NO_CONFIG_FILE: true
NEW_RELIC_DISTRIBUTED_TRACING_ENABLED: true
NEW_RELIC_LOG: stdout
NODE_ENV: PROD
volumes:
- evolution_instances:/evolution/instances
networks:
- evolution-net
env_file:
- .env
expose:
- 8080
extra_hosts:
- "host.docker.internal:host-gateway"
redis:
image: redis:latest
image: redis:7.4.2-alpine
networks:
- evolution-net
container_name: redis
@ -26,33 +37,27 @@ services:
redis-server --port 6379 --appendonly yes
volumes:
- evolution_redis:/data
ports:
- 6379:6379
postgres:
container_name: postgres
image: postgres:15
build:
context: .postgres/
networks:
- evolution-net
command: ["postgres", "-c", "max_connections=1000", "-c", "listen_addresses=*"]
restart: always
ports:
- 5432:5432
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=pass
- POSTGRES_PASSWORD=nGYh5UIg4cg9Xwec1AeJ
- POSTGRES_DB=evolution
- POSTGRES_HOST_AUTH_METHOD=trust
volumes:
- postgres_data:/var/lib/postgresql/data
expose:
- 5432
volumes:
evolution_instances:
evolution_redis:
postgres_data:
evolution_redis:
networks:
evolution-net:

22
newrelic.js Normal file
View File

@ -0,0 +1,22 @@
exports.config = {
app_name: [`${process.env.CHATFLUX_ENV} Evolution API`],
license_key: process.env.NEW_RELIC_LICENSE_KEY,
logging: {
level: process.env.LOG_LEVEL
},
allow_all_headers: true,
attributes: {
exclude: [
'request.headers.cookie',
'request.headers.authorization',
'request.headers.proxyAuthorization',
'request.headers.setCookie*',
'request.headers.x*',
'response.headers.cookie',
'response.headers.authorization',
'response.headers.proxyAuthorization',
'response.headers.setCookie*',
'response.headers.x*'
]
}
}

691
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -82,6 +82,7 @@
"mime-types": "^2.1.35",
"minio": "^8.0.3",
"multer": "^1.4.5-lts.1",
"newrelic": "^12.11.3",
"node-cache": "^5.1.2",
"node-cron": "^3.0.3",
"openai": "^4.77.3",

View File

@ -1,5 +1,6 @@
// Import this first from sentry instrument!
import '@utils/instrumentSentry';
import './newrelic';
// Now import other modules
import { ProviderFiles } from '@api/provider/sessions';

3
src/newrelic.ts Normal file
View File

@ -0,0 +1,3 @@
if (process.env.NODE_ENV === 'PROD') {
require('newrelic');
}