buildbot-nix icon indicating copy to clipboard operation
buildbot-nix copied to clipboard

Hercules-effects support

Open Mic92 opened this issue 1 year ago • 8 comments

Started in https://github.com/Mic92/buildbot-nix/pull/68

Mic92 avatar Apr 06 '24 10:04 Mic92

@Mic92 How you you plan to handle secrets? Separate secrets file for each repo or just one secret file per instance like hercules?

zowoq avatar Aug 03 '24 02:08 zowoq

Ideally one per repository if I can make it secure. Maybe each repository gets a public key for encryption.

Mic92 avatar Aug 03 '24 09:08 Mic92

I forgot to ask about the GitToken secret, it is a short lived token from the github app set by the hercules backend.

Possible that some repos may not even need to set secrets if they had this token as it could be used for pushing to the repo, pages, releases, etc.

zowoq avatar Oct 15 '24 04:10 zowoq

https://github.com/hercules-ci/hercules-ci-agent/blob/master/docs/modules/ROOT/pages/effects.adoc The store and a nix-daemon socket are accessible.

There is some logic for the socket in hercules-ci-agent/src/Hercules/Effect.hs, not sure how much of that would need to be replicated.

zowoq avatar Dec 07 '24 04:12 zowoq

These are the changes that were needed for a hci-effects.runNixDarwin deployment to work. I guess this would be okay while buildbot effects are restricted to running on the default branch?

https://buildbot.nix-community.org/#/builders/3618/builds/24/steps/3/logs/stdio

diff --git a/buildbot_effects/buildbot_effects/__init__.py b/buildbot_effects/buildbot_effects/__init__.py
index 7b2273e90..c60aa5dcc 100644
--- a/buildbot_effects/buildbot_effects/__init__.py
+++ b/buildbot_effects/buildbot_effects/__init__.py
@@ -190,6 +190,7 @@ def run_effects(
     env["HERCULES_CI_SECRETS_JSON"] = "/run/secrets.json"
     env["NIX_BUILD_TOP"] = "/build"
     env["TMPDIR"] = "/tmp"  # noqa: S108
+    env["NIX_REMOTE"] = "daemon"
     clear_env = set()
     clear_env.add("TMP")
     clear_env.add("TEMP")
@@ -235,6 +236,9 @@ def run_effects(
         "/nix/store",
         "--hostname",
         "hercules-ci",
+        "--bind",
+        "/nix/var/nix/daemon-socket/socket",
+        "/nix/var/nix/daemon-socket/socket",
     ]
 
     with NamedTemporaryFile() as tmp:

zowoq avatar Jan 21 '25 04:01 zowoq

I forgot to ask about the GitToken secret, it is a short lived token from the github app set by the hercules backend.

Possible that some repos may not even need to set secrets if they had this token as it could be used for pushing to the repo, pages, releases, etc.

Should be easy to generate in buildbot as well. Is this provided unconditionally?

Mic92 avatar Jan 21 '25 06:01 Mic92

These are the changes that were needed for a hci-effects.runNixDarwin deployment to work. I guess this would be okay while buildbot effects are restricted to running on the default branch?

https://buildbot.nix-community.org/#/builders/3618/builds/24/steps/3/logs/stdio

diff --git a/buildbot_effects/buildbot_effects/init.py b/buildbot_effects/buildbot_effects/init.py index 7b2273e90..c60aa5dcc 100644 --- a/buildbot_effects/buildbot_effects/init.py +++ b/buildbot_effects/buildbot_effects/init.py @@ -190,6 +190,7 @@ def run_effects( env["HERCULES_CI_SECRETS_JSON"] = "/run/secrets.json" env["NIX_BUILD_TOP"] = "/build" env["TMPDIR"] = "/tmp" # noqa: S108

  • env["NIX_REMOTE"] = "daemon" clear_env = set() clear_env.add("TMP") clear_env.add("TEMP") @@ -235,6 +236,9 @@ def run_effects( "/nix/store", "--hostname", "hercules-ci",

  •    "--bind",
    
  •    "/nix/var/nix/daemon-socket/socket",
    
  •    "/nix/var/nix/daemon-socket/socket",
    

    ]

    with NamedTemporaryFile() as tmp:

We already provide this type of access to CI users anyway. The only thing we should not do is giving it trusted user access.

Mic92 avatar Jan 21 '25 07:01 Mic92

Is this provided unconditionally?

No, not in the base effect, would need to set secretsMap.token = { type = "GitToken"; };. It is set by default for a few of the specialised effects in https://github.com/hercules-ci/hercules-ci-effects, e.g. publishing releases, pushing branches.

zowoq avatar Jan 21 '25 07:01 zowoq