Skip to content
Open
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
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM maven:3.8.1-openjdk-17 AS build

WORKDIR /app

COPY pom.xml /app/
COPY src /app/src

RUN mvn clean package -DskipTests

FROM openjdk:17-jdk-slim

WORKDIR /app

COPY --from=build /app/target/rihal-0.0.1-SNAPSHOT.jar /app/rihal-0.0.1-SNAPSHOT.jar

EXPOSE 8080

ENV SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3307/usersystem?useSSL=false&serverTimezone=UTC&createDatabaseIfNotExist=true&allowPublicKeyRetrieval=true
ENV SPRING_DATASOURCE_USERNAME=root
ENV SPRING_DATASOURCE_PASSWORD=root
ENV SPRING_JPA_HIBERNATE_DDL_AUTO=update
ENV SPRING_JPA_SHOW_SQL=true

ENTRYPOINT ["sh", "-c", "java -jar /app/rihal-0.0.1-SNAPSHOT.jar || (echo 'Application failed, entering sleep mode' && sleep infinity)"]

42 changes: 42 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: '3.8'

services:
mysql:
image: mysql:9.0.0
container_name: mysql-cont
ports:
- "3307:3307"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: usersystem
MYSQL_PASSWORD: root
MYSQL_TCP_PORT: 3307
volumes:
- mysql-data:/var/lib/mysql
networks:
- app-network
restart: always

spring-boot-app:
build: .
container_name: spring-boot-app
ports:
- "8080:8080"
environment:
SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3307/usersystem?useSSL=false&serverTimezone=UTC&createDatabaseIfNotExist=true&allowPublicKeyRetrieval=true
SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_PASSWORD: root
Copy link
Owner

Choose a reason for hiding this comment

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

Defining a password here might be fine, since MySQL container runs locally with dummy data. However, in a docker-compose files, the DB URL might be pointing to a cloud database and its better to pick up the password from a .env file (In any case as a best practice) so it doesn't appear on any public repo.
Here we can include a comment, telling the user to define a .env file with their choice of values and put that in .gitignore

SPRING_JPA_HIBERNATE_DDL_AUTO: update
SPRING_JPA_SHOW_SQL: "true"
depends_on:
- mysql
networks:
- app-network
restart: always

networks:
app-network:

volumes:
mysql-data: