|
| 1 | +def main(ctx): |
| 2 | + versions = [ |
| 3 | + 'latest', |
| 4 | + ] |
| 5 | + |
| 6 | + arches = [ |
| 7 | + 'amd64', |
| 8 | + 'arm32v7', |
| 9 | + 'arm64v8', |
| 10 | + ] |
| 11 | + |
| 12 | + config = { |
| 13 | + 'version': None, |
| 14 | + 'arch': None, |
| 15 | + 'trigger': [], |
| 16 | + 'repo': ctx.repo.name |
| 17 | + } |
| 18 | + |
| 19 | + stages = [] |
| 20 | + |
| 21 | + for version in versions: |
| 22 | + config['version'] = version |
| 23 | + |
| 24 | + if config['version'] == 'latest': |
| 25 | + config['path'] = 'latest' |
| 26 | + else: |
| 27 | + config['path'] = 'v%s' % config['version'] |
| 28 | + |
| 29 | + m = manifest(config) |
| 30 | + inner = [] |
| 31 | + |
| 32 | + for arch in arches: |
| 33 | + config['arch'] = arch |
| 34 | + |
| 35 | + if config['version'] == 'latest': |
| 36 | + config['tag'] = arch |
| 37 | + else: |
| 38 | + config['tag'] = '%s-%s' % (config['version'], arch) |
| 39 | + |
| 40 | + if config['arch'] == 'amd64': |
| 41 | + config['platform'] = 'amd64' |
| 42 | + |
| 43 | + if config['arch'] == 'arm64v8': |
| 44 | + config['platform'] = 'arm64' |
| 45 | + |
| 46 | + if config['arch'] == 'arm32v7': |
| 47 | + config['platform'] = 'arm' |
| 48 | + |
| 49 | + config['internal'] = '%s-%s' % (ctx.build.commit, config['tag']) |
| 50 | + |
| 51 | + d = docker(config) |
| 52 | + m['depends_on'].append(d['name']) |
| 53 | + |
| 54 | + inner.append(d) |
| 55 | + |
| 56 | + inner.append(m) |
| 57 | + stages.extend(inner) |
| 58 | + |
| 59 | + after = [ |
| 60 | + notification(config), |
| 61 | + ] |
| 62 | + |
| 63 | + for s in stages: |
| 64 | + for a in after: |
| 65 | + a['depends_on'].append(s['name']) |
| 66 | + |
| 67 | + return stages + after |
| 68 | + |
| 69 | +def docker(config): |
| 70 | + return { |
| 71 | + 'kind': 'pipeline', |
| 72 | + 'type': 'docker', |
| 73 | + 'name': '%s-%s' % (config['arch'], config['path']), |
| 74 | + 'platform': { |
| 75 | + 'os': 'linux', |
| 76 | + 'arch': config['platform'], |
| 77 | + }, |
| 78 | + 'steps': steps(config), |
| 79 | + 'image_pull_secrets': [ |
| 80 | + 'registries', |
| 81 | + ], |
| 82 | + 'depends_on': [], |
| 83 | + 'trigger': { |
| 84 | + 'ref': [ |
| 85 | + 'refs/heads/master', |
| 86 | + 'refs/pull/**', |
| 87 | + ], |
| 88 | + }, |
| 89 | + } |
| 90 | + |
| 91 | +def manifest(config): |
| 92 | + return { |
| 93 | + 'kind': 'pipeline', |
| 94 | + 'type': 'docker', |
| 95 | + 'name': 'manifest-%s' % config['path'], |
| 96 | + 'platform': { |
| 97 | + 'os': 'linux', |
| 98 | + 'arch': 'amd64', |
| 99 | + }, |
| 100 | + 'steps': [ |
| 101 | + { |
| 102 | + 'name': 'manifest', |
| 103 | + 'image': 'plugins/manifest', |
| 104 | + 'settings': { |
| 105 | + 'username': { |
| 106 | + 'from_secret': 'public_username', |
| 107 | + }, |
| 108 | + 'password': { |
| 109 | + 'from_secret': 'public_password', |
| 110 | + }, |
| 111 | + 'spec': '%s/manifest.tmpl' % config['path'], |
| 112 | + 'ignore_missing': 'true', |
| 113 | + }, |
| 114 | + }, |
| 115 | + ], |
| 116 | + 'depends_on': [], |
| 117 | + 'trigger': { |
| 118 | + 'ref': [ |
| 119 | + 'refs/heads/master', |
| 120 | + 'refs/tags/**', |
| 121 | + ], |
| 122 | + }, |
| 123 | + } |
| 124 | + |
| 125 | +def notification(config): |
| 126 | + steps = [{ |
| 127 | + 'name': 'notify', |
| 128 | + 'image': 'plugins/slack', |
| 129 | + 'settings': { |
| 130 | + 'webhook': { |
| 131 | + 'from_secret': 'private_rocketchat', |
| 132 | + }, |
| 133 | + 'channel': 'builds', |
| 134 | + }, |
| 135 | + 'when': { |
| 136 | + 'status': [ |
| 137 | + 'success', |
| 138 | + 'failure', |
| 139 | + ], |
| 140 | + }, |
| 141 | + }] |
| 142 | + |
| 143 | + downstream = [{ |
| 144 | + 'name': 'downstream', |
| 145 | + 'image': 'plugins/downstream', |
| 146 | + 'settings': { |
| 147 | + 'token': { |
| 148 | + 'from_secret': 'drone_token', |
| 149 | + }, |
| 150 | + 'server': 'https://drone.owncloud.com', |
| 151 | + 'repositories': config['trigger'], |
| 152 | + }, |
| 153 | + 'when': { |
| 154 | + 'status': [ |
| 155 | + 'success', |
| 156 | + ], |
| 157 | + }, |
| 158 | + }] |
| 159 | + |
| 160 | + if config['trigger']: |
| 161 | + steps = downstream + steps |
| 162 | + |
| 163 | + return { |
| 164 | + 'kind': 'pipeline', |
| 165 | + 'type': 'docker', |
| 166 | + 'name': 'notification', |
| 167 | + 'platform': { |
| 168 | + 'os': 'linux', |
| 169 | + 'arch': 'amd64', |
| 170 | + }, |
| 171 | + 'clone': { |
| 172 | + 'disable': True, |
| 173 | + }, |
| 174 | + 'steps': steps, |
| 175 | + 'depends_on': [], |
| 176 | + 'trigger': { |
| 177 | + 'ref': [ |
| 178 | + 'refs/heads/master', |
| 179 | + 'refs/tags/**', |
| 180 | + ], |
| 181 | + 'status': [ |
| 182 | + 'success', |
| 183 | + 'failure', |
| 184 | + ], |
| 185 | + }, |
| 186 | + } |
| 187 | + |
| 188 | +def dryrun(config): |
| 189 | + return [{ |
| 190 | + 'name': 'dryrun', |
| 191 | + 'image': 'plugins/docker', |
| 192 | + 'settings': { |
| 193 | + 'dry_run': True, |
| 194 | + 'tags': config['tag'], |
| 195 | + 'dockerfile': '%s/Dockerfile.%s' % (config['path'], config['arch']), |
| 196 | + 'repo': 'owncloudci/%s' % config['repo'], |
| 197 | + 'context': config['path'], |
| 198 | + }, |
| 199 | + 'when': { |
| 200 | + 'ref': [ |
| 201 | + 'refs/pull/**', |
| 202 | + ], |
| 203 | + }, |
| 204 | + }] |
| 205 | + |
| 206 | +def publish(config): |
| 207 | + return [{ |
| 208 | + 'name': 'publish', |
| 209 | + 'image': 'plugins/docker', |
| 210 | + 'settings': { |
| 211 | + 'username': { |
| 212 | + 'from_secret': 'public_username', |
| 213 | + }, |
| 214 | + 'password': { |
| 215 | + 'from_secret': 'public_password', |
| 216 | + }, |
| 217 | + 'tags': config['tag'], |
| 218 | + 'dockerfile': '%s/Dockerfile.%s' % (config['path'], config['arch']), |
| 219 | + 'repo': 'owncloudci/%s' % config['repo'], |
| 220 | + 'context': config['path'], |
| 221 | + 'pull_image': False, |
| 222 | + }, |
| 223 | + 'when': { |
| 224 | + 'ref': [ |
| 225 | + 'refs/heads/master', |
| 226 | + 'refs/tags/**', |
| 227 | + ], |
| 228 | + }, |
| 229 | + }] |
| 230 | + |
| 231 | +def steps(config): |
| 232 | + return dryrun(config) + publish(config) |
0 commit comments