From ae4ab85f18dfb495154cf94eefa7092ad4581e4c Mon Sep 17 00:00:00 2001 From: taewan2002 Date: Tue, 13 Feb 2024 07:21:08 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B8=B0=EB=B3=B8=20=EC=85=8B=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/prod.yml | 57 +++++++++++++++----------------------- 1 file changed, 22 insertions(+), 35 deletions(-) diff --git a/.github/workflows/prod.yml b/.github/workflows/prod.yml index 0c37183..0aea07c 100644 --- a/.github/workflows/prod.yml +++ b/.github/workflows/prod.yml @@ -5,50 +5,37 @@ on: branches: [main] jobs: - build: + build-and-deploy: runs-on: ubuntu-20.04 steps: - - name: Get current time - uses: josStorer/get-current-time@v2.0.2 - id: current-time + - uses: actions/checkout@v2 + + - name: Setup Node.js + uses: actions/setup-node@v2 with: - format: YYYY-MM-DDTHH-mm-ss - utcOffset: "+09:00" + node-version: '14' # 원하는 Node.js 버전을 지정하세요 - - uses: actions/checkout@v2 - - name: Docker build - run: | - docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }} - docker build -f Dockerfile -t taewan2002/docent-front:${{steps.current-time.outputs.formattedTime}} . - docker push taewan2002/docent-front:${{steps.current-time.outputs.formattedTime}} + - name: Install Dependencies + run: npm install + + - name: Build Project + run: npm run build + + - name: Deploy to Server + uses: appleboy/scp-action@master + with: + host: ${{ secrets.NCP_HOST }} + username: ${{ secrets.NCP_USER }} + password: ${{ secrets.NCP_PASSWORD }} + source: "./build/*" + target: "/sarabwayu" - - name: Deploy + - name: Restart Web Server (Optional) uses: appleboy/ssh-action@master with: host: ${{ secrets.NCP_HOST }} username: ${{ secrets.NCP_USER }} password: ${{ secrets.NCP_PASSWORD }} - key: ${{ secrets.NCP_KEY }} - envs: GITHUB_SHA script: | - sudo systemctl stop nginx || true - # Pull the new image - echo "🐳 Docker Image Pull" - sudo docker pull taewan2002/docent-front:${{steps.current-time.outputs.formattedTime}} - - # Stop & Start - echo "🐳 Docker Stop & Start" - sudo docker stop docent-front - sudo docker run --rm -d --name docent-front -p 80:80 taewan2002/docent-front:${{steps.current-time.outputs.formattedTime}} - - echo "▶️ Restarting Nginx service" - sudo systemctl start nginx || true - - # Check - echo "🐳 Docker ps" - docker ps - - # Cleanup old images - echo "🧹 Cleaning up old Docker images" - sudo docker rmi -f $(sudo docker images -q) || true + sudo systemctl restart nginx