Skip to content

Commit

Permalink
task : AWS ECS & RDS 를 사용한 CI/CD 구축
Browse files Browse the repository at this point in the history
  • Loading branch information
qro-story committed Sep 25, 2024
1 parent fa9af80 commit 784eaac
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 12 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ on:
env:
AWS_REGION: ap-northeast-2 # set this to your preferred AWS region, e.g. us-west-1
ECR_REPOSITORY: qro-story/mkoong # set this to your Amazon ECR repository name
ECS_SERVICE: MY_ECS_SERVICE # set this to your Amazon ECS service name
ECS_CLUSTER: MY_ECS_CLUSTER # set this to your Amazon ECS cluster name
ECS_SERVICE: mkoong-service-v1 # set this to your Amazon ECS service name
ECS_CLUSTER: mkoong-cluster # set this to your Amazon ECS cluster name
ECS_TASK_DEFINITION:
MY_ECS_TASK_DEFINITION # set this to the path to your Amazon ECS task definition
aws/task-definition.json # set this to the path to your Amazon ECS task definition
# file, e.g. .aws/task-definition.json
CONTAINER_NAME:
MY_CONTAINER_NAME # set this to the name of the container in the
app-server # 새 테스크 정의를 할 때 컨테이너 추가 시 작성하는 이름을 적는다.
# containerDefinitions section of your task definition

permissions:
Expand Down Expand Up @@ -43,17 +43,19 @@ jobs:
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} # steps.login-ecr.outputs.registry는 ecr에 로그인을 하게 되면 Amazon ECR의 레지스트리 URI를 의미하게 된다.
IMAGE_TAG: ${{ github.sha }} # commit 시에 출력되는 sha값이다.
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
# $GITHUB_OUTPUT는 GitHub Actions에서 워크플로우 단계 간에 데이터를 전달하는 데 사용되는 특별한 파일이다. 이 파일에 값을 기록하면, 해당 값은 이후 단계에서 출력 변수로 사용할 수 있다.
# image라는 이름의 출력 변수를 생성하고, 그 값으로 새로 빌드된 Docker 이미지의 URI를 설정한다. 이후 단계에서는 이 값을 다음과 같이 참조할 수 있다.
# 뒤에서 사용되는 image: ${{ steps.build-image.outputs.image }} 를 파악해보자.
- name: Fill in the new image ID in the Amazon ECS task definition
- name: Fill in the new image ID in the Amazon ECS task definition # task definition의 json을 수정하게된다.
# 주어진 task definition의 json 파일을 읽고, 새로운 이미지 ID를 포함한 새로운 task definition을 생성하는 작업을 한다.
# 여기서 이미지 ID라 함은 새롭게 구성되는 image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG 를 말한다.
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
Expand Down
104 changes: 104 additions & 0 deletions aws/task-definition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"family": "mkoong-task",
"containerDefinitions": [
{
"name": "app-server",
"image": "654654510251.dkr.ecr.ap-northeast-2.amazonaws.com/qro-story/mkoong:fa9af80f87d227b74b0f6cf6f4caf9f33fd5e1fb",
"cpu": 0,
"portMappings": [
{
"name": "app-server-3000-tcp",
"containerPort": 3000,
"hostPort": 3000,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [
{
"name": "SERVER_PORT",
"value": "3000"
},
{
"name": "DB_MYSQL_TIMEZONE",
"value": "+00:00"
},
{
"name": "JWT_ACCESS_SECRET",
"value": "JWT_ACCESS_SECRET"
},
{
"name": "JWT_REFRESH_SECRET",
"value": "JWT_REFRESH_SECRET"
},
{
"name": "JWT_PHONE_EXPIRED",
"value": "30m"
},
{
"name": "DB_MYSQL_HOST",
"value": "awseb-e-sxhnzkaqmi-stack-awsebrdsdatabase-iueg2m1qravs.c1io2sga0olo.ap-northeast-2.rds.amazonaws.com"
},
{
"name": "JWT_REFRESH_EXPIRED",
"value": "3d"
},
{
"name": "DB_MYSQL_CHARSET",
"value": "utf8mb4"
},
{
"name": "JWT_PHONE_SECRET",
"value": "JWT_PHONE_SECRET"
},
{
"name": "DB_MYSQL_USERNAME",
"value": "root"
},
{
"name": "DB_MYSQL_PASSWORD",
"value": "test1234"
},
{
"name": "DB_MYSQL_DATABASE",
"value": "mkoong"
},
{
"name": "DB_MYSQL_PORT",
"value": "3306"
},
{
"name": "JWT_ACCESS_EXPIRED",
"value": "6h"
}
],
"environmentFiles": [],
"mountPoints": [],
"volumesFrom": [],
"ulimits": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/mkoong-task",
"mode": "non-blocking",
"awslogs-create-group": "true",
"max-buffer-size": "25m",
"awslogs-region": "ap-northeast-2",
"awslogs-stream-prefix": "ecs"
},
"secretOptions": []
},
"systemControls": []
}
],
"executionRoleArn": "arn:aws:iam::654654510251:role/ecsTaskExecutionRole",
"networkMode": "awsvpc",
"requiresCompatibilities": ["FARGATE"],
"cpu": "1024",
"memory": "3072",
"runtimePlatform": {
"cpuArchitecture": "X86_64",
"operatingSystemFamily": "LINUX"
}
}
2 changes: 1 addition & 1 deletion src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
return '첫 ECS CI/CD with RDS 구축';
}
}

0 comments on commit 784eaac

Please sign in to comment.