11FROM node:20-alpine AS builder
22
33RUN apk update && \
4- apk add --no-cache git ffmpeg wget curl bash openssl
4+ apk add --no-cache git ffmpeg wget curl bash openssl dos2unix
55
66LABEL version="2.3.0" description="Api to control whatsapp features through http requests."
77LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
8899
1010WORKDIR /evolution
1111
12- COPY ./package.json ./tsconfig.json ./
12+ # Define variáveis de ambiente padrão para o build
13+ ENV DOCKER_ENV=true
14+ ENV DATABASE_PROVIDER=postgresql
15+ ENV DATABASE_URL=postgresql://user:password@localhost:5432/evolution
16+
17+ # Copia arquivos de configuração primeiro
18+ COPY ./package*.json ./
19+ COPY ./tsconfig.json ./
20+ COPY ./tsup.config.ts ./
1321
14- RUN npm install
22+ # Instala todas as dependências (incluindo dev para build)
23+ RUN npm ci --silent
1524
25+ # Copia código fonte
1626COPY ./src ./src
1727COPY ./public ./public
1828COPY ./prisma ./prisma
1929COPY ./manager ./manager
20- COPY ./.env.example ./.env
2130COPY ./runWithProvider.js ./
22- COPY ./tsup.config.ts ./
2331
32+ # Copia scripts Docker
2433COPY ./Docker ./Docker
2534
2635RUN chmod +x ./Docker/scripts/* && dos2unix ./Docker/scripts/*
2736
37+ # Cria um arquivo .env básico com as variáveis de ambiente para o build
38+ RUN echo "DOCKER_ENV=true" > .env && \
39+ echo "DATABASE_PROVIDER=${DATABASE_PROVIDER}" >> .env && \
40+ echo "DATABASE_URL=${DATABASE_URL}" >> .env
41+
42+ # Executa o script de geração de banco - agora com variáveis definidas
2843RUN ./Docker/scripts/generate_database.sh
2944
30- RUN npm run build
45+ # Build do projeto
46+ RUN npm run build:docker
47+
48+ # Remove devDependencies para reduzir tamanho
49+ RUN npm prune --production
3150
3251FROM node:20-alpine AS final
3352
3453RUN apk update && \
3554 apk add tzdata ffmpeg bash openssl
3655
3756ENV TZ=America/Sao_Paulo
57+ ENV DOCKER_ENV=true
3858
3959WORKDIR /evolution
4060
@@ -46,13 +66,13 @@ COPY --from=builder /evolution/dist ./dist
4666COPY --from=builder /evolution/prisma ./prisma
4767COPY --from=builder /evolution/manager ./manager
4868COPY --from=builder /evolution/public ./public
49- COPY --from=builder /evolution/.env ./.env
5069COPY --from=builder /evolution/Docker ./Docker
5170COPY --from=builder /evolution/runWithProvider.js ./runWithProvider.js
5271COPY --from=builder /evolution/tsup.config.ts ./tsup.config.ts
5372
54- ENV DOCKER_ENV=true
73+ # Cria arquivo .env vazio - as variáveis virão do Railway
74+ RUN touch .env
5575
5676EXPOSE 8080
5777
58- ENTRYPOINT ["/bin/bash" , "-c" , ". ./Docker/scripts/deploy_database.sh && npm run start:prod" ]
78+ ENTRYPOINT ["/bin/bash" , "-c" , ". ./Docker/scripts/deploy_database.sh && npm run start:prod" ]
0 commit comments