github.com/jonsyu1/godel@v0.0.0-20171017211503-64567a0cf169/apps/distgo/params/docker.go (about) 1 // Copyright 2016 Palantir Technologies, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package params 16 17 import ( 18 "github.com/pkg/errors" 19 ) 20 21 type DockerDepType string 22 type DockerImageType string 23 24 const ( 25 DockerDepSLS DockerDepType = "sls" 26 DockerDepBin DockerDepType = "bin" 27 DockerDepRPM DockerDepType = "rpm" 28 DockerDepDocker DockerDepType = "docker" 29 DefaultDockerImageType DockerImageType = "default" 30 SLSDockerImageType DockerImageType = "sls" 31 ) 32 33 type DockerDep struct { 34 Product string 35 Type DockerDepType 36 TargetFile string 37 } 38 39 type DockerImage struct { 40 // Repository and Tag are the part of the image coordinates. 41 // For example, in alpine:latest, alpine is the repository 42 // and the latest is the tag 43 Repository string 44 Tag string 45 // ContextDir is the directory in which the docker build task is executed. 46 ContextDir string 47 BuildArgsScript string 48 // DistDeps is a slice of DockerDistDep. 49 // DockerDistDep contains a product, dist type and target file. 50 // For a particular product's dist type, we create a link from its output 51 // inside the ContextDir with the name specified in target file. 52 // This will be used to order the dist tasks such that all the dependent 53 // products' dist tasks will be executed first, after which the dist tasks for the 54 // current product are executed. 55 Deps []DockerDep 56 Info DockerImageInfo 57 } 58 59 type DockerImageInfo interface { 60 Type() DockerImageType 61 } 62 63 type DefaultDockerImageInfo struct{} 64 65 func (info *DefaultDockerImageInfo) Type() DockerImageType { 66 return DefaultDockerImageType 67 } 68 69 type SLSDockerImageInfo struct { 70 GroupID string 71 ProuductType string 72 Extensions map[string]interface{} 73 } 74 75 func (info *SLSDockerImageInfo) Type() DockerImageType { 76 return SLSDockerImageType 77 } 78 79 func ToDockerDepType(dep string) (DockerDepType, error) { 80 switch dep { 81 case "sls": 82 return DockerDepSLS, nil 83 case "rpm": 84 return DockerDepRPM, nil 85 case "bin": 86 return DockerDepBin, nil 87 case "docker": 88 return DockerDepDocker, nil 89 default: 90 return "", errors.New("Invalid docker dependency type") 91 } 92 }