@@ -43,19 +43,21 @@ type Step struct {
43
43
Args []string
44
44
}
45
45
46
+ // struct for images/<image>/cloudbuild.yaml
47
+ // Example: images/alpine/cloudbuild.yaml
46
48
type CloudBuildYAMLFile struct {
47
49
Steps []Step `yaml:"steps"`
48
50
Substitutions map [string ]string
49
51
Images []string
50
52
}
51
53
52
- func getProjectId () (string , error ) {
54
+ func getProjectID () (string , error ) {
53
55
cmd := exec .Command ("gcloud" , "config" , "get-value" , "project" )
54
- projectId , err := cmd .Output ()
56
+ projectID , err := cmd .Output ()
55
57
if err != nil {
56
58
return "" , fmt .Errorf ("failed to get project_id: %v" , err )
57
59
}
58
- return string (projectId ), nil
60
+ return string (projectID ), nil
59
61
}
60
62
61
63
func getImageName (o options , tag string , config string ) (string , error ) {
@@ -64,9 +66,9 @@ func getImageName(o options, tag string, config string) (string, error) {
64
66
if err := yaml .Unmarshal (buf , & cloudbuildyamlFile ); err != nil {
65
67
return "" , fmt .Errorf ("failed to get image name: %v" , err )
66
68
}
67
- var projectId , _ = getProjectId ()
69
+ var projectID , _ = getProjectID ()
68
70
var imageNames = cloudbuildyamlFile .Images
69
- r := strings .NewReplacer ("$PROJECT_ID" , strings .TrimSpace (projectId ), "$_GIT_TAG" , tag , "$_CONFIG" , config )
71
+ r := strings .NewReplacer ("$PROJECT_ID" , strings .TrimSpace (projectID ), "$_GIT_TAG" , tag , "$_CONFIG" , config )
70
72
var result string
71
73
for _ , name := range imageNames {
72
74
result = result + r .Replace (name ) + " "
@@ -186,13 +188,13 @@ func runSingleJob(o options, jobName, uploaded, version string, subs map[string]
186
188
187
189
cmd := exec .Command ("gcloud" , args ... )
188
190
189
- var p string
191
+ var logFilePath string
190
192
if o .logDir != "" {
191
- p = path .Join (o .logDir , strings .Replace (jobName , "/" , "-" , - 1 )+ ".log" )
192
- f , err := os .Create (p )
193
+ logFilePath = path .Join (o .logDir , strings .Replace (jobName , "/" , "-" , - 1 )+ ".log" )
194
+ f , err := os .Create (logFilePath )
193
195
194
196
if err != nil {
195
- return fmt .Errorf ("couldn't create %s: %v" , p , err )
197
+ return fmt .Errorf ("couldn't create %s: %v" , logFilePath , err )
196
198
}
197
199
198
200
defer f .Sync ()
@@ -207,7 +209,7 @@ func runSingleJob(o options, jobName, uploaded, version string, subs map[string]
207
209
208
210
if err := cmd .Run (); err != nil {
209
211
if o .logDir != "" {
210
- buildLog , _ := ioutil .ReadFile (p )
212
+ buildLog , _ := ioutil .ReadFile (logFilePath )
211
213
fmt .Println (string (buildLog ))
212
214
}
213
215
return fmt .Errorf ("error running %s: %v" , cmd .Args , err )
0 commit comments