2019-08-11 00:29:25 +03:00
// This file contains the logic for building our CI for Drone. The idea here is
// that we create a pipeline for all of the major tasks we need to perform
// (e.g. builds, E2E testing, conformance testing, releases). Each pipeline
// after the default builds on a previous pipeline.
2019-08-03 00:08:24 +03:00
// Generate with `drone jsonnet --source ./hack/drone.jsonnet --stream`
2019-08-11 00:29:25 +03:00
2019-08-03 00:08:24 +03:00
local build_container = 'autonomy/build-container:latest';
2019-08-11 00:29:25 +03:00
local volumes = {
dockersock: {
pipeline: {
2019-08-03 00:08:24 +03:00
name: 'dockersock',
2019-08-11 00:29:25 +03:00
temp: {},
},
step: {
name: $.dockersock.pipeline.name,
2019-08-03 00:08:24 +03:00
path: '/var/run',
2019-08-11 00:29:25 +03:00
},
2019-08-09 06:45:13 +03:00
},
2019-08-11 00:29:25 +03:00
dev: {
pipeline: {
2019-08-03 00:08:24 +03:00
name: 'dev',
2019-08-11 00:29:25 +03:00
host: {
2019-08-03 00:08:24 +03:00
path: '/dev',
2019-08-11 00:29:25 +03:00
},
},
step: {
name: $.dev.pipeline.name,
2019-08-03 00:08:24 +03:00
path: '/dev',
2019-08-11 00:29:25 +03:00
},
2019-08-09 06:45:13 +03:00
},
2019-08-11 00:29:25 +03:00
tmp: {
pipeline: {
2019-08-03 00:08:24 +03:00
name: 'tmp',
2019-08-11 00:29:25 +03:00
temp: {},
},
step: {
name: $.tmp.pipeline.name,
2019-08-03 00:08:24 +03:00
path: '/tmp',
2019-08-11 00:29:25 +03:00
},
2019-08-09 06:45:13 +03:00
},
2019-08-11 00:29:25 +03:00
ForStep(): [
self.dockersock.step,
self.dev.step,
self.tmp.step,
],
ForPipeline(): [
self.dockersock.pipeline,
self.dev.pipeline,
self.tmp.pipeline,
],
};
2019-08-09 06:45:13 +03:00
2019-08-11 00:29:25 +03:00
// This step provides our cloning logic. It is a workaround for a limitation in
// the way promotions work in drone. Promotions are assumed to be against
// the master branch, causing improper clones when promoting a pull request.
2019-08-09 06:45:13 +03:00
local clone = {
2019-08-03 00:08:24 +03:00
name: 'clone',
image: 'autonomy/drone-git:latest',
pull: 'always',
2019-08-09 06:45:13 +03:00
};
2019-08-11 00:29:25 +03:00
// This provides the docker service.
2019-08-09 06:45:13 +03:00
local docker = {
2019-08-03 00:08:24 +03:00
name: 'docker',
image: 'docker:19.03-dind',
entrypoint: ['dockerd'],
2019-08-09 06:45:13 +03:00
privileged: true,
command: [
2019-08-03 00:08:24 +03:00
'--dns=8.8.8.8',
'--dns=8.8.4.4',
'--mtu=1440',
'--log-level=error',
2019-08-09 06:45:13 +03:00
],
2019-08-11 00:29:25 +03:00
volumes: volumes.ForStep(),
2019-08-09 06:45:13 +03:00
};
2019-08-11 00:29:25 +03:00
// This step is used only when `drone exec` is executed.
2019-08-09 06:45:13 +03:00
local buildkit = {
2019-08-03 00:08:24 +03:00
name: 'buildkit',
image: 'moby/buildkit:v0.6.0',
2019-08-09 06:45:13 +03:00
privileged: true,
detach: true,
2019-08-03 00:08:24 +03:00
commands: ['buildkitd --addr tcp://0.0.0.0:1234 --allow-insecure-entitlement security.insecure'],
2019-08-09 06:45:13 +03:00
when: {
event: {
2019-08-03 00:08:24 +03:00
include: [''],
2019-08-09 06:45:13 +03:00
},
},
};
2019-08-11 00:29:25 +03:00
// Step standardizes the creation of build steps. The name of the step is used
// as the target when building the make command. For example, if name equals
// "test", the resulting step command will be "make test". This is done to
// encourage alignment between this file and the Makefile, and gives us a
// standardized structure that should make things easier to reason about if we
// know that each step is essentially a Makefile target.
2019-08-03 00:08:24 +03:00
local Step(name, target='', depends_on=[clone], environment={}) = {
local make = if target == '' then std.format('make %s', name) else std.format('make %s', target),
2019-08-11 00:29:25 +03:00
local common_env_vars = {
2019-08-03 00:08:24 +03:00
BUILDKIT_HOST: '${BUILDKIT_HOST=tcp://buildkitd.ci.svc:1234}',
BINDIR: '/usr/local/bin',
2019-08-11 00:29:25 +03:00
},
2019-08-09 06:45:13 +03:00
2019-08-11 00:29:25 +03:00
name: name,
2019-08-09 06:45:13 +03:00
image: build_container,
2019-08-11 00:29:25 +03:00
commands: [make],
environment: common_env_vars + environment,
volumes: volumes.ForStep(),
2019-08-09 06:45:13 +03:00
depends_on: [x.name for x in depends_on],
};
2019-08-11 00:29:25 +03:00
// Pipeline is a way to standardize the creation of pipelines. It supports
// using and existing pipeline as a base.
local Pipeline(name, steps=[], depends_on=[], with_clone=true, with_buildkit=false, with_docker=true) = {
2019-08-03 00:08:24 +03:00
local node = { 'node-role.kubernetes.io/ci': '' },
2019-08-09 06:45:13 +03:00
2019-08-03 00:08:24 +03:00
kind: 'pipeline',
2019-08-09 06:45:13 +03:00
name: name,
clone: {
disable: true,
},
2019-08-11 00:29:25 +03:00
node: node,
services: [
if with_docker then docker,
if with_buildkit then buildkit,
],
steps: [if with_clone then clone] + steps,
volumes: volumes.ForPipeline(),
depends_on: [x.name for x in depends_on],
2019-08-09 06:45:13 +03:00
};
2019-08-11 00:29:25 +03:00
// Default pipeline.
local machined = Step("machined");
local osd = Step("osd");
local trustd = Step("trustd");
local proxyd = Step("proxyd");
local ntpd = Step("ntpd");
2019-08-03 00:08:24 +03:00
local networkd = Step("networkd");
2019-08-11 00:29:25 +03:00
local osctl_linux = Step("osctl-linux");
local osctl_darwin = Step("osctl-darwin");
2019-08-03 00:08:24 +03:00
local rootfs = Step("rootfs", depends_on=[machined, osd, trustd, proxyd, ntpd, networkd]);
2019-08-11 00:29:25 +03:00
local initramfs = Step("initramfs", depends_on=[rootfs]);
local installer = Step("installer", depends_on=[rootfs]);
local container = Step("container", depends_on=[rootfs]);
local lint = Step("lint");
2019-08-28 00:45:59 +03:00
local protolint = Step("protolint");
2019-08-17 11:51:40 +03:00
local markdownlint = Step("markdownlint");
2019-08-11 20:29:45 +03:00
local image_test = Step("image-test", depends_on=[installer]);
2019-08-11 00:29:25 +03:00
local unit_tests = Step("unit-tests", depends_on=[rootfs]);
local unit_tests_race = Step("unit-tests-race", depends_on=[unit_tests]);
local basic_integration = Step("basic-integration", depends_on=[container, osctl_linux]);
2019-08-09 06:45:13 +03:00
local coverage = {
2019-08-03 00:08:24 +03:00
name: 'coverage',
image: 'plugins/codecov',
settings: {
token: { from_secret: 'codecov_token' },
files: ['coverage.txt'],
2019-08-09 06:45:13 +03:00
},
2019-08-11 00:29:25 +03:00
when: {
2019-08-03 00:08:24 +03:00
event: ['pull_request'],
2019-08-09 06:45:13 +03:00
},
depends_on: [unit_tests.name],
};
local push = {
2019-08-03 00:08:24 +03:00
name: 'push',
image: 'autonomy/build-container:latest',
pull: 'always',
environment: {
DOCKER_USERNAME: { from_secret: 'docker_username' },
DOCKER_PASSWORD: { from_secret: 'docker_password' },
2019-08-09 06:45:13 +03:00
},
2019-08-03 00:08:24 +03:00
commands: ['make gitmeta', 'make login', 'make push'],
2019-08-11 00:29:25 +03:00
volumes: volumes.ForStep(),
2019-08-09 06:45:13 +03:00
when: {
2019-08-12 21:28:42 +03:00
event: {
2019-08-13 03:40:00 +03:00
exclude: [
2019-08-03 00:08:24 +03:00
'pull_request',
'promote',
2019-08-13 03:40:00 +03:00
],
2019-08-12 21:28:42 +03:00
},
2019-08-09 06:45:13 +03:00
},
2019-08-10 09:18:15 +03:00
depends_on: [basic_integration.name],
2019-08-09 06:45:13 +03:00
};
2019-08-11 00:29:25 +03:00
local default_steps = [
machined,
osd,
trustd,
proxyd,
ntpd,
2019-08-03 00:08:24 +03:00
networkd,
2019-08-11 00:29:25 +03:00
osctl_linux,
osctl_darwin,
2019-08-09 06:45:13 +03:00
rootfs,
initramfs,
2019-08-11 00:29:25 +03:00
installer,
2019-08-11 20:29:45 +03:00
container,
2019-08-09 06:45:13 +03:00
lint,
2019-08-28 00:45:59 +03:00
protolint,
2019-08-17 11:51:40 +03:00
markdownlint,
2019-08-11 20:29:45 +03:00
image_test,
2019-08-09 06:45:13 +03:00
unit_tests,
2019-08-11 00:29:25 +03:00
// unit_tests_race,
2019-08-09 06:45:13 +03:00
coverage,
basic_integration,
push,
];
local default_trigger = {
trigger: {
cron: {
2019-08-03 00:08:24 +03:00
exclude: ['nightly'],
2019-08-09 06:45:13 +03:00
},
2019-08-12 21:28:42 +03:00
event: {
2019-08-13 03:40:00 +03:00
exclude: [
2019-08-03 00:08:24 +03:00
'tag',
'promote',
],
2019-08-09 06:45:13 +03:00
},
},
};
2019-08-03 00:08:24 +03:00
local default_pipeline = Pipeline('default', default_steps) + default_trigger;
2019-08-11 00:29:25 +03:00
// E2E pipeline.
local creds_env_vars = {
AZURE_SVC_ACCT: {from_secret: "azure_svc_acct"},
2019-08-12 00:38:24 +03:00
// TODO(andrewrynhard): Rename this to the GCP convention.
2019-08-11 00:29:25 +03:00
GCE_SVC_ACCT: {from_secret: "gce_svc_acct"},
PACKET_AUTH_TOKEN: {from_secret: "packet_auth_token"},
2019-08-09 06:45:13 +03:00
};
2019-08-11 20:29:45 +03:00
local image_azure = Step("image-azure", depends_on=[installer]);
2019-08-12 00:38:24 +03:00
local image_gcp = Step("image-gcp", depends_on=[installer]);
2019-08-11 00:29:25 +03:00
local capi = Step("capi", depends_on=[basic_integration], environment=creds_env_vars);
local push_image_azure = Step("push-image-azure", depends_on=[image_azure], environment=creds_env_vars);
2019-08-12 00:38:24 +03:00
local push_image_gcp = Step("push-image-gcp", depends_on=[image_gcp], environment=creds_env_vars);
2019-08-11 00:29:25 +03:00
local e2e_integration_azure = Step("e2e-integration-azure", "e2e-integration", depends_on=[capi, push_image_azure], environment={PLATFORM: "azure"});
2019-08-12 00:38:24 +03:00
local e2e_integration_gcp = Step("e2e-integration-gcp", "e2e-integration", depends_on=[capi, push_image_gcp], environment={PLATFORM: "gcp"});
2019-08-11 00:29:25 +03:00
local e2e_steps = default_steps + [
capi,
2019-08-11 20:29:45 +03:00
image_azure,
2019-08-12 00:38:24 +03:00
image_gcp,
2019-08-11 00:29:25 +03:00
push_image_azure,
2019-08-12 00:38:24 +03:00
push_image_gcp,
2019-08-11 00:29:25 +03:00
e2e_integration_azure,
2019-08-12 00:38:24 +03:00
e2e_integration_gcp,
2019-08-11 00:29:25 +03:00
];
2019-08-09 06:45:13 +03:00
local e2e_trigger = {
trigger: {
target: {
2019-08-03 00:08:24 +03:00
include: ['e2e'],
2019-08-09 06:45:13 +03:00
},
},
};
2019-08-03 00:08:24 +03:00
local e2e_pipeline = Pipeline('e2e', e2e_steps) + e2e_trigger;
2019-08-11 00:29:25 +03:00
// Conformance pipeline.
local conformance_azure = Step("conformance-azure", "e2e-integration", depends_on=[capi, push_image_azure], environment={PLATFORM: "azure", CONFORMANCE: "run"});
2019-08-12 00:38:24 +03:00
local conformance_gcp = Step("conformance-gcp", "e2e-integration", depends_on=[capi, push_image_gcp], environment={PLATFORM: "gcp", CONFORMANCE: "run"});
2019-08-11 00:29:25 +03:00
local conformance_steps = default_steps + [
2019-08-11 20:52:20 +03:00
capi,
2019-08-11 20:29:45 +03:00
image_azure,
2019-08-12 00:38:24 +03:00
image_gcp,
2019-08-11 00:29:25 +03:00
push_image_azure,
2019-08-12 00:38:24 +03:00
push_image_gcp,
2019-08-11 00:29:25 +03:00
conformance_azure,
2019-08-12 00:38:24 +03:00
conformance_gcp,
2019-08-11 00:29:25 +03:00
];
2019-08-09 06:45:13 +03:00
local conformance_trigger = {
trigger: {
target: {
2019-08-03 00:08:24 +03:00
include: ['conformance'],
2019-08-09 06:45:13 +03:00
},
},
};
2019-08-03 00:08:24 +03:00
local conformance_pipeline = Pipeline('conformance', conformance_steps) + conformance_trigger;
2019-08-11 00:29:25 +03:00
// Nightly pipeline.
local nightly_trigger = {
trigger: {
cron: {
2019-08-03 00:08:24 +03:00
include: ['nightly'],
2019-08-11 00:29:25 +03:00
},
},
};
2019-08-03 00:08:24 +03:00
local nightly_pipeline = Pipeline('nightly', conformance_steps) + nightly_trigger;
2019-08-11 00:29:25 +03:00
// Release pipeline.
2019-08-11 19:54:33 +03:00
local aws_env_vars = {
2019-08-03 00:08:24 +03:00
AWS_ACCESS_KEY_ID: { from_secret: 'aws_access_key_id' },
AWS_SECRET_ACCESS_KEY: { from_secret: 'aws_secret_access_key' },
AWS_DEFAULT_REGION: 'us-west-2',
AWS_PUBLISH_REGIONS: 'us-west-2,us-east-1,us-east-2,us-west-1,eu-central-1',
2019-08-11 19:54:33 +03:00
};
local ami_trigger = {
when: {
2019-08-03 00:08:24 +03:00
event: ['tag'],
},
2019-08-11 19:54:33 +03:00
};
2019-08-03 00:08:24 +03:00
local kernel = Step('kernel');
local iso = Step('iso', depends_on=[installer]);
local image_aws = Step('image-aws', depends_on=[push], environment=aws_env_vars) + ami_trigger;
2019-08-11 19:54:33 +03:00
2019-08-11 00:29:25 +03:00
// TODO(andrewrynhard): We should run E2E tests on a release.
2019-08-03 00:08:24 +03:00
local release = {
name: 'release',
image: 'plugins/github-release',
settings: {
api_key: { from_secret: 'github_token' },
2019-08-11 00:29:25 +03:00
draft: true,
2019-08-03 00:08:24 +03:00
files: ['build/*'],
checksum: ['sha256', 'sha512'],
2019-08-11 00:29:25 +03:00
},
when: {
2019-08-03 00:08:24 +03:00
event: ['tag'],
2019-08-11 00:29:25 +03:00
},
2019-08-12 00:38:24 +03:00
depends_on: [kernel.name, iso.name, image_gcp.name, image_azure.name, image_aws.name, push.name]
2019-08-11 00:29:25 +03:00
};
local release_steps = default_steps + [
2019-08-11 20:29:45 +03:00
kernel,
image_azure,
2019-08-12 00:38:24 +03:00
image_gcp,
2019-08-11 19:54:33 +03:00
image_aws,
2019-08-11 20:29:45 +03:00
iso,
2019-08-11 19:54:33 +03:00
release,
2019-08-11 00:29:25 +03:00
];
2019-08-09 06:45:13 +03:00
local release_trigger = {
trigger: {
2019-08-11 20:52:20 +03:00
event: [
2019-08-03 00:08:24 +03:00
'tag',
2019-08-11 20:52:20 +03:00
],
2019-08-09 06:45:13 +03:00
},
};
2019-08-03 00:08:24 +03:00
local release_pipeline = Pipeline('release', release_steps) + release_trigger;
2019-08-11 00:29:25 +03:00
// Notify pipeline.
local notify = {
2019-08-03 00:08:24 +03:00
name: 'slack',
image: 'plugins/slack',
2019-08-11 00:29:25 +03:00
settings:
{
2019-08-03 00:08:24 +03:00
webhook: { from_secret: 'slack_webhook' },
channel: 'proj-talos-maint',
2019-08-11 00:29:25 +03:00
},
};
local notify_steps = [notify];
2019-08-09 06:45:13 +03:00
local notify_trigger = {
trigger: {
2019-08-03 00:08:24 +03:00
status: ['success', 'failure'],
2019-08-09 06:45:13 +03:00
},
};
local notify_depends_on = {
2019-08-11 00:29:25 +03:00
depends_on: [
default_pipeline.name,
e2e_pipeline.name,
conformance_pipeline.name,
nightly_pipeline.name,
release_pipeline.name,
],
2019-08-09 06:45:13 +03:00
};
2019-08-03 00:08:24 +03:00
local notify_pipeline = Pipeline('notify', notify_steps, [default_pipeline, e2e_pipeline, conformance_pipeline, nightly_pipeline, release_pipeline], false, false, false) + notify_trigger;
2019-08-11 00:29:25 +03:00
// Final configuration file definition.
2019-08-09 06:45:13 +03:00
[
default_pipeline,
e2e_pipeline,
conformance_pipeline,
nightly_pipeline,
release_pipeline,
notify_pipeline,
]