-
Notifications
You must be signed in to change notification settings - Fork 0
/
.drone.star
139 lines (117 loc) · 3.96 KB
/
.drone.star
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
def version(ctx):
# use git commit if this is not a tag event
if ctx.build.event != "tag":
return "git-{}".format(commit(ctx))
return ctx.build.ref.removeprefix("refs/tags/")
def version_tag(ctx, arch):
return "{}-{}".format(version(ctx), arch)
def commit(ctx):
return ctx.build.commit[:7]
def new_pipeline(name, arch, **kwargs):
pipeline = {
"kind": "pipeline",
"name": name,
"platform": {
"arch": arch,
},
"steps": [],
}
pipeline.update(kwargs)
return pipeline
def pipeline_test(ctx):
cache_volume = {"name": "cache", "temp": {}}
cache_mount = {"name": "cache", "path": "/go"}
# licensed-go image only supports amd64
return new_pipeline(
name="test",
arch="amd64",
trigger={"branch": ctx.repo.branch},
volumes=[cache_volume],
workspace={"path": "/go/src/github.com/{}".format(ctx.repo.slug)},
steps=[
{
"commands": ["make test"],
"image": "golangci/golangci-lint",
"name": "test",
"volumes": [cache_mount],
},
{
"commands": ["licensed cache", "licensed status"],
"image": "public.ecr.aws/kanopy/licensed-go",
"name": "license-check",
},
{
"image": "plugins/kaniko-ecr",
"name": "build",
"pull": "always",
"settings": {"no_push": True},
"volumes": [cache_mount],
"when": {"event": ["pull_request"]},
},
],
)
def pipeline_build(ctx, arch):
return new_pipeline(
depends_on=["test"],
name="publish-{}".format(arch),
arch=arch,
steps=[
{
"environment": {
"GIT_COMMIT": commit(ctx),
"VERSION": version(ctx),
},
"image": "plugins/kaniko-ecr",
"name": "publish",
"pull": "always",
"settings": {
"access_key": {"from_secret": "ecr_access_key"},
"secret_key": {"from_secret": "ecr_secret_key"},
"registry": {"from_secret": "ecr_registry"},
"repo": ctx.repo.name,
"tags": [version_tag(ctx, arch)],
"build_args": ["VERSION", "GIT_COMMIT"],
"create_repository": True,
},
}
],
)
def pipeline_manifest(ctx):
targets = [version(ctx)]
# only use "latest" for tagged releases
if ctx.build.event == "tag":
targets.append("latest")
return new_pipeline(
depends_on=["publish-amd64", "publish-arm64"],
name="publish-manifest",
arch="arm64",
steps=[
{
"name": "manifest",
"image": "public.ecr.aws/kanopy/buildah-plugin:v0.1.1",
"settings": {
"access_key": {"from_secret": "ecr_access_key"},
"secret_key": {"from_secret": "ecr_secret_key"},
"registry": {"from_secret": "ecr_registry"},
"repo": ctx.repo.name,
"manifest": {
"sources": [
version_tag(ctx, "amd64"),
version_tag(ctx, "arm64"),
],
"targets": targets,
},
},
},
],
)
def main(ctx):
pipelines = [pipeline_test(ctx)]
# only perform image builds for "push" and "tag" events
if ctx.build.event == "tag" or (
ctx.build.branch == ctx.repo.branch and ctx.build.event == "push"
):
pipelines.append(pipeline_build(ctx, "amd64"))
pipelines.append(pipeline_build(ctx, "arm64"))
pipelines.append(pipeline_manifest(ctx))
return pipelines