Skip to content

Merge remote-tracking branch 'origin/dev' into dev #138

Merge remote-tracking branch 'origin/dev' into dev

Merge remote-tracking branch 'origin/dev' into dev #138

Workflow file for this run

name: Main CICD
on:
push:
branches:
- dev
paths:
- 'server/**'
env:
AWS_REGION: ap-northeast-2
ECR_REPOSITORY: t3-back-mainecr
ECS_CLUSTER: t3-back-ecscluster
ECS_CONTAINER: t3-back-maincontainer
ECS_SERVICE: t3-back-ecscluster/t3-back-mainservice
ECS_TASK_DEFINITION: infra/task-definition-main.json
permissions:
contents: read
jobs:
ci-cd:
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v4
- name: AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
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: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Grant Grant Permission
run: chmod +x server/gradlew
- name: Inject secure
run: echo "${{ secrets.BE_SECURE_DEV }}" > server/src/main/resources/secure.properties
- name: Build with Gradle
run: |
cd server
./gradlew clean build
- name: Replace AWS ID
run: |
sed -i "s/{AWS_ACCOUNT_ID}/${{ secrets.AWS_ACCOUNT_ID }}/g" ${{ env.ECS_TASK_DEFINITION }}
- name: Login ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Push ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: latest
run: |
docker build --no-cache -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./server
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Image ID to ECS TASK
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.ECS_CONTAINER }}
image: ${{ steps.build-image.outputs.image }}
- name: Deploy ECS
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