Example #1
0
func (s *Sous) AssembleTargetContext(targetName string) (Target, *Context) {
	packs := s.Packs
	p := DetectProjectType(packs)
	if p == nil {
		cli.Fatalf("no buildable project detected")
	}
	pack := CompiledPack{Pack: p}
	target, ok := pack.GetTarget(targetName)
	if !ok {
		cli.Fatalf("The %s build pack does not support %s", pack, targetName)
	}
	if fatal := CheckForProblems(pack.Pack); fatal {
		cli.Fatal()
	}
	context := GetContext(targetName)
	err := target.Check()
	if err != nil {
		cli.Fatalf("unable to %s %s project: %s", targetName, pack, err)
	}
	// If the pack specifies a version, check it matches the tagged version
	packAppVersion := strings.Split(pack.AppVersion(), "+")[0]
	if packAppVersion != "" {
		pv := version.Version(packAppVersion)
		gv := version.Version(context.BuildVersion.MajorMinorPatch)
		if !pv.Version.LimitedEqual(gv.Version) {
			cli.Warn("using latest git tagged version %s; your code reports version %s, which is ignored", gv, pv)
		}
	}
	return target, context
}
Example #2
0
func (p *Pack) AvailableNodeVersions() version.VL {
	vs := make([]*version.V, len(*p.Config.AvailableVersions))
	for i, v := range *p.Config.AvailableVersions {
		vs[i] = version.Version(v.Name)
	}
	return vs
}
Example #3
0
func RequireVersion(r *version.R) {
	vs := cmd.Table("docker", "--version")[0][2]
	vs = strings.Trim(vs, ",")
	v := version.Version(vs)
	if !r.IsSatisfiedBy(v) {
		cli.Fatalf("got docker version %s; want %s", v, r)
	}
}
Example #4
0
func RequireVersion(r *version.R) {
	if c := cmd.ExitCode("git", "--version"); c != 0 {
		cli.Fatalf("git required")
	}
	v := version.Version(cmd.Table("git", "--version")[0][2])
	if !r.IsSatisfiedBy(v) {
		cli.Fatalf("you have git version %s; want %s", v, r.Original)
	}
}
Example #5
0
		cli.Fatalf("unable to satisfy NodeJS version '%s' (from package.json); available versions are: %s",
			np.Engines.Node, strings.Join(p.AvailableNodeVersions().Strings(), ", "))
	}
	return nodeVersion.String()
}

func (p *Pack) dockerFrom(nodeVersion, target string) string {
	if tag, ok := p.Config.AvailableVersions.GetBaseImageTag(nodeVersion, target); ok {
		return tag
	}
	cli.Fatalf("No base image available for NodeJS %s, target: %s", nodeVersion, target)
	return ""
}

var npmVersions = version.VersionList("3.3.4", "2.4.15")
var defaultNPMVersion = version.Version("2.4.15")

var wd = "/srv/app/"

func (p *Pack) baseDockerfile(target string) *docker.Dockerfile {
	np := p.PackageJSON
	nodeVersion := p.bestSupportedNodeVersion()
	from := p.dockerFrom(nodeVersion, target) + ":latest"
	npmVer := defaultNPMVersion
	if np.Engines.NPM != "" {
		npmVer = version.Range(np.Engines.NPM).BestMatchFrom(npmVersions)
		if npmVer == nil {
			cli.Logf("NPM version %s not supported, try using a range instead.", np.Engines.NPM)
			cli.Fatalf("Available NPM version ranges are: '^3' and '^2'")
		}
	}