mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 23:05:49 +00:00
Added support of GCP CLoud SQL
This commit is contained in:
parent
6148ddd967
commit
3781fa6276
4 changed files with 49 additions and 0 deletions
21
Dockerfile
Normal file
21
Dockerfile
Normal file
|
@ -0,0 +1,21 @@
|
|||
# First stage: Build the application with Maven
|
||||
FROM maven:3.8.4-openjdk-17 AS build
|
||||
WORKDIR /app
|
||||
COPY pom.xml .
|
||||
COPY src ./src
|
||||
RUN mvn clean package -DskipTests
|
||||
|
||||
# Second stage: Download New Relic Java APM agent
|
||||
FROM alpine:3.14 AS newrelic
|
||||
WORKDIR /newrelic
|
||||
RUN wget https://download.newrelic.com/newrelic/java-agent/newrelic-agent/current/newrelic-java.zip && \
|
||||
unzip newrelic-java.zip
|
||||
|
||||
# Third stage: Copy artifacts to the distroless JRE image and run them
|
||||
FROM gcr.io/distroless/java17-debian11
|
||||
WORKDIR /app
|
||||
USER root
|
||||
COPY --from=build /app/target/spring-petclinic.jar /app/spring-petclinic.jar
|
||||
COPY --from=newrelic /newrelic/newrelic/ /newrelic/
|
||||
ENV NEW_RELIC_APP_NAME=petclinic
|
||||
ENTRYPOINT ["java", "-javaagent:/newrelic/newrelic.jar", "-jar", "/app/spring-petclinic.jar"]
|
6
pom.xml
6
pom.xml
|
@ -88,6 +88,11 @@
|
|||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.cloud.sql</groupId>
|
||||
<artifactId>postgres-socket-factory</artifactId>
|
||||
<version>1.21.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
|
@ -155,6 +160,7 @@
|
|||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
|
19
src/main/resources/application-cloudsql.yml
Normal file
19
src/main/resources/application-cloudsql.yml
Normal file
|
@ -0,0 +1,19 @@
|
|||
database: postgres
|
||||
spring:
|
||||
sql:
|
||||
init:
|
||||
mode: always
|
||||
cloud:
|
||||
gcp:
|
||||
sql:
|
||||
database-name: ${DB_NAME}
|
||||
enable-iam-auth: true
|
||||
instance-connection-name: ${INSTANCE_CONNECTION_NAME}
|
||||
sslmode: disable
|
||||
datasource:
|
||||
url: jdbc:postgresql:///${DB_NAME}?socketFactory=com.google.cloud.sql.postgres.SocketFactory&cloudSqlInstance=${INSTANCE_CONNECTION_NAME}&enableIamAuth=true&user=${DB_USER}&password=dummy&sslmode=disable
|
||||
username: ${DB_USER}
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: update
|
||||
show-sql: true
|
|
@ -23,3 +23,6 @@ logging.level.org.springframework=INFO
|
|||
|
||||
# Maximum time static resources should be cached
|
||||
spring.web.resources.cache.cachecontrol.max-age=12h
|
||||
|
||||
# In the last line, add mysql to the spring.profiles.active property
|
||||
spring.profiles.active=cloudsql
|
Loading…
Reference in a new issue