-
Notifications
You must be signed in to change notification settings - Fork 1
[infra] 개발 / 운영 서버 분리 #182
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,76 @@ | ||||||||||||||||||||||||||||||||||||||
| name: CD with Gradle and Docker | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| on: | ||||||||||||||||||||||||||||||||||||||
| push: | ||||||||||||||||||||||||||||||||||||||
| branches: | ||||||||||||||||||||||||||||||||||||||
| - 'main' | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| permissions: | ||||||||||||||||||||||||||||||||||||||
| contents: read | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||||||||||||||
| RESOURCE_PATH: src/main/resources | ||||||||||||||||||||||||||||||||||||||
| COMPOSE_PATH: /home/ec2-user/compose | ||||||||||||||||||||||||||||||||||||||
| APP_PORT: 8000 | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||||||||||||||||
| build: | ||||||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||
| - uses: actions/checkout@v4 | ||||||||||||||||||||||||||||||||||||||
| - name: ☕️ set up JDK 17 | ||||||||||||||||||||||||||||||||||||||
| uses: actions/setup-java@v3 | ||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||
| java-version: '17' | ||||||||||||||||||||||||||||||||||||||
| distribution: 'temurin' | ||||||||||||||||||||||||||||||||||||||
| server-id: github | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+22
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainGitHub 공식 액션 버전 업데이트 권장 (actionlint 지적사항 반영) actionlint가 예시: - uses: actions/setup-java@v3
+ uses: actions/setup-java@v4
@@
- uses: actions/cache@v3
+ uses: actions/cache@v4동일 변경을 dev 워크플로우에도 적용해주세요. Also applies to: 36-44 🌐 Web query: 💡 Result: GitHub Actions의 예를 들어, steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'이렇게 설정하면 Java 21이 설치되고, 이후 단계에서 해당 버전을 사용할 수 있습니다. Citations: 🌐 Web query: 💡 Result: GitHub Actions의
Citations: actions/setup-java·actions/cache를 v4로 업그레이드하고 태그 고정 적용하기 actionlint 지적사항에 따라 아래 파일들에서 확인 및 수정 위치:
예시 diff: - uses: actions/setup-java@v3
+ uses: actions/setup-java@v4 # 또는 uses: actions/setup-java@<커밋 SHA>
@@
- uses: actions/cache@v3
+ uses: actions/cache@v4 # 또는 uses: actions/cache@<커밋 SHA>
🧰 Tools🪛 actionlint (1.7.7)23-23: the runner of "actions/setup-java@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue (action) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| settings-path: ${{ github.workspace }} | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| - name: 🧾 Create application.yml from secret (base64) | ||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||
| mkdir -p ${{ env.RESOURCE_PATH }} | ||||||||||||||||||||||||||||||||||||||
| echo "${{ secrets.APPLICATION_YML_PROD }}" | base64 --decode > ${{ env.RESOURCE_PATH }}/application.yml | ||||||||||||||||||||||||||||||||||||||
| shell: bash | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| - name: 🐘 Cache Gradle dependencies | ||||||||||||||||||||||||||||||||||||||
| uses: actions/cache@v3 | ||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||
| path: | | ||||||||||||||||||||||||||||||||||||||
| ~/.gradle/caches | ||||||||||||||||||||||||||||||||||||||
| ~/.gradle/wrapper | ||||||||||||||||||||||||||||||||||||||
| key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||||||||||||||||||||||||||||||||||||||
| restore-keys: | | ||||||||||||||||||||||||||||||||||||||
| gradle-${{ runner.os }}- | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| - name: 👏🏻 grant execute permission for gradlew | ||||||||||||||||||||||||||||||||||||||
| run: chmod +x gradlew | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| - name: 🐘 build with Gradle (without test) | ||||||||||||||||||||||||||||||||||||||
| run: ./gradlew clean build -x test --stacktrace | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| - name: 🐳 Docker build & push | ||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||
| docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | ||||||||||||||||||||||||||||||||||||||
| docker build --build-arg PORT=${{env.APP_PORT}} -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE }} . | ||||||||||||||||||||||||||||||||||||||
| docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE }} | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+52
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 이미지 태그 불변성 확보(릴리즈 재현 가능성 및 혼선 방지) 현재 단일 태그(기본 latest)가 사용되어 dev/prod 간 경쟁 조건이나 롤백 어려움이 생길 수 있습니다. SHA를 포함한 불변 태그를 추가로 빌드/푸시하고, 배포에서도 해당 태그를 참조하세요. 예시: - docker build --build-arg PORT=${{env.APP_PORT}} -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE }} .
- docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE }}
+ IMAGE=${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE }}
+ TAG=${{ github.sha }}
+ docker build --build-arg PORT=${{env.APP_PORT}} -f Dockerfile \
+ -t $IMAGE:latest -t $IMAGE:$TAG .
+ docker push $IMAGE:latest
+ docker push $IMAGE:$TAG배포 스크립트(deploy.sh)에서도 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| - name: 🚀 deploy to server | ||||||||||||||||||||||||||||||||||||||
| uses: appleboy/ssh-action@master | ||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||
| host: ${{ secrets.EC2_HOST }} | ||||||||||||||||||||||||||||||||||||||
| username: ${{ secrets.EC2_USERNAME }} | ||||||||||||||||||||||||||||||||||||||
| key: ${{ secrets.EC2_KEY }} | ||||||||||||||||||||||||||||||||||||||
| port: ${{ secrets.EC2_PORT }} | ||||||||||||||||||||||||||||||||||||||
| envs: GITHUB_SHA | ||||||||||||||||||||||||||||||||||||||
| script: | | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+58
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain서드파티 액션 버전 고정 필요(@master 사용 지양)
최신 안정 버전 확인: 확인 후 예시: - uses: appleboy/ssh-action@master
+ uses: appleboy/ssh-action@<verified-latest-tag>🌐 Web query: 💡 Result: appleboy/ssh-action의 최신 안정 릴리스(Stable Release) 태그는 v1.2.2입니다[1][4].
따라서 워크플로우에서 안정 버전을 사용하시려면 아래와 같이 명시하면 됩니다. uses: appleboy/ssh-action@v1.2.2추가 참고
Citations:
서드파티 액션 버전 고정:
- uses: appleboy/ssh-action@master
+ uses: appleboy/ssh-action@v1.2.2📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| echo "🗂️ Change Directory to Compose Path" | ||||||||||||||||||||||||||||||||||||||
| cd ${{ env.COMPOSE_PATH }} | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| sudo docker ps -a | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| echo "🥳 Pulling new image" | ||||||||||||||||||||||||||||||||||||||
| sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_IMAGE }} | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| echo "🚀 Run Blue-Green Deploy Script" | ||||||||||||||||||||||||||||||||||||||
| sudo bash deploy.sh | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
이미지 일괄 삭제(--rmi all)로 불필요한 풀/다운타임 증가 가능성
docker-compose down --rmi all는 서비스 이미지까지 전부 지워 매 배포 시 풀이 강제되어 느리고, 장애 시 롤백 여지도 줄어듭니다. dangling/미사용 이미지는 마지막 prune으로 충분합니다.--rmi all제거를 권장합니다.📝 Committable suggestion
🧰 Tools
🪛 YAMLlint (1.37.1)
[error] 72-72: trailing spaces
(trailing-spaces)
🤖 Prompt for AI Agents