Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/ecs/taskdef.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"family": "table-now-backend-task",
"containerDefinitions": [
{
"name": "table-now-backend",
"image": "257394467546.dkr.ecr.ap-northeast-2.amazonaws.com/table-now-backend:latest",
"cpu": 0,
"portMappings": [
{
"name": "spring-boot-port",
"containerPort": 8080,
"hostPort": 8080,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"entryPoint": [
"java",
"-jar",
"/app/myapp.jar"
],
"environment": [],
"environmentFiles": [
{
"type": "s3",
"value": "arn:aws:s3:::table-now-env/prod/.env"
}
],
"mountPoints": [],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/table-now-backend-task",
"mode": "non-blocking",
"awslogs-create-group": "true",
"max-buffer-size": "25m",
"awslogs-region": "ap-northeast-2",
"awslogs-stream-prefix": "ecs"
}
},
"systemControls": []
}
],
"taskRoleArn": "arn:aws:iam::257394467546:role/ecsTaskExecutionRole",
"executionRoleArn": "arn:aws:iam::257394467546:role/ecsTaskExecutionRole",
"networkMode": "awsvpc",
"volumes": [],
"placementConstraints": [],
"requiresCompatibilities": [
"FARGATE"
],
"cpu": "1024",
"memory": "3072",
"runtimePlatform": {
"cpuArchitecture": "X86_64",
"operatingSystemFamily": "LINUX"
},
"enableFaultInjection": false
}
63 changes: 63 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Deploy to ECS

on:
push:
branches:
- main # 또는 배포 브랜치명

jobs:
deploy:
name: Build & Deploy to Amazon ECS
runs-on: ubuntu-latest

steps:
- name: Checkout source code
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Login to Amazon ECR
uses: aws-actions/amazon-ecr-login@v1

- name: Build and push Docker image to Amazon ECR
id: build-image
run: |
IMAGE_TAG=$(date +%s)
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
docker build -t ${{ secrets.ECR_REPOSITORY }}:$IMAGE_TAG .
docker tag ${{ secrets.ECR_REPOSITORY }}:$IMAGE_TAG ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.ECR_REPOSITORY }}:$IMAGE_TAG
docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.ECR_REPOSITORY }}:$IMAGE_TAG

- name: Render new ECS task definition with new image
id: render-task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: .github/ecs/taskdef.json
container-name: app-container
image: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.ECR_REPOSITORY }}:${{ env.IMAGE_TAG }}

- name: Deploy ECS service
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
cluster: ${{ secrets.ECS_CLUSTER_NAME }}
service: ${{ secrets.ECS_SERVICE_NAME }}
task-definition: ${{ steps.render-task-def.outputs.task-definition }}

- name: Notify Slack on success
if: success()
run: |
curl -X POST -H 'Content-type: application/json' \
--data '{"text":"✅ ECS 배포 성공: `${{ github.repository }}` - `${{ github.ref_name }}`"}' \
${{ secrets.SLACK_WEBHOOK_URL }}

- name: Notify Slack on failure
if: failure()
run: |
curl -X POST -H 'Content-type: application/json' \
--data '{"text":"❌ ECS 배포 실패: `${{ github.repository }}` - `${{ github.ref_name }}`"}' \
${{ secrets.SLACK_WEBHOOK_URL }}