Skip to content

Commit 06e2fa0

Browse files
committed
배포테스트 2차
1 parent 0c83186 commit 06e2fa0

File tree

1 file changed

+48
-16
lines changed

1 file changed

+48
-16
lines changed

.github/workflows/deploy.yml

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ name: deploy-purchase-to-ecs
33
on:
44
push:
55
branches: [ "main" ]
6+
workflow_dispatch:
67

78
env:
89
AWS_REGION: ap-northeast-2
9-
ECR_REPOSITORY: shop-repo
10-
ECS_CLUSTER: shop-cluster
11-
ECS_SERVICE: purchase-api-service
10+
ECR_REPOSITORY: shop-purchase-api-ecr
11+
ECS_CLUSTER: shop-ecs-purchase-cluster
12+
ECS_SERVICE: shop-ecs-purchase-task-service
1213
CONTAINER_NAME: purchase
1314

1415
jobs:
@@ -21,32 +22,63 @@ jobs:
2122
steps:
2223
- uses: actions/checkout@v4
2324

24-
- uses: aws-actions/configure-aws-credentials@v4
25+
# --- 사전 진단: 시크릿/OIDC 토큰 확인 ---
26+
- name: Assert AWS_ROLE_TO_ASSUME is set
27+
run: |
28+
test -n "${{ secrets.AWS_ROLE_TO_ASSUME }}" || { echo "Missing secret: AWS_ROLE_TO_ASSUME"; exit 1; }
29+
echo "Secret is set (value hidden)"
30+
31+
- name: Check OIDC availability
32+
run: |
33+
if [ -z "${ACTIONS_ID_TOKEN_REQUEST_URL}" ]; then
34+
echo "No OIDC token available. Add 'permissions: id-token: write'."; exit 1;
35+
fi
36+
echo "OIDC token endpoint detected"
37+
38+
# --- OIDC로 AWS 자격 구성 (핵심: role-to-assume 추가) ---
39+
- name: Configure AWS credentials (OIDC)
40+
uses: aws-actions/configure-aws-credentials@v4
2541
with:
26-
# access key 사용 시
27-
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
28-
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
42+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
2943
aws-region: ${{ env.AWS_REGION }}
3044

45+
- name: Verify assumed identity
46+
run: |
47+
aws sts get-caller-identity
48+
acct=$(aws sts get-caller-identity --query Account --output text)
49+
[ "$acct" = "782683897698" ] || { echo "Assumed wrong account: $acct" && exit 1; }
50+
51+
# --- ECR 로그인 & 빌드/푸시 ---
3152
- id: login-ecr
3253
uses: aws-actions/amazon-ecr-login@v2
3354

34-
- name: Build & Push
55+
- uses: docker/setup-buildx-action@v3
56+
57+
- name: Build & Push to ECR
58+
uses: docker/build-push-action@v6
59+
with:
60+
context: .
61+
platforms: linux/amd64
62+
push: true
63+
tags: |
64+
${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ github.sha }}
65+
${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:latest
66+
67+
# --- ECS 태스크 정의 렌더 & 배포 ---
68+
- name: Set image output
69+
id: image
3570
run: |
36-
IMAGE_URI=${{ steps.login-ecr.outputs.registry }}/${ECR_REPOSITORY}:${GITHUB_SHA}
37-
docker build -t ${ECR_REPOSITORY}:${GITHUB_SHA} .
38-
docker tag ${ECR_REPOSITORY}:${GITHUB_SHA} ${IMAGE_URI}
39-
docker push ${IMAGE_URI}
40-
echo "IMAGE_URI=${IMAGE_URI}" >> $GITHUB_ENV
71+
echo "image=${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ github.sha }}" >> "$GITHUB_OUTPUT"
4172
42-
- id: render
73+
- name: Render task definition
74+
id: render
4375
uses: aws-actions/amazon-ecs-render-task-definition@v1
4476
with:
4577
task-definition: .github/ecs/task-definition.json
4678
container-name: ${{ env.CONTAINER_NAME }}
47-
image: ${{ env.IMAGE_URI }}
79+
image: ${{ steps.image.outputs.image }}
4880

49-
- name: Deploy
81+
- name: Deploy to ECS
5082
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
5183
with:
5284
task-definition: ${{ steps.render.outputs.task-definition }}

0 commit comments

Comments
 (0)