dagger / dagger-for-github

GitHub Action for Dagger
https://github.com/marketplace/actions/dagger-for-github
Apache License 2.0
120 stars 25 forks source link

Self hosted runners - ARC #106

Closed alex9fredericks closed 5 months ago

alex9fredericks commented 6 months ago

What is the issue?

The issue I'd like to log, just more FYI, is that it seems that you cannot run the GitHub Dagger action, out of the box, with self hosted runners, on Kubernetes. I installed the ARC for GitHub, with Helm, with the quick-start guide. (With Helm, this was actually quite easy to install). I managed to register some runners, and most of the workflows just run fine. For reference, workflows that used the "docker/build-push-action@v4.1.0", did work right away.

Dagger version

dagger v0.9.3

Steps to reproduce

Problem and Solution (1)

The following script works fine with GitHub runners but not with ARC:

name: 40_dagger_demo.yaml
permissions:
  contents: read
  packages: write
on:
  push:
    branches:
      - main
    paths:
      - 'apps/demo/**’
      - '.github/workflows/dagger_demo.yaml'
concurrency:
  group: ${{ github.ref }}-${{ github.workflow }}
  cancel-in-progress: true
jobs:
  build:
    name: build
    # runs-on: ubuntu-latest
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v3
      - name: '* Install dagger-io'
        run: pip install dagger-io
      - name: '* Run Dagger pipeline'
        uses: dagger/dagger-for-github@v5
        with:
          workdir: apps/demo
          verb: run
          args: python main.py "${{ secrets.DAGGER_KEY }}" github_username
          version: "0.9.3"
error

Solution

This is my workaround for the moment!! 😄 :

    steps:
      - name: '* Setup python'
        uses: actions/setup-python@v5
        with:
          python-version: 'pypy3.10'
      - name: '* Check out the repo'
        uses: actions/checkout@v4
      - name: '* Install manual'
        run: pip install anyio dagger-io==0.9.3
      - name: '* Run Dagger Pipeline'
        run: cd $GITHUB_WORKSPACE/apps/demo/ && python main.py "${{ secrets.DAGGER_KEY }}" github_username

Another varation that still does not work (2)

I also tried another variation, based on a suggestion from @marcosnils! This still produces another error:

name: 40_dagger_demo.yaml
permissions:
  contents: read
  packages: write
on:
  push:
    branches:
      - main
    paths:
      - 'apps/demo/**'
      - '.github/workflows/40_dagger_demo.yaml'
concurrency:
  group: ${{ github.ref }}-${{ github.workflow }}
  cancel-in-progress: true
jobs:
  build:
    name: build
    # ---
    # runs-on: ubuntu-latest
    # ---
    runs-on: self-hosted
    steps:
      - name: '* Setup python'
        uses: actions/setup-python@v5
        with:
          python-version: 'pypy3.10'
      - name: '* Check out the repo'
        uses: actions/checkout@v4
      - name: '* Run Dagger pipeline'
        uses: dagger/dagger-for-github@v5
        with:
          workdir: apps/demo
          verb: run
          args: python main.py "${{ secrets.DAGGER_KEY }}" github_username
          version: "0.9.3"
best-error-2

Log output

No response

marcosnils commented 6 months ago

The following script works fine with GitHub runners but not with ARC:

Just checked this and it happens because summerwind/actions-runner-dind docker image has an old version of python (3.8) that it's not supported by the dagger python SDK.

marcosnils commented 6 months ago

Another varation that still does not work (2)

this seemed to work, it's the docker stop part that failed after running the pipeline since it seems like the dagger engine wasn't started. @alex9fredericks could it be possible that the python main.py is not currently running a dagger pipeline in this case?

In any case we should handle this gracefully also.

alex9fredericks commented 6 months ago

Just checked this and it happens because summerwind/actions-runner-dind docker image has an old version of python (3.8) that it's not supported by the dagger python SDK.

Yes!! This is a big part of the solution. Here is some yaml to get Summerwind’s ubuntu 22.04 runner:

apiVersion: actions.summerwind.dev/v1alpha1
kind: RunnerDeployment
metadata:
  name: runnerdeploy-for-testing
spec:
  replicas: 1
  template:
    spec:
      repository: git_username/repo
      ephemeral: false
      image: ghcr.io/git_username/actions-runner-dind:ubuntu-22.04  # < nice
      imagePullSecrets:
        - name: regcred

@alex9fredericks could it be possible that the python main.py is not currently running a dagger pipeline in this case?

True, we never get to run a pipeline. The issue is, that the Summerwind image user that runs everything, runner:runner does not have access to the folder /usr/local/, at least, cannot write the dagger binary to it, and therefore the Dagger For GitHub Action fails (here). It would work if you do this, with sudo:

cd /usr/local && { \
curl -sL https://dl.dagger.io/dagger/install.sh 2>/dev/null |  DAGGER_VERSION=0.9.3 sudo sh 

What you can also do, is run a custom version of the Summerwind docker image. Here I change the owernship of the folder /usr/local/bin to runner, and now it all works!

# file
# ---
# /apps/actions-runner-dind/Dockerfile

FROM summerwind/actions-runner-dind:ubuntu-22.04
USER root
RUN apt update -y && \
    apt install -y --no-install-recommends \
    python3-pip \
    && rm -rf /var/lib/apt/lists/*
RUN chown -R runner:runner /usr/local/bin/
USER runner
Screenshot 2023-12-31 at 11 56 20 PM
marcosnils commented 6 months ago

This PR https://github.com/dagger/dagger-for-github/pull/105 fixes the /use/local path issue. This problem will be resolved in the next release

jpadams commented 5 months ago

@alex9fredericks Please confirm that you're good to go with the v5.1.0 release 🙏 https://github.com/marketplace/actions/dagger-for-github

alex9fredericks commented 5 months ago

Hey @jpadams, everything worked fine at the first run! :)

This test was done with a simplified runner image:

FROM summerwind/actions-runner-dind:ubuntu-22.04

USER root
RUN apt update -y && \
    apt install -y --no-install-recommends \
    python3-pip \
    && rm -rf /var/lib/apt/lists/*
USER runner

test1