capistrano / sshkit

A toolkit for deploying code and assets to servers in a repeatable, testable, reliable way.
MIT License
1.16k stars 254 forks source link

parallel.rb:10: terminated with exception Fatal: Could not read from remote repository #546

Closed kashifnaseer closed 2 weeks ago

kashifnaseer commented 3 weeks ago

I used to deploy code from Github to AWS via Github Actions without any issue. But now, the same code suddenly stopped working with the following error:

00:00 git:wrapper
      01 mkdir -p /tmp
    ✔ 01 user@xxxxxIp.345s
    ✔ 01 user@xxxxxip 1.349s
      Uploading /tmp/git-ssh-xxxxx-runner.sh 100.0%
      Uploading /tmp/git-ssh-xxxxx-runner.sh 100.0%
      02 chmod 700 /tmp/git-ssh-xxxxx-runner.sh
    ✔ 02 user@xxxxxxIP 0.342s
    ✔ 02 user@xxxxxxIP 0.342s
00:02 git:check
      01 git ls-remote git@github.com:xxxx/xxxx.git HEAD
      01 ERROR: Repository not found.
      01 fatal: Could not read from remote repository.
      01
      01 Please make sure you have the correct access rights
      01 and the repository exists.
#<Thread:0x000055aecb8f72b0@/home/runner/work/xxxx/xxxx/vendor/bundle/ruby/2.5.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
/home/runner/work/xxxx/xxxx/vendor/bundle/ruby/2.5.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:15:in  rescue in block (2 levels) in execute : Exception while executing on host ip: git exit status: 128 (SSHKit::Runner::ExecuteError)
git stdout: Nothing written
git stderr: ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
    from /home/runner/work/xxxx/xxxx/vendor/bundle/ruby/2.5.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:11:in  block (2 levels) in execute 
      01 ERROR: Repository not found.
      01 fatal: Could not read from remote repository.
      01
      01 Please make sure you have the correct access rights
      01 and the repository exists.
#<Thread:0x000055aecb8f7738@/home/runner/work/xxxx/xxxx/vendor/bundle/ruby/2.5.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
/home/runner/work/xxxx/xxxx/vendor/bundle/ruby/2.5.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:15:in  rescue in block (2 levels) in execute : Exception while executing on host ip: git exit status: 128 (SSHKit::Runner::ExecuteError)
git stdout: Nothing written
git stderr: ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
    from /home/runner/work/xxxx/xxxx/vendor/bundle/ruby/2.5.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:11:in  block (2 levels) in execute 
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host ip: git exit status: 128
git stdout: Nothing written
git stderr: ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Caused by:
SSHKit::Command::Failed: git exit status: 128
git stdout: Nothing written
git stderr: ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Tasks: TOP => deploy:check => git:check
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing on host ip: git exit status: 128
git stdout: Nothing written
git stderr: ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:
 INFO [8a54f66e] Running /usr/bin/env git ls-remote git@github.com:xxxx/xxxx.git HEAD on ip
 DEBUG [40ed32b1]   ERROR: Repository not found.
 DEBUG [40ed32b1]   fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
 DEBUG [5dd77983]   ERROR: Repository not found.
 DEBUG [5dd77983]   fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Error: Error: The process /opt/hostedtoolcache/Ruby/2.5.9/x64/bin/bundle failed with exit code 1

Github Actions Workflow:-

name:  Deployment
on:
  workflow_dispatch:
jobs:
  deploy_to_xyz:
    name: Deploy to xyz
    runs-on: ubuntu-20.04
    env:
      CAP_BRANCH: zzz
      AWS_KEY_ID: xxxx
      AWS_SECRET_KEY:  xxxx
      AWS_REGION:  xxxx
    steps:
    - uses: actions/checkout@v2
    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: 2.5.9
        bundler-cache: true
    - uses: miloserdow/capistrano-deploy@v2.2
      with:
        target: staging
        enc_rsa_key_pth: "config/deploy/path"
        deploy_key: ${{ secrets.DEPLOY_KEY }}
   - name: Success
      # code related to  failure
    - name: Fail deploy notification
      # code related to  failure

it looks it connects to the remote server from github actions, but it fails to get the latest changes from github.

i also tried to ask in stack over flow, but there is still no luck with it. https://stackoverflow.com/questions/79161025/github-actions-could-not-read-from-remote-repository-ruby-on-rails

Any idea, what is causing this issue ?

mattbrictson commented 2 weeks ago

This looks like an authentication issue. The GitHub "repository not found" error often means that the SSH key you are using does not have access to the repository. I would double-check that the key is correctly installed as a "deploy key" for the repository, and that you've configured the capistrano-deploy action to load the right key.

Another thing to consider is that you are using an older version of the capistrano-deploy action that uses RSA keys. I believe RSA has been deprecated by GitHub for quite some time; it is possible that they no longer are allowed. In that case you'll need to upgrade capistrano-deploy and generate and use an ED25519 key instead. Note that you may need to add gems to your Gemfile to support ED25519 keys, see: https://github.com/net-ssh/net-ssh/issues/478

Hope that helps!

kashifnaseer commented 2 weeks ago

Thanks @mattbrictson I'm able to fix the deployment