Ejemplo n.º 1
0
//Verify that valid artifacts exist for the specified provider
//The specified provider must be a member of the given component
func (b *Base) checkProviderArtifact(c Component, provider string, checkedProviders *[]string) {
	logrus.Debugf("Provider : %v", provider)

	//If the provider has already been checked, skip it
	if providerAlreadyChecked(checkedProviders, provider) {
		return
	}

	if artifacts, ok := c.Artifacts[provider]; ok {
		//Iterate through each individual artifact entry for each provider
		for _, artifactEntry := range artifacts {
			//If the entry has a path field, check it for validity
			if artifactEntry.Path != "" {
				fullPath := filepath.Join(b.Target(), utils.SanitizePath(artifactEntry.Path))
				if utils.PathExists(fullPath) && utils.PathIsFile(fullPath) {
					logrus.Infof("Artifact %s: OK.", fullPath)
				} else {
					logrus.Errorf("Artifact %s: MISSING.", fullPath)
				}
			}
			//For this artifact to be 'fully checked',
			//we need to verify that the inherited providers (if any) are valid as well
			b.checkInheritence(c, provider, artifactEntry.Repo.Inherit, checkedProviders)
		}
		*checkedProviders = append(*checkedProviders, provider)
	}
}
Ejemplo n.º 2
0
func arrangeArtifacts(artifacts []ArtifactEntry) []string {
	result := make([]string, 0, len(artifacts))
	for _, artifact := range artifacts {
		if artifact.Path == "" {
			continue
		}
		sanitized := utils.SanitizePath(artifact.Path)
		result = append(result, sanitized)
	}
	return result
}
Ejemplo n.º 3
0
//Iterates through each artifact entry
//It then substitutes the Nulecule parameters in and saves them in the workdir
func (b *Base) processArtifacts(c *Component, provider string, ask bool) {
	for _, artifactEntry := range c.Artifacts[provider] {
		//Process inherited artifacts as well
		if len(artifactEntry.Repo.Inherit) > 0 {
			for _, inheritedProvider := range artifactEntry.Repo.Inherit {
				b.processArtifacts(c, inheritedProvider, ask)
			}
		}
		//sanitize the prefix from the file path
		santitizedPath := utils.SanitizePath(artifactEntry.Path)
		//Form the absolute path of the artifact
		artifactPath := filepath.Join(b.Target(), santitizedPath)
		b.applyTemplate(artifactPath, c, ask)
	}
}
Ejemplo n.º 4
0
//Issues a command to kubectl.
//Path is the path of the kubernets file to pass to kubectl
func (p *Kubernetes) kubectlCmd(path string) error {
	if p.Namespace == "" {
		p.Namespace = constants.DEFAULT_NAMESPACE
	}
	path = utils.SanitizePath(path)
	namespaceFlag := fmt.Sprintf("--namespace=%s", p.Namespace)
	kubeCmd := exec.Command(p.KubeCtl, "create", "-f", path, namespaceFlag)

	//In a dry run, we don't actually execute the commands, so we log and return here
	if p.DryRun() {
		logrus.Infof("DRY RUN: %s\n", kubeCmd.Args)
		return nil
	}

	if _, err := utils.CheckCommandOutput(kubeCmd, false); err != nil {
		return err
	}
	return nil
}