Skip to content

Commit 22aaecc

Browse files
committed
배포테스트 5차
1 parent 5c1cfe7 commit 22aaecc

File tree

1 file changed

+88
-38
lines changed

1 file changed

+88
-38
lines changed
Lines changed: 88 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,88 @@
1-
{
2-
"family": "purchase-api-task",
3-
"networkMode": "awsvpc",
4-
"requiresCompatibilities": ["FARGATE"],
5-
"cpu": "512",
6-
"memory": "1024",
7-
"executionRoleArn": "arn:aws:iam::782683897698:role/ecsTaskExecutionRole",
8-
"containerDefinitions": [
9-
{
10-
"name": "purchase-api",
11-
"image": "782683897698.dkr.ecr.ap-northeast-2.amazonaws.com/shop-purchase-api-ecr:latest",
12-
"essential": true,
13-
"portMappings": [
14-
{ "containerPort": 8082, "protocol": "tcp" }
15-
],
16-
"environment": [
17-
{ "name": "SPRING_PROFILES_ACTIVE", "value": "container" },
18-
{ "name": "APP_CORS_ALLOWED_ORIGINS", "value": "https://d9gv73ip2rojg.cloudfront.net,http://localhost:3000,http://localhost:5173" },
19-
{ "name": "SERVER_PORT", "value": "8082" },
20-
{ "name": "TZ", "value": "Asia/Seoul" }
21-
],
22-
"secrets": [
23-
{ "name": "DB_URL", "valueFrom": "/nextshop/purchase/db/url" },
24-
{ "name": "DB_USERNAME", "valueFrom": "/nextshop/purchase/db/username" },
25-
{ "name": "DB_PASSWORD", "valueFrom": "/nextshop/purchase/db/password" },
26-
{ "name": "JWT_SECRET", "valueFrom": "/nextshop/user/jwt_secret" }
27-
],
28-
"logConfiguration": {
29-
"logDriver": "awslogs",
30-
"options": {
31-
"awslogs-group": "/ecs/purchase-api",
32-
"awslogs-region": "ap-northeast-2",
33-
"awslogs-stream-prefix": "ecs"
34-
}
35-
}
36-
}
37-
]
38-
}
1+
name: deploy-purchase-to-ecs
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
workflow_dispatch:
7+
8+
env:
9+
AWS_REGION: ap-northeast-2
10+
ECR_REPOSITORY: shop-purchase-api-ecr
11+
ECS_CLUSTER: shop-ecs-purchase-cluster
12+
ECS_SERVICE: shop-ecs-purchase-task-service
13+
CONTAINER_NAME: purchase-api
14+
15+
jobs:
16+
deploy:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
id-token: write
20+
contents: read
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
# 사전 점검
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 자격 구성
39+
- name: Configure AWS credentials (OIDC)
40+
uses: aws-actions/configure-aws-credentials@v4
41+
with:
42+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
43+
aws-region: ${{ env.AWS_REGION }}
44+
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 로그인 + 빌드/푸시
52+
- id: login-ecr
53+
uses: aws-actions/amazon-ecr-login@v2
54+
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.ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ github.sha }}
65+
${{ steps.ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:latest
66+
67+
# 태스크 정의 렌더 & 배포
68+
- name: Set image output
69+
id: image
70+
run: |
71+
echo "image=${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ github.sha }}" >> "$GITHUB_OUTPUT"
72+
73+
- name: Render task definition
74+
id: render
75+
uses: aws-actions/amazon-ecs-render-task-definition@v1
76+
with:
77+
task-definition: .github/ecs/task-definition.json
78+
container-name: ${{ env.CONTAINER_NAME }}
79+
image: ${{ steps.image.outputs.image }}
80+
81+
- name: Deploy to ECS
82+
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
83+
with:
84+
task-definition: ${{ steps.render.outputs.task-definition }}
85+
service: ${{ env.ECS_SERVICE }}
86+
cluster: ${{ env.ECS_CLUSTER }}
87+
wait-for-service-stability: true
88+

0 commit comments

Comments
 (0)