Skip to content
Merged
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
66 changes: 66 additions & 0 deletions .github/workflows/Spring-develop-CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Spring Deplot to EC2

on:
pull_request:
types: [closed]
branches: ["develop"]

Comment on lines +3 to +7
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

PR closed 이벤트만으로는 머지 여부를 보장하지 못합니다
닫힌(PR closed) 후에도 ‘머지되지 않은 닫힘’이 포함됩니다. 머지된 경우에만 배포하려면 각 job 또는 step에 조건을 추가하세요.

if: github.event.pull_request.merged == true
🤖 Prompt for AI Agents
In .github/workflows/Spring-develop-CD.yml around lines 3 to 7, the workflow
triggers on pull_request closed events but does not ensure the PR was merged. To
fix this, add a condition to each job or step using 'if:
github.event.pull_request.merged == true' so that deployment only occurs when
the PR is merged, not just closed.

jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: application.properties 파일 설정
run: |
mkdir -p src/main/resources
mkdir -p src/test/resources
echo "${{ secrets.APPLICATION_PROPERTIES }}" > ./src/main/resources/application.properties
echo "${{ secrets.TEST_APPLICATION_PROPERTIES }}" > ./src/test/resources/application.properties

Comment on lines +24 to +30
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

echo로 secrets를 쓰면 줄바꿈·특수문자가 손실됩니다
멀티라인 secret(예: \n 포함) 은 cat <<'EOF' 구문으로 안전하게 기록하세요.

-          echo "${{ secrets.APPLICATION_PROPERTIES }}" > ./src/main/resources/application.properties
-          echo "${{ secrets.TEST_APPLICATION_PROPERTIES }}" > ./src/test/resources/application.properties
+          cat <<'EOF' > ./src/main/resources/application.properties
+${{ secrets.APPLICATION_PROPERTIES }}
+EOF
+          cat <<'EOF' > ./src/test/resources/application.properties
+${{ secrets.TEST_APPLICATION_PROPERTIES }}
+EOF
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: application.properties 파일 설정
run: |
mkdir -p src/main/resources
mkdir -p src/test/resources
echo "${{ secrets.APPLICATION_PROPERTIES }}" > ./src/main/resources/application.properties
echo "${{ secrets.TEST_APPLICATION_PROPERTIES }}" > ./src/test/resources/application.properties
- name: application.properties 파일 설정
run: |
mkdir -p src/main/resources
mkdir -p src/test/resources
cat <<'EOF' > ./src/main/resources/application.properties
${{ secrets.APPLICATION_PROPERTIES }}
EOF
cat <<'EOF' > ./src/test/resources/application.properties
${{ secrets.TEST_APPLICATION_PROPERTIES }}
EOF
🤖 Prompt for AI Agents
In .github/workflows/Spring-develop-CD.yml around lines 24 to 30, the use of
echo to write secrets to application.properties causes loss of newlines and
special characters. Replace the echo commands with a here-document syntax using
cat <<'EOF' to safely write the multiline secrets preserving formatting. This
ensures the secrets are correctly written with all special characters intact.

- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0

- name: Build with Gradle Wrapper
run: ./gradlew clean build

- name: 빌드된 파일 이름 변경하기
run: mv ./build/libs/*SNAPSHOT.jar ./cd.jar

- name: SCP로 EC2에 빌드된 파일 전송하기
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
source: cd.jar
target: /home/ubuntu/clue


deploy:
needs: build
runs-on: ubuntu-latest

steps:

- name: SSH로 EC2에 접속하기
uses: appleboy/ssh-action@v0.1.7
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
script_stop: true
script: |
cd clue
sudo fuser -k -n tcp 8080 || true
sudo nohup java -jar cd.jar > ./output.log 2>&1 &
Comment on lines +56 to +66
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

백그라운드 실행/포트 종료 로직이 취약합니다

  • sudo nohup는 working dir가 /root로 바뀌어 cd.jar를 찾지 못할 위험이 있습니다.
  • 프로세스 관리를 systemd 혹은 pm2 등으로 이관하면 재부팅·재시작 시 안정적입니다.
    최소한 다음과 같이 경로를 절대경로로 지정하세요.
-            sudo nohup java -jar cd.jar > ./output.log 2>&1 &
+            sudo nohup java -jar /home/ubuntu/clue/cd.jar > /home/ubuntu/clue/output.log 2>&1 &
🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 66-66: no new line character at the end of file

(new-line-at-end-of-file)

🤖 Prompt for AI Agents
In .github/workflows/Spring-develop-CD.yml around lines 56 to 66, the SSH action
runs the Java jar with sudo nohup which changes the working directory to /root,
causing potential failure to find cd.jar. To fix this, replace relative paths
with absolute paths for cd.jar and output.log in the script. Additionally,
consider migrating process management to systemd or pm2 for better stability on
reboot or restart.

51 changes: 0 additions & 51 deletions .github/workflows/spring-cd.yml

This file was deleted.

61 changes: 28 additions & 33 deletions .github/workflows/spring-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,37 @@ name: Spring CI

on:
push:
branches: [ "*" ]
branches: ["*"]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle

- name: Grant permission to gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build

- name: Run tests
run: ./gradlew test

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17

- name: Grant permission to gradlew
run: chmod +x gradlew

- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle

- name: Build with Gradle
run: ./gradlew build

- name: Run tests
run: ./gradlew test
Loading