Skip to content

Commit 7155522

Browse files
committed
edit deploy.yml - 4
1 parent 8f505ed commit 7155522

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Deploy to Amazon ECR & EC2
33
on:
44
push:
55
branches:
6-
-main
6+
- main
77

88
env:
99
AWS_REGION: ap-northeast-2
@@ -57,33 +57,7 @@ jobs:
5757
DOCKER_RUN_ARGS: ${{ env.DOCKER_RUN_ARGS }}
5858
run: |
5959
set -euo pipefail
60-
cat > deploy.sh <<'EOF'
61-
#!/usr/bin/env bash
62-
set -euo pipefail
63-
64-
echo "[1/5] ECR 로그인"
65-
aws ecr get-login-password --region "${AWS_REGION}" \
66-
| docker login --username AWS --password-stdin "${ECR_REGISTRY}"
67-
68-
echo "[2/5] 새 이미지 Pull: ${IMAGE_URI}"
69-
docker pull "${IMAGE_URI}"
70-
71-
echo "[3/5] 기존 컨테이너 정리: ${CONTAINER_NAME}"
72-
# 동일 이름 컨테이너가 있으면 중지/삭제
73-
if docker ps -a --format '{{.Names}}' | grep -wq "${CONTAINER_NAME}"; then
74-
docker rm -f "${CONTAINER_NAME}" || true
75-
fi
76-
77-
echo "[4/5] 오래된 이미지 가비지 정리(선택)"
78-
docker image prune -f || true
79-
80-
echo "[5/5] 새 컨테이너 기동"
81-
docker run -d --name "${CONTAINER_NAME}" ${DOCKER_RUN_ARGS} "${IMAGE_URI}"
82-
83-
echo "DONE"
84-
EOF
85-
86-
COMMANDS_JSON=$(jq -Rs . < deploy.sh)
60+
COMMANDS_JSON=$(jq -Rs . < scripts/ssm-run.sh)
8761
echo "commands=[\"bash\",\"-lc\",$COMMANDS_JSON]" >> "$GITHUB_OUTPUT"
8862
8963
- name: Send SSM RunCommand to EC2 (by InstanceIds or by Tag)

scripts/ssm-run.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
echo "[1/5] ECR 로그인"
5+
aws ecr get-login-password --region "${AWS_REGION}" \
6+
| docker login --username AWS --password-stdin "${ECR_REGISTRY}"
7+
8+
echo "[2/5] 새 이미지 Pull: ${IMAGE_URI}"
9+
docker pull "${IMAGE_URI}"
10+
11+
echo "[3/5] 기존 컨테이너 정리: ${CONTAINER_NAME}"
12+
if docker ps -a --format '{{.Names}}' | grep -wq "${CONTAINER_NAME}"; then
13+
docker rm -f "${CONTAINER_NAME}" || true
14+
fi
15+
16+
echo "[4/5] 오래된 이미지 가비지 정리(선택)"
17+
docker image prune -f || true
18+
19+
echo "[5/5] 새 컨테이너 기동"
20+
docker run -d --name "${CONTAINER_NAME}" ${DOCKER_RUN_ARGS} "${IMAGE_URI}"
21+
22+
echo "DONE"

0 commit comments

Comments
 (0)