Skip to content

Commit 748edc3

Browse files
committed
deploy api
1 parent 9e0809e commit 748edc3

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

.github/workflows/deploy.yml

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,52 @@
1-
name: Deploy purchase API to ECS
1+
name: deploy-purchase-to-ecs
22

33
on:
44
push:
5-
branches: ["main"]
6-
workflow_dispatch:
5+
branches: [ "main" ]
76

87
env:
9-
AWS_REGION: ${{ secrets.AWS_REGION }}
10-
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
11-
ECS_CLUSTER: ${{ secrets.ECS_CLUSTER }}
12-
ECS_SERVICE: ${{ secrets.ECS_SERVICE }}
13-
CONTAINER_NAME: ${{ secrets.CONTAINER_NAME }}
14-
IMAGE_TAG_PREFIX: purchase
8+
AWS_REGION: ap-northeast-2
9+
ECR_REPOSITORY: shop-repo
10+
ECS_CLUSTER: shop-cluster
11+
ECS_SERVICE: purchase-api-service
12+
CONTAINER_NAME: purchase
1513

1614
jobs:
1715
deploy:
1816
runs-on: ubuntu-latest
17+
permissions:
18+
id-token: write
19+
contents: read
20+
1921
steps:
2022
- uses: actions/checkout@v4
2123

22-
- name: Set IMAGE_TAG
23-
id: vars
24-
run: echo "IMAGE_TAG=${{ env.IMAGE_TAG_PREFIX }}-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
25-
26-
- name: Configure AWS credentials
27-
uses: aws-actions/configure-aws-credentials@v4
24+
- uses: aws-actions/configure-aws-credentials@v4
2825
with:
26+
# access key 사용 시
2927
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
3028
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
3129
aws-region: ${{ env.AWS_REGION }}
3230

33-
- name: Login to Amazon ECR
34-
id: login-ecr
35-
uses: aws-actions/amazon-ecr-login@v1
36-
37-
- name: Build image
38-
run: docker build -t ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ steps.vars.outputs.IMAGE_TAG }} .
31+
- id: login-ecr
32+
uses: aws-actions/amazon-ecr-login@v2
3933

40-
- name: Push image
41-
run: docker push ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ steps.vars.outputs.IMAGE_TAG }}
34+
- name: Build & Push
35+
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
4241
43-
- name: Render task definition
44-
id: render
42+
- id: render
4543
uses: aws-actions/amazon-ecs-render-task-definition@v1
4644
with:
47-
task-definition: ecs-taskdef.json
45+
task-definition: .github/ecs/task-definition.json
4846
container-name: ${{ env.CONTAINER_NAME }}
49-
image: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ steps.vars.outputs.IMAGE_TAG }}
47+
image: ${{ env.IMAGE_URI }}
5048

51-
- name: Deploy ECS task definition
49+
- name: Deploy
5250
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
5351
with:
5452
task-definition: ${{ steps.render.outputs.task-definition }}

ecs-taskdef.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
"taskRoleArn": "arn:aws:iam::077672914621:role/ecsAppTaskRole",
99
"containerDefinitions": [
1010
{
11-
"name": "purchase-api",
12-
"image": "REPLACED_BY_ACTIONS",
11+
"name": "purchase",
12+
"image": "077672914621.dkr.ecr.ap-northeast-2.amazonaws.com/shop-repo:latest",
1313
"essential": true,
14-
"portMappings": [
15-
{ "containerPort": 8082, "protocol": "tcp" }
16-
],
14+
"portMappings": [{ "containerPort": 8082, "protocol": "tcp" }],
1715
"logConfiguration": {
1816
"logDriver": "awslogs",
1917
"options": {

0 commit comments

Comments
 (0)