github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/graph/artifact_graph.go (about) 1 /* 2 Copyright 2021 The Skaffold Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package graph 18 19 import "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" 20 21 // Artifact is the result corresponding to each successful build. 22 type Artifact struct { 23 ImageName string `json:"imageName"` 24 Tag string `json:"tag"` 25 } 26 27 // ArtifactGraph is a map of [artifact image : artifact definition] 28 type ArtifactGraph map[string]*latest.Artifact 29 30 // ToArtifactGraph creates an instance of `ArtifactGraph` from `[]*latest.Artifact` 31 func ToArtifactGraph(artifacts []*latest.Artifact) ArtifactGraph { 32 m := make(map[string]*latest.Artifact) 33 for _, a := range artifacts { 34 m[a.ImageName] = a 35 } 36 return m 37 } 38 39 // Dependencies returns the de-referenced slice of required artifacts for a given artifact 40 func (g ArtifactGraph) Dependencies(a *latest.Artifact) []*latest.Artifact { 41 var sl []*latest.Artifact 42 for _, d := range a.Dependencies { 43 sl = append(sl, g[d.ImageName]) 44 } 45 return sl 46 }