forked from drone-plugins/drone-manifest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
223 lines (215 loc) · 5.01 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
package main
import (
"log"
"os"
"github.com/drone-plugins/drone-manifest/tagging"
"github.com/urfave/cli"
)
var (
version = "unknown"
)
func main() {
app := cli.NewApp()
app.Name = "manifest plugin"
app.Usage = "manifest plugin"
app.Action = run
app.Version = version
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "username",
Usage: "username for registry",
EnvVar: "PLUGIN_USERNAME,MANIFEST_USERNAME,DOCKER_USERNAME",
},
cli.StringFlag{
Name: "password",
Usage: "password for registry",
EnvVar: "PLUGIN_PASSWORD,MANIFEST_PASSWORD,DOCKER_PASSWORD",
},
cli.BoolFlag{
Name: "publicecr",
Usage: "connecting to public ecr",
EnvVar: "PUBLIC_ECR",
},
cli.BoolFlag{
Name: "insecure",
Usage: "enable allow insecure registry",
EnvVar: "PLUGIN_INSECURE",
},
cli.StringSliceFlag{
Name: "platforms",
Usage: "platforms for manifests",
EnvVar: "PLUGIN_PLATFORMS",
},
cli.StringFlag{
Name: "target",
Usage: "target for manifests",
EnvVar: "PLUGIN_TARGET",
},
cli.StringFlag{
Name: "template",
Usage: "template for manifests",
EnvVar: "PLUGIN_TEMPLATE",
},
cli.StringFlag{
Name: "spec",
Usage: "path to manifest spec",
EnvVar: "PLUGIN_SPEC",
},
cli.BoolFlag{
Name: "ignore-missing",
Usage: "ignore missing images",
EnvVar: "PLUGIN_IGNORE_MISSING",
},
cli.StringSliceFlag{
Name: "tags",
Usage: "list of additional tags",
Value: &cli.StringSlice{},
EnvVar: "PLUGIN_TAG,PLUGIN_TAGS",
FilePath: ".tags",
},
cli.BoolFlag{
Name: "tags.auto",
Usage: "automatically build tags",
EnvVar: "PLUGIN_DEFAULT_TAGS,PLUGIN_AUTO_TAG",
},
cli.BoolFlag{
Name: "dump",
Usage: "dump the spec to stdout for debug purposes",
EnvVar: "PLUGIN_DUMP",
},
cli.StringFlag{
Name: "path",
Usage: "git clone path",
EnvVar: "DRONE_WORKSPACE",
},
cli.StringFlag{
Name: "repo.owner",
Usage: "repository owner",
EnvVar: "DRONE_REPO_OWNER",
},
cli.StringFlag{
Name: "repo.name",
Usage: "repository name",
EnvVar: "DRONE_REPO_NAME",
},
cli.StringFlag{
Name: "repo.branch",
Usage: "repository default branch",
EnvVar: "DRONE_REPO_BRANCH",
},
cli.StringFlag{
Name: "commit.sha",
Usage: "git commit sha",
EnvVar: "DRONE_COMMIT_SHA",
Value: "00000000",
},
cli.StringFlag{
Name: "commit.ref",
Usage: "git commit ref",
EnvVar: "DRONE_COMMIT_REF",
},
cli.StringFlag{
Name: "commit.branch",
Value: "master",
Usage: "git commit branch",
EnvVar: "DRONE_COMMIT_BRANCH",
},
cli.StringFlag{
Name: "commit.pull",
Usage: "git pull request",
EnvVar: "DRONE_PULL_REQUEST",
},
cli.StringFlag{
Name: "build.event",
Value: "push",
Usage: "build event",
EnvVar: "DRONE_BUILD_EVENT",
},
cli.IntFlag{
Name: "build.number",
Usage: "build number",
EnvVar: "DRONE_BUILD_NUMBER",
},
cli.StringFlag{
Name: "build.status",
Usage: "build status",
Value: "success",
EnvVar: "DRONE_BUILD_STATUS",
},
cli.StringFlag{
Name: "build.link",
Usage: "build link",
EnvVar: "DRONE_BUILD_LINK",
},
cli.Int64Flag{
Name: "build.started",
Usage: "build started",
EnvVar: "DRONE_BUILD_STARTED",
},
cli.Int64Flag{
Name: "build.created",
Usage: "build created",
EnvVar: "DRONE_BUILD_CREATED",
},
cli.StringFlag{
Name: "build.tag",
Usage: "build tag",
EnvVar: "DRONE_TAG",
},
cli.Int64Flag{
Name: "job.started",
Usage: "job started",
EnvVar: "DRONE_JOB_STARTED",
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func run(c *cli.Context) error {
plugin := Plugin{
Repo: Repo{
Owner: c.String("repo.owner"),
Name: c.String("repo.name"),
Branch: c.String("repo.branch"),
},
Build: Build{
Path: c.String("path"),
Tag: c.String("build.tag"),
Number: c.Int("build.number"),
Event: c.String("build.event"),
Status: c.String("build.status"),
Commit: c.String("commit.sha"),
Ref: c.String("commit.ref"),
Branch: c.String("commit.branch"),
Pull: c.String("commit.pull"),
Started: c.Int64("build.started"),
Created: c.Int64("build.created"),
Tags: c.StringSlice("tags"),
},
Job: Job{
Started: c.Int64("job.started"),
},
Config: Config{
Username: c.String("username"),
Password: c.String("password"),
Publicecr: c.Bool("publicecr"),
Insecure: c.Bool("insecure"),
Platforms: c.StringSlice("platforms"),
Target: c.String("target"),
Template: c.String("template"),
Spec: c.String("spec"),
IgnoreMissing: c.Bool("ignore-missing"),
Dump: c.Bool("dump"),
},
}
if c.Bool("tags.auto") {
if tagging.UseDefaultTag(c.String("commit.ref"), c.String("repo.branch")) {
plugin.Build.Tags = tagging.DefaultTags(c.String("commit.ref"))
} else {
log.Printf("skipping automated tags for %s", c.String("commit.ref"))
return nil
}
}
return plugin.Exec()
}