mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-10-15 19:42:06 +00:00
feat: allow --memory in workflow container options (#1079)
First hand experience to implement this feature can be found at https://codeberg.org/forgejo/forgejo/issues/9406. In a nutshell it is a service container in the CI that randomly uses massive amounts of memory (>50GB RSS) but normally less than 100MB. --- See also the [matching documentation pull request](https://codeberg.org/forgejo/docs/pulls/1539). --- It is already possible to limit the memory used by all containers in the config file: ```yaml container: options: --memory 200M ``` This limit can be further reduced (but not increased) by the same option in a job: ```yaml jobs: job: runs-on: docker container: image: code.forgejo.org/oci/node:20-bookworm options: --memory 200M steps: - run: echo OK ``` or a service container: ```yaml job: my-job: runs-on: docker services: pgsql: image: postgres:15 options: --memory 1G ``` Refs https://docs.docker.com/engine/containers/resource_constraints/#limit-a-containers-access-to-memory <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - features - [PR](https://code.forgejo.org/forgejo/runner/pulls/1079): <!--number 1079 --><!--line 0 --><!--description ZmVhdDogYWxsb3cgLS1tZW1vcnkgaW4gd29ya2Zsb3cgY29udGFpbmVyIG9wdGlvbnM=-->feat: allow --memory in workflow container options<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1079 Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
parent
44b8b91540
commit
66a7e82c43
2 changed files with 174 additions and 0 deletions
|
@ -483,6 +483,14 @@ func (cr *containerReference) mergeJobOptions(ctx context.Context, config *conta
|
|||
}
|
||||
}
|
||||
|
||||
if jobConfig.HostConfig.Memory > 0 {
|
||||
logger.Debugf("--memory %v", jobConfig.HostConfig.Memory)
|
||||
if hostConfig.Memory > 0 && jobConfig.HostConfig.Memory > hostConfig.Memory {
|
||||
return nil, nil, fmt.Errorf("the --memory %v option found in the workflow cannot be greater than the --memory %v option from the runner configuration file", jobConfig.HostConfig.Memory, hostConfig.Memory)
|
||||
}
|
||||
hostConfig.Memory = jobConfig.HostConfig.Memory
|
||||
}
|
||||
|
||||
if len(jobConfig.Config.Hostname) > 0 {
|
||||
logger.Debugf("--hostname %v", jobConfig.Config.Hostname)
|
||||
config.Hostname = jobConfig.Config.Hostname
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue