Merge pull request #10 from ASAP-Lettering/ASAP-69 #10
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: Deploy Application to ECS | |
on: | |
push: | |
branches: | |
main | |
jobs: | |
deploy: | |
runs-on: ubuntu-22.04 | |
env: | |
ECS_CLUSTER_NAME: Lettering_Cluster | |
ECR_REPOSITORY_NAME: lettering | |
ECS_CONTAINER_NAME: lettering_application | |
ECS_SERVICE_NAME: lettering_service | |
TASK_DEFINITION_NAME: lettering-task | |
ECR_ALIAS: p3m3n4m8 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Setup JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'corretto' | |
- name: Gradle Caching | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Grant Execute Permission For Gradlew | |
run: chmod +x gradlew | |
- name: Build With Gradle | |
run: | | |
./gradlew build | |
- name: Configure AWS credentials For ECR | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-region: us-east-1 | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} | |
- name: Login ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
with: | |
registry-type: 'public' | |
- name: Image build and push | |
id: build-image | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_ALIAS: ${{ env.ECR_ALIAS }} | |
ECR_REPOSITORY_NAME: ${{ env.ECR_REPOSITORY_NAME }} | |
TAG: ${{ github.sha }} | |
run: | | |
docker build -f ./.deploy/Dockerfile -t $ECR_REGISTRY/$ECR_ALIAS/$ECR_REPOSITORY_NAME:$TAG . | |
docker push $ECR_REGISTRY/$ECR_ALIAS/$ECR_REPOSITORY_NAME:$TAG | |
# 추후 버전 정보를 추가로 관리할 것이기 때문에 변수로 추출 | |
echo "new_image_name=$ECR_REGISTRY/$ECR_ALIAS/$ECR_REPOSITORY_NAME:$TAG" >> "$GITHUB_OUTPUT" | |
- name: Configure AWS credentials For ECS | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-region: ap-northeast-2 | |
- name: Download Task Definition Template | |
run: | | |
aws ecs describe-task-definition --task-definition ${{ env.TASK_DEFINITION_NAME }} --query taskDefinition > task-definition.json | |
- name: Replace the image name in ECS task definition | |
id: task-definition | |
uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
with: | |
task-definition: task-definition.json | |
container-name: ${{ env.ECS_CONTAINER_NAME }} | |
image: ${{ steps.build-image.outputs.new_image_name }} | |
- name: Deploy New ECS Task Definition | |
uses: aws-actions/amazon-ecs-deploy-task-definition@v2 | |
with: | |
task-definition: ${{ steps.task-definition.outputs.task-definition }} | |
service: ${{ env.ECS_SERVICE_NAME }} | |
cluster: ${{ env.ECS_CLUSTER_NAME }} | |
wait-for-service-stability: true |