Upload source files to coordinator

This commit is contained in:
Fedor Korotkiy 2020-04-05 00:21:55 +03:00
parent d4e3705be3
commit 106ac182ad
5 changed files with 16 additions and 5 deletions

View file

@ -78,7 +78,7 @@ func newEnv(t *testing.T) (e *env, cancel func()) {
env.Client = client.NewClient( env.Client = client.NewClient(
env.Logger.Named("client"), env.Logger.Named("client"),
coordinatorEndpoint, coordinatorEndpoint,
filepath.Join(absCWD, "testdata/src")) filepath.Join(absCWD, "testdata", t.Name()))
coordinatorCache, err := filecache.New(filepath.Join(env.RootDir, "coordinator", "filecache")) coordinatorCache, err := filecache.New(filepath.Join(env.RootDir, "coordinator", "filecache"))
require.NoError(t, err) require.NoError(t, err)

View file

@ -140,9 +140,7 @@ func TestBuildResultsStreaming(t *testing.T) {
defer cancel() defer cancel()
buildID := build.ID{02} buildID := build.ID{02}
req := &api.BuildRequest{} req := &api.BuildRequest{}
started := &api.BuildStarted{ID: buildID} started := &api.BuildStarted{ID: buildID}
env.mock.EXPECT().StartBuild(gomock.Any(), gomock.Any(), gomock.Any()). env.mock.EXPECT().StartBuild(gomock.Any(), gomock.Any(), gomock.Any()).

View file

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"path/filepath"
"go.uber.org/zap" "go.uber.org/zap"
@ -49,7 +50,8 @@ func (c *Client) uploadSources(ctx context.Context, graph *build.Graph, started
return fmt.Errorf("file is missing in build graph: id=%s", id) return fmt.Errorf("file is missing in build graph: id=%s", id)
} }
if err := c.cache.Upload(ctx, id, path); err != nil { absPath := filepath.Join(c.sourceDir, path)
if err := c.cache.Upload(ctx, id, absPath); err != nil {
return err return err
} }
} }

View file

@ -32,8 +32,16 @@ func NewBuild(graph *build.Graph, c *Coordinator) *Build {
} }
} }
func (b *Build) missingFiles() []build.ID {
var files []build.ID
for id := range b.Graph.SourceFiles {
files = append(files, id)
}
return files
}
func (b *Build) Run(ctx context.Context, w api.StatusWriter) error { func (b *Build) Run(ctx context.Context, w api.StatusWriter) error {
if err := w.Started(&api.BuildStarted{ID: b.ID}); err != nil { if err := w.Started(&api.BuildStarted{ID: b.ID, MissingFiles: b.missingFiles()}); err != nil {
return err return err
} }

View file

@ -46,6 +46,8 @@ func (h *Handler) doGet(w http.ResponseWriter, r *http.Request, id build.ID) err
if _, err = io.Copy(w, f); err != nil { if _, err = io.Copy(w, f); err != nil {
h.l.Warn("error streaming file", zap.Error(err)) h.l.Warn("error streaming file", zap.Error(err))
} }
h.l.Debug("file download complete", zap.String("id", id.String()))
return nil return nil
} }
@ -70,6 +72,7 @@ func (h *Handler) doPut(w http.ResponseWriter, r *http.Request, id build.ID) err
} }
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
h.l.Debug("file upload complete", zap.String("id", id.String()))
return nil return nil
} }