From 7902174ecae2cc41333f61c9a6a81327f50bec3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=EC=A4=80=EC=9A=B0?= <80523328+bviz6542@users.noreply.github.com> Date: Sun, 28 Jul 2024 21:03:38 +0900 Subject: [PATCH] readme-for-app-demo-gif (#43) * feature: readme * fix: git actions rmq settings * fix: delete previos container via docker stop * feature: ApplicationStartup PostConstruct Instant * fix: build and push first * fix: docker image name * fix: gradlew build * fix: build in local * fix: remove docker build from script --- .github/workflows/deploy.yml | 12 ++++++++---- README.MD | 5 +++++ .../config/ApplicationStartup.java | 18 ++++++++++++++++++ .../controller/HealthController.java | 15 ++++++++++++--- 4 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 README.MD create mode 100644 src/main/java/com/example/swiftgathering_server/config/ApplicationStartup.java diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 717a618..0dda55d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -23,12 +23,16 @@ jobs: script: | sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} sudo docker pull ${{ secrets.DOCKER_IMAGE }}:latest + + EXISTING_CONTAINER=$(sudo docker ps --filter "publish=8080" -q) + if [ ! -z "$EXISTING_CONTAINER" ]; then + echo "Stopping and removing existing container on port 8080" + sudo docker stop $EXISTING_CONTAINER + sudo docker rm $EXISTING_CONTAINER + fi sudo docker rm -f ${{ secrets.CONTAINER_NAME }} || true + sudo docker run -d -p 8080:8080 --name ${{ secrets.CONTAINER_NAME }} \ - -e RMQ_HOST=${{ secrets.RMQ_HOST }} \ - -e RMQ_PORT=${{ secrets.RMQ_PORT }} \ - -e RMQ_USERNAME=${{ secrets.RMQ_USERNAME }} \ - -e RMQ_PASSWORD=${{ secrets.RMQ_PASSWORD }} \ -e MYSQL_URL=${{ secrets.MYSQL_URL }} \ -e MYSQL_USERNAME=${{ secrets.MYSQL_USERNAME }} \ -e MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }} \ diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..e18e23b --- /dev/null +++ b/README.MD @@ -0,0 +1,5 @@ +
+ + + two friends gathering +
\ No newline at end of file diff --git a/src/main/java/com/example/swiftgathering_server/config/ApplicationStartup.java b/src/main/java/com/example/swiftgathering_server/config/ApplicationStartup.java new file mode 100644 index 0000000..dbb293a --- /dev/null +++ b/src/main/java/com/example/swiftgathering_server/config/ApplicationStartup.java @@ -0,0 +1,18 @@ +package com.example.swiftgathering_server.config; + +import lombok.Getter; +import org.springframework.stereotype.Component; + +import jakarta.annotation.PostConstruct; +import java.time.Instant; + +@Component +public class ApplicationStartup { + @Getter + private static Instant startTime; + + @PostConstruct + public void onStartup() { + startTime = Instant.now(); + } +} diff --git a/src/main/java/com/example/swiftgathering_server/controller/HealthController.java b/src/main/java/com/example/swiftgathering_server/controller/HealthController.java index cddee5d..ad7ffff 100644 --- a/src/main/java/com/example/swiftgathering_server/controller/HealthController.java +++ b/src/main/java/com/example/swiftgathering_server/controller/HealthController.java @@ -1,15 +1,24 @@ package com.example.swiftgathering_server.controller; +import com.example.swiftgathering_server.config.ApplicationStartup; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; +import java.time.Instant; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + @Controller @RequestMapping("/health") public class HealthController { @GetMapping public ResponseEntity