Update build pipeline to notify on docker fail/success
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
IamTheFij 2020-01-10 14:43:05 -08:00
parent 64e6542a93
commit ad4a3770e7

View File

@ -3,17 +3,13 @@ def main(ctx):
pipelines = [] pipelines = []
# Run tests # Run tests
test_pipelines = build_test_pipelines() pipelines += build_test_pipelines()
pipelines += test_pipelines
# Wait for all tests to complete
pipelines.append(wait_for_all_tests(test_pipelines))
# Add pypi push pipeline # Add pypi push pipeline
pipelines.append(push_to_pypi(ctx)) pipelines += push_to_pypi(ctx)
# Add docker push pipelines # Add docker push pipelines
pipelines += docker_pipelines() pipelines += push_to_docker(ctx)
return pipelines return pipelines
@ -28,7 +24,7 @@ def get_workspace():
# Builds a list of all test pipelines to be executed # Builds a list of all test pipelines to be executed
def build_test_pipelines(): def build_test_pipelines():
return [ test_pipelines = [
test("python:3.5"), test("python:3.5"),
test("python:3.6"), test("python:3.6"),
test("python:3.7"), test("python:3.7"),
@ -38,16 +34,21 @@ def build_test_pipelines():
test("pypy:3", "pypy3", "pypy3"), test("pypy:3", "pypy3", "pypy3"),
] ]
# Converge all tests on a single pipeline "py-tests"
test_pipelines.append(wait_for_all_tests(test_pipelines))
return test_pipelines
# Waits for the completion of all test pipelines # Waits for the completion of all test pipelines
def wait_for_all_tests(test_pipelines): def wait_for_all_tests(test_pipelines, name="py-tests"):
depends_on = [] depends_on = []
for pipeline in test_pipelines: for pipeline in test_pipelines:
depends_on.append(pipeline["name"]) depends_on.append(pipeline["name"])
return { return {
"kind": "pipeline", "kind": "pipeline",
"name": "py-tests", "name": name,
"steps": [], "steps": [],
"depends_on": depends_on, "depends_on": depends_on,
} }
@ -57,7 +58,7 @@ def wait_for_all_tests(test_pipelines):
def test(docker_tag, python_cmd="python", tox_env="py3"): def test(docker_tag, python_cmd="python", tox_env="py3"):
return { return {
"kind": "pipeline", "kind": "pipeline",
"name": "test-{}".format(docker_tag.replace(":", "")), "name": "test {}".format(docker_tag.replace(":", "")),
"workspace": get_workspace(), "workspace": get_workspace(),
"steps": [ "steps": [
{ {
@ -105,9 +106,9 @@ def notify_step():
# Push package to pypi # Push package to pypi
def push_to_pypi(ctx): def push_to_pypi(ctx):
return { return [{
"kind": "pipeline", "kind": "pipeline",
"name": "deploy-pypi", "name": "deploy to pypi",
"trigger": { "trigger": {
"event": ["tag"], "event": ["tag"],
"ref": [ "ref": [
@ -149,29 +150,12 @@ def push_to_pypi(ctx):
}, },
notify_step(), notify_step(),
] ]
} }]
# Deploys image to docker hub # Build and push docker image
def push_docker(tag_suffix, arch, repo): def push_docker_step(tag_suffix, arch, repo):
return { return {
"kind": "pipeline",
"name": "deploy-docker-{}".format(tag_suffix),
"trigger": {
"event": ["tag", "push"],
"ref": [
"refs/heads/master",
"refs/tags/v*",
],
},
"workspace": get_workspace(),
"steps": [
{
"name": "get qemu",
"image": "busybox",
"commands": ["sh ./get_qemu.sh {}".format(arch)],
},
{
"name": "build", "name": "build",
"image": "plugins/docker", "image": "plugins/docker",
"settings": { "settings": {
@ -189,29 +173,16 @@ def push_docker(tag_suffix, arch, repo):
"REPO={}".format(repo), "REPO={}".format(repo),
], ],
}, },
},
],
} }
# generate all docker pipelines to push images and manifest # Builds a pipeline to push to docker
def docker_pipelines(): def push_to_docker(ctx):
# build list of images to push return [{
docker_pipelines = [
push_docker("linux-amd64", "x86_64", "library"),
push_docker("linux-arm", "arm", "arm32v6"),
push_docker("linux-arm64", "aarch64", "arm64v8"),
]
# build list of dependencies
pipeline_names = []
for pipeline in docker_pipelines:
pipeline_names.append(pipeline["name"])
# append manifest pipeline
docker_pipelines.append({
"kind": "pipeline", "kind": "pipeline",
"name": "deploy-docker-manifest", "name": "push to docker",
"depends_on": ["py-tests"],
"workspace": get_workspace(),
"trigger": { "trigger": {
"event": ["tag"], "event": ["tag"],
"ref": [ "ref": [
@ -219,9 +190,11 @@ def docker_pipelines():
"refs/tags/v*", "refs/tags/v*",
], ],
}, },
"workspace": get_workspace(), "steps": [
"depends_on": pipeline_names, push_docker_step("linux-amd64", "x86_64", "library"),
"steps": [{ push_docker_step("linux-arm", "arm", "arm32v6"),
push_docker_step("linux-arm64", "aarch64", "arm64v8"),
{
"name": "publish manifest", "name": "publish manifest",
"image": "plugins/manifest", "image": "plugins/manifest",
"settings": { "settings": {
@ -235,7 +208,9 @@ def docker_pipelines():
"from_secret": "docker_password", "from_secret": "docker_password",
}, },
} }
}], },
}) notify_step(),
],
}]
return docker_pipelines # vim: ft=python