eu2525 is testing out GitHub Actions 🚀 #17
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy Dittodining-Server to ECS | |
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 | |
# Github Actsion가 Trigger 되는 조건 | |
on: | |
push: | |
#Test용으로 해당 브랜치에서 바뀐 게 있으면 Deploy 하게끔 진행 | |
branches: | |
- feat/cd-pipeline-with-github-actions | |
jobs: | |
deploy: | |
name: Deploy to ECS | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
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: ap-northeast-2 | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Build, tag, and push image to Amazon ECR | |
id: build-image | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: dittodining | |
IMAGE_TAG: ${{ github.sha }} | |
run: | | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" | |
- name: Fill in the new image ID in the Amazon ECS task definition | |
id: task-def | |
uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
with: | |
task-definition: task-definition.json | |
container-name: dittodining | |
image: ${{ steps.build-image.outputs.image }} | |
- name: Save task definition output to a file | |
run: echo "${{ steps.task-def.outputs.task-definition }}" | jq . > task-definition-updated.json | |
- name: Register Task Definition with ECS | |
run: aws ecs register-task-definition --cli-input-json file://task-definition-updated.json | |
# - name: Register Task Definition with ECS | |
# run: | | |
# aws ecs register-task-definition \ | |
# --cli-input-json '${{ steps.task-def.outputs.task-definition }}' | |
# 아래 명령어를 실행하면 ECS Cluster에 EC2 Instance에 Service로 올라가려고 함. 근데 기존 꺼랑 충돌나서 계속 Pending 인 상태만 유지 | |
# Task Definition을 AWS ECS에 정식으로 등록하려면 반드시 작업을 끝내고 결과를 ECS 서비스에 적용해야 합니다. | |
# 그런데 주석 처리만 하면 그 결과가 AWS ECS에 반영되지 않습니다. | |
# - name: Deploy Amazon ECS task definition | |
# uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | |
# with: | |
# task-definition: ${{ steps.task-def.outputs.task-definition }} | |
# service: dittodining | |
# cluster: dittodining | |
# wait-for-service-stability: true |