Skip to content

Commit

Permalink
fix(worker): fix path with grpc plugin directory
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
  • Loading branch information
bnjjj authored and richardlt committed Jan 17, 2020
1 parent dea6e82 commit e747fa2
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions engine/worker/internal/action/grpc_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"os"
"path"
"strings"

"github.com/golang/protobuf/ptypes/empty"
Expand Down Expand Up @@ -93,7 +94,7 @@ func RunGRPCPlugin(ctx context.Context, actionName string, params []sdk.Paramete
envs = append(envs, fmt.Sprintf("%s=%s", envName, p.Value))
}

pluginSocket, err := startGRPCPlugin(context.Background(), pluginName, w, nil, startGRPCPluginOptions{
pluginSocket, err := startGRPCPlugin(ctx, pluginName, w, nil, startGRPCPluginOptions{
envs: envs,
})
if err != nil {
Expand Down Expand Up @@ -231,19 +232,36 @@ func startGRPCPlugin(ctx context.Context, pluginName string, w workerruntime.Run
}
}

var basedir string
if x, ok := w.BaseDir().(*afero.BasePathFs); ok {
basedir, _ = x.RealPath(".")
} else {
basedir = w.BaseDir().Name()
}

cmd := binary.Cmd
if _, err := sdk.LookPath(w.BaseDir(), cmd); err != nil {
return nil, sdk.WrapError(err, "plugin:%s unable to start GRPC plugin, binary command not found.", pluginName)
return nil, sdk.WrapError(err, "plugin:%s unable to find GRPC plugin, binary command not found.", pluginName)
}
cmd = path.Join(basedir, cmd)

for i := range binary.Entrypoints {
binary.Entrypoints[i] = path.Join(basedir, binary.Entrypoints[i])
}
args := append(binary.Entrypoints, binary.Args...)
var errstart error

workdir, err := workerruntime.WorkingDirectory(ctx)
if err != nil {
return nil, err
}
var dir string
if x, ok := w.BaseDir().(*afero.BasePathFs); ok {
dir, _ = x.RealPath(".")
dir, _ = x.RealPath(workdir.Name())
} else {
dir = w.BaseDir().Name()
dir = workdir.Name()
}

if c.StdPipe, c.Socket, errstart = grpcplugin.StartPlugin(ctx, pluginName, dir, cmd, args, envs); errstart != nil {
return nil, sdk.WrapError(errstart, "plugin:%s unable to start GRPC plugin... Aborting", pluginName)
}
Expand Down

0 comments on commit e747fa2

Please sign in to comment.