7

Since I need to use a self-hosted runner, the option to use existing marketplace SSH Actions is not viable because they tend to docker and build an image on GitHub Actions which fails because of a lack of permissions for an unknown user. Existing GitHub SSH Actions such as appleboy fail due to reliance on Docker for me.

Please note: Appleboy & other similar actions work great when using GitHub Actions Runners.

2 Answers 2

5

Since it's a self-hosted runner i.e. I have access to it all the time. So using an SSH profile and then using native-run command works pretty well.

To create an SSH profile & use it in GitHub Actions:

  1. Create (if doesn't exist already) a "config" file in "~/.ssh/".

  2. Add a profile in "~/.ssh/config". For example-

    Host dev HostName qa.bluerelay.com User ec2-user Port 22 IdentityFile /home/ec2-user/mykey/something.pem

  3. Now to test it, on self-hosted runner run:

    ssh dev ls

This should run the ls command inside the dev server. 4. Now since the SSH profile is set up, you can easily run remote SSH commands using GitHub Actions. For example-

name: Test Workflow

on:
  push:
    branches: ["main"]

jobs:
  build:
    runs-on: self-hosted

steps:
  - uses: actions/checkout@v2

    - name: Download Artifacts into Dev 
    run: |
      ssh dev 'cd GADeploy && pwd && sudo wget https://somelink.amazon.com/web.zip'

  - name: Deploy Web Artifact to Dev 
    run: |
      ssh dev 'cd GADeploy && sudo ./deploy-web.sh web.zip'

This works like a charm!!

Sign up to request clarification or add additional context in comments.

Comments

1

Independently of the runner itself, you would need first to check if SSH does work from your server

curl -v telnet://github.com:22
# Assuming your ~/.ssh/id_rsa.pub is copied to your GitHub profile page
git ls-remote [email protected]:you/YourRepository

Then you can install your runner, without Docker.

Finally, your runner script can execute jobs.<job_id>.steps[*].run commands, using git with SSH URLs.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.