1
+ # this starlark script should be used to generate the .drone.yml
2
+ # configuration file.
3
+
4
+ def main(ctx):
5
+ # TODO consider running unit tests before building and
6
+ # publishing docker images.
7
+ before = {}
8
+
9
+ stages = [
10
+ linux('arm'),
11
+ linux('arm64'),
12
+ linux('amd64'),
13
+ windows('1903'),
14
+ windows('1809'),
15
+ ]
16
+
17
+ after = manifest()
18
+
19
+ # the after stage should only execute after all previous
20
+ # stages complete. this builds the dependency graph.
21
+ for stage in stages:
22
+ after['depends_on'].append(stage['name'])
23
+
24
+ return stages + [ after ]
25
+
26
+ # create a pipeline stage responsible for building and
27
+ # publishing the Docker image on linux.
28
+ def linux(arch):
29
+ return {
30
+ 'kind': 'pipeline',
31
+ 'type': 'docker',
32
+ 'name': 'linux-%s' % arch,
33
+ 'platform': {
34
+ 'os': 'linux',
35
+ 'arch': arch,
36
+ },
37
+ 'steps': [
38
+ {
39
+ 'name': 'build',
40
+ 'image': 'golang:1.10',
41
+ 'commands': [
42
+ 'cd posix',
43
+ 'tar -xf fixtures.tar -C /',
44
+ 'go test -v',
45
+ ],
46
+ },
47
+ {
48
+ 'name': 'publish',
49
+ 'image': 'plugins/docker',
50
+ 'settings': {
51
+ 'auto_tag': 'true',
52
+ 'auto_tag_suffix': 'linux-%s' % arch,
53
+ 'dockerfile': 'docker/Dockerfile.linux.%s' % arch,
54
+ 'password': {
55
+ 'from_secret': 'docker_password',
56
+ },
57
+ 'repo': 'drone/git',
58
+ 'username': 'drone',
59
+ },
60
+ 'when': {
61
+ 'event': ['push', 'tag']
62
+ }
63
+ }
64
+ ]
65
+ }
66
+
67
+ # create a pipeline stage responsible for building and
68
+ # publishing the Docker image on windows. The windows stage
69
+ # uses an ssh runner, as opposed to a docker runner.
70
+ def windows(version):
71
+ return {
72
+ 'kind': 'pipeline',
73
+ 'type': 'ssh',
74
+ 'name': 'windows-%s-amd64' % version,
75
+ 'platform': {
76
+ 'os': 'windows'
77
+ },
78
+ 'server': {
79
+ 'host': { 'from_secret': 'windows_server_%s' % version },
80
+ 'user': { 'from_secret': 'windows_username' },
81
+ 'password': { 'from_secret': 'windows_password' },
82
+ },
83
+ 'steps': [
84
+ {
85
+ 'name': 'build',
86
+ 'environment': {
87
+ 'USERNAME': { 'from_secret': 'docker_username' },
88
+ 'PASSWORD': { 'from_secret': 'docker_password' },
89
+ },
90
+ # TODO these commands build and publish the latest
91
+ # docker tag regardless of git tag.
92
+ 'commands': [
93
+ 'docker login -u $env:USERNAME -p $env:PASSWORD',
94
+ 'docker build -f docker/Dockerfile.windows.%s -t drone/git:windows-%s-amd64 .' % (version, version),
95
+ 'docker push drone/git:windows-%s-amd64' % version,
96
+ ],
97
+ },
98
+ ],
99
+ 'trigger': {
100
+ 'event': ['push']
101
+ }
102
+ }
103
+
104
+ # create a pipeline stage responsible for creating and
105
+ # publishing a docker manifest to the registry.
106
+ def manifest():
107
+ return {
108
+ 'kind': 'pipeline',
109
+ 'type': 'docker',
110
+ 'name': 'manifest',
111
+ 'steps': [
112
+ {
113
+ 'name': 'manifest',
114
+ 'image': 'plugins/manifest',
115
+ 'settings': {
116
+ 'auto_tag': 'true',
117
+ 'username': 'drone',
118
+ 'password': {
119
+ 'from_secret': 'docker_password'
120
+ },
121
+ 'spec': 'docker/manifest.tmpl',
122
+ 'ignore_missing': 'true',
123
+ },
124
+ },
125
+ ],
126
+ 'depends_on': [],
127
+ 'trigger': {
128
+ 'event': ['push', 'tag']
129
+ }
130
+ }
0 commit comments