Skip to content

Commit 64d72d8

Browse files
authored
Merge pull request #10 from netlify/deploy_abs_path
use the absolute path for finding files
2 parents 71b38ba + af3ff22 commit 64d72d8

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

go/porcelain/context/context.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package context
22

33
import (
4-
"github.com/docker/distribution/context"
4+
"context"
5+
6+
"github.com/Sirupsen/logrus"
57
"github.com/go-openapi/runtime"
68
)
79

@@ -18,3 +20,15 @@ func WithAuthInfo(ctx Context, authInfo runtime.ClientAuthInfoWriter) Context {
1820
func GetAuthInfo(ctx Context) runtime.ClientAuthInfoWriter {
1921
return ctx.Value("netlify.auth_info").(runtime.ClientAuthInfoWriter)
2022
}
23+
24+
func WithLogger(ctx Context, entry *logrus.Entry) Context {
25+
return context.WithValue(ctx, "netlify.logger", entry)
26+
}
27+
28+
func GetLogger(ctx Context) *logrus.Entry {
29+
logger := ctx.Value("netlify.logger")
30+
if logger == nil {
31+
return logrus.NewEntry(logrus.StandardLogger())
32+
}
33+
return logger.(*logrus.Entry)
34+
}

go/porcelain/deploy.go

+27-16
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import (
1313
"sync"
1414
"time"
1515

16+
"github.com/Sirupsen/logrus"
1617
"github.com/cenkalti/backoff"
17-
logContext "github.com/docker/distribution/context"
18+
1819
"github.com/netlify/open-api/go/models"
1920
"github.com/netlify/open-api/go/plumbing/operations"
2021
"github.com/netlify/open-api/go/porcelain/context"
@@ -31,9 +32,10 @@ type uploadError struct {
3132
}
3233

3334
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
3739
}
3840

3941
func (f *file) Sum() string {
@@ -98,8 +100,10 @@ func (n *Netlify) createDeploy(ctx context.Context, siteID string, files *deploy
98100
Files: files.Sums,
99101
Async: files.OverCommitted(),
100102
}
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")
103107
authInfo := context.GetAuthInfo(ctx)
104108

105109
params := operations.NewCreateSiteDeployParams().WithSiteID(siteID).WithDeploy(deployFiles)
@@ -137,8 +141,10 @@ func (n *Netlify) WaitUntilDeployReady(ctx context.Context, d *models.Deploy) (*
137141
time.Sleep(3 * time.Second)
138142
continue
139143
}
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")
142148

143149
if resp.Payload.State == "prepared" || resp.Payload.State == "ready" {
144150
return resp.Payload, nil
@@ -190,7 +196,11 @@ func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *file, wg
190196

191197
authInfo := context.GetAuthInfo(ctx)
192198

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")
194204

195205
b := backoff.NewExponentialBackOff()
196206
b.MaxElapsedTime = 2 * time.Minute
@@ -204,11 +214,11 @@ func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *file, wg
204214
}
205215
sharedErr.mutex.Unlock()
206216

207-
params := operations.NewUploadDeployFileParams().WithDeployID(d.ID).WithPath(f.Name).WithFileBody(f)
217+
params := operations.NewUploadDeployFileParams().WithDeployID(d.ID).WithPath(f.AbsPath).WithFileBody(f)
208218
_, err := n.Operations.UploadDeployFile(params, authInfo)
209219

210220
if err != nil {
211-
logContext.GetLogger(ctx).Error(err)
221+
context.GetLogger(ctx).WithError(err).Error("Failed to upload file")
212222
}
213223

214224
return err
@@ -239,23 +249,24 @@ func walk(dir string) (*deployFiles, error) {
239249
return nil
240250
}
241251

242-
o, err := os.Open(rel)
252+
o, err := os.Open(path)
243253
if err != nil {
244254
return err
245255
}
246256

247257
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),
251262
}
252263
m := io.MultiWriter(file.SHA1, file.Buffer)
253264

254265
if _, err := io.Copy(m, o); err != nil {
255266
return err
256267
}
257268

258-
files.Add(rel, file)
269+
files.Add(path, file)
259270
}
260271

261272
return nil

0 commit comments

Comments
 (0)