Exemple #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
}
Exemple #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
}