2019-08-10 21:29:25 +00: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-09-06 22:37:37 -05:00
// Generate with `drone jsonnet --source ./hack/drone.jsonnet --stream --format`
2019-08-10 21:29:25 +00:00
2019-08-02 16:08:24 -05:00
local build_container = ' a u t o n o m y / b u i l d - c o n t a i n e r : l a t e s t ' ;
2019-08-10 21:29:25 +00:00
local volumes = {
dockersock : {
pipeline : {
2019-08-02 16:08:24 -05:00
name : ' d o c k e r s o c k ' ,
2019-08-10 21:29:25 +00:00
temp : { } ,
} ,
step : {
name : $ . dockersock . pipeline . name ,
2019-08-02 16:08:24 -05:00
path : ' / v a r / r u n ' ,
2019-08-10 21:29:25 +00:00
} ,
2019-08-09 03:45:13 +00:00
} ,
2019-08-10 21:29:25 +00:00
dev : {
pipeline : {
2019-08-02 16:08:24 -05:00
name : ' d e v ' ,
2019-08-10 21:29:25 +00:00
host : {
2019-08-02 16:08:24 -05:00
path : ' / d e v ' ,
2019-08-10 21:29:25 +00:00
} ,
} ,
step : {
name : $ . dev . pipeline . name ,
2019-08-02 16:08:24 -05:00
path : ' / d e v ' ,
2019-08-10 21:29:25 +00:00
} ,
2019-08-09 03:45:13 +00:00
} ,
2019-08-10 21:29:25 +00:00
tmp : {
pipeline : {
2019-08-02 16:08:24 -05:00
name : ' t m p ' ,
2019-08-10 21:29:25 +00:00
temp : { } ,
} ,
step : {
name : $ . tmp . pipeline . name ,
2019-08-02 16:08:24 -05:00
path : ' / t m p ' ,
2019-08-10 21:29:25 +00:00
} ,
2019-08-09 03:45:13 +00:00
} ,
2019-08-10 21:29:25 +00:00
ForStep ( ) : [
self . dockersock . step ,
self . dev . step ,
self . tmp . step ,
] ,
ForPipeline ( ) : [
self . dockersock . pipeline ,
self . dev . pipeline ,
self . tmp . pipeline ,
] ,
} ;
2019-08-09 03:45:13 +00:00
2019-08-10 21:29:25 +00:00
// This provides the docker service.
2019-08-09 03:45:13 +00:00
local docker = {
2019-08-02 16:08:24 -05:00
name : ' d o c k e r ' ,
image : ' d o c k e r : 1 9 . 0 3 - d i n d ' ,
entrypoint : [ ' d o c k e r d ' ] ,
2019-08-09 03:45:13 +00:00
privileged : true ,
command : [
2019-08-02 16:08:24 -05:00
' - - d n s = 8 . 8 . 8 . 8 ' ,
' - - d n s = 8 . 8 . 4 . 4 ' ,
' - - m t u = 1 4 4 0 ' ,
' - - l o g - l e v e l = e r r o r ' ,
2019-08-09 03:45:13 +00:00
] ,
2019-08-10 21:29:25 +00:00
volumes : volumes . ForStep ( ) ,
2019-08-09 03:45:13 +00:00
} ;
2019-08-10 21:29:25 +00:00
// This step is used only when `drone exec` is executed.
2019-08-09 03:45:13 +00:00
local buildkit = {
2019-08-02 16:08:24 -05:00
name : ' b u i l d k i t ' ,
image : ' m o b y / b u i l d k i t : v 0 . 6 . 0 ' ,
2019-08-09 03:45:13 +00:00
privileged : true ,
detach : true ,
2019-08-02 16:08:24 -05:00
commands : [ ' b u i l d k i t d - - a d d r t c p : / / 0 . 0 . 0 . 0 : 1 2 3 4 - - a l l o w - i n s e c u r e - e n t i t l e m e n t s e c u r i t y . i n s e c u r e ' ] ,
2019-08-09 03:45:13 +00:00
when : {
event : {
2019-08-02 16:08:24 -05:00
include : [ ' ' ] ,
2019-08-09 03:45:13 +00:00
} ,
} ,
} ;
2019-08-10 21:29:25 +00: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-09-23 21:45:21 -07:00
local Step ( name , target = ' ' , depends_on = [ ] , environment = { } ) = {
2019-08-02 16:08:24 -05:00
local make = if target = = ' ' then std.format ( ' m a k e % s ' , name ) else std.format ( ' m a k e % s ' , target ) ,
2019-08-10 21:29:25 +00:00
local common_env_vars = {
2019-08-02 16:08:24 -05:00
BUILDKIT_HOST : ' $ { B U I L D K I T _ H O S T = t c p : / / b u i l d k i t d . c i . s v c : 1 2 3 4 } ' ,
BINDIR : ' / u s r / l o c a l / b i n ' ,
2019-08-10 21:29:25 +00:00
} ,
2019-08-09 03:45:13 +00:00
2019-08-10 21:29:25 +00:00
name : name ,
2019-08-09 03:45:13 +00:00
image : build_container ,
2019-09-23 21:45:21 -07:00
pull : " a l w a y s " ,
2019-08-10 21:29:25 +00:00
commands : [ make ] ,
environment : common_env_vars + environment ,
volumes : volumes . ForStep ( ) ,
2019-08-09 03:45:13 +00:00
depends_on : [ x . name for x in depends_on ] ,
} ;
2019-08-10 21:29:25 +00:00
// Pipeline is a way to standardize the creation of pipelines. It supports
// using and existing pipeline as a base.
2019-09-23 21:45:21 -07:00
local Pipeline ( name , steps = [ ] , depends_on = [ ] , with_buildkit = false , with_docker = true ) = {
2019-08-02 16:08:24 -05:00
local node = { ' node-role.kubernetes.io/ci' : ' ' } ,
2019-08-09 03:45:13 +00:00
2019-08-02 16:08:24 -05:00
kind : ' p i p e l i n e ' ,
2019-08-09 03:45:13 +00:00
name : name ,
2019-08-10 21:29:25 +00:00
node : node ,
services : [
if with_docker then docker ,
if with_buildkit then buildkit ,
] ,
2019-09-23 21:45:21 -07:00
steps : steps ,
2019-08-10 21:29:25 +00:00
volumes : volumes . ForPipeline ( ) ,
depends_on : [ x . name for x in depends_on ] ,
2019-08-09 03:45:13 +00:00
} ;
2019-08-10 21:29:25 +00:00
// Default pipeline.
2019-10-22 00:53:54 +03:00
local fetchtags = {
name : ' f e t c h - t a g s ' ,
image : ' d o c k e r : g i t ' ,
commands : [
' g i t f e t c h - - t a g s ' ,
] ,
} ;
2019-08-10 21:29:25 +00:00
2019-10-22 00:53:54 +03:00
local machined = Step ( " m a c h i n e d " , depends_on = [ fetchtags ] ) ;
local osd = Step ( " o s d " , depends_on = [ fetchtags ] ) ;
local trustd = Step ( " t r u s t d " , depends_on = [ fetchtags ] ) ;
local ntpd = Step ( " n t p d " , depends_on = [ fetchtags ] ) ;
local networkd = Step ( " n e t w o r k d " , depends_on = [ fetchtags ] ) ;
local osctl_linux = Step ( " o s c t l - l i n u x " , depends_on = [ fetchtags ] ) ;
local osctl_darwin = Step ( " o s c t l - d a r w i n " , depends_on = [ fetchtags ] ) ;
2019-10-11 21:49:53 +00:00
local rootfs = Step ( " r o o t f s " , depends_on = [ machined , osd , trustd , ntpd , networkd ] ) ;
2019-08-10 21:29:25 +00:00
local initramfs = Step ( " i n i t r a m f s " , depends_on = [ rootfs ] ) ;
local installer = Step ( " i n s t a l l e r " , depends_on = [ rootfs ] ) ;
local container = Step ( " c o n t a i n e r " , depends_on = [ rootfs ] ) ;
local lint = Step ( " l i n t " ) ;
2019-08-27 21:45:59 +00:00
local protolint = Step ( " p r o t o l i n t " ) ;
2019-08-17 08:51:40 +00:00
local markdownlint = Step ( " m a r k d o w n l i n t " ) ;
2019-08-11 17:29:45 +00:00
local image_test = Step ( " i m a g e - t e s t " , depends_on = [ installer ] ) ;
2019-08-10 21:29:25 +00:00
local unit_tests = Step ( " u n i t - t e s t s " , depends_on = [ rootfs ] ) ;
2019-09-02 21:55:42 +03:00
local unit_tests_race = Step ( " u n i t - t e s t s - r a c e " , depends_on = [ lint ] ) ;
2019-08-10 21:29:25 +00:00
local basic_integration = Step ( " b a s i c - i n t e g r a t i o n " , depends_on = [ container , osctl_linux ] ) ;
2019-08-09 03:45:13 +00:00
local coverage = {
2019-08-02 16:08:24 -05:00
name : ' c o v e r a g e ' ,
image : ' p l u g i n s / c o d e c o v ' ,
settings : {
token : { from_secret : ' c o d e c o v _ t o k e n ' } ,
files : [ ' c o v e r a g e . t x t ' ] ,
2019-08-09 03:45:13 +00:00
} ,
2019-08-10 21:29:25 +00:00
when : {
2019-08-02 16:08:24 -05:00
event : [ ' p u l l _ r e q u e s t ' ] ,
2019-08-09 03:45:13 +00:00
} ,
depends_on : [ unit_tests . name ] ,
} ;
local push = {
2019-08-02 16:08:24 -05:00
name : ' p u s h ' ,
image : ' a u t o n o m y / b u i l d - c o n t a i n e r : l a t e s t ' ,
pull : ' a l w a y s ' ,
environment : {
DOCKER_USERNAME : { from_secret : ' d o c k e r _ u s e r n a m e ' } ,
DOCKER_PASSWORD : { from_secret : ' d o c k e r _ p a s s w o r d ' } ,
2019-08-09 03:45:13 +00:00
} ,
2019-08-02 16:08:24 -05:00
commands : [ ' m a k e g i t m e t a ' , ' m a k e l o g i n ' , ' m a k e p u s h ' ] ,
2019-08-10 21:29:25 +00:00
volumes : volumes . ForStep ( ) ,
2019-08-09 03:45:13 +00:00
when : {
2019-08-12 18:28:42 +00:00
event : {
2019-08-13 00:40:00 +00:00
exclude : [
2019-08-02 16:08:24 -05:00
' p u l l _ r e q u e s t ' ,
' p r o m o t e ' ,
2019-08-13 00:40:00 +00:00
] ,
2019-08-12 18:28:42 +00:00
} ,
2019-08-09 03:45:13 +00:00
} ,
2019-08-10 06:18:15 +00:00
depends_on : [ basic_integration . name ] ,
2019-08-09 03:45:13 +00:00
} ;
2019-08-10 21:29:25 +00:00
local default_steps = [
2019-10-22 00:53:54 +03:00
fetchtags ,
2019-08-10 21:29:25 +00:00
machined ,
osd ,
trustd ,
ntpd ,
2019-08-02 16:08:24 -05:00
networkd ,
2019-08-10 21:29:25 +00:00
osctl_linux ,
osctl_darwin ,
2019-08-09 03:45:13 +00:00
rootfs ,
initramfs ,
2019-08-10 21:29:25 +00:00
installer ,
2019-08-11 17:29:45 +00:00
container ,
2019-08-09 03:45:13 +00:00
lint ,
2019-08-27 21:45:59 +00:00
protolint ,
2019-08-17 08:51:40 +00:00
markdownlint ,
2019-08-11 17:29:45 +00:00
image_test ,
2019-08-09 03:45:13 +00:00
unit_tests ,
2019-09-02 21:55:42 +03:00
unit_tests_race ,
2019-08-09 03:45:13 +00:00
coverage ,
basic_integration ,
push ,
] ;
local default_trigger = {
trigger : {
cron : {
2019-08-02 16:08:24 -05:00
exclude : [ ' n i g h t l y ' ] ,
2019-08-09 03:45:13 +00:00
} ,
2019-08-12 18:28:42 +00:00
event : {
2019-08-13 00:40:00 +00:00
exclude : [
2019-08-02 16:08:24 -05:00
' t a g ' ,
' p r o m o t e ' ,
] ,
2019-08-09 03:45:13 +00:00
} ,
} ,
} ;
2019-08-02 16:08:24 -05:00
local default_pipeline = Pipeline ( ' d e f a u l t ' , default_steps ) + default_trigger ;
2019-08-10 21:29:25 +00:00
// E2E pipeline.
local creds_env_vars = {
AZURE_SVC_ACCT : { from_secret : " a z u r e _ s v c _ a c c t " } ,
2019-08-11 21:38:24 +00:00
// TODO(andrewrynhard): Rename this to the GCP convention.
2019-08-10 21:29:25 +00:00
GCE_SVC_ACCT : { from_secret : " g c e _ s v c _ a c c t " } ,
PACKET_AUTH_TOKEN : { from_secret : " p a c k e t _ a u t h _ t o k e n " } ,
2019-09-06 22:37:37 -05:00
AWS_SVC_ACCT : { from_secret : " a w s _ s v c _ a c c t " } ,
2019-08-09 03:45:13 +00:00
} ;
2019-09-09 22:21:58 +00:00
local image_aws = Step ( " i m a g e - a w s " , depends_on = [ installer ] ) ;
2019-08-11 17:29:45 +00:00
local image_azure = Step ( " i m a g e - a z u r e " , depends_on = [ installer ] ) ;
2019-08-11 21:38:24 +00:00
local image_gcp = Step ( " i m a g e - g c p " , depends_on = [ installer ] ) ;
2019-08-10 21:29:25 +00:00
local capi = Step ( " c a p i " , depends_on = [ basic_integration ] , environment = creds_env_vars ) ;
2019-09-09 22:21:58 +00:00
local push_image_aws = Step ( " p u s h - i m a g e - a w s " , depends_on = [ image_aws ] , environment = creds_env_vars ) ;
2019-08-10 21:29:25 +00:00
local push_image_azure = Step ( " p u s h - i m a g e - a z u r e " , depends_on = [ image_azure ] , environment = creds_env_vars ) ;
2019-08-11 21:38:24 +00:00
local push_image_gcp = Step ( " p u s h - i m a g e - g c p " , depends_on = [ image_gcp ] , environment = creds_env_vars ) ;
2019-09-09 22:21:58 +00:00
local e2e_integration_aws = Step ( " e 2 e - i n t e g r a t i o n - a w s " , " e 2 e - i n t e g r a t i o n " , depends_on = [ capi , push_image_aws ] , environment = { PLATFORM : " a w s " } ) ;
2019-08-10 21:29:25 +00:00
local e2e_integration_azure = Step ( " e 2 e - i n t e g r a t i o n - a z u r e " , " e 2 e - i n t e g r a t i o n " , depends_on = [ capi , push_image_azure ] , environment = { PLATFORM : " a z u r e " } ) ;
2019-08-11 21:38:24 +00:00
local e2e_integration_gcp = Step ( " e 2 e - i n t e g r a t i o n - g c p " , " e 2 e - i n t e g r a t i o n " , depends_on = [ capi , push_image_gcp ] , environment = { PLATFORM : " g c p " } ) ;
2019-08-10 21:29:25 +00:00
local e2e_steps = default_steps + [
capi ,
2019-09-09 22:21:58 +00:00
image_aws ,
2019-08-11 17:29:45 +00:00
image_azure ,
2019-08-11 21:38:24 +00:00
image_gcp ,
2019-09-09 22:21:58 +00:00
push_image_aws ,
2019-08-10 21:29:25 +00:00
push_image_azure ,
2019-08-11 21:38:24 +00:00
push_image_gcp ,
2019-09-09 22:21:58 +00:00
e2e_integration_aws ,
2019-08-10 21:29:25 +00:00
e2e_integration_azure ,
2019-08-11 21:38:24 +00:00
e2e_integration_gcp ,
2019-08-10 21:29:25 +00:00
] ;
2019-08-09 03:45:13 +00:00
local e2e_trigger = {
trigger : {
target : {
2019-08-02 16:08:24 -05:00
include : [ ' e 2 e ' ] ,
2019-08-09 03:45:13 +00:00
} ,
} ,
} ;
2019-08-02 16:08:24 -05:00
local e2e_pipeline = Pipeline ( ' e 2 e ' , e2e_steps ) + e2e_trigger ;
2019-08-10 21:29:25 +00:00
// Conformance pipeline.
2019-09-09 22:21:58 +00:00
local conformance_aws = Step ( " c o n f o r m a n c e - a w s " , " e 2 e - i n t e g r a t i o n " , depends_on = [ capi , push_image_aws ] , environment = { PLATFORM : " a w s " , CONFORMANCE : " r u n " } ) ;
2019-08-10 21:29:25 +00:00
local conformance_azure = Step ( " c o n f o r m a n c e - a z u r e " , " e 2 e - i n t e g r a t i o n " , depends_on = [ capi , push_image_azure ] , environment = { PLATFORM : " a z u r e " , CONFORMANCE : " r u n " } ) ;
2019-08-11 21:38:24 +00:00
local conformance_gcp = Step ( " c o n f o r m a n c e - g c p " , " e 2 e - i n t e g r a t i o n " , depends_on = [ capi , push_image_gcp ] , environment = { PLATFORM : " g c p " , CONFORMANCE : " r u n " } ) ;
2019-08-10 21:29:25 +00:00
local conformance_steps = default_steps + [
2019-08-11 17:52:20 +00:00
capi ,
2019-09-09 22:21:58 +00:00
image_aws ,
2019-08-11 17:29:45 +00:00
image_azure ,
2019-08-11 21:38:24 +00:00
image_gcp ,
2019-09-09 22:21:58 +00:00
push_image_aws ,
2019-08-10 21:29:25 +00:00
push_image_azure ,
2019-08-11 21:38:24 +00:00
push_image_gcp ,
2019-09-09 22:21:58 +00:00
conformance_aws ,
2019-08-10 21:29:25 +00:00
conformance_azure ,
2019-08-11 21:38:24 +00:00
conformance_gcp ,
2019-08-10 21:29:25 +00:00
] ;
2019-08-09 03:45:13 +00:00
local conformance_trigger = {
trigger : {
target : {
2019-08-02 16:08:24 -05:00
include : [ ' c o n f o r m a n c e ' ] ,
2019-08-09 03:45:13 +00:00
} ,
} ,
} ;
2019-08-02 16:08:24 -05:00
local conformance_pipeline = Pipeline ( ' c o n f o r m a n c e ' , conformance_steps ) + conformance_trigger ;
2019-08-10 21:29:25 +00:00
// Nightly pipeline.
local nightly_trigger = {
trigger : {
cron : {
2019-08-02 16:08:24 -05:00
include : [ ' n i g h t l y ' ] ,
2019-08-10 21:29:25 +00:00
} ,
} ,
} ;
2019-08-02 16:08:24 -05:00
local nightly_pipeline = Pipeline ( ' n i g h t l y ' , conformance_steps ) + nightly_trigger ;
2019-08-10 21:29:25 +00:00
// Release pipeline.
2019-08-11 16:54:33 +00:00
local aws_env_vars = {
2019-08-02 16:08:24 -05:00
AWS_ACCESS_KEY_ID : { from_secret : ' a w s _ a c c e s s _ k e y _ i d ' } ,
AWS_SECRET_ACCESS_KEY : { from_secret : ' a w s _ s e c r e t _ a c c e s s _ k e y ' } ,
AWS_DEFAULT_REGION : ' u s - w e s t - 2 ' ,
AWS_PUBLISH_REGIONS : ' u s - w e s t - 2 , u s - e a s t - 1 , u s - e a s t - 2 , u s - w e s t - 1 , e u - c e n t r a l - 1 ' ,
2019-08-11 16:54:33 +00:00
} ;
local ami_trigger = {
when : {
2019-08-02 16:08:24 -05:00
event : [ ' t a g ' ] ,
} ,
2019-08-11 16:54:33 +00:00
} ;
2019-08-02 16:08:24 -05:00
local kernel = Step ( ' k e r n e l ' ) ;
local iso = Step ( ' i s o ' , depends_on = [ installer ] ) ;
2019-08-11 16:54:33 +00:00
2019-08-10 21:29:25 +00:00
// TODO(andrewrynhard): We should run E2E tests on a release.
2019-08-02 16:08:24 -05:00
local release = {
name : ' r e l e a s e ' ,
image : ' p l u g i n s / g i t h u b - r e l e a s e ' ,
settings : {
api_key : { from_secret : ' g i t h u b _ t o k e n ' } ,
2019-08-10 21:29:25 +00:00
draft : true ,
2019-08-02 16:08:24 -05:00
files : [ ' b u i l d / * ' ] ,
checksum : [ ' s h a 2 5 6 ' , ' s h a 5 1 2 ' ] ,
2019-08-10 21:29:25 +00:00
} ,
when : {
2019-08-02 16:08:24 -05:00
event : [ ' t a g ' ] ,
2019-08-10 21:29:25 +00:00
} ,
2019-08-11 21:38:24 +00:00
depends_on : [ kernel . name , iso . name , image_gcp . name , image_azure . name , image_aws . name , push . name ]
2019-08-10 21:29:25 +00:00
} ;
local release_steps = default_steps + [
2019-08-11 17:29:45 +00:00
kernel ,
image_azure ,
2019-08-11 21:38:24 +00:00
image_gcp ,
2019-08-11 16:54:33 +00:00
image_aws ,
2019-08-11 17:29:45 +00:00
iso ,
2019-08-11 16:54:33 +00:00
release ,
2019-08-10 21:29:25 +00:00
] ;
2019-08-09 03:45:13 +00:00
local release_trigger = {
trigger : {
2019-08-11 17:52:20 +00:00
event : [
2019-08-02 16:08:24 -05:00
' t a g ' ,
2019-08-11 17:52:20 +00:00
] ,
2019-08-09 03:45:13 +00:00
} ,
} ;
2019-08-02 16:08:24 -05:00
local release_pipeline = Pipeline ( ' r e l e a s e ' , release_steps ) + release_trigger ;
2019-08-10 21:29:25 +00:00
// Notify pipeline.
local notify = {
2019-08-02 16:08:24 -05:00
name : ' s l a c k ' ,
image : ' p l u g i n s / s l a c k ' ,
2019-08-10 21:29:25 +00:00
settings :
{
2019-08-02 16:08:24 -05:00
webhook : { from_secret : ' s l a c k _ w e b h o o k ' } ,
2019-09-09 10:51:10 -05:00
channel : ' p r o j - t a l o s - m a i n t a i n e r s ' ,
2019-08-10 21:29:25 +00:00
} ,
} ;
local notify_steps = [ notify ] ;
2019-08-09 03:45:13 +00:00
local notify_trigger = {
trigger : {
2019-08-02 16:08:24 -05:00
status : [ ' s u c c e s s ' , ' f a i l u r e ' ] ,
2019-08-09 03:45:13 +00:00
} ,
} ;
local notify_depends_on = {
2019-08-10 21:29:25 +00:00
depends_on : [
default_pipeline . name ,
e2e_pipeline . name ,
conformance_pipeline . name ,
nightly_pipeline . name ,
release_pipeline . name ,
] ,
2019-08-09 03:45:13 +00:00
} ;
2019-09-23 21:45:21 -07:00
local notify_pipeline = Pipeline ( ' n o t i f y ' , notify_steps , [ default_pipeline , e2e_pipeline , conformance_pipeline , nightly_pipeline , release_pipeline ] , false , false ) + notify_trigger ;
2019-08-10 21:29:25 +00:00
// Final configuration file definition.
2019-08-09 03:45:13 +00:00
[
default_pipeline ,
e2e_pipeline ,
conformance_pipeline ,
nightly_pipeline ,
release_pipeline ,
notify_pipeline ,
]