Configurable container prefix #78

Open
opened 2023-03-25 13:46:31 +00:00 by cthu1hoo · 5 comments

I'd like to run several org runners on a single, shared VM to conserve resources. They use different host users, systemd units, and settings.

Would it be possible to make ContainerNamePrefix configurable via environment so that there would be no chance of different runner jobs conflicting?

Thanks in advance for considering.

I'd like to run several org runners on a single, shared VM to conserve resources. They use different host users, systemd units, and settings. Would it be possible to make ContainerNamePrefix configurable via environment so that there would be no chance of different runner jobs conflicting? Thanks in advance for considering.
Owner

Every task has their own container, the name contains a task id. So I think they should not be conflicted if they are on the same Gitea instance.

Every task has their own container, the name contains a task id. So I think they should not be conflicted if they are on the same Gitea instance.
Author

I'm sharing between two Gitea instances (on the same LAN). One has two runners bound to two different orgs, another one has a global runner.

I think a collision is possible because Sprintf("GITEA-ACTIONS-TASK-%s", eventName) is not enough to guarantee container name uniqueness.

p.s. I understand that this is not best practice in any way whatsoever but it's not practical to make a separate VM for every runner which are mostly idle, too much wasted RAM on the hypervisor.

I'm sharing between two Gitea instances (on the same LAN). One has two runners bound to two different orgs, another one has a global runner. I think a collision is possible because ``Sprintf("GITEA-ACTIONS-TASK-%s", eventName)`` is not enough to guarantee container name uniqueness. p.s. I understand that this is not best practice in any way whatsoever but it's not practical to make a separate VM for every runner which are mostly idle, too much wasted RAM on the hypervisor.
Author
diff --git a/cmd/exec.go b/cmd/exec.go
index 7b20974..0fef6b9 100644
--- a/cmd/exec.go
+++ b/cmd/exec.go
@@ -380,7 +380,7 @@ func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command
                        NoSkipCheckout:     execArgs.noSkipCheckout,
                        // PresetGitHubContext:   preset,
                        // EventJSON:             string(eventJSON),
-                       ContainerNamePrefix:   fmt.Sprintf("GITEA-ACTIONS-TASK-%s", eventName),
+                       ContainerNamePrefix:   fmt.Sprintf("%s-GITEA-ACTIONS-TASK-%s", os.Getenv("GITEA_RUNNER_CONTAINER_NAME_PREFIX"), eventName),
                        ContainerMaxLifetime:  maxLifetime,
                        ContainerNetworkMode:  "bridge",
                        DefaultActionInstance: execArgs.defaultActionsUrl,
diff --git a/runtime/task.go b/runtime/task.go
index 86cde60..8dfeee2 100644
--- a/runtime/task.go
+++ b/runtime/task.go
@@ -238,7 +238,7 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task, runnerName, runnerV
                NoSkipCheckout:        true,
                PresetGitHubContext:   preset,
                EventJSON:             string(eventJSON),
-               ContainerNamePrefix:   fmt.Sprintf("GITEA-ACTIONS-TASK-%d", task.Id),
+               ContainerNamePrefix:   fmt.Sprintf("%s-GITEA-ACTIONS-TASK-%d", os.Getenv("GITEA_RUNNER_CONTAINER_NAME_PREFIX"), task.Id),
                ContainerMaxLifetime:  maxLifetime,
                ContainerNetworkMode:  input.containerNetworkMode,
                DefaultActionInstance: dataContext["gitea_default_actions_url"].GetStringValue(),

In the end here's what I did as a temporary workaround (this envvar pair is saved to runner/.env by an ansible role which deploys runner instance), hoping for a proper fix tho.

``` diff --git a/cmd/exec.go b/cmd/exec.go index 7b20974..0fef6b9 100644 --- a/cmd/exec.go +++ b/cmd/exec.go @@ -380,7 +380,7 @@ func runExec(ctx context.Context, execArgs *executeArgs) func(cmd *cobra.Command NoSkipCheckout: execArgs.noSkipCheckout, // PresetGitHubContext: preset, // EventJSON: string(eventJSON), - ContainerNamePrefix: fmt.Sprintf("GITEA-ACTIONS-TASK-%s", eventName), + ContainerNamePrefix: fmt.Sprintf("%s-GITEA-ACTIONS-TASK-%s", os.Getenv("GITEA_RUNNER_CONTAINER_NAME_PREFIX"), eventName), ContainerMaxLifetime: maxLifetime, ContainerNetworkMode: "bridge", DefaultActionInstance: execArgs.defaultActionsUrl, diff --git a/runtime/task.go b/runtime/task.go index 86cde60..8dfeee2 100644 --- a/runtime/task.go +++ b/runtime/task.go @@ -238,7 +238,7 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task, runnerName, runnerV NoSkipCheckout: true, PresetGitHubContext: preset, EventJSON: string(eventJSON), - ContainerNamePrefix: fmt.Sprintf("GITEA-ACTIONS-TASK-%d", task.Id), + ContainerNamePrefix: fmt.Sprintf("%s-GITEA-ACTIONS-TASK-%d", os.Getenv("GITEA_RUNNER_CONTAINER_NAME_PREFIX"), task.Id), ContainerMaxLifetime: maxLifetime, ContainerNetworkMode: input.containerNetworkMode, DefaultActionInstance: dataContext["gitea_default_actions_url"].GetStringValue(), ``` In the end here's what I did as a temporary workaround (this envvar pair is saved to runner/.env by an ansible role which deploys runner instance), hoping for a proper fix tho.
wolfogre added the
kind
proposal
label 2023-03-26 07:57:22 +00:00

Try to use dind(docker in docker) to isolate different runner environments

Try to use dind(docker in docker) to isolate different runner environments
Author

No, rewriting all pipelines to use docker-on-docker is not a valid workaround here.

It's also an objectively bad practice but that's beside the point.

No, rewriting all pipelines to use docker-on-docker is not a valid workaround here. It's also an objectively bad practice but that's beside the point.
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#78
No description provided.