Skip to content

Commit

Permalink
feat: secret manager에서 yml 읽어오기 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
BaeJinho4028 committed Sep 12, 2024
1 parent d286299 commit 7202fd5
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 133 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/CD_stage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Deploy to Amazon ECS

on:
push:
branches: [ "develop" ]

env:
AWS_REGION: ap-northeast-2
ECR_REPOSITORY: oatnote
ECS_SERVICE: oatnote-service
ECS_CLUSTER: oatnote-cluster
ECS_TASK_DEFINITION: oatnote-family-revision.json
CONTAINER_NAME: oatnote-container
SECRET_NAME: stage/oatnote

permissions:
contents: read

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew

- name: Build with Gradle
run: ./gradlew build

- 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: Retrieve secrets from Secrets Manager
id: get-secret
uses: aws-actions/aws-secretsmanager-get-secret-value@v1
with:
secret-id: ${{ env.SECRET_NAME }}
region: ${{ env.AWS_REGION }}

- name: Write application.yml
run: |
echo "${{ steps.get-secret.outputs.secret }}" > ./src/main/resources/application.yml
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- 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: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_ENV
- 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: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ env.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
File renamed without changes.
75 changes: 0 additions & 75 deletions .github/workflows/aws.yml

This file was deleted.

34 changes: 0 additions & 34 deletions oatnote-family-revision.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,6 @@
"environment": [],
"mountPoints": [],
"volumesFrom": [],
"secrets": [
{
"name": "MONGODB_URI",
"valueFrom": "arn:aws:secretsmanager:ap-northeast-2:905418277583:secret:dev/oatnote-3hjwsn:MONGODB_URI::"
},
{
"name": "AI_URL",
"valueFrom": "arn:aws:secretsmanager:ap-northeast-2:905418277583:secret:dev/oatnote-3hjwsn:AI_URL::"
},
{
"name": "JWT_SECRET_KEY",
"valueFrom": "arn:aws:secretsmanager:ap-northeast-2:905418277583:secret:dev/oatnote-3hjwsn:JWT_SECRET_KEY::"
},
{
"name": "SWAGGER_SERVER_URL",
"valueFrom": "arn:aws:secretsmanager:ap-northeast-2:905418277583:secret:dev/oatnote-3hjwsn:SWAGGER_SERVER_URL::"
},
{
"name": "ALLOWED_ORIGINS_PRODUCT",
"valueFrom": "arn:aws:secretsmanager:ap-northeast-2:905418277583:secret:dev/oatnote-3hjwsn:ALLOWED_ORIGINS_PRODUCT::"
},
{
"name": "ALLOWED_ORIGINS_STAGE",
"valueFrom": "arn:aws:secretsmanager:ap-northeast-2:905418277583:secret:dev/oatnote-3hjwsn:ALLOWED_ORIGINS_STAGE::"
},
{
"name": "ALLOWED_ORIGINS_LOCAL",
"valueFrom": "arn:aws:secretsmanager:ap-northeast-2:905418277583:secret:dev/oatnote-3hjwsn:ALLOWED_ORIGINS_LOCAL::"
},
{
"name": "ALLOWED_ORIGINS_AI",
"valueFrom": "arn:aws:secretsmanager:ap-northeast-2:905418277583:secret:dev/oatnote-3hjwsn:ALLOWED_ORIGINS_AI::"
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
Expand Down
24 changes: 0 additions & 24 deletions src/main/resources/application.yml

This file was deleted.

0 comments on commit 7202fd5

Please sign in to comment.