go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/buildbucket/proto/backend.proto (about) 1 // Copyright 2022 The LUCI Authors. All rights reserved. 2 // Use of this source code is governed under the Apache License, Version 2.0 3 // that can be found in the LICENSE file. 4 5 syntax = "proto3"; 6 7 package buildbucket.v2; 8 9 option go_package = "go.chromium.org/luci/buildbucket/proto;buildbucketpb"; 10 11 import "google/protobuf/timestamp.proto"; 12 import "google/protobuf/duration.proto"; 13 import "google/protobuf/struct.proto"; 14 import "google/rpc/status.proto"; 15 16 import "go.chromium.org/luci/buildbucket/proto/common.proto"; 17 import "go.chromium.org/luci/buildbucket/proto/launcher.proto"; 18 import "go.chromium.org/luci/buildbucket/proto/task.proto"; 19 20 // Services can implement TaskBackend in order for Buildbucket to run Builds 21 // on them and track the tasks. 22 // 23 // Besides implementing all the RPCs below, we also expect the backends to send 24 // UpdateBuildTask messages to Buildbucket via Pub/Sub. 25 // 26 // So that Buildbucket is able to 27 // * get task updates from these backends via the UpdateBuildTask messages, 28 // * periodically fetch tasks it has not heard from for a while, 29 // * give commands about tasks which it has previously issued (e.g. CancelTasks). 30 // 31 // Simple backends that opt out of backend task syncing/tracking with Buildbucket 32 // should use `TaskBackendLite` instead. 33 service TaskBackend { 34 // RunTask instructs the backend to run a task (which contains payload for 35 // executing a Buildbucket Build). 36 // 37 // The RunTaskResponse should contain the created task. 38 // And the implementation of this RPC should be idempotent. 39 // 40 // Buildbucket will invoke this RPC with the Project-scoped identity. 41 rpc RunTask(RunTaskRequest) returns (RunTaskResponse) {}; 42 43 // Buildbucket will call FetchTasks when it needs to understand the current 44 // status of tasks. 45 // 46 // This will happen at a regular, unspecified, interval when 47 // UpdateBuild/UpdateBuildTask haven't been called recently. 48 // 49 // Once the build is in a terminal state, FetchTasks SHOULD return 50 // the same response every time. 51 // 52 // Buildbucket will invoke this RPC with the Project-scoped identity. 53 rpc FetchTasks(FetchTasksRequest) returns (FetchTasksResponse) {}; 54 55 // Buildbucket will call this if it was requested to cancel some build(s). 56 // The backend SHOULD implement cancelation as best as it can, but 57 // simple backends may choose to ignore this (because the next call 58 // to UpdateBuild will indicate that the build is Canceled, and so the 59 // agent would quit). 60 // 61 // Buildbucket will invoke this RPC with the Project-scoped identity. 62 rpc CancelTasks(CancelTasksRequest) returns (CancelTasksResponse) {}; 63 64 // Buildbucket will call this when it is asked to validate project 65 // configuration i.e. the Builder.backend.config_json field. 66 // 67 // Buildbucket will invoke this RPC with the Project-scoped identity. 68 rpc ValidateConfigs(ValidateConfigsRequest) 69 returns (ValidateConfigsResponse) {}; 70 71 } 72 73 message RunTaskRequest { 74 // A string supplied by the builder configuration which will be interpreted 75 // by this backend. This should be used to encapsulate the connection 76 // information needed to target the specific backend host. 77 // 78 // For example, a backend might accept a target of 79 // 'swarming://chromium-swarm.appspot.com' to indicate "swarming" 80 // protocol and which Swarming instance it should issue the task on. 81 // 82 // In this example, we use 'swarming://' to allow for the possibility 83 // of a single backend handling multiple different protocols. 84 string target = 1; 85 86 // A REGISTER_TASK token that the backend can use to register the backend task 87 // to Buildbucket via the RegisterBuildTask RPC. 88 // DEPRECATED: The StartBuildToken in RunTaskRequest.Secrets will be used. 89 string register_backend_task_token = 2 [deprecated = true]; 90 91 // The LUCI Realm that the created task should be associated with. 92 string realm = 3; 93 94 message AgentExecutable { 95 message AgentSource { 96 string sha256 = 1; // required 97 int64 size_bytes = 2; // required 98 string url = 3; // required 99 } 100 // Mapping of cipd "${platform}" values to the direct download URL 101 // and sha256+size of the agent binary. 102 // 103 // ${platform} has the form $OS-$ARCH. 104 // 105 // $OS values: 106 // * mac 107 // * windows 108 // * linux 109 // 110 // $ARCH values: 111 // * amd64 112 // * arm64 113 // * i386 114 // 115 // The urls will be guaranteed to be valid until at least 116 // start_deadline+execution_timeout. 117 map<string, AgentSource> source = 1; 118 } 119 // The backend must run the agent with the given command line arguments 120 // (see `agent_args`) for full functionality. 121 AgentExecutable agent = 4; 122 123 // An opaque argv[1:] to be passed to the agent. 124 // 125 // Must contain build-id and hostname. 126 // i.e. 127 // `-build-id=<build id>` 128 // `-host=cr-buildbucket@appspot.com` 129 // 130 // Named caches set for this Build must be mounted all under some directory 131 // and that root directory must be passed by appending a CLI argument: 132 // `-cache-base=/path/to/cache/base`. 133 // 134 // Additionally, the Backend must arrange for the agent to know the backend 135 // task id. This must exactly match the task id used by UpdateBuildTask, 136 // and the agent will use it to make UpdateBuild calls. The backend must 137 // supply the task id to the agent by appending a CLI argument: 138 // `-task-id=<task id>` 139 // 140 // Also see `secrets` for one more potential CLI argument. 141 // 142 // For full functionality, the Backend must run the agent with this 143 // list of arguments. The agent knows how to execute the Build as defined 144 // by Buildbucket. 145 // 146 // Implementation note; I'd like to fix crbug.com/1219018 at the same time 147 // that we implement this. Otherwise we will continue to have the 148 // command-line-length issues that we do today, but they may get worse from 149 // e.g. -task-id and -cache-base. 150 repeated string agent_args = 5; 151 152 // Secrets contains key material for clients to call StartBuild or UpdateBuild. 153 // This should be added to the BuildbucketAgentContext file for use in the agent. 154 // Alternatively (but not suggested), this can be passed via LUCI_CONTEXT['secrets'] 155 // to the agent. There should be no CLI support for secrets in the agent. 156 // 157 BuildSecrets secrets = 6; 158 159 // The hostname of the buildbucket service to send RPCs back to. 160 // 161 // e.g. `cr-buildbucket.appspot.com`. 162 string buildbucket_host = 7; 163 164 // The id of the build that this request is for. 165 // 166 // For backends which are NOT using the agent, they can use this build_id to 167 // directly service the build (e.g. by calling UpdateBuild). 168 // 169 // It's possible for multiple RunTaskRequests to be issued for the same 170 // build_id; See `request_id` for how this could happen. 171 string build_id = 8; 172 173 // Dimensions are key/value pairs which describe the type of "bot" which 174 // can process this build. The specific values depend on the Backend. 175 // 176 // These also detail how long the Backend should wait for each of these 177 // before dropping them as a requirement. 178 // 179 // NOTE: These do not include Swarming's "special" named cache dimensions. 180 // see `caches` for that information. 181 repeated RequestedDimension dimensions = 9; 182 183 // Start deadline is the absolute timestamp of when this Build must start 184 // by before Buildbucket marks it as INFRA_FAILURE. 185 google.protobuf.Timestamp start_deadline = 10; 186 187 // Execution timeout is the amount of time after the Build starts that 188 // the Backend should allow it to run before beginning the graceful shutdown 189 // process (described in LUCI_CONTEXT['deadline']). 190 // 191 // Builds which run for longer than this will be marked as INFRA_FAILURE. 192 google.protobuf.Duration execution_timeout = 11; 193 194 // The amount of time on either `execution_timeout` or on a `cancel` event 195 // that the agent should be given to shut down. 196 // 197 // See LUCI_CONTEXT['deadline']. 198 // 199 // Buildbucket may mark the build as INFRA_FAILURE if it fails to terminate 200 // this much time after being canceled, or after hitting execution_timeout. 201 google.protobuf.Duration grace_period = 12; 202 203 // Describes the list of cache ids, their paths (relative to the cache root) 204 // and how long the Backend should wait for a bot with a warm cache to 205 // become available. 206 repeated CacheEntry caches = 13; 207 208 // Additional backend-specific settings. For Swarming this would include: 209 // * priority 210 // * wait_for_capacity 211 // * containment 212 google.protobuf.Struct backend_config = 14; 213 214 // Experiments are provided in order to allow Backends to roll out new 215 // features or behaviors triggered on experiments. 216 // 217 // This will be the full set of experiments selected for this Build 218 // (as they might appear in Build.input.experiments). 219 repeated string experiments = 15; 220 221 // Buildbucket will provide a request id (formatted as a UUID), which the 222 // TaskBackend SHOULD use to deduplicate the RunTaskRequest within a 10 223 // minute window. 224 // 225 // If the backend does NOT deduplicate the requests, it will put extra 226 // burden on the backend (because some useless tasks will be scheduled). 227 // However proper deduplication can be difficult to properly implement, 228 // so it may be worth the tradeoff for simple backends to just accept 229 // the possibility of occasional duplicated, useless, work. 230 string request_id = 16; 231 232 // The pubsub topic that the backend will use to send 233 // UpdateBuildTask messages to buildbucket. It is set by buildbucket using 234 // service_config and the current buildbucket host. 235 string pubsub_topic = 17; 236 } 237 238 message RunTaskResponse { 239 // The backend task created by RunTask. 240 Task task = 1; 241 } 242 243 message FetchTasksRequest { 244 // The number of TaskID will never be more than 1000. 245 repeated TaskID task_ids = 1; 246 } 247 248 message FetchTasksResponse { 249 message Response { 250 oneof response { 251 // The backend task. 252 Task task = 1; 253 254 // Error code and details of the unsuccessful RPC. 255 google.rpc.Status error = 100; 256 } 257 } 258 // These should represent the current state of the requested tasks. 259 repeated Response responses = 1; 260 } 261 262 message CancelTasksRequest { 263 // The number of TaskID will never be more than 500. 264 repeated TaskID task_ids = 1; 265 } 266 267 message CancelTasksResponse { 268 // These represent the current state of the tasks. 269 // 270 // If they're not indicated as canceled, Buildbucket will continue 271 // to call FetchTasks, or wait until the TaskBackend calls UpdateBuildTask. 272 // In other words, cancellation may be sync OR async (and this is up to 273 // the specific backend). 274 // 275 // The TaskBackend SHOULD only indicate a Task is in the canceled when that 276 // task has actually stopped execution. For example, if cancelation entails 277 // leaving a note for the bot to do the cancelation, ideally these Task 278 // objects should only contain the canceled status once the bot has actually 279 // terminated (not just when the 'please cancel' note was written). 280 repeated Task tasks = 1; 281 } 282 283 message ValidateConfigsRequest { 284 message ConfigContext { 285 string target = 1; 286 google.protobuf.Struct config_json = 2; // guaranteed to be valid JSON 287 } 288 // A list of all unique target+config_jsons that Buildbucket is requesting 289 // validation for. 290 repeated ConfigContext configs = 1; 291 } 292 293 message ValidateConfigsResponse { 294 message ErrorDetail { 295 // The 0-based index in the ValidateConfigsRequest.configs list. 296 // 297 // Note: `config_errors` can contain multiple ErrorDetail messages with 298 // the same `index` value, to indicate multiple errors on the same item. 299 int32 index = 1; 300 string error = 2; 301 } 302 // Must be sorted by `index`, and multiple ErrorDetails for the same index 303 // should be assumed to be in an order which makes sense to the backend. 304 repeated ErrorDetail config_errors = 1; 305 } 306 307 308 // Services can implement TaskBackendLite in order for Buildbucket to run Builds 309 // on them. 310 // 311 // This is for the simple use cases where the backends don't have tasks or don't 312 // need Buildbucket to track tasks. 313 // 314 // For example, some Buildbucket v1 users only want to pull builds from 315 // Buildbucket to execute and update Buildbucket about the 316 // final state of the builds. 317 // 318 // Note: Because Buildbucket cannot track the underlying tasks, the following 319 // service degradation occurs: 320 // TODO(crbug.com/1502975): Update this docstring after we implement the proposed 321 // improvement. 322 // * if the underlying task fails, BB will not know about this until the 323 // execution deadline, at which point the build will be marked as infra_failure 324 // * there is no way to get to the real underlying task via the BB API 325 // (you would have to go to the backend and somehow look for the build id) 326 // 327 // Backends that opt in backend task syncing/tracking with Buildbucket 328 // should use `TaskBackend` instead. 329 service TaskBackendLite { 330 // RunTask instructs the backend to run a task (which contains payload for 331 // executing a Buildbucket Build). 332 // 333 // This should return a dummy or empty task. 334 // 335 // While idempotency is not required, it's still nice to have if possible. 336 // 337 // Buildbucket will invoke this RPC with the Project-scoped identity. 338 rpc RunTask(RunTaskRequest) returns (RunTaskResponse) {}; 339 }