Skip to content

Commit b158dbd

Browse files
fix: workflow 수정 (#172)
1 parent cd4dfbe commit b158dbd

1 file changed

Lines changed: 32 additions & 47 deletions

File tree

.github/workflows/deploy-to-dev-ec2.yml

Lines changed: 32 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: 🧾 Checkout
2222
uses: actions/checkout@v4
2323

24-
# GHCR 레포(org/repo) 소문자 정규화 → output + env 모두 세팅
24+
# GHCR 레포(org/repo) 소문자 정규화 → outputs + env
2525
- name: 🔧 Normalize image repo
2626
id: normalize
2727
run: |
@@ -107,57 +107,17 @@ jobs:
107107
docker compose version
108108
endsection
109109
110-
section "1) Stop legacy raw JAR if running (PID-safe, single shell)"
111-
bash -lc '
112-
set +e
113-
JAR_PIDS="$(pgrep -f "java .* -jar" || true)"
114-
115-
if [ -n "$JAR_PIDS" ]; then
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
143-
else
144-
echo "::notice::No raw JAR process found."
145-
fi
146-
exit 0
147-
'
148-
endsection
149-
150-
section "2) Prepare workspace"
110+
section "1) Prepare workspace"
151111
mkdir -p ~/saerok
152112
cd ~/saerok
153113
pwd
154114
endsection
155115
156-
section "3) Docker login (GHCR pull)"
116+
section "2) Docker login (GHCR pull)"
157117
echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u "${{ secrets.GHCR_USERNAME }}" --password-stdin
158118
endsection
159119
160-
section "4) Generate ${COMPOSE_FILE_REMOTE}"
120+
section "3) Generate ${COMPOSE_FILE_REMOTE}"
161121
cat > ${COMPOSE_FILE_REMOTE} <<'YAML'
162122
services:
163123
app:
@@ -199,13 +159,38 @@ jobs:
199159
docker compose -f ${COMPOSE_FILE_REMOTE} config --services || true
200160
endsection
201161
202-
section "5) Pull & Up (recreate)"
162+
section "4) Pull & Up (recreate with port-fallback)"
163+
# 1차 시도
164+
set +e
203165
docker compose -f ${COMPOSE_FILE_REMOTE} pull
204166
docker compose -f ${COMPOSE_FILE_REMOTE} up -d --force-recreate
167+
UP_RC=$?
168+
set -e
169+
170+
if [ $UP_RC -ne 0 ]; then
171+
echo "::warning::compose up failed (rc=$UP_RC). Checking port 8080..."
172+
ss -lntp || true
173+
174+
if ss -lntp | grep -q ':8080 '; then
175+
echo "::warning::Port 8080 is busy. Trying to free it."
176+
if ! command -v fuser >/dev/null 2>&1; then
177+
sudo apt-get -qq update
178+
sudo DEBIAN_FRONTEND=noninteractive apt-get -y -qq install psmisc
179+
fi
180+
sudo fuser -k 8080/tcp || true
181+
sleep 2
182+
# 2차 시도
183+
docker compose -f ${COMPOSE_FILE_REMOTE} up -d --force-recreate
184+
else
185+
echo "::error::Compose up failed and port 8080 is not busy. Aborting."
186+
exit 1
187+
fi
188+
fi
189+
205190
docker compose -f ${COMPOSE_FILE_REMOTE} ps
206191
endsection
207192
208-
section "6) Wait for health=healthy"
193+
section "5) Wait for health=healthy"
209194
set +e
210195
ATTEMPTS=40
211196
for i in $(seq 1 ${ATTEMPTS}); do
@@ -226,7 +211,7 @@ jobs:
226211
set -e
227212
endsection
228213
229-
section "7) Tail last logs"
214+
section "6) Tail last logs"
230215
docker logs --tail=200 ${{ env.CONTAINER_NAME }} || true
231216
endsection
232217

0 commit comments

Comments
 (0)