forked from Ivasoft/drone-docker
Compare commits
1 Commits
master
...
card-refac
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e311310166 |
48
card.go
Normal file
48
card.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package docker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (p Plugin) writeCard() error {
|
||||||
|
cmd := exec.Command("docker", "inspect", p.Build.Name)
|
||||||
|
data, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
out := map[string]interface{}{} // replace with docker inspect struct
|
||||||
|
if err := json.Unmarshal(data, &out); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
card := map[string]interface{}{} // replace with card struct, populate with docker inspect output
|
||||||
|
|
||||||
|
writeCard( /*p.CardPath*/ "", &card)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeCard(path string, card interface{}) {
|
||||||
|
data, _ := json.Marshal(card)
|
||||||
|
switch {
|
||||||
|
case path == "/dev/stdout":
|
||||||
|
writeCardTo(os.Stdout, data)
|
||||||
|
case path == "/dev/stderr":
|
||||||
|
writeCardTo(os.Stderr, data)
|
||||||
|
case path != "":
|
||||||
|
ioutil.WriteFile(path, data, 0644)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeCardTo(out io.Writer, data []byte) {
|
||||||
|
encoded := base64.StdEncoding.EncodeToString(data)
|
||||||
|
io.WriteString(out, "\u001B]1338;")
|
||||||
|
io.WriteString(out, encoded)
|
||||||
|
io.WriteString(out, "\u001B]0m")
|
||||||
|
io.WriteString(out, "\n")
|
||||||
|
}
|
||||||
25
docker.go
25
docker.go
@@ -156,11 +156,6 @@ func (p Plugin) Exec() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.Cleanup {
|
|
||||||
cmds = append(cmds, commandRmi(p.Build.Name)) // docker rmi
|
|
||||||
cmds = append(cmds, commandPrune()) // docker system prune -f
|
|
||||||
}
|
|
||||||
|
|
||||||
// execute all commands in batch mode.
|
// execute all commands in batch mode.
|
||||||
for _, cmd := range cmds {
|
for _, cmd := range cmds {
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
@@ -179,6 +174,26 @@ func (p Plugin) Exec() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// output the adaptive card
|
||||||
|
if err := p.writeCard(); err != nil {
|
||||||
|
fmt.Printf("Could not create adaptive card. %s\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// execute cleanup routines in batch mode
|
||||||
|
if p.Cleanup {
|
||||||
|
// clear the slice
|
||||||
|
cmds = nil
|
||||||
|
|
||||||
|
cmds = append(cmds, commandRmi(p.Build.Name)) // docker rmi
|
||||||
|
cmds = append(cmds, commandPrune()) // docker system prune -f
|
||||||
|
|
||||||
|
for _, cmd := range cmds {
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
trace(cmd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user