Skip to content

Commit

Permalink
Merge pull request #13 from ivan0dyatlyukkk/feat-docker
Browse files Browse the repository at this point in the history
Features related to docker
  • Loading branch information
ivan0dyatlyukkk authored Oct 17, 2023
2 parents 61d1d20 + 1956609 commit 057049e
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 7 deletions.
10 changes: 10 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MYSQL_DB_USER=admin
MYSQL_DB_PASSWORD=admin2023admin
MYSQL_DB_ROOT_PASSWORD=redblack0root
MYSQL_DATABASE=book_store_storage
MYSQL_LOCAL_PORT=3308
MYSQL_DOCKER_PORT=3306

SPRING_LOCAL_PORT=8088
SPRING_DOCKER_PORT=8080
DEBUG_PORT=5005
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#BUILDER STAGE
FROM openjdk:17-jdk-slim as builder
WORKDIR application
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract

#FINAL STAGE
FROM openjdk:17-jdk-slim
WORKDIR application
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
EXPOSE 8080
35 changes: 35 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '3.8'

services:
mysqldb:
image: mysql:8.1.0
container_name: book-store-mysqldb
restart: on-failure
env_file: ./.env
environment:
MYSQL_ROOT_PASSWORD: $MYSQL_DB_ROOT_PASSWORD
MYSQL_USER: $MYSQL_DB_USER
MYSQL_PASSWORD: $MYSQL_DB_PASSWORD
MYSQL_DB: $MYSQL_DATABASE
ports:
- $MYSQL_LOCAL_PORT:$MYSQL_DOCKER_PORT
app:
depends_on:
- mysqldb
restart: on-failure
image: dyatlyuk/book-store
build: .
env_file: ./.env
ports:
- $SPRING_LOCAL_PORT:$SPRING_DOCKER_PORT
- $DEBUG_PORT:$DEBUG_PORT
environment:
SPRING_APPLICATION_JSON: '{
"spring.datasource.url" : "jdbc:mysql://mysqldb:$MYSQL_DOCKER_PORT/$MYSQL_DATABASE",
"spring.datasource.username" : "$MYSQL_DB_USER",
"spring.datasource.password" : "$MYSQL_DB_PASSWORD",
"spring.jpa.properties.hibernate.dialect" : "org.hibernate.dialect.MySQLDialect",
"spring.datasource.driver-class-name" : "com.mysql.cj.jdbc.Driver",
"spring.jpa.hibernate.ddl-auto" : "validate"
}'
JAVA_TOOL_OPTIONS: "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-docker-compose</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/book_store_storage
spring.datasource.username=root
spring.datasource.password=redblack0root
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.show-sql=true
spring.jpa.open-in-view=false
server.servlet.context-path=/api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

@SpringBootTest
class BookStoreApplicationTests {

@Test
void contextLoads() {
}

}

0 comments on commit 057049e

Please sign in to comment.