Skip to content

Commit

Permalink
Merge pull request #506 from 89luca89/fix/git_clone_fallback
Browse files Browse the repository at this point in the history
Fix/git clone fallback
  • Loading branch information
FabianKramm authored Jul 12, 2023
2 parents 0caf09c + 88cc270 commit f42de42
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 73 deletions.
22 changes: 21 additions & 1 deletion cmd/agent/workspace/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,12 @@ func prepareWorkspace(ctx context.Context, workspaceInfo *provider2.AgentWorkspa
// check what type of workspace this is
if workspaceInfo.Workspace.Source.GitRepository != "" {
log.Debugf("Clone Repository")
return CloneRepository(ctx, workspaceInfo.Agent.Local == "true", workspaceInfo.ContentFolder, workspaceInfo.Workspace.Source.GitRepository, workspaceInfo.Workspace.Source.GitBranch, helper, log)
err = CloneRepository(ctx, workspaceInfo.Agent.Local == "true", workspaceInfo.ContentFolder, workspaceInfo.Workspace.Source.GitRepository, workspaceInfo.Workspace.Source.GitBranch, helper, log)
if err != nil {
// fallback
log.Errorf("Cloning failed: %v. Trying cloning on local machine and uploading folder", err)
return RemoteCloneAndDownload(ctx, workspaceInfo.ContentFolder, client, log)
}
} else if workspaceInfo.Workspace.Source.LocalFolder != "" {
log.Debugf("Download Local Folder")
return DownloadLocalFolder(ctx, workspaceInfo.ContentFolder, client, log)
Expand Down Expand Up @@ -330,6 +335,21 @@ func installDaemon(workspaceInfo *provider2.AgentWorkspaceInfo, log log.Logger)
return nil
}

func RemoteCloneAndDownload(ctx context.Context, workspaceDir string, client tunnel.TunnelClient, log log.Logger) error {
log.Infof("Cloning from host and upload folder to server")
stream, err := client.GitCloneAndRead(ctx, &tunnel.Empty{})
if err != nil {
return errors.Wrap(err, "local cloning")
}

err = extract.Extract(tunnelserver.NewStreamReader(stream, log), workspaceDir)
if err != nil {
return errors.Wrap(err, "cloning local folder")
}

return nil
}

func DownloadLocalFolder(ctx context.Context, workspaceDir string, client tunnel.TunnelClient, log log.Logger) error {
log.Infof("Upload folder to server")
stream, err := client.ReadWorkspace(ctx, &tunnel.Empty{})
Expand Down
2 changes: 2 additions & 0 deletions hack/build-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ then
mkdir ./$BUILD_DIR
fi

cat ../pkg/agent/tunnelserver/proxyserver.go

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o $BUILD_DIR/devpod-linux-amd64 $SRC_DIR
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w" -o $BUILD_DIR/devpod-linux-arm64 $SRC_DIR
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w" -o $BUILD_DIR/devpod-darwin-arm64 $SRC_DIR
Expand Down
8 changes: 8 additions & 0 deletions hack/build-grpc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

# sudo apt install protobuf-compiler
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest

cd pkg/agent/tunnel/
protoc -I . tunnel.proto --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative
108 changes: 57 additions & 51 deletions pkg/agent/tunnel/tunnel.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/agent/tunnel/tunnel.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package tunnel;
service Tunnel {
rpc Ping(Empty) returns (Empty) {}
rpc Log(LogMessage) returns (Empty) {}
rpc GitCloneAndRead(Empty) returns (stream Chunk) {}
rpc ReadWorkspace(Empty) returns (stream Chunk) {}
rpc SendResult(Message) returns (Empty) {}
rpc DockerCredentials(Message) returns (Message) {}
Expand Down Expand Up @@ -57,4 +58,3 @@ message LogMessage {
message Empty {

}

Loading

0 comments on commit f42de42

Please sign in to comment.