fix:backcicd.yaml 멤버모듈 테스트 #34
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
name: Backend CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- 48-Develop브랜치-푸시시-CI/CD-구현 | |
jobs: | |
build_and_deploy_member: | |
name: Build and Deploy Member Module | |
runs-on: ubuntu-latest | |
steps: | |
# 1단계: 코드 체크아웃 | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# 2단계: AWS 자격 증명 구성 | |
- 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: ap-northeast-2 | |
# 3단계: Docker Hub에 로그인 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
# 4단계: Docker 이미지 빌드 | |
- name: Build the Docker image | |
run: | | |
docker build \ | |
--build-arg MEMBER_MYSQL_DB_HOST=${{ secrets.MEMBER_MYSQL_DB_HOST }} \ | |
--build-arg MEMBER_MYSQL_DB_PORT=${{ secrets.MEMBER_MYSQL_DB_PORT }} \ | |
--build-arg MEMBER_MYSQL_DB_NAME=${{ secrets.MEMBER_MYSQL_DB_NAME }} \ | |
--build-arg MEMBER_MYSQL_DB_USERNAME=${{ secrets.MEMBER_MYSQL_DB_USERNAME }} \ | |
--build-arg MEMBER_MYSQL_DB_PASSWORD=${{ secrets.MEMBER_MYSQL_DB_PASSWORD }} \ | |
--build-arg MEMBER_MONGO_DB_USERNAME=${{ secrets.MEMBER_MONGO_DB_USERNAME }} \ | |
--build-arg MEMBER_MONGO_DB_PORT=${{ secrets.MEMBER_MONGO_DB_PORT }} \ | |
--build-arg MEMBER_MONGO_DB_DATABASE=${{ secrets.MEMBER_MONGO_DB_DATABASE }} \ | |
-f ./gitfolio-member/Dockerfile \ | |
-t aida0/gitfolio_member:test \ | |
./gitfolio-member | |
# 5단계: Docker 이미지 푸시 | |
- name: Push the Docker image | |
run: | | |
docker push aida0/gitfolio_member:test | |
# 6단계: EC2 인스턴스 ID 가져오기 | |
- name: Get EC2 Instance IDs | |
id: get_instances | |
run: | | |
INSTANCE_IDS=$(aws ec2 describe-instances \ | |
--region ap-northeast-2 \ | |
--filters 'Name=tag:Name,Values=Gitfolio BE1' 'Name=tag:Environment,Values=dev' 'Name=tag:Type,Values=ec2' \ | |
--query 'Reservations[].Instances[].InstanceId' \ | |
--output text) | |
echo "INSTANCE_IDS=$INSTANCE_IDS" | |
echo "instance_ids=$INSTANCE_IDS" >> $GITHUB_OUTPUT | |
# 7단계: AWS SSM을 통해 EC2 인스턴스에 배포 | |
- name: Deploy to EC2 instances | |
run: | | |
if [ -z "${{ steps.get_instances.outputs.instance_ids }}" ]; then | |
echo "No instance IDs found for Member module. Exiting." | |
exit 1 | |
fi | |
aws ssm send-command \ | |
--instance-ids "${{ steps.get_instances.outputs.instance_ids }}" \ | |
--document-name "AWS-RunShellScript" \ | |
--comment "Deploying Member module" \ | |
--parameters commands='cd /home/ec2-user && docker-compose down -v --rmi all && docker-compose pull && docker-compose up -d' \ | |
--timeout-seconds 600 \ | |
--region ap-northeast-2 | |
# 8단계: 명령 실행 완료 대기 (선택 사항) | |
- name: Wait for command to complete | |
run: | | |
echo "Deployment command sent. Monitoring is not implemented in this step." |