Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions .github/workflows/discord.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: Discord Notifications
# name: Discord Notifications

on:
pull_request: # pr - opened, reopened 이벤트 발생 시 discord 알림
types: [opened, reopened]

jobs:
discordNotification:
runs-on: ubuntu-latest
# on:
# pull_request: # pr - opened, reopened 이벤트 발생 시 discord 알림
# types: [opened, reopened]

steps:
- name: Discord Github Notification
uses: Aleph-Kim/discord-github-notification@v1.2.1
with:
discord-webhook-url: ${{ secrets.NEXTBOT_WEBHOOK }} # secret key에 저장한 discord webhook url
language: "korean" # 필수 X
custom: true # 필수 X
# jobs:
# discordNotification:
# runs-on: ubuntu-latest

# steps:
# - name: Discord Github Notification
# uses: Aleph-Kim/discord-github-notification@v1.2.1
# with:
# discord-webhook-url: ${{ secrets.NEXTBOT_WEBHOOK }} # secret key에 저장한 discord webhook url
# language: "korean" # 필수 X
# custom: true # 필수 X
186 changes: 93 additions & 93 deletions .github/workflows/nextjs-cicd.yaml
Original file line number Diff line number Diff line change
@@ -1,104 +1,104 @@
name: Next.js CI/CD Pipeline
# name: Next.js CI/CD Pipeline

on:
push:
branches:
- develop
# on:
# push:
# branches:
# - develop

jobs:
build_and_deploy:
runs-on: ubuntu-latest
# jobs:
# build_and_deploy:
# runs-on: ubuntu-latest

steps:
# 1단계: 코드 체크아웃-테스트용 netlify 비활성화
- name: Checkout code
uses: actions/checkout@v3
# steps:
# # 1단계: 코드 체크아웃-테스트용 netlify 비활성화
# - 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
# # 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 }}
# # 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 NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }} \
--build-arg NEXT_PUBLIC_S3_URL=${{ secrets.NEXT_PUBLIC_S3_URL }} \
--build-arg NEXT_PUBLIC_SERVICE_URL=${{ secrets.NEXT_PUBLIC_SERVICE_URL }} \
--build-arg NEXT_PUBLIC_AUTH_SERVER_URL=${{ secrets.NEXT_PUBLIC_AUTH_SERVER_URL }} \
--build-arg NEXT_PUBLIC_MEMBERS_SERVER_URL=${{ secrets.NEXT_PUBLIC_MEMBERS_SERVER_URL }} \
--build-arg NEXT_PUBLIC_RESUMES_SERVER_URL=${{ secrets.NEXT_PUBLIC_RESUMES_SERVER_URL }} \
--build-arg NEXT_PUBLIC_PAYMENTS_SERVER_URL=${{ secrets.NEXT_PUBLIC_PAYMENTS_SERVER_URL }} \
--build-arg NEXT_PUBLIC_NOTIFICATIONS_SERVER_URL=${{ secrets.NEXT_PUBLIC_NOTIFICATIONS_SERVER_URL }} \
--build-arg AUTH_SERVER_URL=${{ secrets.AUTH_SERVER_URL }} \
--build-arg MEMBERS_SERVER_URL=${{ secrets.MEMBERS_SERVER_URL }} \
--build-arg RESUMES_SERVER_URL=${{ secrets.RESUMES_SERVER_URL }} \
--build-arg NOTIFICATIONS_SERVER_URL=${{ secrets.NOTIFICATIONS_SERVER_URL }} \
--build-arg PAYMENTS_SERVER_URL=${{ secrets.PAYMENTS_SERVER_URL }} \
--build-arg SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }} \
--build-arg NEXT_PUBLIC_SENTRY_KEY=${{ secrets.NEXT_PUBLIC_SENTRY_KEY }} \
-t aida0/gitfolio_front:test .
# # 4단계: Docker 이미지 빌드
# - name: Build the Docker image
# run: |
# docker build \
# --build-arg NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }} \
# --build-arg NEXT_PUBLIC_S3_URL=${{ secrets.NEXT_PUBLIC_S3_URL }} \
# --build-arg NEXT_PUBLIC_SERVICE_URL=${{ secrets.NEXT_PUBLIC_SERVICE_URL }} \
# --build-arg NEXT_PUBLIC_AUTH_SERVER_URL=${{ secrets.NEXT_PUBLIC_AUTH_SERVER_URL }} \
# --build-arg NEXT_PUBLIC_MEMBERS_SERVER_URL=${{ secrets.NEXT_PUBLIC_MEMBERS_SERVER_URL }} \
# --build-arg NEXT_PUBLIC_RESUMES_SERVER_URL=${{ secrets.NEXT_PUBLIC_RESUMES_SERVER_URL }} \
# --build-arg NEXT_PUBLIC_PAYMENTS_SERVER_URL=${{ secrets.NEXT_PUBLIC_PAYMENTS_SERVER_URL }} \
# --build-arg NEXT_PUBLIC_NOTIFICATIONS_SERVER_URL=${{ secrets.NEXT_PUBLIC_NOTIFICATIONS_SERVER_URL }} \
# --build-arg AUTH_SERVER_URL=${{ secrets.AUTH_SERVER_URL }} \
# --build-arg MEMBERS_SERVER_URL=${{ secrets.MEMBERS_SERVER_URL }} \
# --build-arg RESUMES_SERVER_URL=${{ secrets.RESUMES_SERVER_URL }} \
# --build-arg NOTIFICATIONS_SERVER_URL=${{ secrets.NOTIFICATIONS_SERVER_URL }} \
# --build-arg PAYMENTS_SERVER_URL=${{ secrets.PAYMENTS_SERVER_URL }} \
# --build-arg SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }} \
# --build-arg NEXT_PUBLIC_SENTRY_KEY=${{ secrets.NEXT_PUBLIC_SENTRY_KEY }} \
# -t aida0/gitfolio_front:test .

