@@ -7,6 +7,7 @@ package cmd
7
7
import (
8
8
"context"
9
9
"fmt"
10
+ "log"
10
11
"os"
11
12
"os/exec"
12
13
"path/filepath"
@@ -36,7 +37,7 @@ var buildCmd = &cobra.Command{
36
37
37
38
tmpDir , err := os .MkdirTemp ("" , "gp-build-*" )
38
39
if err != nil {
39
- utils . LogError ( ctx , err , "Could not create temporary directory" , client )
40
+ log . Fatal ( "Could not create temporary directory" )
40
41
return
41
42
}
42
43
defer os .RemoveAll (tmpDir )
@@ -50,7 +51,7 @@ var buildCmd = &cobra.Command{
50
51
ctx = context .Background ()
51
52
gitpodConfig , err := util .ParseGitpodConfig (wsInfo .CheckoutLocation )
52
53
if err != nil {
53
- utils . LogError ( ctx , err , "Could not parse gitpod config" , client )
54
+ log . Fatal ( "Could not parse gitpod config" )
54
55
return
55
56
}
56
57
@@ -72,14 +73,14 @@ var buildCmd = &cobra.Command{
72
73
baseimage = "FROM " + img
73
74
case map [interface {}]interface {}:
74
75
dockerfilePath := filepath .Join (wsInfo .CheckoutLocation , img ["file" ].(string ))
75
- fmt . Println ( dockerfilePath )
76
+
76
77
if _ , err := os .Stat (dockerfilePath ); os .IsNotExist (err ) {
77
78
fmt .Println ("Your .gitpod.yml points to a Dockerfile that doesn't exist: " + dockerfilePath )
78
79
return
79
80
}
80
81
dockerfile , err := os .ReadFile (dockerfilePath )
81
82
if err != nil {
82
- utils . LogError ( ctx , err , "Could not read the Dockerfile" , client )
83
+ log . Fatal ( "Could not read the Dockerfile" )
83
84
return
84
85
}
85
86
if string (dockerfile ) == "" {
@@ -105,6 +106,13 @@ var buildCmd = &cobra.Command{
105
106
return
106
107
}
107
108
109
+ err = os .WriteFile (filepath .Join (tmpDir , "Dockerfile" ), []byte (baseimage ), 0644 )
110
+ if err != nil {
111
+ fmt .Println ("Could not write the temporary Dockerfile" )
112
+ log .Fatal (err )
113
+ return
114
+ }
115
+
108
116
tag := "temp-build-" + time .Now ().Format ("20060102150405" )
109
117
110
118
dockerCmd := exec .Command ("docker" , "build" , "-t" , tag , "--progress=tty" , "." )
@@ -113,25 +121,22 @@ var buildCmd = &cobra.Command{
113
121
dockerCmd .Stdout = os .Stdout
114
122
dockerCmd .Stderr = os .Stderr
115
123
116
- err = os .WriteFile (filepath .Join (tmpDir , "Dockerfile" ), []byte (baseimage ), 0644 )
117
- if err != nil {
118
- utils .LogError (ctx , err , "Could not write the temporary Dockerfile" , client )
119
- return
120
- }
121
-
122
124
go func () {
123
125
<- ctx .Done ()
124
126
if proc := dockerCmd .Process ; proc != nil {
125
127
_ = proc .Kill ()
126
128
}
127
129
}()
128
130
131
+ // TODO: duration
129
132
err = dockerCmd .Run ()
130
133
if _ , ok := err .(* exec.ExitError ); ok {
131
- utils .LogError (ctx , err , "Workspace image build failed" , client )
134
+ fmt .Println ("Image Build Failed" )
135
+ log .Fatal (err )
132
136
return
133
137
} else if err != nil {
134
- utils .LogError (ctx , err , "Docker error" , client )
138
+ fmt .Println ("Docker error" )
139
+ log .Fatal (err )
135
140
return
136
141
}
137
142
},
0 commit comments