-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) publish docker data to create drone card (#347)
* plugin logic to write card data to publish drone card
- Loading branch information
1 parent
3593c41
commit 246dfb3
Showing
7 changed files
with
244 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package docker | ||
|
||
import ( | ||
"encoding/base64" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"os/exec" | ||
"time" | ||
|
||
"github.com/drone/drone-go/drone" | ||
|
||
"github.com/inhies/go-bytesize" | ||
) | ||
|
||
func (p Plugin) writeCard() error { | ||
cmd := exec.Command("docker", "inspect", p.Build.Name) | ||
data, err := cmd.CombinedOutput() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
out := Inspect{} | ||
if err := json.Unmarshal(data, &out); err != nil { | ||
return err | ||
} | ||
|
||
inspect := out[0] | ||
inspect.SizeString = fmt.Sprint(bytesize.New(float64(inspect.Size))) | ||
inspect.VirtualSizeString = fmt.Sprint(bytesize.New(float64(inspect.VirtualSize))) | ||
inspect.Time = fmt.Sprint(inspect.Metadata.LastTagTime.Format(time.RFC3339)) | ||
cardData, _ := json.Marshal(inspect) | ||
|
||
card := drone.CardInput{ | ||
Schema: "https://drone-plugins.github.io/drone-docker/card.json", | ||
Data: cardData, | ||
} | ||
|
||
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
{ | ||
"type": "AdaptiveCard", | ||
"body": [ | ||
{ | ||
"type": "ColumnSet", | ||
"columns": [ | ||
{ | ||
"type": "Column", | ||
"items": [ | ||
{ | ||
"type": "Image", | ||
"url": "https://d36jcksde1wxzq.cloudfront.net/be7833db9bddb4494d2a7c3dd659199a.png", | ||
"size": "Medium" | ||
} | ||
], | ||
"width": "auto" | ||
}, | ||
{ | ||
"type": "Column", | ||
"items": [ | ||
{ | ||
"type": "TextBlock", | ||
"text": "${RepoTags[0]}", | ||
"size": "Medium" | ||
}, | ||
{ | ||
"type": "TextBlock", | ||
"text": "DIGEST: ${RepoDigests[0]}", | ||
"wrap": true, | ||
"size": "Small", | ||
"weight": "Lighter", | ||
"isSubtle": true, | ||
"spacing": "Small" | ||
}, | ||
{ | ||
"type": "ColumnSet", | ||
"columns": [ | ||
{ | ||
"type": "Column", | ||
"items": [ | ||
{ | ||
"type": "TextBlock", | ||
"weight": "Lighter", | ||
"text": "OS/ARCH", | ||
"wrap": true, | ||
"size": "Small", | ||
"isSubtle": true, | ||
"spacing": "Medium" | ||
}, | ||
{ | ||
"type": "TextBlock", | ||
"text": "${OS}/${Architecture}", | ||
"wrap": true, | ||
"size": "Small", | ||
"spacing": "Small" | ||
} | ||
], | ||
"separator": true, | ||
"width": "auto" | ||
}, | ||
{ | ||
"type": "Column", | ||
"items": [ | ||
{ | ||
"type": "TextBlock", | ||
"weight": "Lighter", | ||
"text": "SIZE", | ||
"wrap": true, | ||
"size": "Small", | ||
"isSubtle": true | ||
}, | ||
{ | ||
"type": "TextBlock", | ||
"spacing": "Small", | ||
"text": "${SizeString}", | ||
"wrap": true, | ||
"size": "Small" | ||
} | ||
], | ||
"width": "auto", | ||
"separator": true, | ||
"spacing": "Medium" | ||
}, | ||
{ | ||
"type": "Column", | ||
"items": [ | ||
{ | ||
"type": "TextBlock", | ||
"weight": "Lighter", | ||
"text": "LAST PUSHED", | ||
"wrap": true, | ||
"size": "Small", | ||
"isSubtle": true | ||
}, | ||
{ | ||
"type": "TextBlock", | ||
"spacing": "Small", | ||
"text": "{{DATE(${Time})}} - {{TIME(${Time})}}", | ||
"wrap": true, | ||
"size": "Small" | ||
} | ||
], | ||
"width": "auto", | ||
"separator": true, | ||
"spacing": "Medium" | ||
} | ||
], | ||
"style": "default" | ||
} | ||
], | ||
"width": "stretch" | ||
} | ||
] | ||
} | ||
], | ||
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json", | ||
"version": "1.0" | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters