fixed issue with windows using bash script
This commit is contained in:
@@ -41,11 +41,6 @@ type Config struct {
|
|||||||
Acme bool `envconfig:"DRONE_HTTP_ACME"`
|
Acme bool `envconfig:"DRONE_HTTP_ACME"`
|
||||||
}
|
}
|
||||||
|
|
||||||
Keypair struct {
|
|
||||||
Public string `envconfig:"DRONE_PUBLIC_KEY_FILE"`
|
|
||||||
Private string `envconfig:"DRONE_PRIVATE_KEY_FILE"`
|
|
||||||
}
|
|
||||||
|
|
||||||
Runner struct {
|
Runner struct {
|
||||||
Name string `envconfig:"DRONE_RUNNER_NAME"`
|
Name string `envconfig:"DRONE_RUNNER_NAME"`
|
||||||
Capacity int `envconfig:"DRONE_RUNNER_CAPACITY" default:"2"`
|
Capacity int `envconfig:"DRONE_RUNNER_CAPACITY" default:"2"`
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ func (c *Compiler) Compile(ctx context.Context, args Args) *engine.Spec {
|
|||||||
dst.Envs = environ.Combine(envs, dst.Envs)
|
dst.Envs = environ.Combine(envs, dst.Envs)
|
||||||
dst.Volumes = append(dst.Volumes, mount)
|
dst.Volumes = append(dst.Volumes, mount)
|
||||||
dst.Labels = labels
|
dst.Labels = labels
|
||||||
setupScript(src, dst, full)
|
setupScript(src, dst, os)
|
||||||
setupWorkdir(src, dst, full)
|
setupWorkdir(src, dst, full)
|
||||||
spec.Steps = append(spec.Steps, dst)
|
spec.Steps = append(spec.Steps, dst)
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,9 @@ func setupScript(src *resource.Step, dst *engine.Step, os string) {
|
|||||||
// windows operating system.
|
// windows operating system.
|
||||||
func setupScriptWindows(src *resource.Step, dst *engine.Step) {
|
func setupScriptWindows(src *resource.Step, dst *engine.Step) {
|
||||||
dst.Entrypoint = []string{"powershell", "-noprofile", "-noninteractive", "-command"}
|
dst.Entrypoint = []string{"powershell", "-noprofile", "-noninteractive", "-command"}
|
||||||
dst.Command = []string{"echo $DRONE_SCRIPT | iex"}
|
dst.Command = []string{"echo $Env:DRONE_SCRIPT | iex"}
|
||||||
dst.Envs["DRONE_SCRIPT"] = powershell.Script(src.Commands)
|
dst.Envs["DRONE_SCRIPT"] = powershell.Script(src.Commands)
|
||||||
|
dst.Envs["SHELL"] = "powershell.exe"
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function configures the pipeline script for the
|
// helper function configures the pipeline script for the
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
|
"github.com/drone-runners/drone-runner-docker/internal/docker/errors"
|
||||||
"github.com/drone-runners/drone-runner-docker/internal/docker/image"
|
"github.com/drone-runners/drone-runner-docker/internal/docker/image"
|
||||||
"github.com/drone-runners/drone-runner-docker/internal/docker/jsonmessage"
|
"github.com/drone-runners/drone-runner-docker/internal/docker/jsonmessage"
|
||||||
"github.com/drone-runners/drone-runner-docker/internal/docker/stdcopy"
|
"github.com/drone-runners/drone-runner-docker/internal/docker/stdcopy"
|
||||||
@@ -68,7 +69,7 @@ func (e *Docker) Setup(ctx context.Context, spec *Spec) error {
|
|||||||
Labels: vol.EmptyDir.Labels,
|
Labels: vol.EmptyDir.Labels,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.TrimExtraInfo(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +84,7 @@ func (e *Docker) Setup(ctx context.Context, spec *Spec) error {
|
|||||||
Labels: spec.Network.Labels,
|
Labels: spec.Network.Labels,
|
||||||
})
|
})
|
||||||
|
|
||||||
return err
|
return errors.TrimExtraInfo(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy the pipeline environment.
|
// Destroy the pipeline environment.
|
||||||
@@ -132,17 +133,17 @@ func (e *Docker) Run(ctx context.Context, spec *Spec, step *Step, output io.Writ
|
|||||||
// create the container
|
// create the container
|
||||||
err := e.create(ctx, spec, step, output)
|
err := e.create(ctx, spec, step, output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, errors.TrimExtraInfo(err)
|
||||||
}
|
}
|
||||||
// start the container
|
// start the container
|
||||||
err = e.start(ctx, step.ID)
|
err = e.start(ctx, step.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, errors.TrimExtraInfo(err)
|
||||||
}
|
}
|
||||||
// tail the container
|
// tail the container
|
||||||
err = e.tail(ctx, step.ID, output)
|
err = e.tail(ctx, step.ID, output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, errors.TrimExtraInfo(err)
|
||||||
}
|
}
|
||||||
// wait for the response
|
// wait for the response
|
||||||
return e.wait(ctx, step.ID)
|
return e.wait(ctx, step.ID)
|
||||||
|
|||||||
26
internal/docker/errors/errors.go
Normal file
26
internal/docker/errors/errors.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by the Polyform License
|
||||||
|
// that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package errors
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TrimExtraInfo is a helper function that trims extra information
|
||||||
|
// from a Docker error. Specifically, on Windows, this can expose
|
||||||
|
// environment variables and other sensitive data.
|
||||||
|
func TrimExtraInfo(err error) error {
|
||||||
|
s := err.Error()
|
||||||
|
i := strings.Index(s, "extra info:")
|
||||||
|
if i > 0 {
|
||||||
|
s = s[:i]
|
||||||
|
s = strings.TrimSpace(s)
|
||||||
|
s = strings.TrimSuffix(s, "(0x2)")
|
||||||
|
s = strings.TrimSpace(s)
|
||||||
|
return errors.New(s)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
22
internal/docker/errors/errors_test.go
Normal file
22
internal/docker/errors/errors_test.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by the Polyform License
|
||||||
|
// that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package errors
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTrimExtraInfo(t *testing.T) {
|
||||||
|
const (
|
||||||
|
before = `Error response from daemon: container encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2) extra info: { "User":"ContainerUser" }`
|
||||||
|
after = `Error response from daemon: container encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified.`
|
||||||
|
)
|
||||||
|
errBefore := errors.New(before)
|
||||||
|
errAfter := TrimExtraInfo(errBefore)
|
||||||
|
if errAfter.Error() != after {
|
||||||
|
t.Errorf("Expect trimmed image")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user