diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5288897c..372ff688 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,65 +1,53 @@ -name: Deploy to VPS +name: CI/CD Pipeline on: push: branches: [main] -env: - IMAGE_NAME: biztaghavi - jobs: - deploy: - runs-on: ubuntu-latest + lint-typecheck: + name: Lint & Type Check + runs-on: nodecloud-runner + container: + image: node:20-bullseye + steps: - name: Checkout uses: actions/checkout@v4 - - - name: Setup pnpm - uses: pnpm/action-setup@v4 with: - version: latest + token: ${{ github.token }} + repository: ${{ github.repository }} - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: 22 - cache: pnpm + - name: Enable pnpm + run: corepack enable && corepack prepare pnpm@latest --activate - name: Install dependencies - run: pnpm install --frozen-lockfile + run: pnpm install --frozen-lockfile --ignore-scripts - name: Lint run: pnpm lint - name: Type check - run: pnpm exec tsc --noEmit + run: pnpm typecheck - - name: Build Docker image - run: docker build -t $IMAGE_NAME:${{ github.sha }} . + deploy: + name: Deploy to NODE Cloud + runs-on: nodecloud-runner + needs: lint-typecheck + if: success() - - name: Save Docker image - run: docker save $IMAGE_NAME:${{ github.sha }} | gzip > image.tar.gz - - - name: Copy image to VPS - uses: appleboy/scp-action@v0.1.7 - with: - host: ${{ secrets.VPS_HOST }} - username: ${{ secrets.VPS_USER }} - key: ${{ secrets.VPS_SSH_KEY }} - source: image.tar.gz - target: /tmp/ - - - name: Deploy on VPS - uses: appleboy/ssh-action@v1.0.3 - with: - host: ${{ secrets.VPS_HOST }} - username: ${{ secrets.VPS_USER }} - key: ${{ secrets.VPS_SSH_KEY }} - script: | - cd /srv/biztaghavi - docker load < /tmp/image.tar.gz - docker tag biztaghavi:${{ github.sha }} biztaghavi:latest - docker compose up -d --no-build --remove-orphans - docker image prune -f - rm /tmp/image.tar.gz - echo "✅ Deployed ${{ github.sha }}" + steps: + - name: Deploy via SSH + run: | + mkdir -p ~/.ssh + echo "${{ secrets.SERVER_SSH_KEY }}" > ~/.ssh/deploy_key + chmod 600 ~/.ssh/deploy_key + ssh -i ~/.ssh/deploy_key \ + -o StrictHostKeyChecking=no \ + -o UserKnownHostsFile=/dev/null \ + ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} \ + "cd /srv/nodecloud/apps/biztaghavisite && \ + git pull && \ + docker compose build --no-cache && \ + docker compose up -d --force-recreate && \ + echo '✅ Deploy done'" \ No newline at end of file