Example #1
0
func loadBrickMetadata(context *pongo2.Context, baseDir *string, brick *string) (*data.BrickMetadata, *string, error) {
	// Check if simple metadata file exists
	brickMetadataFile := filepath.Join(*baseDir, fmt.Sprintf("%s.%s", *brick, brickExt))
	log.Debug("  Search brick metadata file:\n    %s", brickMetadataFile)
	if exists, _ := util.FileExists(brickMetadataFile); !exists {
		// Check if complex module metadata file exists
		brickMetadataFile = filepath.Join(*baseDir, *brick, brickModuleName)
		log.Debug("  Search brick metadata file:\n    %s", brickMetadataFile)
		if exists, _ := util.FileExists(brickMetadataFile); !exists {
			return nil, nil, errors.New(fmt.Sprintf("Could not load brick module:\n  %s\nfrom path:\n  %s", *brick, brickMetadataFile))
		}
	}

	log.Debug("  Loading brick metadata from file:\n    %s", brickMetadataFile)

	brickBaseDir := filepath.Dir(brickMetadataFile)
	log.Debug("  Brick base dir:\n  %s", brickMetadataFile)

	// Compile template
	if compiled, err := compileTemplateFromFile(context, &brickMetadataFile); err == nil {
		var metadata data.BrickMetadata
		if err := util.LoadYAMLFromString(*compiled, &metadata); err != nil {
			return nil, nil, err
		}
		return &metadata, &brickBaseDir, nil
	} else {
		return nil, nil, err
	}
}
Example #2
0
func (c ProjectCompiler) Compile(projectPath *string, dataFile *string, baseDir *string, workDir *string) {
	log.Notice("▶ Loading environment data from file:\n  %s", *projectPath)

	environment, source, err := loadEnvironment(*projectPath)
	if err != nil {
		util.HandleFatalError(err)
	}

	for _, provider := range environment.Providers {
		log.Notice("▶ Switching provider to: %s", provider.Name)
		log.Debug("  Creating template context")
		if context, err := createContext(&environment.Data, &provider, dataFile); err == nil {

			log.Notice("▶ Context data:")
			printContextData(context, false)

			log.Notice("▶ Compiling artifacts")

			if compiled, err := compileTemplateFromString(context, source); err == nil {
				var project data.Project
				if err := util.LoadYAMLFromString(*compiled, &project); err == nil {
					// Compile each artifact
					for _, artifact := range project.Artifacts {
						//log.Info("  Compiling:\n  artifact: %s\n  provider: %s", artifact.Name, provider.Name)
						if err := compileArtifact(context, &artifact, provider.Name, baseDir, workDir); err != nil {
							util.HandleFatalError(err)
						}
					}
				} else {
					err := errors.New(fmt.Sprintf("Error parsing project artifacts\nerror:\n  %s", err.Error()))
					util.HandleFatalError(err)
				}
			} else {
				util.HandleFatalError(err)
			}
		} else {
			util.HandleFatalError(err)
		}
	}
	log.Notice("▶ Completed successfully")
}
Example #3
0
func loadEnvironment(projectPath string) (*data.Environment, *string, error) {
	// YAML doesn't like the Pongo2 syntax, so we need to do the project file parsing in 2 steps
	log.Debug("  Loading project file as plain string")
	source, err := util.LoadFileAsString(projectPath)
	if err != nil {
		log.Debug("Error loading project from:\n  %s", projectPath)
		return nil, nil, err
	}
	log.Trace("-- %s --\n%s\n----", "project source", *source)

	// Extract data section from project file
	log.Debug("  Extracting environment data")

	environmentSource := regexExtractEnvironment.FindString(*source)
	log.Trace("-- %s --\n%s\n----", "environment source", environmentSource)

	var tmpProject data.Project
	if err := util.LoadYAMLFromString(environmentSource, &tmpProject); err != nil {
		log.Debug("Error parsing environment data from file:\n  %s", projectPath)
		return nil, nil, err
	}

	return &tmpProject.Environment, source, nil
}