From 284465e1b95ef5f561b0fadead2468c0c63c0f82 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Wed, 23 Aug 2023 15:15:29 -0700 Subject: [PATCH] ci: Prepare to make compute resources for CI configurable cirrus-ci will soon restrict the amount of free resources every user gets (as have many other CI providers). For most users of CI that should not be an issue. But e.g. for cfbot it will be an issue. To allow configuring different resources on a per-repository basis, introduce infrastructure for overriding the task execution environment. Unfortunately this is not entirely trivial, as yaml anchors have to be defined before their use, and cirrus-ci only allows injecting additional contents at the end of .cirrus.yml. To deal with that, move the definition of the CI tasks to .cirrus.tasks.yml. The main .cirrus.yml is loaded first, then, if defined, the file referenced by the REPO_CI_CONFIG_GIT_URL variable, will be added, followed by the contents of .cirrus.tasks.yml. That allows REPO_CI_CONFIG_GIT_URL to override the yaml anchors defined in .cirrus.yml. Unfortunately git's default merge / rebase strategy does not handle copied files, just renamed ones. To avoid painful rebasing over this change, this commit just renames .cirrus.yml to .cirrus.tasks.yml, without adding a new .cirrus.yml. That's done in the followup commit, which moves the relevant portion of .cirrus.tasks.yml to .cirrus.yml. Until that is done, REPO_CI_CONFIG_GIT_URL does not fully work. The subsequent commit adds documentation for how to configure custom compute resources to src/tools/ci/README Reviewed-by: Daniel Gustafsson Reviewed-by: Nazir Bilal Yavuz Discussion: https://postgr.es/m/20230808021541.7lbzdefvma7qmn3w@awork3.anarazel.de Backpatch: 15-, where CI support was added --- .cirrus.star | 63 ++++++++++++++++++++++++++++++++ .cirrus.yml => .cirrus.tasks.yml | 0 2 files changed, 63 insertions(+) create mode 100644 .cirrus.star rename .cirrus.yml => .cirrus.tasks.yml (100%) diff --git a/.cirrus.star b/.cirrus.star new file mode 100644 index 0000000000..d2d6ceca20 --- /dev/null +++ b/.cirrus.star @@ -0,0 +1,63 @@ +"""Additional CI configuration, using the starlark language. See +https://cirrus-ci.org/guide/programming-tasks/#introduction-into-starlark + +See also the starlark specification at +https://github.com/bazelbuild/starlark/blob/master/spec.md + +See also .cirrus.yml and src/tools/ci/README +""" + +load("cirrus", "env", "fs") + + +def main(): + """The main function is executed by cirrus-ci after loading .cirrus.yml and can + extend the CI definition further. + + As documented in .cirrus.yml, the final CI configuration is composed of + + 1) the contents of .cirrus.yml + + 2) if defined, the contents of the file referenced by the, repository + level, REPO_CI_CONFIG_GIT_URL variable (see + https://cirrus-ci.org/guide/programming-tasks/#fs for the accepted + format) + + 3) .cirrus.tasks.yml + """ + + output = "" + + # 1) is evaluated implicitly + + # Add 2) + repo_config_url = env.get("REPO_CI_CONFIG_GIT_URL") + if repo_config_url != None: + print("loading additional configuration from \"{}\"".format(repo_config_url)) + output += config_from(repo_config_url) + else: + output += "\n# REPO_CI_CONFIG_URL was not set\n" + + # Add 3) + output += config_from(".cirrus.tasks.yml") + + return output + + +def config_from(config_src): + """return contents of config file `config_src`, surrounded by markers + indicating start / end of the the included file + """ + + config_contents = fs.read(config_src) + config_fmt = """ + +### +# contents of config file `{0}` start here +### +{1} +### +# contents of config file `{0}` end here +### +""" + return config_fmt.format(config_src, config_contents) diff --git a/.cirrus.yml b/.cirrus.tasks.yml similarity index 100% rename from .cirrus.yml rename to .cirrus.tasks.yml