Beispiel #1
0
// TarGzFile creates and returns the filename of the created file
func (t *Tar) Build() (string, error) {
	var buildFolder string

	if t.ImportPath != "" {
		gopath := os.Getenv("GOPATH")
		if gopath == "" {
			return "", errors.New("GOPATH is not set")
		}

		// or use "go list <importPath>" for all packages and commands
		d, err := deps.LoadDeps(deps.NewPkg(t.ImportPath, t.AppName))
		if err != nil {
			return "", err
		}

		err = d.InstallDeps()
		if err != nil {
			return "", err
		}

		buildFolder = filepath.Join(d.BuildGoPath, t.AppName)
		defer os.RemoveAll(d.BuildGoPath)

	} else {
		tmpDir, err := ioutil.TempDir(".", "kd-build")
		if err != nil {
			return "", err
		}
		defer os.RemoveAll(tmpDir)

		buildFolder = filepath.Join(tmpDir, t.AppName)
		os.MkdirAll(buildFolder, 0755)

		err = util.Copy(t.BinaryPath, buildFolder)
		if err != nil {
			log.Println("copy binaryPath", err)
		}
	}

	// include given files
	if t.Files != "" {
		files := strings.Split(t.Files, ",")
		for _, path := range files {
			err := util.Copy(path, buildFolder)
			if err != nil {
				log.Println("copy assets", err)
			}
		}
	}

	// create tar.gz file from final director
	tarFile := t.Output + ".tar.gz"
	err := util.MakeTar(tarFile, filepath.Dir(buildFolder))
	if err != nil {
		return "", err
	}

	return tarFile, nil
}
Beispiel #2
0
func (d *Deb) createInstallDir() error {
	gopath := os.Getenv("GOPATH")
	if gopath == "" {
		return errors.New("GOPATH is not set")
	}

	dp, err := deps.LoadDeps(deps.NewPkg(d.ImportPath, d.AppName))
	if err != nil {
		return err
	}
	dp.Ldflags = d.Ldflags

	err = dp.InstallDeps()
	if err != nil {
		return err
	}

	appFolder := filepath.Join(dp.BuildGoPath, d.AppName)
	if d.Files != "" {
		files := strings.Split(d.Files, ",")
		for _, path := range files {
			err := util.Copy(path, appFolder)
			if err != nil {
				log.Println("copy assets", err)
			}
		}
	}

	if d.SysvinitScript != "" {
		err := util.Copy(d.SysvinitScript, appFolder)

		if err != nil {
			log.Println("copy assets", err)
		}
	}

	if d.UpstartScript != "" {
		upstartPath := filepath.Join(d.BuildFolder, "debian/")
		upstartFile := filepath.Base(d.UpstartScript)

		err := util.Copy(d.UpstartScript, upstartPath)
		if err != nil {
			log.Println("copy assets", err)
		}

		oldFile := filepath.Join(upstartPath, upstartFile)
		newFile := filepath.Join(upstartPath, d.AppName+".upstart")

		err = os.Rename(oldFile, newFile)
		if err != nil {
			return err
		}
	}

	// move files to installprefix
	os.MkdirAll(filepath.Join(d.BuildFolder, d.InstallPrefix), 0755)
	installFolder := filepath.Join(d.BuildFolder, d.InstallPrefix, d.AppName)
	if err := os.Rename(appFolder, installFolder); err != nil {
		return err
	}

	return nil
}
Beispiel #3
0
// Darwin is building a new .pkg installer for darwin based OS'es. It returns
// the created filename of the .pkg file.
func (d *Darwin) Build() (string, error) {
	installRoot, err := ioutil.TempDir(".", "kd-build-darwin_")
	if err != nil {
		return "", err
	}
	defer os.RemoveAll(installRoot)

	buildFolder, err := ioutil.TempDir(".", "kd-build-darwin_")
	if err != nil {
		return "", err
	}
	defer os.RemoveAll(buildFolder)

	scriptDir := filepath.Join(buildFolder, "scripts")
	installRootUsr := filepath.Join(installRoot, "/usr/local/bin")

	os.MkdirAll(installRootUsr, 0755)
	err = util.Copy(d.BinaryPath, installRootUsr+"/"+d.AppName)
	if err != nil {
		return "", err
	}

	tempDest, err := ioutil.TempDir("", "tempDest")
	if err != nil {
		return "", err
	}
	defer os.RemoveAll(tempDest)

	d.createScripts(scriptDir)
	d.createLaunchAgent(installRoot)

	cmdPkg := exec.Command("pkgbuild",
		"--identifier", fmt.Sprintf("%s.kite.%s.pkg", d.Identifier, d.AppName),
		"--version", d.Version,
		"--scripts", scriptDir,
		"--root", installRoot,
		"--install-location", "/",
		fmt.Sprintf("%s/%s.kite.%s.pkg", tempDest, d.Identifier, d.AppName),
		// used for next step, also set up for distribution.xml
	)

	_, err = cmdPkg.CombinedOutput()
	if err != nil {
		return "", err
	}

	distributionFile := filepath.Join(buildFolder, "Distribution.xml")
	resources := "build/darwin/Resources"
	targetFile := d.Output + ".pkg"

	d.createDistribution(distributionFile)

	cmdBuild := exec.Command("productbuild",
		"--distribution", distributionFile,
		"--resources", resources,
		"--package-path", tempDest,
		targetFile,
	)

	_, err = cmdBuild.CombinedOutput()
	if err != nil {
		return "", err
	}

	return targetFile, nil
}