config.yaml: container options are ignored with custom container #483

Closed
opened 2024-02-12 16:56:32 +00:00 by hgeerts · 2 comments

We wanted to use the container options to inject the internal gitea hostname in the job containers. But this only works for jobs that do not use a container image.

# config.yaml
container:
  # And other options to be used when the container is started (eg, --add-host=my.gitea.url:host-gateway).
  options: "--add-host=my.gitea.url:host-gateway"

The following workflow succeeds and can checkout the gitea repo.

# workflow/test.yaml
name: Test
run-name: Test
on: [push]

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

This workflow fails because it cannot resolve my.gitea.url

# workflow/test-container.yaml
name: Test container
run-name: Test container
on: [push]

jobs:
  lint:
    runs-on: ubuntu-latest
    container:
      image: python:3.10
      env:
        DEBIAN_FRONTEND: noninteractive
    steps:
      - name: Install nodejs for the checkout action
        run: apt-get -qy update && apt-get -qy --no-install-recommends install nodejs
      - name: Checkout
        uses: actions/checkout@v4

Cause

This is triggered in act which uses the following to set the options.

# pkg/runner/run_context.go
func (rc *RunContext) options(ctx context.Context) string {
    job := rc.Run.Job()
    c := job.Container()
    if c != nil {
        return rc.ExprEval.Interpolate(ctx, c.Options)
    }

    return rc.Config.ContainerOptions
}

So for every workflow that uses a custom container you are required to copy the default container options to the workflow.

Solution

The default container options are copied to the container options of the workflow when not defined.

We wanted to use the container options to inject the internal gitea hostname in the job containers. But this only works for jobs that do not use a container image. ``` # config.yaml container: # And other options to be used when the container is started (eg, --add-host=my.gitea.url:host-gateway). options: "--add-host=my.gitea.url:host-gateway" ``` The following workflow succeeds and can checkout the gitea repo. ``` # workflow/test.yaml name: Test run-name: Test on: [push] jobs: lint: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 ``` This workflow fails because it cannot resolve `my.gitea.url` ``` # workflow/test-container.yaml name: Test container run-name: Test container on: [push] jobs: lint: runs-on: ubuntu-latest container: image: python:3.10 env: DEBIAN_FRONTEND: noninteractive steps: - name: Install nodejs for the checkout action run: apt-get -qy update && apt-get -qy --no-install-recommends install nodejs - name: Checkout uses: actions/checkout@v4 ``` ### Cause This is triggered in `act` which uses the following to set the options. ``` # pkg/runner/run_context.go func (rc *RunContext) options(ctx context.Context) string { job := rc.Run.Job() c := job.Container() if c != nil { return rc.ExprEval.Interpolate(ctx, c.Options) } return rc.Config.ContainerOptions } ``` So for every workflow that uses a custom container you are required to copy the default container options to the workflow. ### Solution The default container options are copied to the container options of the workflow when not defined.

This issue is similar to this and this other ones (I'd like to inject Docker configuration params into started child containers).

I've opened a PR for it more than 3 months ago but... nobody is taking care of it🙄

This issue is similar to [this](https://gitea.com/gitea/act_runner/issues/79#issuecomment-746463) and [this](https://gitea.com/gitea/act_runner/issues/475) other ones (I'd like to inject Docker configuration params into started child containers). I've opened a [PR](https://gitea.com/gitea/act/pulls/80) for it more than 3 months ago but... nobody is taking care of it🙄
sillyguodong added the
kind
bug
label 2024-02-22 02:31:17 +00:00
Member

closed by gitea/act#80

closed by https://gitea.com/gitea/act/pulls/80
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: gitea/act_runner#483
No description provided.