-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from joon6093/main
feat : Github Actions를 이용한 AWS ECS 배포를 통한 CI/CD 구축
- Loading branch information
Showing
6 changed files
with
173 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
name: Deploy to Amazon ECS | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
types: | ||
- closed | ||
paths-ignore: | ||
- 'batch/**' # 배치 관련 코드는 배포하지 않음 | ||
|
||
env: | ||
AWS_REGION: ap-northeast-2 | ||
ECR_REPOSITORY: webti_api | ||
ECS_SERVICE: webti_api | ||
ECS_CLUSTER: webti_api | ||
ECS_TASK_FAMILY: webti_api | ||
CONTAINER_NAME: was | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
deploy: | ||
if: github.event.pull_request.merged == true | ||
name: Deploy | ||
runs-on: ubuntu-latest | ||
environment: production | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
token: ${{ secrets.ACTION_TOKEN }} | ||
|
||
- 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: ${{ env.AWS_REGION }} | ||
|
||
- 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 }} | ||
IMAGE_TAG: ${{ github.sha }} | ||
run: | | ||
# Build a docker container and | ||
# push it to ECR so that it can | ||
# be deployed to ECS. | ||
docker build --build-arg SERVICE=api -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 | ||
- name: Retrieve most recent ECS task definition JSON file | ||
id: retrieve-task-def | ||
run: | | ||
aws ecs describe-task-definition --task-definition ${{ env.ECS_TASK_FAMILY }} --query taskDefinition > task-definition.json | ||
cat task-definition.json | ||
echo "::set-output name=task-def-file::task-definition.json" | ||
- 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: ${{ steps.retrieve-task-def.outputs.task-def-file }} | ||
container-name: ${{ env.CONTAINER_NAME }} | ||
image: ${{ steps.build-image.outputs.image }} | ||
|
||
- 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: ${{ env.ECS_SERVICE }} | ||
cluster: ${{ env.ECS_CLUSTER }} | ||
wait-for-service-stability: true |
24 changes: 24 additions & 0 deletions
24
api/src/main/java/org/meotppo/webti/controller/status/StatusController.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.meotppo.webti.controller.status; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.meotppo.webti.response.ResponseBody; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import static org.meotppo.webti.response.ResponseUtil.createSuccessResponse; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/status/v1") | ||
public class StatusController { | ||
|
||
@GetMapping("/check") | ||
public ResponseEntity<ResponseBody<String>> checkStatus() { | ||
return ResponseEntity | ||
.status(HttpStatus.OK) | ||
.body(createSuccessResponse("Service is up and running")); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
spring: | ||
datasource: | ||
driver-class-name: org.postgresql.Driver | ||
url: jdbc:postgresql://${dev-db.postgres.host}:${dev-db.postgres.port}/${dev-db.postgres.name} | ||
username: ${dev-db.postgres.username} | ||
password: ${dev-db.postgres.password} | ||
|
||
jpa: | ||
properties: | ||
hibernate: | ||
format_sql: true | ||
highlight_sql: true | ||
hbm2ddl.auto: validate | ||
default_batch_fetch_size: 100 | ||
open-in-view: false | ||
show-sql: true | ||
|
||
data: | ||
mongodb: | ||
uri: mongodb+srv://${dev-db.mongo.username}:${dev-db.mongo.password}@${dev-db.mongo.host}/?retryWrites=true&w=majority&appName=${dev-db.mongo.database} | ||
database: ${dev-db.mongo.database} | ||
|
||
logging: | ||
level: | ||
org.hibernate.orm.jdbc.bind: trace | ||
# org.springframework.data.mongodb.core.MongoTemplate: debug | ||
# org.springframework.data.mongodb.core.convert: debug | ||
# org.springframework.data.mongodb.core.query: debug | ||
# org.springframework.transaction.interceptor: trace |
Submodule security
updated
from 053fa6 to 692ec5
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
spring: | ||
datasource: | ||
meta: | ||
hikari: | ||
driver-class-name: org.postgresql.Driver | ||
jdbc-url: jdbc:postgresql://${dev-db.postgres.meta-db.host}:${dev-db.postgres.meta-db.port}/${dev-db.postgres.meta-db.name} | ||
username: ${dev-db.postgres.meta-db.username} | ||
password: ${dev-db.postgres.meta-db.password} | ||
|
||
domain: | ||
hikari: | ||
driver-class-name: org.postgresql.Driver | ||
jdbc-url: jdbc:postgresql://${dev-db.postgres.domain-db.host}:${dev-db.postgres.domain-db.port}/${dev-db.postgres.domain-db.name} | ||
username: ${dev-db.postgres.domain-db.username} | ||
password: ${dev-db.postgres.domain-db.password} | ||
auto-commit: false | ||
|
||
jpa: | ||
properties: | ||
hibernate: | ||
format_sql: true | ||
highlight_sql: true | ||
hbm2ddl.auto: validate | ||
default_batch_fetch_size: 100 | ||
open-in-view: false | ||
show-sql: true | ||
|
||
data: | ||
mongodb: | ||
uri: mongodb+srv://${dev-db.mongo.username}:${dev-db.mongo.password}@${dev-db.mongo.host}/?retryWrites=true&w=majority&appName=${dev-db.mongo.database} | ||
database: ${dev-db.mongo.database} | ||
|
||
logging: | ||
level: | ||
org.hibernate.orm.jdbc.bind: trace | ||
# org.springframework.transaction.interceptor: trace |
Submodule security
updated
from 6cf4d6 to 438f5a