Skip to content

refactor: 오래된 이미지 삭제 후 이미지 pull하도록 변경#653

Merged
whqtker merged 1 commit intosolid-connection:developfrom
whqtker:fix/652-modify-docker-image-managing-process
Feb 14, 2026
Merged

refactor: 오래된 이미지 삭제 후 이미지 pull하도록 변경#653
whqtker merged 1 commit intosolid-connection:developfrom
whqtker:fix/652-modify-docker-image-managing-process

Conversation

@whqtker
Copy link
Member

@whqtker whqtker commented Feb 14, 2026

관련 이슈

작업 내용

기존에는 도커 이미지를 pull한 후, 오래된 이미지를 사용하기에 이후 deploy 시 오래된 이미지로 인해 디스크 용량이 부족해지는 경우 pull을 받지 못해 배포가 실패하는 상황이 있었습니다.

이에 deploy 전 오래된 이미지를 삭제하고 pull하도록 프로세스 순서를 변경하였습니다.

추가로 기존에는 이미지를 5개 유지하고 있었는데, 현재 실행하는 이미지 + 롤백용 이미지 총 2개만 유지해도 된다고 판단하여, 추가 수정했습니다.

특이 사항

리뷰 요구사항 (선택)

@whqtker whqtker self-assigned this Feb 14, 2026
@whqtker whqtker added the 버그 Something isn't working label Feb 14, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 14, 2026

Walkthrough

  1. dev-cd.yml 변경: GHCR 이미지 보존을 5개에서 2개로 줄이고, 배포 전에 오래된 태그 삭제 및 댕글링 이미지 프룬(사전 정리) 과정을 추가하여 도커 로그인·풀·업 이전에 정리 흐름을 재배치했습니다.
  2. dev-cd.yml 추가 수정: 배포 후 정리 블록을 제거하고 Spring Boot 재시작을 풀 직후로 조정했으며, 관련 출력 메시지와 변수(IMAGE_NAME_BASE 등)를 정리했습니다.
  3. prod-cd.yml 포맷팅: SSH heredoc의 후행 개행 처리만 조정했으며 실행 동작은 변경되지 않았습니다.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • wibaek
  • JAEHEE25
  • lsy1307
  • sukangpunch
  • Gyuhyeok99
🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목은 작업 내용의 핵심 변경사항인 '오래된 이미지 삭제 후 이미지 pull하도록 변경'을 명확하게 요약하고 있습니다.
Description check ✅ Passed PR 설명이 템플릿 구조를 따르고 있으며, 관련 이슈, 작업 내용이 충분히 기재되어 있습니다.
Linked Issues check ✅ Passed 배포 시 디스크 용량 부족으로 인한 이미지 pull 실패 방지 요구사항 [#652]에 대해, 코드 변경이 이를 충분히 충족합니다.
Out of Scope Changes check ✅ Passed 모든 변경사항이 #652 요구사항(이미지 정리 순서 변경, 유지 이미지 수 축소)과 연관되어 있으며, 범위를 벗어난 변경은 없습니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into develop

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
.github/workflows/dev-cd.yml (2)

128-136: Pull 전 정리 로직이 잘 구성되어 있습니다. 다만, 엣지 케이스 하나를 확인해 주세요.

  1. sort -rYYYYMMDD-HHMMSS 형식 태그에 대해 사전순 = 시간순이므로 정확하게 동작합니다.
  2. tail -n +3으로 최신 2개를 제외하고, || true로 실행 중인 컨테이너가 사용하는 이미지 삭제 실패를 안전하게 무시합니다.
  3. docker image prune -f로 댕글링 이미지까지 정리하여 디스크 공간 확보가 이루어집니다.

한 가지 참고 사항: 현재 정리 시점(Lines 128-136)에서는 기존 컨테이너가 아직 실행 중(docker compose down은 Line 146)이므로, 실행 중인 이미지는 docker rmi가 실패합니다. || true 덕분에 워크플로우는 중단되지 않지만, 실질적으로 유지되는 이미지 수가 의도한 2개보다 많을 수 있습니다. 현재 동작에 문제는 없지만, 이 점을 인지하고 계시면 좋겠습니다.

💡 (선택) 더 확실한 정리를 원한다면 down 후 정리하는 방안

컨테이너를 먼저 내린 뒤 정리하면 실행 중 이미지도 확실히 삭제할 수 있습니다. 다만, 새 이미지 pull 실패 시 롤백할 컨테이너가 없어지는 트레이드오프가 있으므로 현재 방식도 합리적입니다.

-            # 2. Pull 전 정리 (디스크 공간 확보)
-            echo "Cleaning up old tagged images (keeping last 2)..."
-            docker images "${IMAGE_NAME_BASE}" --format "{{.Tag}}" | \
-            sort -r | \
-            tail -n +3 | \
-            xargs -I {} docker rmi "${IMAGE_NAME_BASE}:{}" || true
-
-            echo "Pruning dangling images..."
-            docker image prune -f
-
-            # 3. GHCR 로그인 & Pull
+            # 2. GHCR 로그인
             echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
+
+            # 3. 기존 컨테이너 중지 & 정리 & Pull
+            cd /home/${{ secrets.DEV_USERNAME }}/solid-connection-dev
+            docker compose -f docker-compose.dev.yml down || true
+
+            echo "Cleaning up old tagged images (keeping last 2)..."
+            docker images "${IMAGE_NAME_BASE}" --format "{{.Tag}}" | \
+            sort -r | \
+            tail -n +3 | \
+            xargs -I {} docker rmi "${IMAGE_NAME_BASE}:{}" || true
+            docker image prune -f
+
             echo "Pulling new image: $FULL_IMAGE_NAME"
             docker pull $FULL_IMAGE_NAME
+
+            # 4. Spring Boot 앱 시작
-            # 4. Spring Boot 앱 재시작
-            echo "Restarting Docker Compose with tag: $IMAGE_TAG_ONLY"
-            cd /home/${{ secrets.DEV_USERNAME }}/solid-connection-dev
-            docker compose -f docker-compose.dev.yml down || true
+            echo "Starting Docker Compose with tag: $IMAGE_TAG_ONLY"
             OWNER_LOWERCASE=$OWNER_LOWERCASE IMAGE_TAG=$IMAGE_TAG_ONLY docker compose -f docker-compose.dev.yml up -d

130-133: docker images 출력에 <none> 태그가 포함될 수 있는 점을 방어해 주세요.

docker images "${IMAGE_NAME_BASE}" --format "{{.Tag}}" 결과에 태그가 없는 이미지가 <none>으로 출력될 수 있습니다. 이 경우 docker rmi "${IMAGE_NAME_BASE}:<none>"이 실행되어 불필요한 에러가 발생합니다. || true로 인해 실패하지는 않지만, grep으로 필터링하면 더 깔끔합니다.

🔧 `` 태그 필터링 추가
             docker images "${IMAGE_NAME_BASE}" --format "{{.Tag}}" | \
+            grep -v '<none>' | \
             sort -r | \
             tail -n +3 | \
             xargs -I {} docker rmi "${IMAGE_NAME_BASE}:{}" || true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @.github/workflows/dev-cd.yml:
- Around line 148-150: The SSH command string in the "Run deployment on server"
step is missing its closing single quote, leaving the SSH heredoc/unquoted
string unclosed (you can spot the block that begins with a single quote and ends
near the echo "Deployment finished successfully."); fix by adding the missing
trailing single quote to close that SSH command string in the dev-cd.yml deploy
step (ensure the closing quote mirrors the opening quote used), then validate
the YAML by checking quotes are balanced for the deploy SSH block and that
indentation/pipe/quote usage remains correct so the workflow parses and the SSH
command runs.

- 추가로 이미지는 5개 -> 2개 보관하도록 변경
@whqtker whqtker force-pushed the fix/652-modify-docker-image-managing-process branch from ed37b46 to dc64b54 Compare February 14, 2026 07:48
@whqtker whqtker merged commit 6e9ee44 into solid-connection:develop Feb 14, 2026
1 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

버그 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: 서버 용량 부족으로 인한 도커 이미지 다운로드 실패

1 participant