From fefa1bc9d01c9c3ef62f615455d6937a6e98c0b8 Mon Sep 17 00:00:00 2001 From: Bogdan <97698639+don-bigdad@users.noreply.github.com> Date: Sun, 26 Nov 2023 21:38:56 +0200 Subject: [PATCH 1/2] add docker to project --- .env.sample | 10 ++++++++++ .gitignore | 4 +++- Dockerfile | 16 ++++++++++++++++ docker-compose.yml | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 .env.sample create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..e38437d --- /dev/null +++ b/.env.sample @@ -0,0 +1,10 @@ +MYSQLDB_ROOT_PASSWORD= +MYSQLDB_DATABASE= +MYSQLDB_LOCAL_PORT=3307 +MYSQLDB_DOCKER_PORT=3306 +SPRING_LOCAL_PORT=8088 +SPRING_DOCKER_PORT=8080 +DEBUG_PORT=5005 +MYSQLDB_USER= +JWT_EXPIRATION= +JWT_SECRET= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5eac309..1d0e93b 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,6 @@ build/ !**/src/test/**/build/ ### VS Code ### -.vscode/ \ No newline at end of file +.vscode/ + +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e27b4ff --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +# Builder stage +FROM openjdk:17-jdk-slim as builder +WORKDIR application +ARG JAR_FILE=target/*.jar +COPY ${JAR_FILE} booking-app.jar +RUN java -Djarmode=layertools -jar booking-app.jar extract + +#Final stage +FROM openjdk:17-jdk-slim +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.JarLauncher"] +EXPOSE 8080 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ca39842 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,32 @@ +version: "3.8" + +services: + book-shop-db: + container_name: book-shop-db + image: mysql:8 + restart: unless-stopped + env_file: ./.env + ports: + - $MYSQLDB_LOCAL_PORT:$MYSQLDB_DOCKER_PORT + environment: + - MYSQL_ROOT_PASSWORD=$MYSQLDB_ROOT_PASSWORD + - MYSQL_DATABASE=$MYSQLDB_DATABASE + book-app: + build: . + container_name: book-app + image: book-app + restart: on-failure + depends_on: + - book-shop-db + env_file: ./.env + ports: + - $SPRING_LOCAL_PORT:$SPRING_DOCKER_PORT + - $DEBUG_PORT:$DEBUG_PORT + environment: + SPRING_APPLICATION_JSON: '{ + "spring.datasource.url" : "jdbc:mysql://book-shop-db:$MYSQLDB_DOCKER_PORT/$MYSQLDB_DATABASE?serverTimezone=UTC", + "spring.datasource.username" : "$MYSQLDB_USER", + "spring.datasource.password" : "$MYSQLDB_ROOT_PASSWORD", + "spring.datasource.driverClassName" : "com.mysql.cj.jdbc.Driver" + }' + JAVA_TOOL_OPTIONS: "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" \ No newline at end of file From 4653cf88a4084c7b478cd7f4c7f87bf32191493a Mon Sep 17 00:00:00 2001 From: Bogdan <97698639+don-bigdad@users.noreply.github.com> Date: Tue, 28 Nov 2023 17:28:05 +0200 Subject: [PATCH 2/2] add empty line --- .env.sample | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.sample b/.env.sample index e38437d..0aa9133 100644 --- a/.env.sample +++ b/.env.sample @@ -7,4 +7,4 @@ SPRING_DOCKER_PORT=8080 DEBUG_PORT=5005 MYSQLDB_USER= JWT_EXPIRATION= -JWT_SECRET= \ No newline at end of file +JWT_SECRET=