MCPcopy Index your code
hub / github.com/rilldata/rill / CreateDeployment

Method CreateDeployment

admin/server/deployment.go:249–390  ·  view source on GitHub ↗

CreateDeployment creates a new deployment for a project.

(ctx context.Context, req *adminv1.CreateDeploymentRequest)

Source from the content-addressed store, hash-verified

247
248// CreateDeployment creates a new deployment for a project.
249func (s *Server) CreateDeployment(ctx context.Context, req *adminv1.CreateDeploymentRequest) (*adminv1.CreateDeploymentResponse, error) {
250 observability.AddRequestAttributes(ctx,
251 attribute.String("args.organization_name", req.Org),
252 attribute.String("args.project_name", req.Project),
253 attribute.String("args.environment", req.Environment),
254 attribute.String("args.branch", req.Branch),
255 attribute.Bool("args.editable", req.Editable),
256 )
257
258 proj, err := s.admin.DB.FindProjectByName(ctx, req.Org, req.Project)
259 if err != nil {
260 return nil, err
261 }
262
263 claims := auth.GetClaims(ctx)
264 permissions := claims.ProjectPermissions(ctx, proj.OrganizationID, proj.ID)
265
266 if req.Environment == "dev" {
267 if !permissions.ManageDev {
268 return nil, status.Error(codes.PermissionDenied, "does not have permission to manage dev deployment")
269 }
270 } else {
271 if !permissions.ManageProd {
272 return nil, status.Error(codes.PermissionDenied, "does not have permission to manage prod deployment")
273 }
274 }
275
276 // Determine branch and slots based on environment.
277 var branch string
278 var autogeneratedBranch bool
279 var slots int
280 switch req.Environment {
281 case "prod":
282 if req.Branch != "" {
283 branch = req.Branch
284 } else {
285 branch = proj.PrimaryBranch
286 }
287 if req.Editable {
288 return nil, status.Error(codes.InvalidArgument, "editable cannot be set for prod deployments")
289 }
290 slots = proj.ProdSlots
291 case "dev":
292 if req.Branch != "" {
293 branch = req.Branch
294 } else {
295 autogeneratedBranch = true
296 // Generate a random branch name for dev deployments
297 b := make([]byte, 8)
298 _, err := rand.Read(b)
299 if err != nil {
300 return nil, status.Error(codes.Internal, err.Error())
301 }
302 branch = fmt.Sprintf("rill/%s", hex.EncodeToString(b))
303 }
304 slots = proj.DevSlots
305 default:
306 return nil, status.Error(codes.InvalidArgument, "invalid environment specified, must be 'prod' or 'dev'")

Callers

nothing calls this directly

Calls 15

AddRequestAttributesFunction · 0.92
GetClaimsFunction · 0.92
deploymentToDTOFunction · 0.85
StringMethod · 0.65
FindProjectByNameMethod · 0.65
ProjectPermissionsMethod · 0.65
ErrorfMethod · 0.65
FindOrganizationMethod · 0.65
OwnerTypeMethod · 0.65
OwnerIDMethod · 0.65

Tested by

no test coverage detected