Skip to content

Commit dc64b54

Browse files
committed
refactor: 오래된 이미지 삭제 후 이미지 pull하도록 변경
- 추가로 이미지는 5개 -> 2개 보관하도록 변경
1 parent 61fad78 commit dc64b54

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

.github/workflows/dev-cd.yml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
token: ${{ secrets.PACKAGE_DELETE_TOKEN }}
7777
image-names: solid-connection-dev
7878
delete-untagged: true
79-
keep-n-tags: 5
79+
keep-n-tags: 2
8080
account-type: org
8181
org-name: ${{ github.repository_owner }}
8282
cut-off: '7 days ago UTC'
@@ -123,28 +123,28 @@ jobs:
123123
export OWNER_LOWERCASE=$(echo "${{ github.repository_owner }}" | tr "[:upper:]" "[:lower:]")
124124
export IMAGE_TAG_ONLY="${{ needs.build-and-push.outputs.image_tag }}"
125125
export FULL_IMAGE_NAME="ghcr.io/${OWNER_LOWERCASE}/solid-connection-dev:${IMAGE_TAG_ONLY}"
126-
127-
# 2. GHCR 로그인 & Pull
126+
export IMAGE_NAME_BASE="ghcr.io/${OWNER_LOWERCASE}/solid-connection-dev"
127+
128+
# 2. Pull 전 정리 (디스크 공간 확보)
129+
echo "Cleaning up old tagged images (keeping last 2)..."
130+
docker images "${IMAGE_NAME_BASE}" --format "{{.Tag}}" | \
131+
sort -r | \
132+
tail -n +3 | \
133+
xargs -I {} docker rmi "${IMAGE_NAME_BASE}:{}" || true
134+
135+
echo "Pruning dangling images..."
136+
docker image prune -f
137+
138+
# 3. GHCR 로그인 & Pull
128139
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
129140
echo "Pulling new image: $FULL_IMAGE_NAME"
130141
docker pull $FULL_IMAGE_NAME
131-
132-
# 3. Spring Boot 앱 재시작
142+
143+
# 4. Spring Boot 앱 재시작
133144
echo "Restarting Docker Compose with tag: $IMAGE_TAG_ONLY"
134145
cd /home/${{ secrets.DEV_USERNAME }}/solid-connection-dev
135146
docker compose -f docker-compose.dev.yml down || true
136147
OWNER_LOWERCASE=$OWNER_LOWERCASE IMAGE_TAG=$IMAGE_TAG_ONLY docker compose -f docker-compose.dev.yml up -d
137-
138-
# 4. 정리 작업
139-
echo "Pruning dangling images..."
140-
docker image prune -f
141-
142-
echo "Cleaning up old tagged images (keeping last 5)..."
143-
IMAGE_NAME_BASE="ghcr.io/${OWNER_LOWERCASE}/solid-connection-dev"
144-
docker images "${IMAGE_NAME_BASE}" --format "{{.Tag}}" | \
145-
sort -r | \
146-
tail -n +6 | \
147-
xargs -I {} docker rmi "${IMAGE_NAME_BASE}:{}" || true
148-
148+
149149
echo "Deployment finished successfully."
150-
'
150+
'

.github/workflows/prod-cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,4 @@ jobs:
155155
# 6. 정리
156156
docker image prune -f
157157
echo "Deployment finished successfully."
158-
'
158+
'

0 commit comments

Comments
 (0)