diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000000..da5bb239da9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM schoolofdevops/maven:spring + +WORKDIR /app + +COPY . . + +RUN mvn spring-javaformat:apply && \ + mvn package -DskipTests && \ + mv target/spring-petclinic-2.3.1.BUILD-SNAPSHOT.jar /run/petclinic.jar + +EXPOSE 8080 + +CMD java -jar /run/petclinic.jar \ No newline at end of file diff --git a/Dockerfile.multistage.v1 b/Dockerfile.multistage.v1 new file mode 100644 index 00000000000..0a1780a2522 --- /dev/null +++ b/Dockerfile.multistage.v1 @@ -0,0 +1,16 @@ +FROM schoolofdevops/maven:spring AS build + +WORKDIR /app + +COPY . . + +RUN mvn spring-javaformat:apply && \ + mvn package -DskipTests + +FROM openjdk:8-alpine AS run + +COPY --from=build /app/target/spring-petclinic-2.3.1.BUILD-SNAPSHOT.jar /run/petclinic.jar + +EXPOSE 8080 + +CMD java -jar /run/petclinic.jar \ No newline at end of file diff --git a/Dockerfile.multistage.v2 b/Dockerfile.multistage.v2 new file mode 100644 index 00000000000..5e90fbe25d8 --- /dev/null +++ b/Dockerfile.multistage.v2 @@ -0,0 +1,19 @@ +FROM schoolofdevops/maven:spring AS build + +WORKDIR /app + +COPY . . + +RUN mvn spring-javaformat:apply && \ + mvn package -DskipTests + +FROM build AS test +CMD mvn clean test + +FROM openjdk:8-alpine AS run + +COPY --from=build /app/target/spring-petclinic-2.3.1.BUILD-SNAPSHOT.jar /run/petclinic.jar + +EXPOSE 8080 + +CMD java -jar /run/petclinic.jar \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000000..5675b47f93b --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,31 @@ +version: "3.7" + +networks: + petclinic: + driver: bridge + +services: + app: + image: sagordondevops/petclinic:v3 + build: + context: . + dockerfile: Dockerfile.multistage.v2 + ports: + - 8080:8080 + environment: + - SPRING_PROFILES_ACTIVE=mysql + networks: + - petclinic + depends_on: + - db + + db: + image: mysql:5.7 + environment: + - MYSQL_ROOT_PASSWORD= + - MYSQL_ALLOW_EMPTY_PASSWORD=true + - MYSQL_USER=petclinic + - MYSQL_PASSWORD=petclinic + - MYSQL_DATABASE=petclinic + networks: + - petclinic \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index b6e964e368d..00000000000 --- a/docker-compose.yml +++ /dev/null @@ -1,10 +0,0 @@ -db: - image: mysql:5.7 - ports: - - "3306:3306" - environment: - - MYSQL_ROOT_PASSWORD= - - MYSQL_ALLOW_EMPTY_PASSWORD=true - - MYSQL_USER=petclinic - - MYSQL_PASSWORD=petclinic - - MYSQL_DATABASE=petclinic diff --git a/src/main/resources/application-mysql.properties b/src/main/resources/application-mysql.properties index d388c9e6d50..39a0fcd866b 100644 --- a/src/main/resources/application-mysql.properties +++ b/src/main/resources/application-mysql.properties @@ -1,6 +1,6 @@ # database init, supports mysql too database=mysql -spring.datasource.url=${MYSQL_URL:jdbc:mysql://localhost/petclinic} +spring.datasource.url=${MYSQL_URL:jdbc:mysql://db/petclinic} spring.datasource.username=${MYSQL_USER:petclinic} spring.datasource.password=${MYSQL_PASS:petclinic} # SQL is written to be idempotent so this is safe diff --git a/src/main/resources/messages/messages.properties b/src/main/resources/messages/messages.properties index 173417a1014..aaf60fe016d 100644 --- a/src/main/resources/messages/messages.properties +++ b/src/main/resources/messages/messages.properties @@ -1,4 +1,4 @@ -welcome=Welcome +welcome=Welcome to PetClinic required=is required notFound=has not been found duplicate=is already in use