/
main.go
57 lines (44 loc) · 1.06 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"io/ioutil"
"log"
"os"
"os/exec"
"github.com/drone/drone-plugin-go/plugin"
)
// SSHConfig the config used on the test runner
var SSHConfig = `Host *
StrictHostKeyChecking no`
type deployer struct {
Task string `json:"task"`
Stage string `json:"stage"`
}
func main() {
d := new(deployer)
w := new(plugin.Workspace)
plugin.Param("vargs", d)
plugin.Param("workspace", w)
plugin.MustParse()
// Save ssh keys
if err := os.MkdirAll("/root/.ssh", 0700); err != nil {
log.Fatal(err)
}
if err := ioutil.WriteFile("/root/.ssh/config", []byte(SSHConfig), 0644); err != nil {
log.Fatal(err)
}
if err := ioutil.WriteFile("/root/.ssh/id_rsa", []byte(w.Keys.Private), 0600); err != nil {
log.Fatal(err)
}
if err := ioutil.WriteFile("/root/.ssh/id_rsa.pub", []byte(w.Keys.Public), 0644); err != nil {
log.Fatal(err)
}
c := exec.Command("/bin/dep", "-n", d.Task, d.Stage)
c.Dir = w.Path
c.Stdout = os.Stdout
c.Stderr = os.Stderr
err := c.Run()
if err != nil {
log.Fatal(err)
}
log.Println("Command completed successfully")
}