// IsBuilderImage checks whether the provided Docker image is
// a builder image or not
501092
func IsBuilderImage(image *dockerv10.DockerImage) bool {
	if image == nil || image.Config == nil {
		return false
	}
	// Has the scripts annotation
	if _, ok := image.Config.Labels[s2iScriptsLabel]; ok {
		return true
	}
	// Has the legacy environment variables
	for _, env := range image.Config.Env {
		for _, name := range s2iEnvironmentNames {
			if strings.HasPrefix(env, name+"=") {
				return true
			}
		}
	}
	return false
}
243931
func checkBuildReadiness(obj runtime.Object) (bool, bool, error) {
	b, ok := obj.(*buildv1.Build)
	if !ok {
		return false, false, fmt.Errorf("object %T is not v1.Build", obj)
	}

	ready := buildutil.IsTerminalPhase(b.Status.Phase) &&
		b.Status.Phase == buildv1.BuildPhaseComplete

	failed := buildutil.IsTerminalPhase(b.Status.Phase) &&
		b.Status.Phase != buildv1.BuildPhaseComplete

	return ready, failed, nil
}
406201
func processBuilders(c context.Context, r *swarmbucketAPI.LegacySwarmbucketApiGetBuildersResponseMessage) ([]model.PoolDescriptor, error) {
	var builderPools []model.BuilderPool
	var descriptors []model.PoolDescriptor
	seen := stringset.New(0)
	for _, bucket := range r.Buckets {
		for _, builder := range bucket.Builders {
			bid := NewBuilderID(bucket.Name, builder.Name)
			if bid.Project == "" {
				// This may happen if the bucket or builder does not fulfill the LUCI
				// naming convention.
				logging.Warningf(c, "invalid bucket/builder %q/%q, skipping", bucket.Name, builder.Name)
				continue
			}
			id := bid.String()
			dimensions := stripEmptyDimensions(builder.SwarmingDimensions)
			descriptor := model.NewPoolDescriptor(builder.SwarmingHostname, dimensions)
			dID := descriptor.PoolID()
			builderPools = append(builderPools, model.BuilderPool{
				BuilderID: datastore.MakeKey(c, model.BuilderSummaryKind, id),
				PoolKey:   datastore.MakeKey(c, model.BotPoolKind, dID),
			})
			if added := seen.Add(dID); added {
				descriptors = append(descriptors, descriptor)
			}
		}
	}
	return descriptors, datastore.Put(c, builderPools)
}
561304
func filterAuthorizedBuilders(c context.Context, builders []string) ([]string, error) {
	buckets := stringset.New(0)
	for _, b := range builders {
		id := buildsource.BuilderID(b)
		buildType, bucket, _, err := id.Split()
		if err != nil {
			logging.Warningf(c, "found malformed builder ID %q", id)
			continue
		}
		if buildType == "buildbucket" {
			buckets.Add(bucket)
		}
	}
	perms, err := common.BucketPermissions(c, buckets.ToSlice()...)
	if err != nil {
		return nil, err
	}
	okBuilders := make([]string, 0, len(builders))
	for _, b := range builders {
		id := buildsource.BuilderID(b)
		buildType, bucket, _, err := id.Split()
		if err != nil {
			continue
		}
		if buildType != "buildbucket" || perms.Can(bucket, access.AccessBucket) {
			okBuilders = append(okBuilders, b)
		}
	}
	return okBuilders, nil
}
615392
func ParseBuilderID(s string) (*pb.BuilderID, error) {
	parts := strings.Split(s, "/")
	if len(parts) != 3 {
		return nil, fmt.Errorf("invalid builder id; must have 2 slashes")
	}
	return &pb.BuilderID{
		Project: parts[0],
		Bucket:  parts[1],
		Builder: parts[2],
	}, nil
}
1060552
func (c *CheckType) IsDocker() bool {
	return c.IsScript() && c.DockerContainerID != "" && c.Interval > 0
}
606674
func (c *Container) IsRunning(ctx context.Context) (bool, error) {
	return false, project.ErrUnsupported
}
538262
func (r *MongoRegistry) LookupBSONBuilder(paramType string) (builder BSONBuilder, err error) {
	r.buildersLock.RLock()
	defer r.buildersLock.RUnlock()
	b, ok := r.builders[paramType]
	if !ok {
		return nil, fmt.Errorf("Could not find BSON builder for %s", paramType)
	}
	return b, nil
}
181692
func (c *Client) BuildImage(opts BuildImageOptions) error {
	if opts.OutputStream == nil {
		return ErrMissingOutputStream
	}
	headers, err := headersWithAuth(opts.Auth, c.versionedAuthConfigs(opts.AuthConfigs))
	if err != nil {
		return err
	}

	if opts.Remote != "" && opts.Name == "" {
		opts.Name = opts.Remote
	}
	if opts.InputStream != nil || opts.ContextDir != "" {
		headers["Content-Type"] = "application/tar"
	} else if opts.Remote == "" {
		return ErrMissingRepo
	}
	if opts.ContextDir != "" {
		if opts.InputStream != nil {
			return ErrMultipleContexts
		}
		var err error
		if opts.InputStream, err = createTarStream(opts.ContextDir, opts.Dockerfile); err != nil {
			return err
		}
	}
	qs := queryString(&opts)

	if c.serverAPIVersion.GreaterThanOrEqualTo(apiVersion125) && len(opts.CacheFrom) > 0 {
		if b, err := json.Marshal(opts.CacheFrom); err == nil {
			item := url.Values(map[string][]string{})
			item.Add("cachefrom", string(b))
			qs = fmt.Sprintf("%s&%s", qs, item.Encode())
		}
	}

	if len(opts.Ulimits) > 0 {
		if b, err := json.Marshal(opts.Ulimits); err == nil {
			item := url.Values(map[string][]string{})
			item.Add("ulimits", string(b))
			qs = fmt.Sprintf("%s&%s", qs, item.Encode())
		}
	}

	if len(opts.BuildArgs) > 0 {
		v := make(map[string]string)
		for _, arg := range opts.BuildArgs {
			v[arg.Name] = arg.Value
		}
		if b, err := json.Marshal(v); err == nil {
			item := url.Values(map[string][]string{})
			item.Add("buildargs", string(b))
			qs = fmt.Sprintf("%s&%s", qs, item.Encode())
		}
	}

	return c.stream("POST", fmt.Sprintf("/build?%s", qs), streamOptions{
		setRawTerminal:    true,
		rawJSONStream:     opts.RawJSONStream,
		headers:           headers,
		in:                opts.InputStream,
		stdout:            opts.OutputStream,
		stderr:            opts.ErrorStream,
		inactivityTimeout: opts.InactivityTimeout,
		context:           opts.Context,
	})
}
293909
func filterBuilds(builds []*BuildSummary, without ...Status) []*BuildSummary {
	filtered := builds[:0]
outer:
	for _, build := range builds {
		for _, status := range without {
			if status == build.Summary.Status {
				continue outer
			}
		}
		filtered = append(filtered, build)
	}
	return filtered
}
74203
func (t *Loader) IsBinary() bool {
	return t.AssetFn != nil && t.NamesFn != nil
}
521487
func (b Base) IsImage() bool {
	_, err := getImageFormat(b.URL())
	return err == nil
}
738787
func (c *ChainConfig) IsByzantium(num *big.Int) bool {
	return isForked(c.ByzantiumBlock, num)
}
1224310
func checkBuildConfigReadiness(oc buildv1client.Interface, obj runtime.Object) (bool, bool, error) {
	bc, ok := obj.(*buildv1.BuildConfig)
	if !ok {
		return false, false, fmt.Errorf("object %T is not v1.BuildConfig", obj)
	}

	builds, err := oc.BuildV1().Builds(bc.Namespace).List(metav1.ListOptions{LabelSelector: buildutil.BuildConfigSelector(bc.Name).String()})
	if err != nil {
		return false, false, err
	}

	for _, item := range builds.Items {
		if item.Annotations[buildutil.BuildNumberAnnotation] == strconv.FormatInt(bc.Status.LastVersion, 10) {
			return checkBuildReadiness(&item)
		}
	}

	return false, false, nil
}
1041070
func (_m *APIClient) ImageBuild(ctx context.Context, _a1 io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
	ret := _m.Called(ctx, _a1, options)

	var r0 types.ImageBuildResponse
	if rf, ok := ret.Get(0).(func(context.Context, io.Reader, types.ImageBuildOptions) types.ImageBuildResponse); ok {
		r0 = rf(ctx, _a1, options)
	} else {
		r0 = ret.Get(0).(types.ImageBuildResponse)
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(context.Context, io.Reader, types.ImageBuildOptions) error); ok {
		r1 = rf(ctx, _a1, options)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
637791
func isExtensionField(pb extendableProto, field int32) bool {
	for _, er := range pb.ExtensionRangeArray() {
		if er.Start <= field && field <= er.End {
			return true
		}
	}
	return false
}
431670
func IsBuilderUnexpectedType(err error) bool {
	_, ok := Cause(err).(BuilderUnexpectedTypeError)
	return ok
}