harness-drone/.drone.script

153 lines
4.4 KiB
Text
Raw Normal View History

2019-08-07 05:47:04 +00:00
def main(ctx):
2019-02-20 18:34:26 +00:00
return [
pipeline('linux-amd64', 'linux', 'amd64'),
pipeline('linux-arm64', 'linux', 'arm64'),
pipeline('linux-arm', 'linux', 'arm'),
2019-08-07 05:47:04 +00:00
pipeline_windows('1809'),
pipeline_windows('1903'),
2019-02-20 18:34:26 +00:00
manifest(),
]
# defines a pipeline step that builds and publishes a docker
# image to a docker remote registry.
def docker_step(name, os, arch):
repo = 'drone/%s' % name
if repo == 'server':
repo = 'drone/drone'
return {
'name': 'publish_%s' % name,
2019-08-07 05:47:04 +00:00
'image': 'plugins/docker:18',
2019-02-20 18:34:26 +00:00
'settings': {
'repo': repo,
'auto_tag': True,
'auto_tag_suffix': '%s-%s' % (os, arch),
2019-08-07 05:47:04 +00:00
'username': { 'from_secret': 'docker_username' },
2019-02-20 18:34:26 +00:00
'password': { 'from_secret': 'docker_password' },
'dockerfile': 'docker/Dockerfile.%s.%s.%s' % (name, os, arch),
},
'when': {
'event': [ 'push', 'tag' ],
},
}
# defines a pipeline step that executes the Go unit tests.
# this will also download dependencies and cache in /go
def test_step():
return {
'name': 'test',
2019-08-07 05:47:04 +00:00
'image': 'golang:1.12',
2019-02-20 18:34:26 +00:00
'commands': [
'go test ./...',
],
}
# defines a pipeline step that executes the Go unit tests.
# this will also download dependencies and cache in /go
def build_step(os, arch):
2019-08-07 05:47:04 +00:00
return {
'name': 'build',
'image': 'golang:1.12',
'commands': [
'sh scripts/build.sh',
],
'environment': {
'GOOS': os,
'GOARCH': arch,
},
2019-02-20 18:34:26 +00:00
}
# defines a pipeline that builds, tests and publishes
# docker images for the Drone agent, server and controller.
def pipeline(name, os, arch):
return {
'kind': 'pipeline',
2019-08-07 05:47:04 +00:00
'type': 'docker',
'name': 'linux-%s' % arch,
2019-02-20 18:34:26 +00:00
'platform': {
2019-08-07 05:47:04 +00:00
'os': 'linux',
2019-02-20 18:34:26 +00:00
'arch': arch,
},
'steps': [
test_step(),
build_step(os, arch),
docker_step('drone', os, arch),
docker_step('agent', os, arch),
docker_step('controller', os, arch),
],
}
2019-08-07 05:47:04 +00:00
# defines a pipeline that builds and publishes docker images
# for the Drone agent for the Windows kernel.
def pipeline_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': [
'powershell.exe scripts/build.ps1',
'docker login -u $env:USERNAME -p $env:PASSWORD',
'docker build -f docker/Dockerfile.agent.windows.%s -t drone/agent:windows-%s-amd64 .' % (version, version),
'docker push drone/agent:windows-%s-amd64' % version,
],
},
],
'trigger': {
'event': ['push']
}
}
2019-02-20 18:34:26 +00:00
# defines a pipeline that updates the docker manifest
# for the architecture-specific images previously published
# to dockerhub.
def manifest():
return {
'kind': 'pipeline',
2019-08-07 05:47:04 +00:00
'type': 'docker',
2019-02-20 18:34:26 +00:00
'name': 'manifest',
'steps': [
manifest_step('server'),
manifest_step('agent'),
manifest_step('controller'),
],
2019-08-07 05:47:04 +00:00
'trigger': {
'event': [ 'push', 'tag' ],
},
2019-02-20 18:34:26 +00:00
'depends_on': [
'linux-amd64',
'linux-arm64',
'linux-arm',
2019-08-07 05:47:04 +00:00
'windows-1903-amd64',
'windows-1809-amd64',
2019-02-20 18:34:26 +00:00
],
}
2019-08-07 05:47:04 +00:00
# defines a pipeline step that creates and publishes
# a docker manifest to a docker remote registry.
def manifest_step(name):
return {
'name': 'publish_%s' % name,
'image': 'plugins/manifest:1',
'settings': {
'auto_tag': True,
'ignore_missing': True,
'spec': 'docker/manifest.%s.tmpl' % name,
'username': { 'from_secret': 'docker_username' },
'password': { 'from_secret': 'docker_password' },
},
}