Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to override default signal and stop timeout #72

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bradrydzewski
Copy link
Collaborator

@bradrydzewski bradrydzewski commented Oct 19, 2023

let user override the default container termination signal and timeout

kind: pipeline
type: docker
steps:
- name: foo
  image: golang
  stop_signal: SIGTERM
  stop_timeout: 1m
  commands:
  - go build

note that you can also specify system-wide defaults

./drone-runner-docker compile --stop-timeout=2h --stop-signal=SIGTERM --source=/tmp/.drone.yml

Status Update 11/16

This pull request is incomplete and only works with the Drone exec command for local testing. It is not yet hooked up to the docker daemon, which would require patching the daemon environment variables [1] and then mapping those environment variables into the compiler [2]

	Runner struct {
		Name        string            `envconfig:"DRONE_RUNNER_NAME"`
		Capacity    int               `envconfig:"DRONE_RUNNER_CAPACITY" default:"2"`
		Procs       int64             `envconfig:"DRONE_RUNNER_MAX_PROCS"`
		Environ     map[string]string `envconfig:"DRONE_RUNNER_ENVIRON"`
		EnvFile     string            `envconfig:"DRONE_RUNNER_ENV_FILE"`
		Secrets     map[string]string `envconfig:"DRONE_RUNNER_SECRETS"`
		Labels      map[string]string `envconfig:"DRONE_RUNNER_LABELS"`
		Volumes     map[string]string `envconfig:"DRONE_RUNNER_VOLUMES"`
		Devices     []string          `envconfig:"DRONE_RUNNER_DEVICES"`
		Networks    []string          `envconfig:"DRONE_RUNNER_NETWORKS"`
		NetworkOpts map[string]string `envconfig:"DRONE_RUNNER_NETWORK_OPTS"`
		Privileged  []string          `envconfig:"DRONE_RUNNER_PRIVILEGED_IMAGES"`
		Clone       string            `envconfig:"DRONE_RUNNER_CLONE_IMAGE"`
+		StopSignal     string         `envconfig:"DRONE_RUNNER_STOP_SIGNAL"`
+		StopTimeout    time.Duration  `envconfig:"DRONE_RUNNER_STOP_TIMEOUT"`
+		StopTimeoutMax time.Duration  `envconfig:"DRONE_RUNNER_STOP_TIMEOUT_MAX"`
	}
		Compiler: &compiler.Compiler{
			Clone:          config.Runner.Clone,
			Privileged:     append(config.Runner.Privileged, compiler.Privileged...),
			Networks:       config.Runner.Networks,
			NetrcCloneOnly: config.Netrc.CloneOnly,
			Volumes:        config.Runner.Volumes,

+			StopSignal:     config.Runner.StopSignal,
+			StopTimeout:    config.Runner.StopTimeout,
+			StopTimeoutMax: config.Runner.StopTimeoutMax,

It is also important to note and document that the default max stop timeout is zero, which means by default, no pipelines are able to configure a custom stop timeout or stop signal. First, one needs to set DRONE_RUNNER_STOP_TIMEOUT_MAX=<duration> which allows pipelines to set a custom stop value less than or equal to <duration>

This logic can be found in the below section of code that was added to the compiler. If no max timeout is set, the value is zero. This means any user-defined values will be greater than the max value (zero) and will be reset to zero. This is by design because we don't want people setting a custom stop timeout unless it has been explicitly enabled by the system admin.

		// if the user configures a timeout that is
		// greater than the global timeout, the user
		// timeout is overriden.
		if step.StopTimeout > c.StopTimeoutMax {
			step.StopTimeout = c.StopTimeoutMax
		}

[1] https://github.com/drone-runners/drone-runner-docker/blob/stop_signal/command/daemon/config.go#L44
[2] https://github.com/drone-runners/drone-runner-docker/blob/stop_signal/command/daemon/process.go#L76

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant