Skip to content
Merged
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
8 changes: 8 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MYSQLDB_ROOT_PASSWORD=your_root_password
MYSQLDB_USERNAME=your_username
MYSQLDB_DATABASE=your_database_name
MYSQLDB_LOCAL_PORT=3307
MYSQLDB_DOCKER_PORT=3306

APP_LOCAL_PORT=8081
APP_DOCKER_PORT=8080
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ target/
.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
.env

### STS ###
.apt_generated
Expand Down
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM eclipse-temurin:17-jdk-alpine AS builder
WORKDIR application
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract


FROM eclipse-temurin:17-jdk-alpine
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.launch.JarLauncher"]
EXPOSE 8080
55 changes: 55 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
services:
mysqldb:
image: mysql:9.5.0
container_name: mysqldb
restart: unless-stopped
env_file:
- .env
environment:
MYSQL_ROOT_PASSWORD: ${MYSQLDB_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQLDB_DATABASE}

ports:
- "${MYSQLDB_LOCAL_PORT}:${MYSQLDB_DOCKER_PORT}"

volumes:
- mysql_data:/var/lib/mysql

healthcheck:
test: [ "CMD-SHELL", "mysqladmin", "ping", "-h", "localhost" ]
interval: 30s
timeout: 30s
retries: 3
networks:
- bookstore-network

app:
image: bookstore
build: .
container_name: bookstore
depends_on:
- mysqldb

ports:
- "${APP_LOCAL_PORT}:${APP_DOCKER_PORT}"
- "${DEBUG_PORT}:${DEBUG_PORT}"

env_file:
- .env

environment:
SPRING_APPLICATION_JSON: '{
"spring.datasource.url" : "jdbc:mysql://mysqldb:$MYSQLDB_DOCKER_PORT/$MYSQLDB_DATABASE",
"spring.datasource.username" : "$MYSQLDB_USERNAME",
"spring.datasource.password" : "$MYSQLDB_ROOT_PASSWORD",
"spring.jpa.properties.hibernate.dialect" : "org.hibernate.dialect.MySQLDialect"
}'
JAVA_TOOL_OPTIONS: "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:$DEBUG_PORT"
networks:
- bookstore-network

volumes:
mysql_data:
networks:
bookstore-network:
driver: bridge
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-docker-compose</artifactId>
</dependency>

</dependencies>

<build>
Expand Down
17 changes: 11 additions & 6 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
spring.application.name=spring
spring.datasource.url=jdbc:mysql://localhost:3306/db?serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=andriiw010107aA
spring.application.name=bookstore

spring.datasource.url=jdbc:mysql://\
localhost:${MYSQLDB_DOCKER_PORT}/${MYSQLDB_DATABASE}?serverTimezone=UTC
spring.datasource.username=${MYSQLDB_USERNAME}
spring.datasource.password=${MYSQLDB_ROOT_PASSWORD}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

spring.jpa.hibernate.ddl-auto=validate
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.jpa.show-sql=true

spring.jackson.deserialization.fail-on-unknown-properties=true
spring.config.import=optional:file:.env

spring.docker.compose.enabled=false

jwt.expiration=500000
jwt.secret=imustspendmoretimeonmateacademytillendofthe2025
jwt.expiration=${JWT_EXPIRATION}
jwt.secret=${JWT_SECRET}