From 981550ab490333222e98710adbe7d18e67dd2e80 Mon Sep 17 00:00:00 2001 From: Anton Babych Date: Wed, 20 Dec 2023 18:14:20 +0200 Subject: [PATCH] Some changes to docker --- .env | 2 +- Dockerfile | 2 +- docker-compose.yml | 30 ++++++++----------- pom.xml | 4 +++ src/main/resources/application.properties | 11 ++----- .../BookStoreAppApplicationTests.java | 5 ---- 6 files changed, 21 insertions(+), 33 deletions(-) diff --git a/.env b/.env index c554ae7..338dbbc 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -MYSQL_USER=myuser +MYSQL_USER=admin123 MYSQL_PASSWORD=password MYSQL_DATABASE=book_store MYSQL_ROOT_PASSWORD=password diff --git a/Dockerfile b/Dockerfile index 6fa3d00..1a1418f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,5 +12,5 @@ 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"] +ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"] EXPOSE 8080 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 9d597f9..d37304e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,8 @@ version: "3.8" services: - db: - image: mysql:latest + mysqldb: + image: mysql restart: unless-stopped env_file: ./.env ports: @@ -12,14 +12,10 @@ services: MYSQL_DATABASE: $MYSQL_DATABASE MYSQL_USER: $MYSQL_USER MYSQL_PASSWORD: $MYSQL_PASSWORD - healthcheck: - test: [ "CMD", "mysql_isready -U mysql" ] - interval: 30s - timeout: 30s - retries: 3 + app: depends_on: - - db + - mysqldb restart: on-failure image: book-store-app build: . @@ -29,13 +25,13 @@ services: - $DEBUG_PORT:$DEBUG_PORT environment: SPRING_APPLICATION_JSON: '{ - "spring.datasource.url" : "jdbc:mysql://db:$MYSQL_DOCKER_PORT/$MYSQL_DATABASE", - "spring.datasource.username" : "$MYSQL_USER", - "spring.datasource.password" : "$MYSQL_PASSWORD", - "spring.datasource.driver-class-name" : "com.mysql.cj.jdbc.Driver", - "spring.jpa.hibernate.ddl-aut" : "validate", - "spring.jpa.show-sql" : "true", - "jwt.expiration" : "$JWT_EXPIRATION_TIME", - "jwt_secret" : "$JWT_SECRET" - }' + "spring.datasource.url" : "jdbc:mysql://mysqldb:$MYSQL_DOCKER_PORT/$MYSQL_DATABASE?serverTimezone=UTC", + "spring.datasource.username" : "$MYSQL_USER", + "spring.datasource.password" : "$MYSQL_PASSWORD", + "spring.datasource.driver-class-name" : "com.mysql.cj.jdbc.Driver", + "spring.jpa.hibernate.ddl-aut" : "validate", + "spring.jpa.show-sql" : "true", + "jwt.expiration" : "$JWT_EXPIRATION_TIME", + "jwt_secret" : "$JWT_SECRET" + }' JAVA_TOOL_OPTIONS: "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" diff --git a/pom.xml b/pom.xml index 73e7df5..6ce059a 100644 --- a/pom.xml +++ b/pom.xml @@ -100,6 +100,10 @@ jjwt-jackson ${jjwt.version} + + org.springframework.boot + spring-boot-docker-compose + diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 56d4505..435be3d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,13 +1,6 @@ -spring.datasource.url=jdbc:mysql://localhost:${MYSQL_DOCKER_PORT}\ - /${MYSQL_DATABASE}?serverTimeZone=UTC -spring.datasource.username=${MYSQL_USER} -spring.datasource.password=${MYSQL_ROOT_PASSWORD} -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.jpa.hibernate.ddl-auto=validate spring.jpa.show-sql=true -jwt.expiration=${JWT_EXPIRATION_TIME} -jwt.secret=${JWT_SECRET} - - +jwt.expiration=1000000 +jwt.secret=p1tbookstoreappsomerandomsymholstokey1231488p1t diff --git a/src/test/java/store/bookstoreapp/BookStoreAppApplicationTests.java b/src/test/java/store/bookstoreapp/BookStoreAppApplicationTests.java index 2f5cb0f..8352eb4 100644 --- a/src/test/java/store/bookstoreapp/BookStoreAppApplicationTests.java +++ b/src/test/java/store/bookstoreapp/BookStoreAppApplicationTests.java @@ -1,13 +1,8 @@ package store.bookstoreapp; -import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest class BookStoreAppApplicationTests { - @Test - void contextLoads() { - } - }