Skip to content

Commit b6c9110

Browse files
author
TP Honey
authored
Merge pull request #356 from tphoney/DRON-232
(DRON-232) enable build-kit for secrets consumption
2 parents ad28b4d + 05357ea commit b6c9110

File tree

6 files changed

+91
-50
lines changed

6 files changed

+91
-50
lines changed

card.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (p Plugin) writeCard() error {
2222
return err
2323
}
2424

25-
out := Inspect{}
25+
out := Card{}
2626
if err := json.Unmarshal(data, &out); err != nil {
2727
return err
2828
}
@@ -31,6 +31,12 @@ func (p Plugin) writeCard() error {
3131
inspect.SizeString = fmt.Sprint(bytesize.New(float64(inspect.Size)))
3232
inspect.VirtualSizeString = fmt.Sprint(bytesize.New(float64(inspect.VirtualSize)))
3333
inspect.Time = fmt.Sprint(inspect.Metadata.LastTagTime.Format(time.RFC3339))
34+
// change slice of tags to slice of TagStruct
35+
var sliceTagStruct []TagStruct
36+
for _, tag := range inspect.RepoTags {
37+
sliceTagStruct = append(sliceTagStruct, TagStruct{Tag: tag})
38+
}
39+
inspect.ParsedRepoTags = sliceTagStruct
3440
cardData, _ := json.Marshal(inspect)
3541

3642
card := drone.CardInput{

cmd/drone-docker/main.go

+6
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ func main() {
249249
Usage: "additional host:IP mapping",
250250
EnvVar: "PLUGIN_ADD_HOST",
251251
},
252+
cli.StringFlag{
253+
Name: "secret",
254+
Usage: "secret key value pair eg id=MYSECRET",
255+
EnvVar: "PLUGIN_SECRET",
256+
},
252257
cli.StringFlag{
253258
Name: "drone-card-path",
254259
Usage: "card path location to write to",
@@ -292,6 +297,7 @@ func run(c *cli.Context) error {
292297
AutoLabel: c.BoolT("auto-label"),
293298
Link: c.String("link"),
294299
NoCache: c.Bool("no-cache"),
300+
Secret: c.String("secret"),
295301
AddHost: c.StringSlice("add-host"),
296302
Quiet: c.Bool("quiet"),
297303
},

docker.go

+28-16
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type (
5858
Labels []string // Label map
5959
Link string // Git repo link
6060
NoCache bool // Docker build no-cache
61+
Secret string // secret keypair
6162
AddHost []string // Docker build add-host
6263
Quiet bool // Docker build quiet
6364
}
@@ -72,27 +73,31 @@ type (
7273
CardPath string // Card path to write file to
7374
}
7475

75-
Inspect []struct {
76-
ID string `json:"Id"`
77-
RepoTags []string `json:"RepoTags"`
78-
RepoDigests []interface{} `json:"RepoDigests"`
79-
Parent string `json:"Parent"`
80-
Comment string `json:"Comment"`
81-
Created time.Time `json:"Created"`
82-
Container string `json:"Container"`
83-
DockerVersion string `json:"DockerVersion"`
84-
Author string `json:"Author"`
85-
Architecture string `json:"Architecture"`
86-
Os string `json:"Os"`
87-
Size int `json:"Size"`
88-
VirtualSize int `json:"VirtualSize"`
89-
Metadata struct {
76+
Card []struct {
77+
ID string `json:"Id"`
78+
RepoTags []string `json:"RepoTags"`
79+
ParsedRepoTags []TagStruct `json:"ParsedRepoTags"`
80+
RepoDigests []interface{} `json:"RepoDigests"`
81+
Parent string `json:"Parent"`
82+
Comment string `json:"Comment"`
83+
Created time.Time `json:"Created"`
84+
Container string `json:"Container"`
85+
DockerVersion string `json:"DockerVersion"`
86+
Author string `json:"Author"`
87+
Architecture string `json:"Architecture"`
88+
Os string `json:"Os"`
89+
Size int `json:"Size"`
90+
VirtualSize int `json:"VirtualSize"`
91+
Metadata struct {
9092
LastTagTime time.Time `json:"LastTagTime"`
9193
} `json:"Metadata"`
9294
SizeString string
9395
VirtualSizeString string
9496
Time string
9597
}
98+
TagStruct struct {
99+
Tag string `json:"Tag"`
100+
}
96101
)
97102

98103
// Exec executes the plugin step
@@ -175,7 +180,7 @@ func (p Plugin) Exec() error {
175180
for _, tag := range p.Build.Tags {
176181
cmds = append(cmds, commandTag(p.Build, tag)) // docker tag
177182

178-
if p.Dryrun == false {
183+
if !p.Dryrun {
179184
cmds = append(cmds, commandPush(p.Build, tag)) // docker push
180185
}
181186
}
@@ -297,6 +302,9 @@ func commandBuild(build Build) *exec.Cmd {
297302
for _, host := range build.AddHost {
298303
args = append(args, "--add-host", host)
299304
}
305+
if build.Secret != "" {
306+
args = append(args, "--secret", build.Secret)
307+
}
300308
if build.Target != "" {
301309
args = append(args, "--target", build.Target)
302310
}
@@ -328,6 +336,10 @@ func commandBuild(build Build) *exec.Cmd {
328336
}
329337
}
330338

339+
// we need to enable buildkit, for secret support
340+
if build.Secret != "" {
341+
os.Setenv("DOCKER_BUILDKIT", "1")
342+
}
331343
return exec.Command(dockerExe, args...)
332344
}
333345

docs/card.data.json

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"Id": "sha256:3b0709c9afb41629c79c93355feed114d08a8c1bedd975eb53af08f4b867fd91",
3+
"RepoTags": [
4+
"798a0dae10d63d281eff4c06eaa12001ffd23740:latest",
5+
"tphoney/test:latest"
6+
],
7+
"ParsedRepoTags": [
8+
{
9+
"Tag": ""
10+
},
11+
{
12+
"Tag": ""
13+
},
14+
{
15+
"Tag": "798a0dae10d63d281eff4c06eaa12001ffd23740:latest"
16+
},
17+
{
18+
"Tag": "tphoney/test:latest"
19+
}
20+
],
21+
"RepoDigests": [
22+
"tphoney/test@sha256:93f8b95aaae7d194208b72e94a3a90544b00c8f2ad45aeb89d81a0c6ccbc5e19"
23+
],
24+
"Parent": "sha256:493aa330a5929027dd8ecded9fa8c473a1508d17c0fd7d6a94a7f197f8d22c60",
25+
"Comment": "",
26+
"Created": "2022-02-16T11:13:40.8956582Z",
27+
"Container": "a57c0ca4dd2e081df8758e00549f7abe83803f1a1a7aaaf1cd8e685a5eb5a097",
28+
"DockerVersion": "20.10.9",
29+
"Author": "",
30+
"Architecture": "amd64",
31+
"Os": "linux",
32+
"Size": 14045949,
33+
"VirtualSize": 14045949,
34+
"Metadata": {
35+
"LastTagTime": "2022-02-16T11:13:40.9433973Z"
36+
},
37+
"SizeString": "13.40MB",
38+
"VirtualSizeString": "13.40MB",
39+
"Time": "2022-02-16T11:13:40Z"
40+
}

docs/card.json

+10-7
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,22 @@
5151
{
5252
"type": "TextBlock",
5353
"weight": "Lighter",
54-
"text": "OS/ARCH",
54+
"text": "TAGS",
5555
"wrap": true,
5656
"size": "Small",
5757
"isSubtle": true,
5858
"spacing": "Medium"
5959
},
6060
{
61-
"type": "TextBlock",
62-
"text": "${OS}/${Architecture}",
63-
"wrap": true,
64-
"size": "Small",
61+
"type": "FactSet",
62+
"facts": [
63+
{
64+
"title": "-",
65+
"value": "${Tag}"
66+
}
67+
],
6568
"spacing": "Small",
66-
"weight": "Bolder"
69+
"$data": "${ParsedRepoTags}"
6770
}
6871
],
6972
"separator": true,
@@ -124,4 +127,4 @@
124127
],
125128
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
126129
"version": "1.5"
127-
}
130+
}

docs/sample_data.json

-26
This file was deleted.

0 commit comments

Comments
 (0)