Code Monkey home page Code Monkey logo

Comments (16)

lielran avatar lielran commented on May 20, 2024 1

@snussik thank you for the discovery!

In the meantime, @lielran found that the Docker container actions don't run on the self-hosted runner and created PR #11 for that.

So I will check both your ideas together as the action should be a bit updated in order to run any kind of action on it.

yes, I've tried to install docker via user-data and also used ready-made AMI with docker.
but the action wasn't able to access docker-engine due to permissions issues.

from ec2-github-runner.

snussik avatar snussik commented on May 20, 2024 1

@machulav yep, it's a common "problem" with this bash script. Dumb working receipt is:export RUNNER_ALLOW_RUNASROOT=1 and then run ./run.sh

from ec2-github-runner.

lielran avatar lielran commented on May 20, 2024 1

@machulav yep, it's a common "problem" with this bash script. Dumb working receipt is:export RUNNER_ALLOW_RUNASROOT=1 and then run ./run.sh

Boom! works like magic.
Thanks for the comment on this "Dumb" workaround that saves me hours of debugging

from ec2-github-runner.

lielran avatar lielran commented on May 20, 2024 1

Wow, very nice! 🎉

@lielran May I ask you to describe your use case a bit? What do you use the self-hosted runner for and why is it important in your CD pipeline?

Sure,
we are using flyway to align our DB schema (rds,pg). the db is running in isolated subnet without(direct) internet access. the easist thing to do is run the migration from within the vpc on a public subnet(application subnet).

from ec2-github-runner.

machulav avatar machulav commented on May 20, 2024

@snussik have you found the issue?

As I see, you set up the workflow for the master branch. But there is no master branch for this repository. The main branch here is the main. I hope it helps.

from ec2-github-runner.

snussik avatar snussik commented on May 20, 2024

@machulav hi! Yep, I've discovered it. And I have a new problem now )) When I create remote runner on aws and try to run npm ci (or npm install), I get:
npm ERR! correctMkdir failed to make directory /home/github/.npm/_locks
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /home/github
npm ERR! errno -13

The commands: whoami shows that bash runs under the github user.

The part of workflow file, is:

# Test WF for GA

name: CI

# Controls when the action will run. 
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  start-runner:
    name: Start self-hosted EC2 runner
    runs-on: ubuntu-latest
    outputs:
      label: ${{ steps.start-ec2-runner.outputs.label }}
      ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }}
    steps:
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_RUNNER }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_RUNNER }}
          aws-region: ${{ secrets.AWS_REGION_RUNNER }}
      - name: Start EC2 runner
        id: start-ec2-runner
        uses: machulav/[email protected]
        with:
          mode: start
          github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
          ec2-image-id: ami-02501629bfc260e9c
          ec2-instance-type: t2.micro
          subnet-id: subnet-04850abda92c62906
          security-group-id: sg-0fda70c804d158ece
  do-the-job:
    name: Do the job on the runner
    runs-on: ${{needs.start-runner.outputs.label}} # run the job on the newly created runner
    needs: start-runner # required to start the main job when the runner is ready
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Use Node.js 12
        uses: actions/setup-node@v1
        with:
          node-version: 12.18.2
      - name: Cache node modules
        uses: actions/cache@v1
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: ${{ runner.os }}-node-
      - name: Build
        run: |
          whoami
          npm ci

Is that related to AWS Credentials? I thought that github user runs ints workflow under needed permissons inside the runner instance?

from ec2-github-runner.

snussik avatar snussik commented on May 20, 2024

@machulav found out with npm config list that npm HOME variable is set in /home/github. That is why npm tries to mkdir in /home/github and meets EACCES error in this dir.
I think that it's a problem of self-hosted runners when you create new users in them, as on GitHub hosted runner or even sell-hosted, created in order with official GitHub doc doesn't have such problem.

from ec2-github-runner.

snussik avatar snussik commented on May 20, 2024

I think that in aws.js (on line 11) it should be something like:
useradd -m -d /home/actions-runner && cd /home/actions-runner

from ec2-github-runner.

machulav avatar machulav commented on May 20, 2024

@snussik thank you for the discovery!

In the meantime, @lielran found that the Docker container actions don't run on the self-hosted runner and created PR #11 for that.

So I will check both your ideas together as the action should be a bit updated in order to run any kind of action on it.

from ec2-github-runner.

machulav avatar machulav commented on May 20, 2024

Yeah, as both of you pointed, there is a general issue with permissions. So I renamed the issue to correspond to that.

The main reason why I create github user is the following: all the bootstrap scripts from ./src/aws.js entered as user data and run as the root user. At the same time, GitHub's run.sh can not be run as a root.

from ec2-github-runner.

machulav avatar machulav commented on May 20, 2024

The RUNNER_ALLOW_RUNASROOT fixed the issue!
Also, I've made a couple of additional improvements. See more details in PR #14. I hope it helps.
Later I will create a new release with these changes.

Please note that to reduce the scope of changes and testing, I limited supported Linux distributive to only Amazon Linux 2.
In the future, I'm going to add support for the other distributive if required.

@lielran @snussik thank you for your support and contributions! It means a lot!
You, folks, really motivate me to continue working on the action! 🙌

from ec2-github-runner.

lielran avatar lielran commented on May 20, 2024

The RUNNER_ALLOW_RUNASROOT fixed the issue!
Also, I've made a couple of additional improvements. See more details in PR #14. I hope it helps.
Later I will create a new release with these changes.

Please note that to reduce the scope of changes and testing, I limited supported Linux distributive to only Amazon Linux 2.
In the future, I'm going to add support for the other distributive if required.

@lielran @snussik thank you for your support and contributions! It means a lot!
You, folks, really motivate me to continue working on the action! 🙌

here is the final result, we are already using it in our CD pipeline.
Screen Shot 2021-01-08 at 8 32 42

from ec2-github-runner.

machulav avatar machulav commented on May 20, 2024

Wow, very nice! 🎉

@lielran May I ask you to describe your use case a bit? What do you use the self-hosted runner for and why is it important in your CD pipeline?

from ec2-github-runner.

machulav avatar machulav commented on May 20, 2024

Cool! Thank you for the information!

from ec2-github-runner.

sasrinivasan-exelixis avatar sasrinivasan-exelixis commented on May 20, 2024

@lielran I am slo planning to use this and flyway. Can you please share an example action and your flyway setup?

from ec2-github-runner.

lielran avatar lielran commented on May 20, 2024

@lielran I am slo planning to use this and flyway. Can you please share an example action and your flyway setup?

I personally moved to use hosted Github runners on the VPC and also plan to move to GitHub action code build

from ec2-github-runner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.