From 70baa8af1591786b0b31a7b519faf5e86d867e2a Mon Sep 17 00:00:00 2001 From: sungjiwoon Date: Thu, 8 Feb 2024 01:12:50 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20docker=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 17 ++++++++-------- Dockerfile | 5 ++++- build.gradle | 1 + .../config/properties/RedisProperties.java | 2 +- .../global/healthcheck/CheckController.java | 20 +++++++++++++++++++ 5 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/catchroom/chat/global/healthcheck/CheckController.java diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index eb1f450..76d7730 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -28,6 +28,8 @@ jobs: mkdir -p src/main/resources echo "${{ secrets.APPLICATION_YML }}" > src/main/resources/application.yml cat ./src/main/resources/application.yml + echo "${{ secrets.DOCKER-COMPOSE }}" > docker-compose.yml + cat docker-compose.yml - name: Run chmod to make gradlew executable run: chmod +x ./gradlew @@ -39,8 +41,6 @@ jobs: run: | docker login -u ${{ secrets.DOCKER_ID }} -p ${{ secrets.DOCKER_PWD }} docker buildx build --push --platform linux/amd64 -t ${{ secrets.DOCKER_IMAGE_NAME }} . -# docker build -t ${{ secrets.DOCKER_IMAGE_NAME }} . -# docker push ${{ secrets.DOCKER_IMAGE_NAME }} - name: Deploy uses: appleboy/ssh-action@master @@ -49,10 +49,11 @@ jobs: username: ${{ secrets.USER_NAME }} key: ${{ secrets.PRIVATE_KEY }} script: | - sudo docker image prune -af + sudo docker stop prod1 + sudo docker stop prod2 sudo docker pull ${{ secrets.DOCKER_IMAGE_NAME }} - sudo docker stop chat-server-1 - sudo docker run -d --rm --name chat-server-1 -p 8081:8080 ${{ secrets.DOCKER_IMAGE_NAME }} - sleep 10 - sudo docker stop chat-server-2 - sudo docker run -d --rm --name chat-server-2 -p 8082:8080 ${{ secrets.DOCKER_IMAGE_NAME }} + docker-compose up -d + sudo docker image prune -af +# sleep 10 +# sudo docker stop chat-server-2 +# sudo docker run -d --rm --name chat-server-2 -p 8082:8080 ${{ secrets.DOCKER_IMAGE_NAME }} diff --git a/Dockerfile b/Dockerfile index 060c615..28bec70 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,7 @@ FROM openjdk:17-jdk + +ARG PROFILES ARG JAR_FILE=build/libs/*.jar + COPY ${JAR_FILE} app.jar -ENTRYPOINT ["java", "-Dspring.profiles.active=docker", "-jar", "app.jar"] \ No newline at end of file +ENTRYPOINT ["java", "-Dspring.profiles.active=${PROFILES}", "-jar", "app.jar"] \ No newline at end of file diff --git a/build.gradle b/build.gradle index cb35655..06bc497 100644 --- a/build.gradle +++ b/build.gradle @@ -52,6 +52,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-websocket' implementation 'org.springframework.boot:spring-boot-starter-freemarker' implementation 'org.springframework.boot:spring-boot-devtools' + implementation "org.springframework.boot:spring-boot-starter-actuator" //redis implementation 'org.springframework.boot:spring-boot-starter-data-redis' diff --git a/src/main/java/com/catchroom/chat/global/config/properties/RedisProperties.java b/src/main/java/com/catchroom/chat/global/config/properties/RedisProperties.java index 4281ed0..0b1bfc8 100644 --- a/src/main/java/com/catchroom/chat/global/config/properties/RedisProperties.java +++ b/src/main/java/com/catchroom/chat/global/config/properties/RedisProperties.java @@ -10,6 +10,6 @@ public class RedisProperties { private String host; private int port; - private String password; +// private String password; } diff --git a/src/main/java/com/catchroom/chat/global/healthcheck/CheckController.java b/src/main/java/com/catchroom/chat/global/healthcheck/CheckController.java new file mode 100644 index 0000000..aaa9353 --- /dev/null +++ b/src/main/java/com/catchroom/chat/global/healthcheck/CheckController.java @@ -0,0 +1,20 @@ +package com.catchroom.chat.global.healthcheck; + +import java.util.Arrays; +import lombok.RequiredArgsConstructor; +import org.springframework.core.env.Environment; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/utils") +public class CheckController { + private final Environment env; + + @GetMapping("/profile") + public String getProfile() { + return Arrays.stream(env.getActiveProfiles()).findFirst().orElse(""); + } +}