fix: 변경된 로드밸런서 반영 테스트 2 #96
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_builder: | |
name: Build and Push Builder Image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- 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 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build and push builder image | |
run: | | |
docker build \ | |
--build-arg REDIRECT_ONBOARDING_URL=${{ secrets.REDIRECT_ONBOARDING_URL }} \ | |
--build-arg REDIRECT_MAIN_URL=${{ secrets.REDIRECT_MAIN_URL }} \ | |
--build-arg MEMBER_SERVER_URL=${{ secrets.MEMBER_SERVER_URL }} \ | |
--build-arg PAYMENT_SERVER_URL=${{ secrets.PAYMENT_SERVER_URL }} \ | |
--build-arg NOTIFICATION_SERVER_URL=${{ secrets.NOTIFICATION_SERVER_URL }} \ | |
--build-arg AI_SERVER_URL=${{ secrets.AI_SERVER_URL }} \ | |
--build-arg PAYMENT_SUCCESS_REDIRECT_URL=${{ secrets.PAYMENT_SUCCESS_REDIRECT_URL }} \ | |
--build-arg MEMBER_GRPC_PORT=${{ secrets.MEMBER_GRPC_PORT }} \ | |
--build-arg AUTH_SERVER_PORT=${{ secrets.AUTH_SERVER_PORT }} \ | |
--build-arg MEMBER_SERVER_PORT=${{ secrets.MEMBER_SERVER_PORT }} \ | |
--build-arg RESUME_SERVER_PORT=${{ secrets.RESUME_SERVER_PORT }} \ | |
--build-arg PAYMENT_SERVER_PORT=${{ secrets.PAYMENT_SERVER_PORT }} \ | |
--build-arg NOTIFICATION_SERVER_PORT=${{ secrets.NOTIFICATION_SERVER_PORT }} \ | |
--build-arg CHAT_SERVER_PORT=${{ secrets.CHAT_SERVER_PORT }} \ | |
--build-arg GH_CLIENT_ID=${{ secrets.GH_CLIENT_ID }} \ | |
--build-arg GH_CLIENT_SECRET=${{ secrets.GH_CLIENT_SECRET }} \ | |
--build-arg GH_REDIRECT_URI=${{ secrets.GH_REDIRECT_URI }} \ | |
--build-arg GH_API_TOKEN=${{ secrets.GH_API_TOKEN }} \ | |
--build-arg JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }} \ | |
--build-arg ACCESS_TOKEN_EXPIRY=${{ secrets.ACCESS_TOKEN_EXPIRY }} \ | |
--build-arg REFRESH_TOKEN_EXPIRY=${{ secrets.REFRESH_TOKEN_EXPIRY }} \ | |
--build-arg AUTH_REDIS_HOST=${{ secrets.AUTH_REDIS_HOST }} \ | |
--build-arg AUTH_REDIS_PORT=${{ secrets.AUTH_REDIS_PORT }} \ | |
--build-arg RESUME_REDIS_HOST=${{ secrets.RESUME_REDIS_HOST }} \ | |
--build-arg RESUME_REDIS_PORT=${{ secrets.RESUME_REDIS_PORT }} \ | |
--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_PASSWORD=${{ secrets.MEMBER_MYSQL_DB_PASSWORD }} \ | |
--build-arg MEMBER_MYSQL_DB_USERNAME=${{ secrets.MEMBER_MYSQL_DB_USERNAME }} \ | |
--build-arg LIKE_MYSQL_DB_HOST=${{ secrets.LIKE_MYSQL_DB_HOST }} \ | |
--build-arg LIKE_MYSQL_DB_PORT=${{ secrets.LIKE_MYSQL_DB_PORT }} \ | |
--build-arg LIKE_MYSQL_DB_NAME=${{ secrets.LIKE_MYSQL_DB_NAME }} \ | |
--build-arg LIKE_MYSQL_DB_PASSWORD=${{ secrets.LIKE_MYSQL_DB_PASSWORD }} \ | |
--build-arg LIKE_MYSQL_DB_USERNAME=${{ secrets.LIKE_MYSQL_DB_USERNAME }} \ | |
--build-arg PAYMENT_MYSQL_DB_HOST=${{ secrets.PAYMENT_MYSQL_DB_HOST }} \ | |
--build-arg PAYMENT_MYSQL_DB_PORT=${{ secrets.PAYMENT_MYSQL_DB_PORT }} \ | |
--build-arg PAYMENT_MYSQL_DB_NAME=${{ secrets.PAYMENT_MYSQL_DB_NAME }} \ | |
--build-arg PAYMENT_MYSQL_DB_PASSWORD=${{ secrets.PAYMENT_MYSQL_DB_PASSWORD }} \ | |
--build-arg PAYMENT_MYSQL_DB_USERNAME=${{ secrets.PAYMENT_MYSQL_DB_USERNAME }} \ | |
--build-arg NOTIFICATION_MYSQL_DB_HOST=${{ secrets.NOTIFICATION_MYSQL_DB_HOST }} \ | |
--build-arg NOTIFICATION_MYSQL_DB_PORT=${{ secrets.NOTIFICATION_MYSQL_DB_PORT }} \ | |
--build-arg NOTIFICATION_MYSQL_DB_NAME=${{ secrets.NOTIFICATION_MYSQL_DB_NAME }} \ | |
--build-arg NOTIFICATION_MYSQL_DB_PASSWORD=${{ secrets.NOTIFICATION_MYSQL_DB_PASSWORD }} \ | |
--build-arg NOTIFICATION_MYSQL_DB_USERNAME=${{ secrets.NOTIFICATION_MYSQL_DB_USERNAME }} \ | |
--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 }} \ | |
--build-arg RESUME_MONGO_DB_USERNAME=${{ secrets.RESUME_MONGO_DB_USERNAME }} \ | |
--build-arg RESUME_MONGO_DB_PORT=${{ secrets.RESUME_MONGO_DB_PORT }} \ | |
--build-arg RESUME_MONGO_DB_DATABASE=${{ secrets.RESUME_MONGO_DB_DATABASE }} \ | |
--build-arg CHAT_MONGO_DB_USERNAME=${{ secrets.CHAT_MONGO_DB_USERNAME }} \ | |
--build-arg CHAT_MONGO_DB_PORT=${{ secrets.CHAT_MONGO_DB_PORT }} \ | |
--build-arg CHAT_MONGO_DB_DATABASE=${{ secrets.CHAT_MONGO_DB_DATABASE }} \ | |
--build-arg S3_ACCESS_KEY=${{ secrets.S3_ACCESS_KEY }} \ | |
--build-arg S3_SECRET_KEY=${{ secrets.S3_SECRET_KEY }} \ | |
--build-arg S3_URL_PREFIX=${{ secrets.S3_URL_PREFIX }} \ | |
--build-arg KAKAO_API_URL=${{ secrets.KAKAO_API_URL }} \ | |
--build-arg KAKAOPAY_SECRET_KEY=${{ secrets.KAKAOPAY_SECRET_KEY }} \ | |
--build-arg KAFKA_HOST1=${{ secrets.KAFKA_HOST1 }} \ | |
--build-arg KAFKA_PORT1=${{ secrets.KAFKA_PORT1 }} \ | |
--build-arg KAFKA_BROKER_ID=${{ secrets.KAFKA_BROKER_ID }} \ | |
--build-arg KAFKA_ZOOKEEPER_CONNECT=${{ secrets.KAFKA_ZOOKEEPER_CONNECT }} \ | |
--build-arg KAFKA_LISTENER_DOCKER=${{ secrets.KAFKA_LISTENER_DOCKER }} \ | |
--build-arg KAFKA_LISTENER_EXTERNAL=${{ secrets.KAFKA_LISTENER_EXTERNAL }} \ | |
--build-arg KAFKA_ADVERTISED_LISTENER_DOCKER=${{ secrets.KAFKA_ADVERTISED_LISTENER_DOCKER }} \ | |
--build-arg KAFKA_ADVERTISED_LISTENER_EXTERNAL=${{ secrets.KAFKA_ADVERTISED_LISTENER_EXTERNAL }} \ | |
--build-arg KAFKA_INTER_BROKER_LISTENER_NAME=${{ secrets.KAFKA_INTER_BROKER_LISTENER_NAME }} \ | |
--build-arg KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=${{ secrets.KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR }} \ | |
-f dockerfile \ | |
-t aida0/gitfolio_builder:backup \ | |
--platform linux/amd64 \ | |
. | |
docker push aida0/gitfolio_builder:backup | |
build_and_deploy: | |
needs: build_builder # 빌더가 실행되고 나서 실행 | |
name: Build and Deploy Modules | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- module: auth | |
dockerfile_path: ./gitfolio-auth/dockerfile | |
build_context: ./gitfolio-auth | |
# image_name: aida0/gitfolio_auth:test | |
image_name: aida0/gitfolio_auth:backup | |
instance_index: '1' | |
- module: member | |
dockerfile_path: ./gitfolio-member/dockerfile | |
build_context: ./gitfolio-member | |
# image_name: aida0/gitfolio_member:test | |
image_name: aida0/gitfolio_member:backup | |
instance_index: '1' | |
- module: payment | |
dockerfile_path: ./gitfolio-payment/dockerfile | |
build_context: ./gitfolio-payment | |
# image_name: aida0/gitfolio_payment:test | |
image_name: aida0/gitfolio_payment:backup | |
instance_index: '2' | |
- module: resume | |
dockerfile_path: ./gitfolio-resume/dockerfile | |
build_context: ./gitfolio-resume | |
# image_name: aida0/gitfolio_resume:test | |
image_name: aida0/gitfolio_resume:backup | |
instance_index: '2' | |
- module: notification | |
dockerfile_path: ./gitfolio-notification/dockerfile | |
build_context: ./gitfolio-notification | |
# image_name: aida0/gitfolio_notification:test | |
image_name: aida0/gitfolio_notification:backup | |
instance_index: '3' | |
- module: chat | |
dockerfile_path: ./gitfolio-chat/dockerfile | |
build_context: ./gitfolio-chat | |
# image_name: aida0/gitfolio_chat:test | |
image_name: aida0/gitfolio_chat:backup | |
instance_index: '4' | |
# '48-Develop브랜치')의 코드를 GitHub Actions 실행 환경으로 복사 | |
# 그동안 localhost 8080 에 떳었던 이유는 develop 브랜치가 아닌 내 브랜치의 코드를 가져와서 그랬음 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- 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 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Build the Docker image | |
run: | | |
docker build \ | |
-f ${{ matrix.dockerfile_path }} \ | |
-t ${{ matrix.image_name }} \ | |
${{ matrix.build_context }} | |
- name: Push the Docker image | |
run: | | |
docker push ${{ matrix.image_name }} | |
- name: Get EC2 Instance IDs | |
id: get_instances | |
run: | | |
INSTANCE_IDS=$(aws ec2 describe-instances \ | |
--region ap-northeast-2 \ | |
--filters 'Name=tag:Service,Values=back' \ | |
'Name=tag:Index,Values=${{ matrix.instance_index }}' \ | |
'Name=tag:Environment,Values=dev' \ | |
'Name=instance-state-name,Values=running' \ | |
'Name=tag:Type,Values=ec2' \ | |
--query 'Reservations[].Instances[].InstanceId' \ | |
--output text) | |
echo "INSTANCE_IDS=$INSTANCE_IDS" | |
echo "instance_ids=$INSTANCE_IDS" >> $GITHUB_OUTPUT | |
# - name: Update .env file on EC2 instances | |
# run: | | |
# aws ssm send-command \ | |
# --instance-ids "${{ steps.get_instances.outputs.instance_ids }}" \ | |
# --document-name "AWS-RunShellScript" \ | |
# --comment "Updating .env for ${{ matrix.module }} module" \ | |
# --parameters commands=" | |
# cat <<EOF > /home/ec2-user/.env | |
# REDIRECT_ONBOARDING_URL=${{ secrets.REDIRECT_ONBOARDING_URL }} | |
# REDIRECT_MAIN_URL=${{ secrets.REDIRECT_MAIN_URL }} | |
# MEMBER_SERVER_URL=${{ secrets.MEMBER_SERVER_URL }} | |
# PAYMENT_SERVER_URL=${{ secrets.PAYMENT_SERVER_URL }} | |
# AI_SERVER_URL=${{ secrets.AI_SERVER_URL }} | |
# MEMBER_GRPC_PORT=${{ secrets.MEMBER_GRPC_PORT }} | |
# AUTH_SERVER_PORT=${{ secrets.AUTH_SERVER_PORT }} | |
# MEMBER_SERVER_PORT=${{ secrets.MEMBER_SERVER_PORT }} | |
# RESUME_SERVER_PORT=${{ secrets.RESUME_SERVER_PORT }} | |
# PAYMENT_SERVER_PORT=${{ secrets.PAYMENT_SERVER_PORT }} | |
# NOTIFICATION_SERVER_PORT=${{ secrets.NOTIFICATION_SERVER_PORT }} | |
# CHAT_SERVER_PORT=${{ secrets.CHAT_SERVER_PORT }} | |
# GH_CLIENT_ID=${{ secrets.GH_CLIENT_ID }} | |
# GH_CLIENT_SECRET=${{ secrets.GH_CLIENT_SECRET }} | |
# GH_REDIRECT_URI=${{ secrets.GH_REDIRECT_URI }} | |
# GH_API_TOKEN=${{ secrets.GH_API_TOKEN }} | |
# JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }} | |
# ACCESS_TOKEN_EXPIRY=${{ secrets.ACCESS_TOKEN_EXPIRY }} | |
# REFRESH_TOKEN_EXPIRY=${{ secrets.REFRESH_TOKEN_EXPIRY }} | |
# AUTH_REDIS_HOST=${{ secrets.AUTH_REDIS_HOST }} | |
# AUTH_REDIS_PORT=${{ secrets.AUTH_REDIS_PORT }} | |
# RESUME_REDIS_HOST=${{ secrets.RESUME_REDIS_HOST }} | |
# RESUME_REDIS_PORT=${{ secrets.RESUME_REDIS_PORT }} | |
# MEMBER_MYSQL_DB_HOST=${{ secrets.MEMBER_MYSQL_DB_HOST }} | |
# MEMBER_MYSQL_DB_PORT=${{ secrets.MEMBER_MYSQL_DB_PORT }} | |
# MEMBER_MYSQL_DB_NAME=${{ secrets.MEMBER_MYSQL_DB_NAME }} | |
# MEMBER_MYSQL_DB_PASSWORD=${{ secrets.MEMBER_MYSQL_DB_PASSWORD }} | |
# MEMBER_MYSQL_DB_USERNAME=${{ secrets.MEMBER_MYSQL_DB_USERNAME }} | |
# LIKE_MYSQL_DB_HOST=${{ secrets.LIKE_MYSQL_DB_HOST }} | |
# LIKE_MYSQL_DB_PORT=${{ secrets.LIKE_MYSQL_DB_PORT }} | |
# LIKE_MYSQL_DB_NAME=${{ secrets.LIKE_MYSQL_DB_NAME }} | |
# LIKE_MYSQL_DB_PASSWORD=${{ secrets.LIKE_MYSQL_DB_PASSWORD }} | |
# LIKE_MYSQL_DB_USERNAME=${{ secrets.LIKE_MYSQL_DB_USERNAME }} | |
# PAYMENT_MYSQL_DB_HOST=${{ secrets.PAYMENT_MYSQL_DB_HOST }} | |
# PAYMENT_MYSQL_DB_PORT=${{ secrets.PAYMENT_MYSQL_DB_PORT }} | |
# PAYMENT_MYSQL_DB_NAME=${{ secrets.PAYMENT_MYSQL_DB_NAME }} | |
# PAYMENT_MYSQL_DB_PASSWORD=${{ secrets.PAYMENT_MYSQL_DB_PASSWORD }} | |
# PAYMENT_MYSQL_DB_USERNAME=${{ secrets.PAYMENT_MYSQL_DB_USERNAME }} | |
# NOTIFICATION_MYSQL_DB_HOST=${{ secrets.NOTIFICATION_MYSQL_DB_HOST }} | |
# NOTIFICATION_MYSQL_DB_PORT=${{ secrets.NOTIFICATION_MYSQL_DB_PORT }} | |
# NOTIFICATION_MYSQL_DB_NAME=${{ secrets.NOTIFICATION_MYSQL_DB_NAME }} | |
# NOTIFICATION_MYSQL_DB_PASSWORD=${{ secrets.NOTIFICATION_MYSQL_DB_PASSWORD }} | |
# NOTIFICATION_MYSQL_DB_USERNAME=${{ secrets.NOTIFICATION_MYSQL_DB_USERNAME }} | |
# MEMBER_MONGO_DB_HOST=${{ secrets.MEMBER_MONGO_DB_HOST }} | |
# MEMBER_MONGO_DB_PORT=${{ secrets.MEMBER_MONGO_DB_PORT }} | |
# MEMBER_MONGO_DB_DATABASE=${{ secrets.MEMBER_MONGO_DB_DATABASE }} | |
# MEMBER_MONGO_DB_USERNAME=${{ secrets.MEMBER_MONGO_DB_USERNAME }} | |
# MEMBER_MONGO_DB_PASSWORD=${{ secrets.MEMBER_MONGO_DB_PASSWORD }} | |
# RESUME_MONGO_DB_PORT=${{ secrets.RESUME_MONGO_DB_PORT }} | |
# RESUME_MONGO_DB_DATABASE=${{ secrets.RESUME_MONGO_DB_DATABASE }} | |
# RESUME_MONGO_DB_USERNAME=${{ secrets.RESUME_MONGO_DB_USERNAME }} | |
# RESUME_MONGO_DB_PASSWORD=${{ secrets.RESUME_MONGO_DB_PASSWORD }} | |
# CHAT_MONGO_DB_HOST=${{ secrets.CHAT_MONGO_DB_HOST }} | |
# CHAT_MONGO_DB_PORT=${{ secrets.CHAT_MONGO_DB_PORT }} | |
# CHAT_MONGO_DB_DATABASE=${{ secrets.CHAT_MONGO_DB_DATABASE }} | |
# CHAT_MONGO_DB_USERNAME=${{ secrets.CHAT_MONGO_DB_USERNAME }} | |
# CHAT_MONGO_DB_PASSWORD=${{ secrets.CHAT_MONGO_DB_PASSWORD }} | |
# S3_ACCESS_KEY=${{ secrets.S3_ACCESS_KEY }} | |
# S3_SECRET_KEY=${{ secrets.S3_SECRET_KEY }} | |
# S3_URL_PREFIX=${{ secrets.S3_URL_PREFIX }} | |
# KAKAO_API_URL=${{ secrets.KAKAO_API_URL }} | |
# KAKAOPAY_SECRET_KEY=${{ secrets.KAKAOPAY_SECRET_KEY }} | |
# KAFKA_HOST1=${{ secrets.KAFKA_HOST1 }} | |
# KAFKA_PORT1=${{ secrets.KAFKA_PORT1 }} | |
# NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }} | |
# NEXT_PUBLIC_S3_URL=${{ secrets.NEXT_PUBLIC_S3_URL }} | |
# AUTH_SERVER_URL=${{ secrets.AUTH_SERVER_URL }} | |
# MEMBERS_SERVER_URL=${{ secrets.MEMBERS_SERVER_URL }} | |
# RESUMES_SERVER_URL=${{ secrets.RESUMES_SERVER_URL }} | |
# NOTIFICATIONS_SERVER_URL=${{ secrets.NOTIFICATIONS_SERVER_URL }} | |
# EOF | |
# " \ | |
# --timeout-seconds 600 \ | |
# --region ap-northeast-2 | |
- name: Deploy to EC2 instances | |
run: | | |
if [ -z "${{ steps.get_instances.outputs.instance_ids }}" ]; then | |
echo "No instance IDs found for ${{ matrix.module }} module. Exiting." | |
exit 1 | |
fi | |
aws ssm send-command \ | |
--instance-ids "${{ steps.get_instances.outputs.instance_ids }}" \ | |
--document-name "AWS-RunShellScript" \ | |
--comment "Deploying ${{ matrix.module }} 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 | |
- name: Wait for command to complete | |
run: | | |
echo "Deployment command sent for ${{ matrix.module }} module." |