Example #1
0
func handleCommand(context *cli.Context, filter func(string)) {
	cfg, err := buildconfig.LoadFromFile(context.GlobalString("config"))
	if err != nil {
		fmt.Printf("Unable to open / parse .gobuilder.yml file: \"%s\" - %s\n", context.GlobalString("config"), err)
		os.Exit(1)
	}

	if len(context.Args()) != 1 {
		fmt.Println("Please provide a key to retrieve")
		os.Exit(1)
	}

	key := context.Args()[0]

	switch key {
	case "readme_file":
		filter(cfg.ReadmeFile)
	case "triggers":
		filter(strings.Join(cfg.Triggers, "\n"))
	case "version_file":
		filter(cfg.VersionFile)
	case "arch_matrix":
		filter(strings.Join(buildArchList(cfg), " "))
	case "build_tags":
		filter(getBuildTags(cfg))
	case "ld_flags":
		filter(getLDFlags(cfg))
	}
}
Example #2
0
func main() {
	if len(os.Args) != 3 {
		fmt.Printf("Missing arguments.")
		os.Exit(1)
	}

	fromPathPrefix := os.Args[1]
	toPathPrefix := os.Args[2]

	cfg, err := buildconfig.LoadFromFile(".gobuilder.yml")
	if err != nil {
		fmt.Printf("Unable to open / parse .gobuilder.yml file.\n")
		os.Exit(1)
	}

	i := 0
	for to, from := range cfg.Artifacts {
		i++
		fromPath := path.Join(fromPathPrefix, from)
		toPath := path.Join(toPathPrefix, to)
		fmt.Printf("(%d/%d) %s => %s...\n", i, len(cfg.Artifacts), fromPath, toPath)

		if exists(toPath) {
			fmt.Printf("  ERR: Target path '%s' already exists.\n", toPath)
			continue
		}

		if !exists(fromPath) {
			fmt.Printf("  ERR: Source path '%s' does not exist.\n", fromPath)
		}

		src, err := os.Stat(fromPath)
		if err != nil {
			fmt.Printf("  ERR: Unable to read file stats\n")
			continue
		}

		if src.IsDir() {
			if err := copyDir(fromPath, toPath); err != nil {
				fmt.Printf("  ERR: %s\n", err)
				continue
			}
		} else {
			if err := copyFile(fromPath, toPath); err != nil {
				fmt.Printf("  ERR: %s\n", err)
				continue
			}
		}

		fmt.Printf("  OK\n")
	}
}
Example #3
0
func (b *builder) Build() error {
	log.WithFields(logrus.Fields{
		"host":   hostname,
		"repo":   b.job.Repository,
		"commit": b.job.Commit,
	}).Info("Beginning to process repo")

	cfg := &docker.Config{
		AttachStdin:  false,
		AttachStdout: true,
		AttachStderr: true,
		Image:        conf.BuildImage.ImageName,
		Env: []string{
			fmt.Sprintf("REPO=%s", b.job.Repository),
			fmt.Sprintf("GPG_DECRYPT_KEY=%s", conf.BuildImage.GPGDecryptKey),
			fmt.Sprintf("COMMIT=%s", b.job.Commit),
		},
	}
	container, err := dockerClient.CreateContainer(docker.CreateContainerOptions{
		Config: cfg,
	})
	if err != nil {
		return err
	}

	b.container = container

	err = dockerClient.StartContainer(container.ID, &docker.HostConfig{
		Binds:        []string{fmt.Sprintf("%s:/artifacts", b.tmpDir)},
		Privileged:   false,
		PortBindings: make(map[docker.Port][]docker.PortBinding),
	})
	if err != nil {
		return err
	}

	if err := redisClient.Set(fmt.Sprintf("project::%s::build-status", b.job.Repository), "building", 0, 0, false, false); err != nil {
		return err
	}

	status, err := dockerClient.WaitContainer(container.ID)
	if err != nil {
		return err
	}

	switch status {
	case 0:
		b.BuildOK = true
		b.UploadRequired = true
	case 130: // Special case: Build was aborted due to redundant build request
		b.BuildOK = true
		b.UploadRequired = false
	default:
		b.BuildOK = false
		b.UploadRequired = false
	}

	b.buildConfig, err = buildconfig.LoadFromFile(fmt.Sprintf("%s/.gobuilder.yml", b.tmpDir))
	if err != nil {
		// We got no .gobuilder.yml? Assume something was terribly wrong and requeue build.
		b.BuildOK = false
	}

	return nil
}