Skip to content

Commit

Permalink
Merge pull request #1 from ASAP-Lettering/chore/deploy
Browse files Browse the repository at this point in the history
chore: ecs, ecr 기반 배포 설정 추가
  • Loading branch information
tlarbals824 authored Aug 22, 2024
2 parents 545465e + 1a223a1 commit e8d88b7
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .deploy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM amazoncorretto:17-alpine-jdk

ARG TARGET_JAR=/api/build/libs/api.jar

COPY ${TARGET_JAR} /app.jar

EXPOSE 8080
ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=dev", "/app.jar"]
34 changes: 34 additions & 0 deletions .deploy/task/task-definition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"executionRoleArn": "arn:aws:iam::396608783702:role/ecsTaskExecutionRole",
"containerDefinitions": [
{
"name": "lettering_application",
"image": "public.ecr.aws/p3m3n4m8/lettering:latest",
"essential": true,
"portMappings": [
{
"hostPort": 80,
"protocol": "tcp",
"containerPort": 8080
}
],
"secrets": [
{
"valueFrom": "arn:aws:secretsmanager:ap-northeast-2:396608783702:secret:dev/mysql-vHY6zz:DB_URL::",
"name": "DB_URL"
},
{
"valueFrom": "arn:aws:secretsmanager:ap-northeast-2:396608783702:secret:dev/mysql-vHY6zz:DB_USERNAME::",
"name": "DB_USERNAME"
},
{
"valueFrom": "arn:aws:secretsmanager:ap-northeast-2:396608783702:secret:dev/mysql-vHY6zz:DB_PASSWORD::",
"name": "DB_PASSWORD"
}
]
}
],
"cpu": "512",
"memory": "768",
"family": "lettering-task"
}
98 changes: 98 additions & 0 deletions .github/workflows/ECS_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
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: task-definition.json
service: ${{ env.ECS_SERVICE_NAME }}
cluster: ${{ env.ECS_CLUSTER_NAME }}
wait-for-service-stability: true
39 changes: 39 additions & 0 deletions .github/workflows/Integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Continuous Integration

on:
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
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
29 changes: 29 additions & 0 deletions .github/workflows/Upload_ECS_Task_Definition.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Upload ECS Task Definition

on:
push:
branches:
- main
paths:
- ".deploy/task/task-definition.json"

jobs:
upload_task:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Configure AWS credentials For ECS
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: ap-northeast-2
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}

- name: Upload ECS Task Definition
run: |
cd .deploy/task
aws ecs register-task-definition --cli-input-json file://task-definition.json
13 changes: 13 additions & 0 deletions api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
spring:
config:
activate:
on-profile: dev


---


spring:
config:
activate:
on-profile: default

0 comments on commit e8d88b7

Please sign in to comment.