MCPcopy Create free account
hub / github.com/cloudbase/garm / ensureTemplates

Method ensureTemplates

database/sql/sql.go:534–688  ·  view source on GitHub ↗
(migrateTemplates bool)

Source from the content-addressed store, hash-verified

532}
533
534func (s *sqlDatabase) ensureTemplates(migrateTemplates bool) error {
535 if !migrateTemplates {
536 return nil
537 }
538 // make sure we have a default forge/OSType template. Currently we have Windows
539 // and Linux for GitHub and Linux for Gitea.
540 githubWindowsData, err := templates.GetTemplateContent(commonParams.Windows, params.GithubEndpointType)
541 if err != nil {
542 return fmt.Errorf("failed to get windows template for github: %w", err)
543 }
544
545 githubLinuxData, err := templates.GetTemplateContent(commonParams.Linux, params.GithubEndpointType)
546 if err != nil {
547 return fmt.Errorf("failed to get linux template for github: %w", err)
548 }
549
550 giteaLinuxData, err := templates.GetTemplateContent(commonParams.Linux, params.GiteaEndpointType)
551 if err != nil {
552 return fmt.Errorf("failed to get linux template for gitea: %w", err)
553 }
554
555 giteaWindowsData, err := templates.GetTemplateContent(commonParams.Windows, params.GiteaEndpointType)
556 if err != nil {
557 return fmt.Errorf("failed to get windows template for gitea: %w", err)
558 }
559
560 adminCtx := auth.GetAdminContext(s.ctx)
561
562 githubWindowsParams := params.CreateTemplateParams{
563 Name: "github_windows",
564 Description: "Default Windows runner install template for GitHub",
565 OSType: commonParams.Windows,
566 ForgeType: params.GithubEndpointType,
567 Data: githubWindowsData,
568 IsSystem: true,
569 }
570 githubWindowsSystemTemplate, err := s.CreateTemplate(adminCtx, githubWindowsParams)
571 if err != nil {
572 return fmt.Errorf("failed to create github windows template: %w", err)
573 }
574
575 githubLinuxParams := params.CreateTemplateParams{
576 Name: "github_linux",
577 Description: "Default Linux runner install template for GitHub",
578 OSType: commonParams.Linux,
579 ForgeType: params.GithubEndpointType,
580 Data: githubLinuxData,
581 IsSystem: true,
582 }
583 githubLinuxSystemTemplate, err := s.CreateTemplate(adminCtx, githubLinuxParams)
584 if err != nil {
585 return fmt.Errorf("failed to create github linux template: %w", err)
586 }
587
588 giteaLinuxParams := params.CreateTemplateParams{
589 Name: "gitea_linux",
590 Description: "Default Linux runner install template for Gitea",
591 OSType: commonParams.Linux,

Callers 1

migrateDBMethod · 0.95

Calls 8

CreateTemplateMethod · 0.95
ListAllPoolsMethod · 0.95
UpdateEntityPoolMethod · 0.95
ListAllScaleSetsMethod · 0.95
UpdateEntityScaleSetMethod · 0.95
GetTemplateContentFunction · 0.92
GetAdminContextFunction · 0.92
GetEntityMethod · 0.65

Tested by

no test coverage detected