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

docker #16

Merged
merged 7 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
9 changes: 9 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MYSQLDB_USER=user
MYSQLDB_DATABASE=db

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MYSQLDB_DATABASE=db
MYSQLDB_DATABASE=

MYSQLDB_ROOT_PASSWORD=pass
MYSQLDB_LOCAL_PORT=port
MYSQLDB_DOCKER_PORT=port

SPRING_LOCAL_PORT=port
SPRING_DOCKER_PORT=port
DEBUG_PORT=port

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MYSQLDB_ROOT_PASSWORD=pass
MYSQLDB_LOCAL_PORT=port
MYSQLDB_DOCKER_PORT=port
SPRING_LOCAL_PORT=port
SPRING_DOCKER_PORT=port
DEBUG_PORT=port
MYSQLDB_ROOT_PASSWORD=
MYSQLDB_LOCAL_PORT=
MYSQLDB_DOCKER_PORT=
SPRING_LOCAL_PORT=
SPRING_DOCKER_PORT=
DEBUG_PORT=

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ target/
*.iws
*.iml
*.ipr
.env

### NetBeans ###
/nbproject/private/
Expand Down
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Builder stage
FROM openjdk: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

# Final stage
FROM openjdk: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
EXPOSE 5005
40 changes: 40 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
services:
mysqldb:
platform: linux/arm64
image: mysql:8.0.33
restart: unless-stopped
env_file: ./.env
environment:
- MYSQL_ROOT_PASSWORD=$MYSQLDB_ROOT_PASSWORD
- MYSQL_DATABASE=$MYSQLDB_DATABASE
ports:
- $MYSQLDB_LOCAL_PORT:$MYSQLDB_DOCKER_PORT
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 30s
timeout: 30s
retries: 3

app:
depends_on:
mysqldb:
condition: service_healthy
restart: on-failure
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:$MYSQLDB_DOCKER_PORT/$MYSQLDB_DATABASE",
"spring.datasource.username" : "$MYSQLDB_USER",
"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"
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:$SPRING_LOCAL_PORT/actuator/health || exit 1"]
interval: 30s
timeout: 10s
retries: 3
4 changes: 1 addition & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
spring.application.name=BookStore
spring.datasource.url=jdbc:mysql://localhost/book_store?serverTimezone=UTC
spring.datasource.url=jdbc:mysql://localhost:3306/book_store?serverTimezone=UTC
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=pass

spring.jpa.hibernate.ddl-auto=validate
spring.jpa.show-sql=true
Expand Down
Loading