diff --git a/.env.example b/.env.example index db7ce345..32417dfa 100644 --- a/.env.example +++ b/.env.example @@ -30,7 +30,8 @@ CLEAN_STORE_CONTACTS=true CLEAN_STORE_CHATS=true DATABASE_ENABLED=false -DATABASE_PROVIDER=mongodb # postgresql, mysql, mongodb +DATABASE_PROVIDER=postgresql # postgresql, mysql +DATABASE_PROVIDER=mongodb # postgresql, mysql DATABASE_CONNECTION_URI='mongodb://root:root@mongodb:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true' DATABASE_CONNECTION_CLIENT_NAME=evolution DATABASE_SAVE_DATA_INSTANCE=true diff --git a/Dockerfile b/Dockerfile index bc0842bc..15be3f80 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,31 @@ -FROM node:20.7.0-alpine AS builder +FROM node:20-bullseye-slim AS base + +RUN apt-get update -y +RUN apt-get upgrade -y + +RUN apt-get install -y git tzdata ffmpeg wget curl + +RUN npm i -g npm@latest + +FROM base AS builder LABEL version="1.8.0" description="Api to control whatsapp features through http requests." LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes" LABEL contact="contato@agenciadgcode.com" -RUN apk update && apk upgrade && \ - apk add --no-cache git tzdata ffmpeg wget curl - WORKDIR /evolution -COPY ./package.json . +COPY ./package.json ./tsconfig.json ./ RUN npm install COPY . . +RUN chmod +x ./deploy_database.sh + ENV DATABASE_CONNECTION_URI=postgres://postgres:pass@localhost/evolution -RUN npx prisma generate + +RUN ./deploy_database.sh RUN npm run build @@ -26,11 +35,13 @@ ENV TZ=America/Sao_Paulo WORKDIR /evolution +COPY --from=builder /evolution/package.json ./package.json +COPY --from=builder /evolution/package-lock.json ./package-lock.json + +RUN npm install --omit=dev + COPY --from=builder /evolution . ENV DOCKER_ENV=true -RUN npx prisma migrate deploy -RUN npx prisma generate - -CMD [ "node", "./dist/src/main.js" ] +ENTRYPOINT ["/bin/bash", "-c", ". ./scripts/run_database_operation_deploy.sh && npm run start:prod" ] diff --git a/deploy_database.sh b/deploy_database.sh new file mode 100644 index 00000000..a478414a --- /dev/null +++ b/deploy_database.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +source ./scripts/env_functions.sh + +if [ "$DOCKER_ENV" != "true" ]; then + export_env_vars +fi + +if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" ]]; then + export DATABASE_URL + echo "Database URL: $DATABASE_URL" + ./node_modules/.bin/prisma generate --schema=prisma/$DATABASE_PROVIDER-schema.prisma +else + echo "Error: Database provider $DATABASE_PROVIDER invalid." + exit 1 +fi