implement basic exec [ci skip]

This commit is contained in:
Brad Rydzewski
2019-10-22 15:21:57 -07:00
parent 00df09b842
commit 4d3f9c66af
24 changed files with 304 additions and 60 deletions

View File

@@ -369,6 +369,30 @@ func (c *Compiler) Compile(ctx context.Context, args Args) *engine.Spec {
}
}
// append volumes
for _, v := range args.Pipeline.Volumes {
id := random()
src := new(engine.Volume)
if v.EmptyDir != nil {
src.EmptyDir = &engine.VolumeEmptyDir{
ID: id,
Name: v.Name,
Medium: v.EmptyDir.Medium,
SizeLimit: int64(v.EmptyDir.SizeLimit),
Labels: labels,
}
} else if v.HostPath != nil {
src.HostPath = &engine.VolumeHostPath{
ID: id,
Name: v.Name,
Path: v.HostPath.Path,
}
} else {
continue
}
spec.Volumes = append(spec.Volumes, src)
}
return spec
}

View File

@@ -30,6 +30,6 @@ func setupScriptWindows(src *resource.Step, dst *engine.Step) {
func setupScriptPosix(src *resource.Step, dst *engine.Step) {
dst.Entrypoint = []string{"/bin/sh", "-c"}
dst.Command = []string{"echo $DRONE_SCRIPT | /bin/sh -e"}
dst.Command = []string{`echo "$DRONE_SCRIPT" | /bin/sh`}
dst.Envs["DRONE_SCRIPT"] = shell.Script(src.Commands)
}

View File

@@ -34,9 +34,8 @@ func Script(commands []string) string {
// optionScript is a helper script this is added to the build
// to set shell options, in this case, to exit on error.
const optionScript = `
if [[ ! -z "${DRONE_NETRC_FILE}" ]]; then
if [ ! -z "${DRONE_NETRC_FILE}" ]; then
echo $DRONE_NETRC_FILE > $HOME/.netrc
EOF
fi
unset DRONE_SCRIPT

View File

@@ -43,7 +43,7 @@ func createStep(spec *resource.Pipeline, src *resource.Step) *engine.Step {
Networks: nil, // set in compiler.go
Files: nil, // set below
Volumes: nil, // set below
// Devices: nil, // TODO
Devices: nil, // see below
// Resources: toResources(src), // TODO
}
@@ -55,6 +55,14 @@ func createStep(spec *resource.Pipeline, src *resource.Step) *engine.Step {
})
}
// appends the devices to the container def.
for _, vol := range src.Devices {
dst.Devices = append(dst.Devices, &engine.VolumeDevice{
Name: vol.Name,
DevicePath: vol.DevicePath,
})
}
// appends the settings variables to the
// container definition.
for key, value := range src.Settings {
@@ -82,19 +90,6 @@ func createStep(spec *resource.Pipeline, src *resource.Step) *engine.Step {
}
}
// // if the step specifies shell commands we generate a
// // script. The script is copied to the container at
// // runtime (or mounted as a config map) and then executed
// // as the entrypoint.
// if len(src.Commands) > 0 {
// switch spec.Platform.OS {
// case "windows":
// setupScriptWin(spec, dst, src)
// default:
// setupScript(spec, dst, src)
// }
// }
// set the pipeline step run policy. steps run on
// success by default, but may be optionally configured
// to run on failure.

View File

@@ -22,7 +22,12 @@ func createWorkspace(from *resource.Pipeline) (base, path, full string) {
base = from.Workspace.Base
path = from.Workspace.Path
if base == "" {
base = workspacePath
if strings.HasPrefix(path, "/") {
base = path
path = ""
} else {
base = workspacePath
}
}
full = stdpath.Join(base, path)