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
11 changes: 11 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
MYSQL_USER
MYSQL_PASSWORD
MYSQL_ROOT_PASSWORD
MYSQL_DB
MYSQL_LOCAL_PORT
MYSQL_DOCKER_PORT
SPRING_LOCAL_PORT
SPRING_DOCKER_PORT
DEBUG_PORT
TOKEN_SECRET
TOKEN_EXPIRATION
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ build/

### VS Code ###
.vscode/

!.env.sample
.env
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM eclipse-temurin:21-jdk AS builder
WORKDIR /app
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract

FROM eclipse-temurin:17-jre-focal
WORKDIR /app
COPY --from=builder /app/dependencies/ ./
COPY --from=builder /app/spring-boot-loader/ ./
COPY --from=builder /app/snapshot-dependencies/ ./
COPY --from=builder /app/application/ ./

RUN groupadd -r bookstore && useradd -r -g bookstore bookstore
USER bookstore

EXPOSE 8080

ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "org.springframework.boot.loader.launch.JarLauncher"]
45 changes: 45 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
services:
mysqldb:
image: mysql:latest
container_name: bookstore-mysql
restart: unless-stopped
env_file: ./.env
environment:
- MYSQL_USER=$MYSQL_USER
- MYSQL_PASSWORD=$MYSQL_PASSWORD
- MYSQL_DATABASE=$MYSQL_DB
- MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD
ports:
- $MYSQL_LOCAL_PORT:$MYSQL_DOCKER_PORT
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p$$MYSQL_ROOT_PASSWORD"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s

app:
container_name: bookstore-app
depends_on:
mysqldb:
condition: service_healthy
restart: on-failure
image: bookstore-app:latest
build:
context: .
dockerfile: Dockerfile
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_DB",
"spring.datasource.username": "$MYSQL_USER",
"spring.datasource.password": "$MYSQL_PASSWORD",
"spring.datasource.driver-class-name": "com.mysql.cj.jdbc.Driver",
"spring.jpa.hibernate.ddl-auto": "validate",
"spring.jpa.open-in-view": "false",
"token.expiration": "$TOKEN_EXPIRATION",
"token.secret": "$TOKEN_SECRET"
}'
10 changes: 1 addition & 9 deletions src/main/resources/application-prod.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
spring.application.name=book-store
spring.datasource.url=jdbc:mysql://localhost:3306/mate
spring.datasource.username=root
spring.datasource.password=1111
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.show-sql=true
spring.jackson.deserialization.fail-on-unknown-properties=true
spring.jpa.open-in-view=false
token.expiration=1200000
token.secret=123very_confidential_token1234567890
springdoc.swagger-ui.path=/swagger-ui.html