๐ท [Ci] timezone ๊ด๋ จ ์ค์ ์ถ๊ฐ #3
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] | |
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 |