# 5단계: Docker 이미지 푸시
- name: Push the Docker image
run: |
docker push aida0/gitfolio_front:test
# # 5단계: Docker 이미지 푸시
# - name: Push the Docker image
# run: |
# docker push aida0/gitfolio_front: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 Frontend"]},{"Name":"tag:Service","Values":["front"]},{"Name":"tag:Environment","Values":["dev"]},{"Name":"tag:Type","Values":["ec2"]},{"Name":"instance-state-name","Values":["running"]}]' \
--query 'Reservations[].Instances[].InstanceId' \
--output text)
echo "INSTANCE_IDS=$INSTANCE_IDS"
echo "instance_ids=$INSTANCE_IDS" >> $GITHUB_OUTPUT
# # 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 Frontend"]},{"Name":"tag:Service","Values":["front"]},{"Name":"tag:Environment","Values":["dev"]},{"Name":"tag:Type","Values":["ec2"]},{"Name":"instance-state-name","Values":["running"]}]' \
# --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
id: deploy
run: |
if [ -z "${{ steps.get_instances.outputs.instance_ids }}" ]; then
echo "No instance IDs found. Exiting."
exit 1
fi
COMMAND_OUTPUT=$(aws ssm send-command \
--instance-ids ${{ steps.get_instances.outputs.instance_ids }} \
--document-name "AWS-RunShellScript" \
--comment "Deploying new Docker image" \
--parameters '{"commands":["cd /home/ec2-user && docker-compose down -v --rmi all && docker-compose pull && docker-compose up -d"], "workingDirectory":["/home/ec2-user"]}' \
--timeout-seconds 600 \
--region ap-northeast-2)
echo "COMMAND_OUTPUT=$COMMAND_OUTPUT"
COMMAND_ID=$(echo "$COMMAND_OUTPUT" | jq -r '.Command.CommandId')
echo "COMMAND_ID=$COMMAND_ID"
echo "command_id=$COMMAND_ID" >> $GITHUB_OUTPUT
# # 7단계: AWS SSM을 통해 EC2 인스턴스에 배포
# - name: Deploy to EC2 instances
# id: deploy
# run: |
# if [ -z "${{ steps.get_instances.outputs.instance_ids }}" ]; then
# echo "No instance IDs found. Exiting."
# exit 1
# fi
# COMMAND_OUTPUT=$(aws ssm send-command \
# --instance-ids ${{ steps.get_instances.outputs.instance_ids }} \
# --document-name "AWS-RunShellScript" \
# --comment "Deploying new Docker image" \
# --parameters '{"commands":["cd /home/ec2-user && docker-compose down -v --rmi all && docker-compose pull && docker-compose up -d"], "workingDirectory":["/home/ec2-user"]}' \
# --timeout-seconds 600 \
# --region ap-northeast-2)
# echo "COMMAND_OUTPUT=$COMMAND_OUTPUT"
# COMMAND_ID=$(echo "$COMMAND_OUTPUT" | jq -r '.Command.CommandId')
# echo "COMMAND_ID=$COMMAND_ID"
# echo "command_id=$COMMAND_ID" >> $GITHUB_OUTPUT

# 8단계: 명령 실행 완료 대기
- name: Wait for command to complete
run: |
aws ssm wait command-executed \
--command-id ${{ steps.deploy.outputs.command_id }} \
--instance-id ${{ steps.get_instances.outputs.instance_ids }} \
--region ap-northeast-2
# # 8단계: 명령 실행 완료 대기
# - name: Wait for command to complete
# run: |
# aws ssm wait command-executed \
# --command-id ${{ steps.deploy.outputs.command_id }} \
# --instance-id ${{ steps.get_instances.outputs.instance_ids }} \
# --region ap-northeast-2

# 9단계: 명령 결과 확인 (선택 사항)
- name: Get command result
run: |
aws ssm get-command-invocation \
--command-id ${{ steps.deploy.outputs.command_id }} \
--instance-id ${{ steps.get_instances.outputs.instance_ids }} \
--region ap-northeast-2
# # 9단계: 명령 결과 확인 (선택 사항)
# - name: Get command result
# run: |
# aws ssm get-command-invocation \
# --command-id ${{ steps.deploy.outputs.command_id }} \
# --instance-id ${{ steps.get_instances.outputs.instance_ids }} \
# --region ap-northeast-2
Loading