added native copy command for multi-arch support
This commit is contained in:
@@ -25,6 +25,7 @@ func Command() {
|
||||
app := kingpin.New("drone", "drone docker runner")
|
||||
registerCompile(app)
|
||||
registerExec(app)
|
||||
registerCopy(app)
|
||||
daemon.Register(app)
|
||||
|
||||
kingpin.Version(version)
|
||||
|
||||
74
command/copy.go
Normal file
74
command/copy.go
Normal file
@@ -0,0 +1,74 @@
|
||||
// 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 command
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
type copyCommand struct {
|
||||
source string
|
||||
target string
|
||||
}
|
||||
|
||||
func (c *copyCommand) run(*kingpin.ParseContext) error {
|
||||
return Copy(c.source, c.target)
|
||||
}
|
||||
|
||||
func Copy(src, dst string) error {
|
||||
in, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
out, err := os.Create(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
_, err = io.Copy(out, in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = out.Sync()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
info, err := os.Stat(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = os.Chmod(dst, info.Mode())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return out.Close()
|
||||
}
|
||||
|
||||
// Register registers the copy command.
|
||||
func registerCopy(app *kingpin.Application) {
|
||||
c := new(copyCommand)
|
||||
|
||||
cmd := app.Command("copy", "entrypoint copy").
|
||||
Hidden().
|
||||
Action(c.run)
|
||||
|
||||
cmd.Flag("source", "source binary path").
|
||||
Default("/bin/tmate").
|
||||
StringVar(&c.source)
|
||||
|
||||
cmd.Flag("target", "target binary path").
|
||||
Default("/usr/drone/bin/tmate").
|
||||
StringVar(&c.target)
|
||||
}
|
||||
@@ -327,8 +327,8 @@ func (c *Compiler) Compile(ctx context.Context, args runtime.CompilerArgs) runti
|
||||
Labels: labels,
|
||||
Pull: engine.PullIfNotExists,
|
||||
Image: image.Expand(c.Tmate.Image),
|
||||
Entrypoint: []string{"/bin/sh", "-c"},
|
||||
Command: []string{"cp /bin/tmate /usr/drone/bin/"},
|
||||
Entrypoint: []string{"/bin/drone-runner-docker"},
|
||||
Command: []string{"copy"},
|
||||
Network: "none",
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user