MCPcopy Create free account
hub / github.com/OpenCSGs/csghub-server / Deploy

Method Deploy

component/space.go:527–581  ·  view source on GitHub ↗
(ctx context.Context, namespace, name, currentUser string)

Source from the content-addressed store, hash-verified

525}
526
527func (c *SpaceComponent) Deploy(ctx context.Context, namespace, name, currentUser string) (int64, error) {
528 s, err := c.ss.FindByPath(ctx, namespace, name)
529 if err != nil {
530 slog.Error("can't deploy space", slog.Any("error", err), slog.String("namespace", namespace), slog.String("name", name))
531 return -1, err
532 }
533 // found user id
534 user, err := c.us.FindByUsername(ctx, currentUser)
535 if err != nil {
536 slog.Error("can't find user for create deploy space", slog.Any("error", err), slog.String("username", currentUser))
537 return -1, err
538 }
539
540 // put repo-type and namespace/name in annotation
541 annotations := make(map[string]string)
542 annotations[types.ResTypeKey] = string(types.SpaceRepo)
543 annotations[types.ResNameKey] = fmt.Sprintf("%s/%s", namespace, name)
544 annoStr, err := json.Marshal(annotations)
545 if err != nil {
546 slog.Error("fail to create annotations for deploy space", slog.Any("error", err), slog.String("username", currentUser))
547 return -1, err
548 }
549
550 containerImg := ""
551 slog.Info("get space for deploy", slog.Any("space", s), slog.Any("NGINX", scheduler.NGINX))
552 slog.Info("compare space sdk", slog.Any("s.Sdk", s.Sdk), slog.Any("scheduler.NGINX.Name", scheduler.NGINX.Name))
553 if s.Sdk == scheduler.NGINX.Name {
554 slog.Warn("space use nginx pre-define image", slog.Any("namespace", namespace), slog.Any("name", name), slog.Any("scheduler.NGINX.Image", scheduler.NGINX.Image))
555 // Use default image for nginx space
556 containerImg = scheduler.NGINX.Image
557 }
558 slog.Info("run space with container image", slog.Any("namespace", namespace), slog.Any("name", name), slog.Any("containerImg", containerImg))
559
560 // create deploy for space
561 return c.deployer.Deploy(ctx, types.DeployRepo{
562 SpaceID: s.ID,
563 Path: s.Repository.Path,
564 GitPath: s.Repository.GitPath,
565 GitBranch: s.Repository.DefaultBranch,
566 Sdk: s.Sdk,
567 SdkVersion: s.SdkVersion,
568 Template: s.Template,
569 Env: s.Env,
570 Hardware: s.Hardware,
571 Secret: s.Secrets,
572 RepoID: s.Repository.ID,
573 ModelID: 0,
574 UserID: user.ID,
575 Annotation: string(annoStr),
576 ImageID: containerImg,
577 Type: types.SpaceType,
578 UserUUID: user.UUID,
579 SKU: s.SKU,
580 })
581}
582
583func (c *SpaceComponent) Wakeup(ctx context.Context, namespace, name string) error {
584 s, err := c.ss.FindByPath(ctx, namespace, name)

Callers

nothing calls this directly

Calls 4

ErrorMethod · 0.80
FindByUsernameMethod · 0.80
DeployMethod · 0.65
FindByPathMethod · 0.45

Tested by

no test coverage detected