Merge pull request #383 from sopt-makers/380-memory_Optimization #239
This file contains hidden or 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: cd-dev | |
on: | |
workflow_dispatch: | |
push: | |
branches: [ develop ] | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: ✅ Checkout | |
uses: actions/checkout@v3 | |
- name: ⚙️ Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: 17 | |
distribution: 'temurin' | |
cache: gradle | |
- name: 🔒 Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
# 🚨 NEW: ECR 이미지 삭제 단계 추가 | |
- name: 🗑️ Delete all ECR images | |
env: | |
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} | |
ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPO_DEV }} | |
run: | | |
echo "Deleting all images from ECR repository..." | |
aws ecr-public batch-delete-image \ | |
--region us-east-1 \ | |
--repository-name $ECR_REPOSITORY \ | |
--image-ids "$(aws ecr-public describe-images --region us-east-1 --repository-name $ECR_REPOSITORY --query 'imageDetails[*].{imageDigest:imageDigest}' --output json)" \ | |
|| echo "No images to delete or repository is empty" | |
- name: 🧱 Build Image and Push to ECR | |
env: | |
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} | |
AWS_ECR_REPO: ${{ secrets.AWS_ECR_REPO_DEV }} | |
run: | | |
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws | |
docker build -t $AWS_ECR_REPO --build-arg PROFILE=test . | |
docker tag $AWS_ECR_REPO:latest public.ecr.aws/$AWS_ACCOUNT_ID/$AWS_ECR_REPO:latest | |
docker push public.ecr.aws/$AWS_ACCOUNT_ID/$AWS_ECR_REPO:latest | |
deploy: | |
needs: build-and-push | |
runs-on: ubuntu-latest | |
steps: | |
- name: ✅ Checkout | |
uses: actions/checkout@v3 | |
- name: 🔒 Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: 📝 Copy Files from S3 | |
env: | |
REGION: ${{ secrets.AWS_REGION }} | |
S3_BUCKET: ${{ secrets.AWS_BUCKET_NAME }} | |
run: | | |
aws s3 cp --region $REGION \ | |
s3://$S3_BUCKET/dev/dev.env ./application.env | |
- name: 🔄 Transfer Files to Server | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.HOST_DEV }} | |
username: ec2-user | |
key: ${{ secrets.PEM_KEY_DEV }} | |
port: 22 | |
source: "application.env" | |
target: /home/ec2-user/operation/env | |
overwrite: true | |
- name: 🚀SSH command deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST_DEV }} | |
username: ec2-user | |
key: ${{ secrets.PEM_KEY_DEV }} | |
port: 22 | |
script: | | |
/home/ec2-user/operation/scripts/deploy.sh |