dimanche 27 septembre 2020

How to deploy nuxt proj with circleci once have new commit to github

Recently I made a dev branch for myrepo in GitHub, I deploy the Nuxt app by running sh deploy-dev.sh in my ubuntu server. I found that manually redeploying my project to the server every time after pushing commits is quite time-consuming; therefore, I tried to find ways to automatically deploy the app once I make a new commit on dev branch. I have read some documentation about CircleCI, but I'm still so confused. I've added the ssh key in the CircleCI project for myrepo, added it as steps: - add-fingerprints -"FI:GE:RP:RI:T" to the config.yml then I'm stuck with the connection problem and how should I actually run the deploy-dev.sh. How should I do the config if i want to:

  1. run the test only when dev has new commit
  2. try if the project can actually build
  3. deploy the project to the server by running the sh script

Here is the config.yml

version: 2
jobs:
  build:
    docker:
      - image: circleci/node:10.19.0
    working_directory: ~/dev
    steps:
      - checkout
      - run: npm install
      - run: npm run build

  deploy:
    machine:
      enabled: true
    steps:
      - add_ssh_keys:
          fingerprints:
            - "FI:GE:RP:RI:T"
      - run:
          name: Deploy Over SSH
          command: |
             ssh USER@ADDRESS "sh dev/reploy-dev.sh"
workflows:
  version: 2
  workflow:
    jobs:
      - build
      - deploy

Here is the deploy-dev.sh

#!/bin/bash
pm2 stop dev
cd ~/dev/Myrepo
git checkout dev
git fetch
git pull
npm install
cp ../.env .env
npm run build
pm2 restart dev



Aucun commentaire:

Enregistrer un commentaire