forked from drone/drone-git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.drone.starlark
130 lines (122 loc) · 3.24 KB
/
.drone.starlark
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
# this starlark script should be used to generate the .drone.yml
# configuration file.
def main(ctx):
# TODO consider running unit tests before building and
# publishing docker images.
before = {}
stages = [
linux('arm'),
linux('arm64'),
linux('amd64'),
windows('1903'),
windows('1809'),
]
after = manifest()
# the after stage should only execute after all previous
# stages complete. this builds the dependency graph.
for stage in stages:
after['depends_on'].append(stage['name'])
return stages + [ after ]
# create a pipeline stage responsible for building and
# publishing the Docker image on linux.
def linux(arch):
return {
'kind': 'pipeline',
'type': 'docker',
'name': 'linux-%s' % arch,
'platform': {
'os': 'linux',
'arch': arch,
},
'steps': [
{
'name': 'build',
'image': 'golang:1.10',
'commands': [
'cd posix',
'tar -xf fixtures.tar -C /',
'go test -v',
],
},
{
'name': 'publish',
'image': 'plugins/docker',
'settings': {
'auto_tag': 'true',
'auto_tag_suffix': 'linux-%s' % arch,
'dockerfile': 'docker/Dockerfile.linux.%s' % arch,
'password': {
'from_secret': 'docker_password',
},
'repo': 'drone/git',
'username': 'drone',
},
'when': {
'event': ['push', 'tag']
}
}
]
}
# create a pipeline stage responsible for building and
# publishing the Docker image on windows. The windows stage
# uses an ssh runner, as opposed to a docker runner.
def windows(version):
return {
'kind': 'pipeline',
'type': 'ssh',
'name': 'windows-%s-amd64' % version,
'platform': {
'os': 'windows'
},
'server': {
'host': { 'from_secret': 'windows_server_%s' % version },
'user': { 'from_secret': 'windows_username' },
'password': { 'from_secret': 'windows_password' },
},
'steps': [
{
'name': 'build',
'environment': {
'USERNAME': { 'from_secret': 'docker_username' },
'PASSWORD': { 'from_secret': 'docker_password' },
},
# TODO these commands build and publish the latest
# docker tag regardless of git tag.
'commands': [
'docker login -u $env:USERNAME -p $env:PASSWORD',
'docker build -f docker/Dockerfile.windows.%s -t drone/git:windows-%s-amd64 .' % (version, version),
'docker push drone/git:windows-%s-amd64' % version,
],
},
],
'trigger': {
'event': ['push']
}
}
# create a pipeline stage responsible for creating and
# publishing a docker manifest to the registry.
def manifest():
return {
'kind': 'pipeline',
'type': 'docker',
'name': 'manifest',
'steps': [
{
'name': 'manifest',
'image': 'plugins/manifest',
'settings': {
'auto_tag': 'true',
'username': 'drone',
'password': {
'from_secret': 'docker_password'
},
'spec': 'docker/manifest.tmpl',
'ignore_missing': 'true',
},
},
],
'depends_on': [],
'trigger': {
'event': ['push', 'tag']
}
}