Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate container deploys compose #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions Dockerfile.multistage.v1
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions Dockerfile.multistage.v2
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 0 additions & 10 deletions docker-compose.yml

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/resources/application-mysql.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/messages/messages.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
welcome=Welcome
welcome=Welcome to PetClinic
required=is required
notFound=has not been found
duplicate=is already in use
Expand Down