简体   繁体   中英

Github Action : failed with "lost connection"

We are Trying to build our gcp instance templated using GitHub Actions.

Where we try to build our java archives and transfer it to GCP instance from GitHub Ubuntu machine.

We have set sshkey to access the GCP instance from Ubuntu machines using ssh-keygen -t rsa -f ~/.ssh/temp -C root -q -N "" && chmod 400 ~/.ssh/temp && chmod 400 ~/.ssh/temp.pub && echo root: cat ~/.ssh/temp.pub > ~/.ssh/temp-formated.pub && chmod 700 /home/runner/.ssh/temp-formated.pub

We get error response when we try to run the following command scp -o StrictHostKeyChecking=no -i /home/runner/.ssh/temp./code-web/target/code.war root@:/opt/code.war

The script worked fine till 5th Dec 2022 and started giving error from 6th Dec 2022.

We used to face some failures but the same worked fine when we re-run the build.

build.yml

# This is a basic workflow to help you get started with Actions

name: build-web

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the develop branch
 
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:
    inputs:
      short_sha:
        description: 'Git sha on which build will be created'     
        required: true
        default: ''

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
        with:
          ref: ${{ github.event.inputs.short_sha }}
     
     # Build using mvn
      - name: Set up JDK 8
        uses: actions/setup-java@v2
        with:
          java-version: '8'
          distribution: 'adopt'
          cache: 'maven'
      - name: Build with Maven
        run: mvn --batch-mode --update-snapshots verify

      - name: Set up Cloud SDK
        uses: google-github-actions/setup-gcloud@v0
        with:
          service_account_key: ${{ secrets.GCP_SA_KEY }}
          export_default_credentials: true

      - name: Gcloud Version
        run: gcloud --version

      - name: Run build script
        run: python ./.github/workflows/build.py ${{ github.event.inputs.short_sha }}

Following is the error log.

We have tried multiple builds for other builds in the other builds in the same repository- those failed too We have confirmed that the secret is still active. And the build also is successful hence the file "code.war" exists

Any idea of how to figure out the root cause or any one facing similar issue

###Running: ssh-keygen -t  rsa  -f ~/.ssh/temp -C root -q -N "" && chmod 400 ~/.ssh/temp && chmod 400 ~/.ssh/temp.pub && echo root:`cat ~/.ssh/temp.pub` > ~/.ssh/temp-formated.pub && chmod 700 /home/runner/.ssh/temp-formated.pub
###Exit Code: 0
###RESPONSE:(b'', b'')
####################################
#########Transfer public key to instance############
###Running: cd ~/ && pwd
###Exit Code: 0
###RESPONSE:(b'/home/runner\n', b'')
###Running: gcloud compute instances add-metadata dummy-temp-web --project=projectname --zone=us-east1-b --metadata-from-file ssh-keys=/home/runner/.ssh/temp-formated.pub
###Exit Code: 0
###RESPONSE:(b'', b'Updated [https://www.googleapis.com/compute/v1/projects/projectname/zones/us-east1-b/instances/dummy-temp-web].\n')
####################################
#Give time for key to propogate
#########copy to remote############
###Running: scp -o StrictHostKeyChecking=no -i /home/runner/.ssh/temp ./code-web/target/code.war root@<ip>:/opt/code.war
###Exit Code: 1
###RESPONSE:(b'', b"Warning: Permanently added '<ip>' (ECDSA) to the list of known hosts.\r\nPermission denied, please try again.\r\nPermission denied, please try again.\r\nroot@<ip>: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\nlost connection\n")
Traceback (most recent call last):
  File "/home/runner/work/code/code/./.github/workflows/gcloudBuild.py", line 100, in <module>
    execute(f'***copyBuldFileToRemoteCMD***', False)
  File "/home/runner/work/code/code/./.github/workflows/gcloudBuild.py", line [30](https://github.com/company/code/actions/runs/3628509641/jobs/6119611343#step:7:31), in execute
    raise Exception(f'Sorry, bad exit code***process.returncode***')
Exception: Sorry, bad exit code1

I had also similar issue when I was using ubuntu-latest as job runner in yml file. Instead of ubuntu-latest I used ubuntu-20.04 then issue resolved for me.

you can try this in your yml file

jobs:
# This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-20.04

It is working for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM