Ejemplo n.º 1
0
func loadReleaseID() (string, error) {
	releaseID := os.Getenv("WERCKER_DISTELLI_RELEASE")

	if releaseID == "" {
		if stat, err := os.Stat(releaseFilename); err == nil {
			if stat.Size() <= 0 {
				return "", errors.New(BadReleaseFile)
			}

			releaseFile, err := os.Open(releaseFilename)
			if err != nil {
				return "", errors.WrapPrefix(err, fmt.Sprintf("Error opening file %s", releaseFilename), 0)
			}
			defer releaseFile.Close()

			reader := bufio.NewReader(releaseFile)
			releaseID, err = reader.ReadString('\n')
			if err != nil && !errors.Is(err, io.EOF) {
				return "", errors.WrapPrefix(err, fmt.Sprintf("Error reading file %s", releaseFilename), 0)
			}
		}
	}

	return strings.TrimSpace(releaseID), nil
}
Ejemplo n.º 2
0
// GetReader returns an io.Reader for the file at index fileIndex
// Successive calls to `GetReader` will attempt to re-use the last
// returned reader if the file index is similar. The cache size is 1, so
// reading in parallel from different files is not supported.
func (cfp *ZipPool) GetReader(fileIndex int64) (io.Reader, error) {
	if cfp.fileIndex != fileIndex {
		if cfp.reader != nil {
			err := cfp.reader.Close()
			if err != nil {
				return nil, errors.Wrap(err, 1)
			}
			cfp.reader = nil
			cfp.fileIndex = -1
		}

		relPath := cfp.GetRelativePath(fileIndex)
		f := cfp.fmap[relPath]
		if f == nil {
			if os.Getenv("VERBOSE_ZIP_POOL") != "" {
				fmt.Printf("\nzip contents:\n")
				for k := range cfp.fmap {
					fmt.Printf("\n- %s", k)
				}
				fmt.Println()
			}
			return nil, errors.WrapPrefix(os.ErrNotExist, relPath, 1)
		}

		reader, err := f.Open()

		if err != nil {
			return nil, errors.Wrap(err, 1)
		}
		cfp.reader = reader
		cfp.fileIndex = fileIndex
	}

	return cfp.reader, nil
}
Ejemplo n.º 3
0
func deploy(description string) error {
	args := []string{"deploy"}

	environment := os.Getenv("WERCKER_DISTELLI_ENVIRONMENT")
	host := os.Getenv("WERCKER_DISTELLI_HOST")

	if environment != "" {
		if host != "" {
			return errors.New(DeployConflict)
		}
		args = append(args, "-e", environment)
	} else if host != "" {
		args = append(args, "-h", host)
	} else {
		return errors.New(DeployMissing)
	}

	_, basename, err := checkManifest()
	if err != nil {
		return err
	}

	args = append(args, "-y", "-f", basename, "-m", description)

	releaseID, err := loadReleaseID()
	if err != nil {
		return err
	}
	if releaseID != "" {
		args = append(args, "-r", releaseID)
	}

	wait := strings.ToLower(os.Getenv("WERCKER_DISTELLI_WAIT")) != "false"
	if !wait {
		args = append(args, "-q")
	}

	// A lovely piece of excrement to satisfy the type system.
	stupidity := make([]interface{}, len(args))
	for i, arg := range args {
		stupidity[i] = arg
	}
	log.Println(stupidity...)

	buffer, err := invoke(args...)
	if err != nil {
		return errors.WrapPrefix(err, "Error invoking distelli", 0)
	}
	output := buffer.String()

	if strings.Contains(output, "Deployment Failed") {
		return errors.Errorf(output)
	}

	log.Printf(output)
	return nil
}
Ejemplo n.º 4
0
func saveReleaseID(releaseID string) error {
	releaseFile, err := os.Create(releaseFilename)
	if err != nil {
		return errors.WrapPrefix(err, "Error saving release ID", 0)
	}
	defer releaseFile.Close()

	_, err = releaseFile.WriteString(releaseID + "\n")
	return err
}