github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/build/buildpacks/metadata.go (about) 1 /* 2 Copyright 2019 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 buildpacks 18 19 import ( 20 "encoding/json" 21 22 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" 23 ) 24 25 type buildMetadata struct { 26 Bom []bom `json:"bom"` 27 } 28 29 type bom struct { 30 Metadata bomMetadata `json:"metadata"` 31 } 32 33 type bomMetadata struct { 34 Sync []syncRule `json:"devmode.sync"` 35 } 36 37 type syncRule struct { 38 Src string `json:"src"` 39 Dest string `json:"dest"` 40 } 41 42 // $ docker inspect demo/buildpacks | jq -r '.[].Config.Labels["io.buildpacks.build.metadata"] | fromjson.bom[].metadata["devmode.sync"]' 43 func SyncRules(labels map[string]string) ([]*latest.SyncRule, error) { 44 metadataJSON, present := labels["io.buildpacks.build.metadata"] 45 if !present { 46 return nil, nil 47 } 48 49 m := buildMetadata{} 50 if err := json.Unmarshal([]byte(metadataJSON), &m); err != nil { 51 return nil, err 52 } 53 54 var rules []*latest.SyncRule 55 56 for _, b := range m.Bom { 57 for _, sync := range b.Metadata.Sync { 58 rules = append(rules, &latest.SyncRule{ 59 Src: sync.Src, 60 Dest: sync.Dest, 61 }) 62 } 63 } 64 65 return rules, nil 66 }