2121 - name : 🧾 Checkout
2222 uses : actions/checkout@v4
2323
24- # GHCR 레포(org/repo)를 소문자로 정규화
24+ # GHCR 레포(org/repo) 소문자 정규화 → output + env 모두 세팅
2525 - name : 🔧 Normalize image repo
26- run : echo "IMAGE_REPO=ghcr.io/${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
26+ id : normalize
27+ run : |
28+ echo "image_repo=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
29+ echo "IMAGE_REPO=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV"
2730
2831 - name : 🔧 Set up Docker Buildx
2932 uses : docker/setup-buildx-action@v3
3942 id : meta
4043 uses : docker/metadata-action@v5
4144 with :
42- images : ${{ env.IMAGE_REPO }}
45+ images : ${{ steps.normalize.outputs.image_repo }}
4346 tags : |
4447 type=raw,value=dev-latest
4548 type=sha,format=long,prefix=dev-,suffix=
6265 push : true
6366 tags : ${{ steps.meta.outputs.tags }}
6467 labels : ${{ steps.meta.outputs.labels }}
65- cache-from : type=registry,ref=${{ env.IMAGE_REPO }}:buildcache
66- cache-to : type=registry,ref=${{ env.IMAGE_REPO }}:buildcache,mode=max
68+ cache-from : type=registry,ref=${{ steps.normalize.outputs.image_repo }}:buildcache
69+ cache-to : type=registry,ref=${{ steps.normalize.outputs.image_repo }}:buildcache,mode=max
6770
6871 - name : ✅ Verify image pushed
6972 run : |
@@ -104,51 +107,46 @@ jobs:
104107 docker compose version
105108 endsection
106109
107- section "1) Stop legacy raw JAR if running (PID-safe)"
108- # pgrep 결과가 없어도 실패하지 않게
110+ section "1) Stop legacy raw JAR if running (PID-safe, single shell )"
111+ bash -lc '
109112 set +e
110- JAR_PIDS="$(pgrep -f 'java .* -jar' || true)"
111- set -e
112-
113+ JAR_PIDS="$(pgrep -f "java .* -jar" || true)"
114+
113115 if [ -n "$JAR_PIDS" ]; then
114- banner "Stopping old raw JAR process... PIDs: $JAR_PIDS"
115-
116- # 1) TERM으로 그레이스풀 종료 시도
117- set +e
118- for pid in $JAR_PIDS; do
119- kill -TERM "$pid" || true
120- done
121-
122- # 2) 종료 대기 (최대 20초)
123- for i in $(seq 1 20); do
124- ALIVE=""
125- for pid in $JAR_PIDS; do
126- if kill -0 "$pid" 2>/dev/null; then ALIVE="$ALIVE $pid"; fi
127- done
128- if [ -z "$ALIVE" ]; then
129- echo "All JAR PIDs exited."
130- break
131- fi
132- echo "waiting old jar... ($i) alive:$ALIVE"
133- sleep 1
134- done
135-
136- # 3) 아직 살아있으면 KILL
137- ALIVE=""
138- for pid in $JAR_PIDS; do
139- if kill -0 "$pid" 2>/dev/null; then ALIVE="$ALIVE $pid"; fi
140- done
141- if [ -n "$ALIVE" ]; then
142- echo "::warning::Force killing remaining PIDs:$ALIVE"
143- kill -KILL $ALIVE || true
144- fi
145- set -e
116+ echo "::notice::Stopping old raw JAR... PIDs: $JAR_PIDS"
117+
118+ for pid in $JAR_PIDS; do
119+ kill -TERM "$pid" 2>/dev/null || true
120+ done
121+
122+ for i in $(seq 1 20); do
123+ ALIVE=""
124+ for pid in $JAR_PIDS; do
125+ kill -0 "$pid" 2>/dev/null && ALIVE="$ALIVE $pid"
126+ done
127+ if [ -z "$ALIVE" ]; then
128+ echo "All JAR PIDs exited."
129+ break
130+ fi
131+ echo "waiting old jar... ($i) alive:$ALIVE"
132+ sleep 1
133+ done
134+
135+ ALIVE=""
136+ for pid in $JAR_PIDS; do
137+ kill -0 "$pid" 2>/dev/null && ALIVE="$ALIVE $pid"
138+ done
139+ if [ -n "$ALIVE" ]; then
140+ echo "::warning::Force killing remaining PIDs:$ALIVE"
141+ kill -KILL $ALIVE 2>/dev/null || true
142+ fi
146143 else
147- banner " No raw JAR process found."
144+ echo "::notice:: No raw JAR process found."
148145 fi
149- endsection
150-
151-
146+ exit 0
147+ '
148+ endsection
149+
152150 section "2) Prepare workspace"
153151 mkdir -p ~/saerok
154152 cd ~/saerok
@@ -163,7 +161,7 @@ jobs:
163161 cat > ${COMPOSE_FILE_REMOTE} <<'YAML'
164162 services:
165163 app:
166- image : ${{ env.IMAGE_REPO }}:dev-latest
164+ image: ${{ steps.normalize.outputs.image_repo }}:dev-latest
167165 container_name: saerok-dev
168166 restart: always
169167 ports:
@@ -198,7 +196,6 @@ jobs:
198196 start_period: 60s
199197 YAML
200198 banner "Compose file written: ${COMPOSE_FILE_REMOTE}"
201- # 비밀 유출 방지: 서비스 이름만 표시
202199 docker compose -f ${COMPOSE_FILE_REMOTE} config --services || true
203200 endsection
204201
@@ -241,7 +238,7 @@ jobs:
241238 {
242239 echo "## 🚀 Deploy Summary";
243240 echo "";
244- echo "- Image repo: \`${{ env. IMAGE_REPO }} \`";
241+ echo "- Image repo: \`$IMAGE_REPO\`";
245242 echo "- Tags pushed:";
246243 echo '${{ steps.meta.outputs.tags }}' | tr ' ' '\n' | sed 's/^/ - /';
247244 echo "";
0 commit comments