github.com/jonsyu1/godel@v0.0.0-20171017211503-64567a0cf169/apps/distgo/cmd/docker/cmd.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 docker 16 17 import ( 18 "github.com/nmiyake/pkg/dirs" 19 "github.com/palantir/pkg/cli" 20 "github.com/palantir/pkg/cli/cfgcli" 21 "github.com/palantir/pkg/cli/flag" 22 23 "github.com/palantir/godel/apps/distgo/cmd" 24 "github.com/palantir/godel/apps/distgo/config" 25 ) 26 27 const ( 28 baseRepoFlagName = "base-repo" 29 verboseFlagName = "verbose" 30 ) 31 32 var ( 33 baseRepoFlag = flag.StringFlag{ 34 Name: baseRepoFlagName, 35 Usage: "This is joined with per image repository path while building/publishing images", 36 Value: "", 37 } 38 verboseFlag = flag.BoolFlag{ 39 Name: verboseFlagName, 40 Alias: "v", 41 Usage: "Print the output from the Docker commands", 42 } 43 ) 44 45 func Command() cli.Command { 46 build := cli.Command{ 47 Name: "build", 48 Flags: []flag.Flag{ 49 verboseFlag, 50 baseRepoFlag, 51 cmd.ProductsParam, 52 }, 53 Action: func(ctx cli.Context) error { 54 cfg, err := config.Load(cfgcli.ConfigPath, cfgcli.ConfigJSON) 55 if err != nil { 56 return err 57 } 58 wd, err := dirs.GetwdEvalSymLinks() 59 if err != nil { 60 return err 61 } 62 return Build( 63 ctx.Slice(cmd.ProductsParamName), 64 cfg, 65 wd, 66 ctx.String(baseRepoFlagName), 67 ctx.Bool(verboseFlagName), 68 ctx.App.Stdout, 69 ) 70 }, 71 } 72 73 publish := cli.Command{ 74 Name: "publish", 75 Flags: []flag.Flag{ 76 verboseFlag, 77 baseRepoFlag, 78 cmd.ProductsParam, 79 }, 80 Action: func(ctx cli.Context) error { 81 cfg, err := config.Load(cfgcli.ConfigPath, cfgcli.ConfigJSON) 82 if err != nil { 83 return err 84 } 85 wd, err := dirs.GetwdEvalSymLinks() 86 if err != nil { 87 return err 88 } 89 return Publish( 90 ctx.Slice(cmd.ProductsParamName), 91 cfg, 92 wd, 93 ctx.String(baseRepoFlagName), 94 ctx.Bool(verboseFlagName), 95 ctx.App.Stdout, 96 ) 97 }, 98 } 99 100 return cli.Command{ 101 Name: "docker", 102 Usage: "Runs docker tasks", 103 Subcommands: []cli.Command{ 104 build, 105 publish, 106 }, 107 } 108 }