[Feat/80] matching-quit socket event 제대로 작동하는지 확인하기 #61
Workflow file for this run
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: Node.js CICD with Docker and EC2 | |
on: | |
pull_request: | |
types: [closed] | |
workflow_dispatch: # 수동 실행 가능하도록 | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
# # .env 파일 생성 | |
# - name: Create .env file | |
# run: | | |
# touch .env.production | |
# echo "PORT=3000" >> .env.production | |
# echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env.production | |
# echo "SOCKETIO_URL=https://socket.gamegoo.co.kr:3000/socket.io/socket.io.js" >> .env.production | |
# echo "API_SERVER_URL=https://api.gamegoo.co.kr" >> .env.production | |
# echo "NODE_SERVER_URL=https://socket.gamegoo.co.kr" >> .env.production | |
# cat .env.production | |
# - name: Verify .env.production file | |
# run: cat .env.production | |
- name: Install dependencies | |
run: npm install | |
docker: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
# Docker 이미지 빌드 | |
- name: Build Docker Image | |
run: docker build -t rimi3226/gamegoo-socket:${{ github.sha }} . | |
# DockerHub 로그인 | |
- name: DockerHub Login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PW }} | |
# DockerHub에 이미지 푸시 | |
- name: Push Docker Image | |
run: docker push rimi3226/gamegoo-socket:${{ github.sha }} | |
deploy-to-ec2: | |
needs: docker | |
runs-on: ubuntu-latest | |
steps: | |
# GitHub IP 가져오기 | |
- name: Get GitHub IP | |
id: ip | |
run: echo "ipv4=$(curl -s https://api.ipify.org)" >> $GITHUB_ENV | |
# AWS 자격증명 구성 - AWS 접근 권한 취득(IAM) | |
- name: Configure 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: ap-northeast-2 | |
# AWS에 GitHub IP 추가 | |
- name: Add GitHub IP to AWS | |
run: | | |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ env.ipv4 }}/32 | |
# # .env.production 파일 복사 | |
# - name: Copy .env.production file to EC2 | |
# uses: appleboy/scp-action@master | |
# with: | |
# host: ${{ secrets.EC2_HOST }} | |
# username: ${{ secrets.EC2_USERNAME }} | |
# key: ${{ secrets.EC2_PEM_KEY }} | |
# port: ${{ secrets.EC2_SSH_PORT }} | |
# source: ".env.production" | |
# target: "./home/ec2-user/.env.production" | |
# AWS EC2 서버 연결 및 Docker 명령어 실행 | |
- name: Deploy to EC2 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_PEM_KEY }} | |
port: ${{ secrets.EC2_SSH_PORT }} | |
script: | | |
echo "Pulling new Docker image..." | |
sudo docker pull rimi3226/gamegoo-socket:${{ github.sha }} | |
echo "Stopping existing Docker container..." | |
sudo docker stop gamegoo_socket || true | |
echo "Removing existing Docker container..." | |
sudo docker rm gamegoo_socket || true | |
echo "Running new Docker container..." | |
sudo docker run -d -p 3000:3000 \ | |
-e PORT=3000 \ | |
-e JWT_SECRET=${{ secrets.JWT_SECRET }} \ | |
-e SOCKETIO_URL=https://socket.gamegoo.co.kr:3000/socket.io/socket.io.js \ | |
-e API_SERVER_URL=https://api.gamegoo.co.kr \ | |
-e NODE_SERVER_URL=https://socket.gamegoo.co.kr \ | |
--name gamegoo_socket rimi3226/gamegoo-socket:${{ github.sha }} | |
# AWS 보안 그룹에서 GitHub IP 제거 | |
- name: Remove IP from Security Group | |
run: | | |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ env.ipv4 }}/32 |