pm2 deploy fails after full fetch

Viewed 1369

I want to deploy a simple app to my ec2 instance but I got this error:

bash: line 0: cd: /home/ubuntu/source: No such file or directory

  fetch failed

Deploy failed
1

I don't understand why is there a 'source' directory when i haven't created it on my virtual or local machine. It's like pm2 created it on its own. Can someone explain why is it there and how can I deploy it successfully?

My ecosystem.config.js:

module.exports = {
    apps: [{
      name: 'puk',
      script: 'project/'
    }],
    deploy: {
      production: {
        user: 'ubuntu',
        host: 'ec2-35-180-119-129.eu-west-3.compute.amazonaws.com',
        key: '~/.ssh/id_rsa.pub',
        ref: 'origin/master',
        repo: 'git@github.com:nalnir/pukinn.git',
        path: '/home/ubuntu/',
        'post-deploy': 'npm install && pm2 startOrRestart ecosystem.config.js'
      }
    }
  }

Full log after pm2 deploy production command:

--> Deploying to production environment
--> on host ec2-35-180-119-129.eu-west-3.compute.amazonaws.com
  ○ deploying origin/master
  ○ executing pre-deploy-local
  ○ hook pre-deploy
  ○ fetching updates
  ○ full fetch
bash: line 0: cd: /home/ubuntu/source: No such file or directory

  fetch failed

Deploy failed
1

2 Answers

I have faced the same issue and got this thread, but the above answer/comments are not very helpful for me. There is no helpful document on the PM2 website too. So I do one by one all steps from initial:

  1. Do first setup before calling update command on any existing folder. Because PM2 create their own folder structure: [Current, Source, Shared] (Read here)

pm2 deploy ecosystem.config.js stage setup

  1. When you want to deploy new code then do with the below command:

pm2 deploy ecosystem.config.js stage update --force

Why --force?
You may have some changes in your local system that aren’t pushed inside your git repository, and since the deploy script get the update via git pull they will not be on your server. If you want to deploy without pushing any data, you can append the --force option:

My deploy object in ecosystem.config.js file :

deploy : {
    stage : {
      // Deploy New: pm2 deploy ecosystem.config.js stage setup
      // Update: pm2 deploy ecosystem.config.js stage update --force
      user : '_MY_SERVER_USER_NAME_', // remote server username
      host : '_MY_REMOTE_SERVER_IP_', // remote server ip
      ref  : 'origin/stage', // remote repo name
      repo : 'git@bitbucket.org:_MY_REPO_SSH_CLONE_URL_.git', // repo url
      path : '_REMOTE_DIRECTIVE_', // src root paths like /home/ubuntu/

      'pre-deploy-local': '',
      'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --only MyAppName',
      'pre-setup': ''
    }
  }

I Hope, It will helpful for others.

script parameter expects the actual script path, not the directory

You should change it to the name of your main script, for example: script: './index.js'

You should also update your deploy.production.path to something like /home/ubuntu/project

As stated in the Ecosystem file reference, script expects the Path of the script to launch

Related