@@ -13,8 +13,9 @@ import (
13
13
"sync"
14
14
"time"
15
15
16
+ "github.com/Sirupsen/logrus"
16
17
"github.com/cenkalti/backoff"
17
- logContext "github.com/docker/distribution/context"
18
+
18
19
"github.com/netlify/open-api/go/models"
19
20
"github.com/netlify/open-api/go/plumbing/operations"
20
21
"github.com/netlify/open-api/go/porcelain/context"
@@ -31,9 +32,10 @@ type uploadError struct {
31
32
}
32
33
33
34
type file struct {
34
- Name string
35
- SHA1 hash.Hash
36
- Buffer * bytes.Buffer
35
+ Name string
36
+ AbsPath string
37
+ SHA1 hash.Hash
38
+ Buffer * bytes.Buffer
37
39
}
38
40
39
41
func (f * file ) Sum () string {
@@ -98,8 +100,10 @@ func (n *Netlify) createDeploy(ctx context.Context, siteID string, files *deploy
98
100
Files : files .Sums ,
99
101
Async : files .OverCommitted (),
100
102
}
101
-
102
- logContext .GetLoggerWithFields (ctx , context.Fields {"site_id" : siteID , "deploy_files" : len (files .Sums )}).Debug ("Deploy files" )
103
+ context .GetLogger (ctx ).WithFields (logrus.Fields {
104
+ "site_id" : siteID ,
105
+ "deploy_files" : len (files .Sums ),
106
+ }).Debug ("Deploy files" )
103
107
authInfo := context .GetAuthInfo (ctx )
104
108
105
109
params := operations .NewCreateSiteDeployParams ().WithSiteID (siteID ).WithDeploy (deployFiles )
@@ -137,8 +141,10 @@ func (n *Netlify) WaitUntilDeployReady(ctx context.Context, d *models.Deploy) (*
137
141
time .Sleep (3 * time .Second )
138
142
continue
139
143
}
140
-
141
- logContext .GetLoggerWithFields (ctx , context.Fields {"deploy_id" : d .ID , "state" : resp .Payload .State }).Debug ("Wait until deploy ready" )
144
+ context .GetLogger (ctx ).WithFields (logrus.Fields {
145
+ "deploy_id" : d .ID ,
146
+ "state" : resp .Payload .State ,
147
+ }).Debug ("Waiting until deploy ready" )
142
148
143
149
if resp .Payload .State == "prepared" || resp .Payload .State == "ready" {
144
150
return resp .Payload , nil
@@ -190,7 +196,11 @@ func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *file, wg
190
196
191
197
authInfo := context .GetAuthInfo (ctx )
192
198
193
- logContext .GetLoggerWithFields (ctx , context.Fields {"deploy_id" : d .ID , "file_path" : f .Name , "file_sum" : f .Sum ()}).Debug ("Upload file" )
199
+ context .GetLogger (ctx ).WithFields (logrus.Fields {
200
+ "deploy_id" : d .ID ,
201
+ "file_path" : f .Name ,
202
+ "file_sum" : f .Sum (),
203
+ }).Debug ("Uploading file" )
194
204
195
205
b := backoff .NewExponentialBackOff ()
196
206
b .MaxElapsedTime = 2 * time .Minute
@@ -204,11 +214,11 @@ func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *file, wg
204
214
}
205
215
sharedErr .mutex .Unlock ()
206
216
207
- params := operations .NewUploadDeployFileParams ().WithDeployID (d .ID ).WithPath (f .Name ).WithFileBody (f )
217
+ params := operations .NewUploadDeployFileParams ().WithDeployID (d .ID ).WithPath (f .AbsPath ).WithFileBody (f )
208
218
_ , err := n .Operations .UploadDeployFile (params , authInfo )
209
219
210
220
if err != nil {
211
- logContext .GetLogger (ctx ).Error (err )
221
+ context .GetLogger (ctx ).WithError (err ). Error ( "Failed to upload file" )
212
222
}
213
223
214
224
return err
@@ -239,23 +249,24 @@ func walk(dir string) (*deployFiles, error) {
239
249
return nil
240
250
}
241
251
242
- o , err := os .Open (rel )
252
+ o , err := os .Open (path )
243
253
if err != nil {
244
254
return err
245
255
}
246
256
247
257
file := & file {
248
- Name : rel ,
249
- SHA1 : sha1 .New (),
250
- Buffer : new (bytes.Buffer ),
258
+ Name : rel ,
259
+ AbsPath : path ,
260
+ SHA1 : sha1 .New (),
261
+ Buffer : new (bytes.Buffer ),
251
262
}
252
263
m := io .MultiWriter (file .SHA1 , file .Buffer )
253
264
254
265
if _ , err := io .Copy (m , o ); err != nil {
255
266
return err
256
267
}
257
268
258
- files .Add (rel , file )
269
+ files .Add (path , file )
259
270
}
260
271
261
272
return nil
0 commit comments