Skip to content

๐Ÿ‘ท [Ci] timezone ๊ด€๋ จ ์„ค์ • ์ถ”๊ฐ€ #3

๐Ÿ‘ท [Ci] timezone ๊ด€๋ จ ์„ค์ • ์ถ”๊ฐ€

๐Ÿ‘ท [Ci] timezone ๊ด€๋ จ ์„ค์ • ์ถ”๊ฐ€ #3

Workflow file for this run

name: Node.js CICD with Docker and EC2
on:
pull_request:
types: [closed]
branches:
- develop
push:
branches:
- cicd/113
workflow_dispatch: # ์ˆ˜๋™ ์‹คํ–‰ ๊ฐ€๋Šฅํ•˜๋„๋ก
jobs:
build-and-deploy:
runs-on: ubuntu-latest
env:
JWT_SECRET: ${{ secrets.JWT_SECRET }}
SOCKETIO_URL: ${{ secrets.SOCKETIO_URL }}
API_SERVER_URL: ${{ secrets.API_SERVER_URL }}
NODE_SERVER_URL: ${{ secrets.NODE_SERVER_URL }}
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
steps:
# 1) GitHub checkout
- name: Checkout repository
uses: actions/checkout@v4
# 2) Node.js ํ™˜๊ฒฝ ์„ค์ •
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16
# 3) npm install
- name: Install dependencies
run: npm install
# 4) Docker Buildx ์„ค์ •
- name: Docker Buildx setup
uses: docker/setup-buildx-action@v3
# 5) Docker Hub ๋กœ๊ทธ์ธ
- name: Docker Hub login
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_TOKEN }}
# 6) Docker ์ด๋ฏธ์ง€ ๋นŒ๋“œ & ํ‘ธ์‹œ
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ env.DOCKERHUB_USERNAME }}/gamegoo-socket:${{ github.sha }}
platforms: linux/amd64
build-args: |
JWT_SECRET=${{ env.JWT_SECRET }}
SOCKETIO_URL=${{ env.SOCKETIO_URL }}
API_SERVER_URL=${{ env.API_SERVER_URL }}
NODE_SERVER_URL=${{ env.NODE_SERVER_URL }}
# 7) SSH๋กœ EC2 ์ ‘์†ํ•˜์—ฌ Docker ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰
- name: Deploy to EC2
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }} # EC2 ํผ๋ธ”๋ฆญ IP
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }} # SSH Private Key
port: 22 # SSH ํฌํŠธ (๊ธฐ๋ณธ 22)
script_stop: true # ์Šคํฌ๋ฆฝํŠธ ์‹คํŒจ ์‹œ ์ค‘๋‹จ
script: |
echo "Stopping existing container..."
docker stop gamegoo_socket || true
echo "Removing existing container..."
docker rm gamegoo_socket || true
echo "Pulling new Docker image..."
docker pull ${{ env.DOCKERHUB_USERNAME }}/gamegoo-socket:${{ github.sha }}
echo "Running new Docker container..."
docker run -d -p 3000:3000 \
--name gamegoo_socket \
-e JWT_SECRET=${{ env.JWT_SECRET }} \
-e SOCKETIO_URL=${{ env.SOCKETIO_URL }} \
-e API_SERVER_URL=${{ env.API_SERVER_URL }} \
-e NODE_SERVER_URL=${{ env.NODE_SERVER_URL }} \
${{ env.DOCKERHUB_USERNAME }}/gamegoo-socket:${{ github.sha }}
# ์‹คํŒจ ์‹œ ๋””์Šค์ฝ”๋“œ์— ์•Œ๋ฆผ ๋ณด๋‚ด๊ธฐ
- name: ๋ฐฐํฌ ์‹คํŒจ ์‹œ ๋””์Šค์ฝ”๋“œ ์•Œ๋ฆผ ์ „์†ก
if: failure() # ์ด์ „ ์Šคํ…์ด ์‹คํŒจํ•œ ๊ฒฝ์šฐ์—๋งŒ ์‹คํ–‰
run: |
PR_NUMBER="${{ github.event.pull_request.number }}"
PR_TITLE="${{ github.event.pull_request.title }}"
PR_AUTHOR="${{ github.event.pull_request.user.login }}"
PR_URL="${{ github.event.pull_request.html_url }}"
curl -X POST -H "Content-Type: application/json" \
-d "{\"content\": \"๐Ÿšจ **Gamegoo Socket ์„œ๋ฒ„ ๋ฐฐํฌ ์‹คํŒจ** ๐Ÿšจ\nPR ๋ฒˆํ˜ธ: '${PR_NUMBER}'\nPR ์ œ๋ชฉ: '${PR_TITLE}'\nPR ์ž‘์„ฑ์ž: '${PR_AUTHOR}'\n[PR ๋ณด๊ธฐ](${PR_URL})\"}" \
$DISCORD_WEBHOOK_URL