forked from docker/awesome-compose
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request docker#7 from glours/update_spring_example
Update spring-postgresql example
- Loading branch information
Showing
10 changed files
with
140 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
FROM maven:3.5-jdk-9 AS build | ||
COPY pom.xml . | ||
RUN mvn --batch-mode dependency:resolve | ||
COPY . . | ||
RUN mvn --batch-mode package | ||
RUN cp target/*jar target/app.jar | ||
FROM maven:3.6.3-jdk-11 AS builder | ||
WORKDIR /workdir/server | ||
COPY pom.xml /workdir/server/pom.xml | ||
RUN mvn dependency:go-offline | ||
|
||
COPY src /workdir/server/src | ||
RUN mvn install | ||
RUN mkdir -p target/depency | ||
WORKDIR /workdir/server/target/dependency | ||
RUN jar -xf ../*.jar | ||
|
||
FROM openjdk:11-jre-slim | ||
|
||
FROM openjdk:9-jre | ||
EXPOSE 8080 | ||
VOLUME /tmp | ||
COPY --from=build target/app.jar app.jar | ||
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] | ||
ARG DEPENDENCY=/workdir/server/target/dependency | ||
COPY --from=builder ${DEPENDENCY}/BOOT-INF/lib /app/lib | ||
COPY --from=builder ${DEPENDENCY}/META-INF /app/META-INF | ||
COPY --from=builder ${DEPENDENCY}/BOOT-INF/classes /app | ||
ENTRYPOINT ["java","-cp","app:app/lib/*","com.company.project.Application"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 8 additions & 1 deletion
9
...spring-postgres/backend/src/main/java/com/company/project/controllers/HomeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
samples/spring-postgres/backend/src/main/java/com/company/project/entity/Greeting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.company.project.entity; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
|
||
@Entity | ||
@Table(name = "GREETINGS") | ||
public class Greeting { | ||
|
||
@Id | ||
private int id; | ||
private String name; | ||
|
||
public Greeting() { | ||
} | ||
|
||
public Greeting(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Greeting(int id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
Greeting greeting = (Greeting) o; | ||
|
||
return name.equals(greeting.name); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return name.hashCode(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ing-postgres/backend/src/main/java/com/company/project/repository/GreetingRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.company.project.repository; | ||
|
||
import com.company.project.entity.Greeting; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface GreetingRepository extends CrudRepository<Greeting, Integer> { | ||
} |
10 changes: 10 additions & 0 deletions
10
samples/spring-postgres/backend/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect | ||
spring.jpa.hibernate.ddl-auto=none | ||
spring.jpa.hibernate.show-sql=true | ||
|
||
spring.datasource.url=jdbc:postgresql://db:5432/${POSTGRES_DB} | ||
spring.datasource.username=postgres | ||
spring.datasource.password=${POSTGRES_PASSWORD:db-wrz2z} | ||
spring.datasource.initialization-mode=always | ||
spring.datasource.initialize=true | ||
spring.datasource.schema=classpath:/schema.sql | ||
spring.datasource.continue-on-error=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
INSERT INTO GREETINGS(name) values ('Docker'); |
4 changes: 4 additions & 0 deletions
4
samples/spring-postgres/backend/src/main/resources/schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CREATE TABLE IF NOT EXISTS GREETINGS ( | ||
id serial PRIMARY KEY, | ||
name varchar(50) NOT NULL | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters