Skip to content
Merged
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
23 changes: 18 additions & 5 deletions .github/workflows/oracle_server_cd_develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,33 @@ jobs:
needs: build

steps:
# oracle ssh 접속 후 배포
- name: Update Container on VM
- name: Deploy to Oracle VM
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.ORACLE_INSTANCE_DEV_IP }}
username: ${{ secrets.ORACLE_INSTANCE_USER }}
key: ${{ secrets.ORACLE_INSTANCE_DEV_PRIVATE_KEY }}
port: ${{ secrets.ORACLE_INSTANCE_DEV_PORT }}
# 타임아웃 설정 (이미지 pull 시간이 길어질 경우 대비)
timeout: 120s
script: |
docker pull ${{ secrets.DOCKER_IMAGE_DEV }}:latest
# 1. 사용할 이미지 태그를 변수로 지정 (latest가 아닌 github.sha 사용)
# github.sha는 빌드 잡에서 생성한 태그와 동일한 값입니다.
TARGET_IMAGE="${{ secrets.DOCKER_IMAGE_DEV }}:${{ github.sha }}"

echo "Deploying target image: $TARGET_IMAGE"

# 2. 명시된 버전의 이미지를 Pull (latest가 아니므로 캐시 문제 없음)
docker pull $TARGET_IMAGE
Comment on lines +104 to +105
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

docker pull 실패 시 스크립트가 중단되지 않아 잘못된 이미지로 배포될 수 있습니다.

docker pull이 실패해도 스크립트가 계속 실행되어 deploy.sh가 존재하지 않거나 이전 버전의 이미지를 사용할 수 있습니다. 스크립트 상단에 set -e를 추가하거나 명시적 에러 처리를 적용해야 합니다.

🛠️ `set -e` 또는 명시적 에러 처리 추가
          script: |
+           set -e
            # 1. 사용할 이미지 태그를 변수로 지정 (latest가 아닌 github.sha 사용)
            # github.sha는 빌드 잡에서 생성한 태그와 동일한 값입니다.
            TARGET_IMAGE="${{ secrets.DOCKER_IMAGE_DEV }}:${{ github.sha }}"

            echo "Deploying target image: $TARGET_IMAGE"

            # 2. 명시된 버전의 이미지를 Pull (latest가 아니므로 캐시 문제 없음)
            docker pull $TARGET_IMAGE
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/oracle_server_cd_develop.yml around lines 104 - 105, The
workflow currently runs the command `docker pull $TARGET_IMAGE` without failing
the job on error; update the script so a failed `docker pull $TARGET_IMAGE`
aborts the run — either add `set -e` near the top of the shell step or add
explicit error handling immediately after `docker pull $TARGET_IMAGE` (e.g.,
check the exit status and `exit 1` if non-zero) to prevent continuing to steps
that expect a valid image or `deploy.sh`.


# 3. 환경 변수 설정
export USERNAME=${{ secrets.ORACLE_INSTANCE_USER }}
export DOCKER_APP_IMAGE=${{ secrets.DOCKER_IMAGE_DEV }}:latest
export DOCKER_APP_IMAGE=$TARGET_IMAGE

# 4. 배포 스크립트 실행
# 주의: deploy.sh 내부에서 'docker run ... $DOCKER_APP_IMAGE'를 사용하도록 작성되어 있어야 합니다.
sudo chmod +x /home/${{ secrets.ORACLE_INSTANCE_USER }}/deploy.sh
sudo -E /home/${{ secrets.ORACLE_INSTANCE_USER }}/deploy.sh

docker image prune -af
# 5. 불필요한 이미지 정리 (공간 확보)
docker image prune -f
Comment on lines +116 to +117
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 18, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

docker image prune -f만으로는 SHA 태그 이미지가 정리되지 않아 디스크가 점진적으로 고갈됩니다.

-f(기본)는 dangling 이미지(태그 없음)만 제거합니다. 이번 PR에서 각 배포마다 고유한 SHA 태그(DOCKER_IMAGE_DEV:${{ github.sha }})가 붙은 이미지가 생성되는데, 이 이미지는 dangling 상태가 아니므로 -f만으로는 삭제되지 않습니다. 배포가 반복될수록 구 버전 SHA 이미지가 서버에 무한 누적되어 결국 디스크 부족으로 장애가 발생할 수 있습니다.

이전 코드의 docker image prune -af(사용 중이지 않은 모든 이미지 제거)로 복원하거나, 현재 배포된 이미지를 제외한 구 버전 이미지를 명시적으로 제거하는 방식을 사용해야 합니다.

🛠️ 구 버전 이미지 정리 방법

방법 1: 사용 중이지 않은 모든 이미지 제거 (deploy.sh가 컨테이너를 정상 구동한 뒤 실행되는 경우 안전)

-            # 5. 불필요한 이미지 정리 (공간 확보)
-            docker image prune -f
+            # 5. 불필요한 이미지 정리 (공간 확보)
+            # 현재 실행 중인 컨테이너가 사용하는 이미지는 제거되지 않음
+            docker image prune -af

방법 2: 해당 리포지토리의 구 버전 이미지만 선택적으로 제거

-            # 5. 불필요한 이미지 정리 (공간 확보)
-            docker image prune -f
+            # 5. 현재 배포 이미지를 제외한 구 버전 이미지 제거
+            docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' \
+              | grep "^${{ secrets.DOCKER_IMAGE_DEV }}:" \
+              | grep -v "$TARGET_IMAGE" \
+              | awk '{print $2}' \
+              | xargs -r docker rmi -f || true
📝 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
# 5. 불필요한 이미지 정리 (공간 확보)
docker image prune -f
# 5. 불필요한 이미지 정리 (공간 확보)
# 현재 실행 중인 컨테이너가 사용하는 이미지는 제거되지 않음
docker image prune -af
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/oracle_server_cd_develop.yml around lines 116 - 117, The
workflow currently runs "docker image prune -f" which only removes dangling
images and will not clean up SHA-tagged images like DOCKER_IMAGE_DEV:${{
github.sha }}; update this step to either run "docker image prune -af" to remove
all unused images after a successful deploy or replace it with a selective
cleanup that lists and removes old images for the same repository while
preserving the currently deployed tag (DOCKER_IMAGE_DEV:${{ github.sha }}),
ensuring you reference the existing docker image prune invocation when making
the change.

Copy link
Contributor

Choose a reason for hiding this comment

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

요건 필요할 수 있겠네요

Copy link
Contributor

Choose a reason for hiding this comment

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

@lepitaaar, 네, 맞습니다! SHA 태그를 사용하는 방식으로 변경하면서 이미지 정리 전략도 함께 조정해야 합니다.

어떤 방식을 선호하시나요?

옵션 1: docker image prune -af 사용 (간단하고 안전)

  • 현재 실행 중인 컨테이너가 사용하는 이미지는 자동으로 보호됨
  • 다른 프로젝트/이미지가 같은 서버에 있다면 해당 이미지도 정리될 수 있음

옵션 2: 선택적 정리 (더 정밀한 제어)

  • 현재 프로젝트의 구 버전 SHA 이미지만 정리
  • 다른 프로젝트/이미지에 영향 없음
  • 스크립트가 약간 복잡해짐

어떤 방식으로 진행하시겠습니까? 원하시는 방식을 알려주시면 코드 변경을 준비해드리겠습니다! 🚀

Loading