3
respostas

Deploy no Heroku com Postgres deu ruim

Boa tarde, estou tentando realizar o deploy da aplicação no heroku com o database criado no heroku, mas não esta dando certo.

application-prod.properties

spring.jpa.database=${DATABASE}
spring.datasource.platform=postgres
spring.datasource.url=${DATABASE_URL}
spring.datasource.username=${DATABASE_USERNAME}
spring.datasource.password=${DATABASE_PASSWORD}
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.generate-ddl=true

#====================
# == FLYWAY CONFIG ==

spring.flyway.url=${DATABASE_URL}
spring.flyway.schemas=checkup
spring.flyway.user=${DATABASE_USERNAME}
spring.flyway.password=${DATABASE_PASSWORD}
#====================

mas no log via terminal aparece assim.

Caused by: org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
2020-11-06T18:06:52.001177+00:00 app[web.1]: at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:285) ~[postgresql-42.2.14.jar!/:42.2.14]

e no log via web, aparece assim

Step 5/6 : COPY ${JAR_FILE} app.jar
COPY failed: no source files were specified

alguem consegue me ajudar???

3 respostas

Oi Ricardo,

Ta com erro no postgres(talvez a porta não seja a 5432, tenta conectar na 5433).

E também problemas ao criar a imagem Docker.

Posta aqui seu Dockerfile.

a configuração do Postgres é a que o heroku me disponibiliza. essa é a porta que o Postgres do Heroku mostra:

Port 5432

Dockerfile

FROM openjdk:14-jdk-alpine
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","-Dserver.port=${SERVER_PORT}","-Xmx512m","/app.jar"]

E no Settings do app, no dashboard do Heroku, setei assim as variáveis

PORT       5432
SERVER_PORT 8080

Pelo log, usando o cmd heroku logs --tail ele reconhece que o application é PROD

com.checkup.CheckupApplication           : The following profiles are active: PROD

mas manda esse erro aqui, logo em seguida

ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.internal.exception.FlywaySqlException:
2020-11-09T11:00:31.348648+00:00 app[web.1]: Unable to obtain connection from database (jdbc:postgresql://localhost:5432/) for user 'postgres': Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

Acredito queu alguma config esta faltando, mas não sei o que pode ser

Oi Ricardo,

A principio é problema com o Postgre mesmo.

Ou não está rodando na porta 5432 ou está com alguma configuração que não permite a conexão da aplicação.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software