Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] feat: 무중단 배포 구축, 헬스체크 API 추가 #683

Merged
merged 9 commits into from
Oct 22, 2024
44 changes: 4 additions & 40 deletions .github/workflows/backend-cd-workflow-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: deploy

on:
push:
branches: ["develop"]
branches: [ "develop" ]
paths:
- "backend/**"

Expand All @@ -20,12 +20,6 @@ jobs:
java-version: "17"
distribution: "corretto"

# - name: Setup Gradle
# uses: gradle/actions/setup-gradle@v3
# with:
# gradle-version: 8.1.1


- name: create-json
uses: jsdaniell/create-json@1.1.2
with:
Expand All @@ -41,12 +35,6 @@ jobs:
working-directory: ./backend
run: ./gradlew build

# - name: Upload build artifact
# uses: actions/upload-artifact@v3
# with:
# name: friendogly-be-develop-jar
# path: ./backend/build/libs/friendogly-0.0.1-SNAPSHOT.jar

deploy:
needs: build
runs-on: self-hosted-dev
Expand All @@ -55,31 +43,7 @@ jobs:
run: |
sudo chown -R ubuntu:ubuntu /home/ubuntu/actions-runner/_work/2024-friendogly

# - name: Download build artifact
# uses: actions/download-artifact@v3
# with:
# name: friendogly-be-develop-jar
# path: ./backend/build/libs

- name: Find Java Application PID And Kill PID
id: find_pid
run: |
sudo pgrep -f friendogly-0.0.1-SNAPSHOT.jar | xargs sudo kill -9 | true

- name: Check if room-esc server is running on port 8080 after stop
run: |
PID=$(lsof -t -i:8080 || true)
if [ -n "$PID" ]; then
echo "Server is still running with PID: $PID"
exit 1
else
echo "Server successfully stopped."
fi

- name: Start server
- name: Deploy
run: |
cd backend/build/libs
echo "File creation time(KR-09:00):"
ls -l --time=ctime friendogly-0.0.1-SNAPSHOT.jar
sudo nohup java -jar friendogly-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev --jwt.secret-key=${{ secrets.JWT_SECRET_KEY }} --jwt.access-expiration-time=${{ secrets.JWT_ACCESS_EXPIRATION_TIME }} --jwt.refresh-expiration-time=${{ secrets.JWT_REFRESH_EXPIRATION_TIME }} --kakao.admin-key=${{ secrets.KAKAO_ADMIN_KEY }} --spring.datasource.username=${{ secrets.H2_CONSOLE_USERNAME }} --spring.datasource.password=${{ secrets.H2_CONSOLE_PASSWORD }} --spring.h2.console.path=${{ secrets.H2_CONSOLE_ENDPOINT }} &
echo "start backend server"
sudo chmod +x /home/ubuntu/deploy/deploy.sh
sudo /home/ubuntu/deploy/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.happy.friendogly.healthcheck;

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
@RequestMapping("/health-check")
public class HealthCheckController {

private final Environment environment;

public HealthCheckController(Environment environment) {
this.environment = environment;
}

@GetMapping("/port")
public String port() {
return environment.getProperty("local.server.port");
}
}
17 changes: 1 addition & 16 deletions backend/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,14 @@ jwt:
kakao:
admin-key: ${KAKAO_ADMIN_KEY}

management:
endpoint:
metrics:
enabled: true
prometheus:
enabled: true

endpoints:
web:
exposure:
include: "*"

server:
port: 8081

file:
firebase:
path: firebase-friendogly-private-key.json

spring:
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:file:/home/ubuntu/h2_test_data
url: jdbc:h2:file:/home/ubuntu/h2_test_data;AUTO_SERVER=true
Comment on lines -37 to +22
Copy link
Contributor

Choose a reason for hiding this comment

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

예리했따

username: ${H2_CONSOLE_USERNAME}
password: ${H2_CONSOLE_PASSWORD}
h2:
Expand Down
Loading