diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..d6d7043c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,20 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## Unreleased +### Added + +- specify a user for the pipeline step, by [@bradrydzewski](https://github.com/bradrydzewski). [#2651](https://github.com/drone/drone/issues/2651). +- update drone-yaml to version 1.0.7. +- update drone-runtime to version 1.0.5. + +## [1.0.1] - 2019-04-10 +### Added + +- pass stage environment variables to pipeline steps, by [@bradrydzewski](https://github.com/bradrydzewski). +- update go-scm to version 1.3.0, by [@bradrydzewski](https://github.com/bradrydzewski). +- update drone-runtime to version to 1.0.4, by [@bradrydzewski](https://github.com/bradrydzewski). +- ping docker daemon before agent starts to ensure connectivity, by [@bradrydzewski](https://github.com/bradrydzewski). diff --git a/LICENSE b/LICENSE index f8847974..b186d8c9 100644 --- a/LICENSE +++ b/LICENSE @@ -59,6 +59,8 @@ legal claim.** ----------------------------------------------------------------- +Waiver: Small Business + Contributor waives the terms of rule 1 for companies meeting all the following criteria, counting all subsidiaries and affiliated entities as one: @@ -69,7 +71,18 @@ entities as one: 2. less than $5 million US dollars in all-time aggregate debt and equity financing -3. less than 15,000 total pipelines executed using this software +Contributor will not revoke this waiver, but may change terms for +future versions of the software. + +----------------------------------------------------------------- + +Waiver: Low Volume + +Contributor waives the terms of rule 1 for companies meeting all +the following criteria, counting all subsidiaries and affiliated +entities as one: + +1. less than 15,000 total pipelines executed using this software in the immediately preceding, year-long period Contributor will not revoke this waiver, but may change terms for diff --git a/cmd/drone-server/config/config.go b/cmd/drone-server/config/config.go index 69fcdaf4..071ce181 100644 --- a/cmd/drone-server/config/config.go +++ b/cmd/drone-server/config/config.go @@ -198,7 +198,7 @@ type ( // Runner provides the runner configuration. Runner struct { Local bool `envconfig:"DRONE_RUNNER_LOCAL"` - Image string `envconfig:"DRONE_RUNNER_IMAGE" default:"drone/controller:1.0.0-rc.6"` + Image string `envconfig:"DRONE_RUNNER_IMAGE" default:"drone/controller:1.0.0"` Platform string `envconfig:"DRONE_RUNNER_PLATFORM" default:"linux/amd64"` OS string `envconfig:"DRONE_RUNNER_OS"` Arch string `envconfig:"DRONE_RUNNER_ARCH"` diff --git a/core/sched.go b/core/sched.go index 9fca2474..58e2488f 100644 --- a/core/sched.go +++ b/core/sched.go @@ -44,6 +44,14 @@ type Scheduler interface { // returns true if the build has been cancelled. Cancelled(context.Context, int64) (bool, error) + // Pause pauses the scheduler and prevents new pipelines + // from being scheduled for execution. + Pause(context.Context) error + + // Resume unpauses the scheduler, allowing new pipelines + // to be scheduled for execution. + Resume(context.Context) error + // Stats provides statistics for underlying scheduler. The // data format is scheduler-specific. Stats(context.Context) (interface{}, error) diff --git a/docker/Dockerfile.agent.linux.amd64 b/docker/Dockerfile.agent.linux.amd64 index 14f657bc..76060ba6 100644 --- a/docker/Dockerfile.agent.linux.amd64 +++ b/docker/Dockerfile.agent.linux.amd64 @@ -11,4 +11,6 @@ ADD release/linux/amd64/drone-agent /bin/ COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +LABEL com.centurylinklabs.watchtower.stop-signal="SIGINT" + ENTRYPOINT ["/bin/drone-agent"] diff --git a/docker/Dockerfile.agent.linux.arm b/docker/Dockerfile.agent.linux.arm index b6430593..47f0d615 100644 --- a/docker/Dockerfile.agent.linux.arm +++ b/docker/Dockerfile.agent.linux.arm @@ -7,4 +7,6 @@ ENV DRONE_RUNNER_CAPACITY=1 ENV DRONE_RUNNER_VARIANT=v7 ADD release/linux/arm/drone-agent /bin/ +LABEL com.centurylinklabs.watchtower.stop-signal="SIGINT" + ENTRYPOINT ["/bin/drone-agent"] diff --git a/docker/Dockerfile.agent.linux.arm64 b/docker/Dockerfile.agent.linux.arm64 index 24b9898e..04ba0154 100644 --- a/docker/Dockerfile.agent.linux.arm64 +++ b/docker/Dockerfile.agent.linux.arm64 @@ -7,4 +7,6 @@ ENV DRONE_RUNNER_CAPACITY=1 ENV DRONE_RUNNER_VARIANT=v8 ADD release/linux/arm64/drone-agent /bin/ +LABEL com.centurylinklabs.watchtower.stop-signal="SIGINT" + ENTRYPOINT ["/bin/drone-agent"] diff --git a/docker/Dockerfile.agent.windows.1803 b/docker/Dockerfile.agent.windows.1803 index d77002eb..1ba62bcb 100644 --- a/docker/Dockerfile.agent.windows.1803 +++ b/docker/Dockerfile.agent.windows.1803 @@ -8,5 +8,7 @@ ENV DRONE_RUNNER_PLATFORM=windows/amd64 ENV DRONE_RUNNER_KERNEL=1803 ENV DRONE_RUNNER_CAPACITY=1 +LABEL com.centurylinklabs.watchtower.stop-signal="SIGINT" + ADD release/windows/1803/amd64/drone-agent.exe C:/drone-agent.exe ENTRYPOINT [ "C:\\drone-agent.exe" ] diff --git a/docker/Dockerfile.agent.windows.1809 b/docker/Dockerfile.agent.windows.1809 index 3ce674d0..e2e0d294 100644 --- a/docker/Dockerfile.agent.windows.1809 +++ b/docker/Dockerfile.agent.windows.1809 @@ -8,5 +8,7 @@ ENV DRONE_RUNNER_PLATFORM=windows/amd64 ENV DRONE_RUNNER_KERNEL=1809 ENV DRONE_RUNNER_CAPACITY=1 +LABEL com.centurylinklabs.watchtower.stop-signal="SIGINT" + ADD release/windows/1809/amd64/drone-agent.exe C:/drone-agent.exe ENTRYPOINT [ "C:\\drone-agent.exe" ] diff --git a/go.mod b/go.mod index 82efdcd8..cfdd48c8 100644 --- a/go.mod +++ b/go.mod @@ -16,13 +16,13 @@ require ( github.com/docker/go-connections v0.3.0 github.com/docker/go-units v0.3.3 github.com/drone/drone-go v0.0.0-20190217024616-3e8b71333e59 - github.com/drone/drone-runtime v0.0.0-20190210191445-ad403a0ca24e - github.com/drone/drone-ui v0.0.0-20190316194615-9f768293daab - github.com/drone/drone-yaml v1.0.4 + github.com/drone/drone-runtime v1.0.5 + github.com/drone/drone-ui v0.0.0-20190318215801-d6c3d11a1c3f + github.com/drone/drone-yaml v1.0.7 github.com/drone/envsubst v1.0.1 github.com/drone/go-license v1.0.2 github.com/drone/go-login v1.0.4-0.20190311170324-2a4df4f242a2 - github.com/drone/go-scm v1.2.0 + github.com/drone/go-scm v1.3.0 github.com/drone/signal v1.0.0 github.com/dustin/go-humanize v1.0.0 github.com/ghodss/yaml v1.0.0 @@ -80,14 +80,14 @@ require ( github.com/sirupsen/logrus v0.0.0-20181103062819-44067abb194b github.com/spf13/pflag v1.0.3 github.com/unrolled/secure v0.0.0-20181022170031-4b6b7cf51606 - golang.org/x/crypto v0.0.0-20181012144002-a92615f3c490 + golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1 golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890 golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f golang.org/x/sys v0.0.0-20181011152604-fa43e7bc11ba golang.org/x/text v0.3.0 golang.org/x/time v0.0.0-20181108054448-85acf8d2951c - google.golang.org/appengine v1.2.0 + google.golang.org/appengine v1.3.0 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect gopkg.in/inf.v0 v0.9.1 gopkg.in/yaml.v2 v2.2.2 diff --git a/go.sum b/go.sum index 8d7d8096..59fbf1a5 100644 --- a/go.sum +++ b/go.sum @@ -3,7 +3,9 @@ docker.io/go-docker v1.0.0/go.mod h1:7tiAn5a0LFmjbPDbyTPOaTTOuG1ZRNXdPA6RvKY+fpY github.com/99designs/httpsignatures-go v0.0.0-20170731043157-88528bf4ca7e h1:rl2Aq4ZODqTDkeSqQBy+fzpZPamacO1Srp8zq7jf2Sc= github.com/99designs/httpsignatures-go v0.0.0-20170731043157-88528bf4ca7e/go.mod h1:Xa6lInWHNQnuWoF0YPSsx+INFA9qk7/7pTjwb3PInkY= github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/asaskevich/govalidator v0.0.0-20180315120708-ccb8e960c48f h1:y2hSFdXeA1y5z5f0vfNO0Dg5qVY036qzlz3Pds0B92o= github.com/asaskevich/govalidator v0.0.0-20180315120708-ccb8e960c48f/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= @@ -15,11 +17,13 @@ github.com/bmatcuk/doublestar v1.1.1 h1:YroD6BJCZBYx06yYFEWvUuKVWQn3vLLQAVmDmvTS github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= github.com/coreos/go-semver v0.2.0 h1:3Jm3tLmsgAYcjC+4Up7hJrFBPr+n7rAqYeSw/SZazuY= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dchest/authcookie v0.0.0-20120917135355-fbdef6e99866 h1:98WJ4YCdjmB7uyrdT3P4A2Oa1hiRPKoa/0zInG6UnfQ= github.com/dchest/authcookie v0.0.0-20120917135355-fbdef6e99866/go.mod h1:x7AK2h2QzaXVEFi1tbMYMDuvHcCEr1QdMDrg3hkW24Q= github.com/dchest/uniuri v0.0.0-20160212164326-8902c56451e9 h1:74lLNRzvsdIlkTgfDSMuaPjBr4cf6k7pwQQANm/yLKU= github.com/dchest/uniuri v0.0.0-20160212164326-8902c56451e9/go.mod h1:GgB8SF9nRG+GqaDtLcwJZsQFhcogVCJ79j4EdT0c2V4= +github.com/docker/distribution v0.0.0-20170726174610-edc3ab29cdff/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug= github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/go-connections v0.3.0 h1:3lOnM9cSzgGwx8VfK/NGOW5fLQ0GjIlCkaktF+n1M6o= @@ -30,10 +34,25 @@ github.com/drone/drone-go v0.0.0-20190217024616-3e8b71333e59 h1:tH7rJBME3tKWunUm github.com/drone/drone-go v0.0.0-20190217024616-3e8b71333e59/go.mod h1:qVb1k1w9X5jgoGyLtbnfWNnd4XZfAwokxBmiutbpGqw= github.com/drone/drone-runtime v0.0.0-20190210191445-ad403a0ca24e h1:Eq0QI9lKe6T5pziU/Kes1xX6QKAA6ZfnYvaZZeyY5TU= github.com/drone/drone-runtime v0.0.0-20190210191445-ad403a0ca24e/go.mod h1:I+wJO4yvngCUAro6wKjkMbuPPDI/jRynqU0LTW+8J44= -github.com/drone/drone-ui v0.0.0-20190316194615-9f768293daab h1:17/O+A6NUQ76sRy+krJJwRtOE2n7mlrw0veGIfYG22A= -github.com/drone/drone-ui v0.0.0-20190316194615-9f768293daab/go.mod h1:NBtVWW7NNJpD9+huMD/5TAE1db2nrEh0i35/9Rf1MPI= +github.com/drone/drone-runtime v1.0.3 h1:0p7ASt0WXbLZRzMOw20e1ahV3YkamRhtZFkm8UvM+JA= +github.com/drone/drone-runtime v1.0.3/go.mod h1:+osgwGADc/nyl40J0fdsf8Z09bgcBZXvXXnLOY48zYs= +github.com/drone/drone-runtime v1.0.4 h1:UdKcFPqh/7tTUE4fKakK2vqEyIaK9pKS3SZLG0EKeSE= +github.com/drone/drone-runtime v1.0.4/go.mod h1:+osgwGADc/nyl40J0fdsf8Z09bgcBZXvXXnLOY48zYs= +github.com/drone/drone-runtime v1.0.5 h1:fEdUvKd5+l8BQaPXntjUtSIVLvGWo3Blgb/zrXLKJoM= +github.com/drone/drone-runtime v1.0.5/go.mod h1:+osgwGADc/nyl40J0fdsf8Z09bgcBZXvXXnLOY48zYs= +github.com/drone/drone-ui v0.0.0-20190318170755-1ca48466a158 h1:u80WYtaGkKWVmxj1BMX9SukAqTxILzGFIKvY5as9zAc= +github.com/drone/drone-ui v0.0.0-20190318170755-1ca48466a158/go.mod h1:NBtVWW7NNJpD9+huMD/5TAE1db2nrEh0i35/9Rf1MPI= +github.com/drone/drone-ui v0.0.0-20190318215801-d6c3d11a1c3f h1:yMdZ/2BZFKrfMbWlc0cNH2TCXdC8MsSR0pnu3Dq4UH4= +github.com/drone/drone-ui v0.0.0-20190318215801-d6c3d11a1c3f/go.mod h1:NBtVWW7NNJpD9+huMD/5TAE1db2nrEh0i35/9Rf1MPI= +github.com/drone/drone-ui v0.8.1 h1:I4WBAlnk/YQzCggQy/Qegb8Nu2T2R9KVzxso/lL98so= github.com/drone/drone-yaml v1.0.4 h1:NYTEGhf/XJMiJT8CwGy+pMOxWC8C2vhhzEo6/gbT4tU= github.com/drone/drone-yaml v1.0.4/go.mod h1:eM365p3g9M5sroFBTR/najiGrZnd/GiIpWHC2UW8PoI= +github.com/drone/drone-yaml v1.0.5 h1:LC74aQhyagrBYFTI3XmLEYNkMpEq4QZSQbwiLGyHrsg= +github.com/drone/drone-yaml v1.0.5/go.mod h1:eM365p3g9M5sroFBTR/najiGrZnd/GiIpWHC2UW8PoI= +github.com/drone/drone-yaml v1.0.6 h1:fsuxVXgoxTM9fdQEydEkqHzUgMYKH8M//sqOx4UxsU4= +github.com/drone/drone-yaml v1.0.6/go.mod h1:eM365p3g9M5sroFBTR/najiGrZnd/GiIpWHC2UW8PoI= +github.com/drone/drone-yaml v1.0.7 h1:qHUI1HA5v3dOCzHfmvPRQTEXbCx8vnaqwHSStbZO/50= +github.com/drone/drone-yaml v1.0.7/go.mod h1:1yrotgyD94qoYwgWWm71vAMbcw7Zd3gDersjeT9lYAk= github.com/drone/envsubst v1.0.1 h1:NOOStingM2sbBwsIUeQkKUz8ShwCUzmqMxWrpXItfPE= github.com/drone/envsubst v1.0.1/go.mod h1:bkZbnc/2vh1M12Ecn7EYScpI4YGYU0etwLJICOWi8Z0= github.com/drone/go-license v1.0.2 h1:7OwndfYk+Lp/cGHkxe4HUn/Ysrrw3WYH2pnd99yrkok= @@ -44,6 +63,8 @@ github.com/drone/go-login v1.0.4-0.20190308175602-213d1719faed h1:Y0qiKFf6gsgTRT github.com/drone/go-login v1.0.4-0.20190308175602-213d1719faed/go.mod h1:FLxy9vRzLbyBxoCJYxGbG9R0WGn6OyuvBmAtYNt43uw= github.com/drone/go-scm v1.2.0 h1:ezb8xCvMHX99cSOf3WPI2bmYS6tDVTTap9BiPsPmmXg= github.com/drone/go-scm v1.2.0/go.mod h1:YT4FxQ3U/ltdCrBJR9B0tRpJ1bYA/PM3NyaLE/rYIvw= +github.com/drone/go-scm v1.3.0 h1:XXg2X8GhSvJRr4RTu40t2o9XUa1WXK7BWzK0AVQHygM= +github.com/drone/go-scm v1.3.0/go.mod h1:YT4FxQ3U/ltdCrBJR9B0tRpJ1bYA/PM3NyaLE/rYIvw= github.com/drone/signal v1.0.0 h1:NrnM2M/4yAuU/tXs6RP1a1ZfxnaHwYkd0kJurA1p6uI= github.com/drone/signal v1.0.0/go.mod h1:S8t92eFT0g4WUgEc/LxG+LCuiskpMNsG0ajAMGnyZpc= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= @@ -61,11 +82,14 @@ github.com/go-sql-driver/mysql v1.4.0 h1:7LxgVwFb2hIQtMm87NdgAVfXjnt4OePseqT1tKx github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/gogo/protobuf v0.0.0-20170307180453-100ba4e88506 h1:zDlw+wgyXdfkRuvFCdEDUiPLmZp2cvf/dWHazY0a5VM= github.com/gogo/protobuf v0.0.0-20170307180453-100ba4e88506/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1 h1:G5FRp8JnTd7RQH5kemVNlMeyXQAztQ3mOWV95KxsXH8= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c h1:964Od4U6p2jUkFxvCydnIczKteheJEzHRToSGK3Bnlw= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-jsonnet v0.12.1 h1:v0iUm/b4SBz7lR/diMoz9tLAz8lqtnNRKIwMrmU2HEU= github.com/google/go-jsonnet v0.12.1/go.mod h1:gVu3UVSfOt5fRFq+dh9duBqXa5905QY8S1QvMNcEIVs= @@ -82,6 +106,7 @@ github.com/gosimple/slug v1.3.0/go.mod h1:ER78kgg1Mv0NQGlXiDe57DpCyfbNywXXZ9mIor github.com/gregjones/httpcache v0.0.0-20181110185634-c63ab54fda8f h1:ShTPMJQes6tubcjzGMODIVG5hlrCeImaBnZzKF2N8SM= github.com/gregjones/httpcache v0.0.0-20181110185634-c63ab54fda8f/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/h2non/gock v1.0.9/go.mod h1:CZMcB0Lg5IWnr9bF79pPMg9WeV6WumxQiUJ1UvdO1iE= +github.com/h2non/gock v1.0.10 h1:EzHYzKKSLN4xk0w193uAy3tp8I3+L1jmaI2Mjg4lCgU= github.com/h2non/gock v1.0.10/go.mod h1:CZMcB0Lg5IWnr9bF79pPMg9WeV6WumxQiUJ1UvdO1iE= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -110,6 +135,8 @@ github.com/kelseyhightower/envconfig v1.3.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= +github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-sqlite3 v1.9.0 h1:pDRiWfl+++eC2FEFRy6jXmQlvp4Yh3z1MJKg4UeYM/4= github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= @@ -161,7 +188,10 @@ golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181012144002-a92615f3c490 h1:va0qYsIOza3Nlf2IncFyOql4/3XUq3vfge/Ad64bhlM= golang.org/x/crypto v0.0.0-20181012144002-a92615f3c490/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 h1:mKdxBk7AujPs8kU4m80U72y/zjbZ3UcXC7dClwKbUI0= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1 h1:Y/KGZSOdz/2r0WJ9Mkmz6NJBusp0kiNx1Cn82lzJQ6w= golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890 h1:uESlIz09WIHT2I+pasSXcpLYqYK8wHcdCetU3VuMBJE= @@ -169,6 +199,7 @@ golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAG golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181005133103-4497e2df6f9e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181011152604-fa43e7bc11ba h1:nZJIJPGow0Kf9bU9QTc1U6OXbs/7Hu4e+cNv+hxH+Zc= golang.org/x/sys v0.0.0-20181011152604-fa43e7bc11ba/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= @@ -177,6 +208,8 @@ golang.org/x/time v0.0.0-20181108054448-85acf8d2951c h1:fqgJT0MGcGpPgpWU7VRdRjuA golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20181017214349-06f26fdaaa28/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -186,8 +219,10 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= k8s.io/api v0.0.0-20181130031204-d04500c8c3dd h1:5aHsneN62ehs/tdtS9tWZlhVk68V7yms/Qw7nsGmvCA= k8s.io/api v0.0.0-20181130031204-d04500c8c3dd/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA= +k8s.io/apimachinery v0.0.0-20181201231028-18a5ff3097b4/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0= k8s.io/apimachinery v0.0.0-20181204150028-eb8c8024849b h1:NBYMVxACHvRjnsH8rkNm2ICFZlXznkXYEefUdEpcueY= k8s.io/apimachinery v0.0.0-20181204150028-eb8c8024849b/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0= +k8s.io/client-go v9.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s= k8s.io/client-go v10.0.0+incompatible h1:F1IqCqw7oMBzDkqlcBymRq1450wD0eNqLE9jzUrIi34= k8s.io/client-go v10.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s= k8s.io/klog v0.1.0 h1:I5HMfc/DtuVaGR1KPwUrTc476K8NCqNBldC7H4dYEzk= diff --git a/handler/api/api.go b/handler/api/api.go index aeeb8d1d..f0de24c0 100644 --- a/handler/api/api.go +++ b/handler/api/api.go @@ -218,6 +218,7 @@ func (s Server) Handler() http.Handler { r.Route("/encrypt", func(r chi.Router) { r.Use(acl.CheckWriteAccess()) r.Post("/", encrypt.Handler(s.Repos)) + r.Post("/secret", encrypt.Handler(s.Repos)) }) r.Route("/cron", func(r chi.Router) { @@ -249,8 +250,8 @@ func (s Server) Handler() http.Handler { r.Route("/queue", func(r chi.Router) { r.Use(acl.AuthorizeAdmin) r.Get("/", queue.HandleItems(s.Stages)) - // r.Post("/", queue.HandleResume(s.Queue)) - // r.Delete("/", queue.HandlePause(s.Queue)) + r.Post("/", queue.HandleResume(s.Scheduler)) + r.Delete("/", queue.HandlePause(s.Scheduler)) }) r.Route("/user", func(r chi.Router) { diff --git a/handler/api/queue/none.go b/handler/api/queue/none.go index 3aa95f7b..0c1f9c5f 100644 --- a/handler/api/queue/none.go +++ b/handler/api/queue/none.go @@ -30,3 +30,11 @@ var notImplemented = func(w http.ResponseWriter, r *http.Request) { func HandleItems(store core.StageStore) http.HandlerFunc { return notImplemented } + +func HandlePause(core.Scheduler) http.HandlerFunc { + return notImplemented +} + +func HandleResume(core.Scheduler) http.HandlerFunc { + return notImplemented +} diff --git a/handler/api/queue/pause.go b/handler/api/queue/pause.go index 3a1b510d..cefbf3d4 100644 --- a/handler/api/queue/pause.go +++ b/handler/api/queue/pause.go @@ -6,26 +6,26 @@ package queue -// import ( -// "net/http" +import ( + "net/http" -// "github.com/drone/drone/core" -// "github.com/drone/drone/handler/api/render" -// "github.com/drone/drone/logger" -// ) + "github.com/drone/drone/core" + "github.com/drone/drone/handler/api/render" + "github.com/drone/drone/logger" +) -// // HandlePause returns an http.HandlerFunc that processes -// // an http.Request to pause the queue. -// func HandlePause(queue core.Queue) http.HandlerFunc { -// return func(w http.ResponseWriter, r *http.Request) { -// ctx := r.Context() -// err := queue.Pause(ctx) -// if err != nil { -// render.InternalError(w, err) -// logger.FromRequest(r).WithError(err). -// Errorln("api: cannot pause queue") -// return -// } -// w.WriteHeader(http.StatusNoContent) -// } -// } +// HandlePause returns an http.HandlerFunc that processes +// an http.Request to pause the scheduler. +func HandlePause(scheduler core.Scheduler) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + err := scheduler.Pause(ctx) + if err != nil { + render.InternalError(w, err) + logger.FromRequest(r).WithError(err). + Errorln("api: cannot pause scheduler") + return + } + w.WriteHeader(http.StatusNoContent) + } +} diff --git a/handler/api/queue/resume.go b/handler/api/queue/resume.go index 2fd517f7..39a88e7b 100644 --- a/handler/api/queue/resume.go +++ b/handler/api/queue/resume.go @@ -6,26 +6,26 @@ package queue -// import ( -// "net/http" +import ( + "net/http" -// "github.com/drone/drone/core" -// "github.com/drone/drone/handler/api/render" -// "github.com/drone/drone/logger" -// ) + "github.com/drone/drone/core" + "github.com/drone/drone/handler/api/render" + "github.com/drone/drone/logger" +) -// // HandleResume returns an http.HandlerFunc that processes -// // an http.Request to pause the queue. -// func HandleResume(queue core.Queue) http.HandlerFunc { -// return func(w http.ResponseWriter, r *http.Request) { -// ctx := r.Context() -// err := queue.Resume(ctx) -// if err != nil { -// render.InternalError(w, err) -// logger.FromRequest(r).WithError(err). -// Errorln("api: cannot resume queue") -// return -// } -// w.WriteHeader(http.StatusNoContent) -// } -// } +// HandleResume returns an http.HandlerFunc that processes +// an http.Request to pause the scheduler. +func HandleResume(scheduler core.Scheduler) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + err := scheduler.Resume(ctx) + if err != nil { + render.InternalError(w, err) + logger.FromRequest(r).WithError(err). + Errorln("api: cannot resume scheduler") + return + } + w.WriteHeader(http.StatusNoContent) + } +} diff --git a/metric/sink/tags.go b/metric/sink/tags.go index eb6229be..91ce06cd 100644 --- a/metric/sink/tags.go +++ b/metric/sink/tags.go @@ -41,7 +41,7 @@ func createTags(config Config) []string { tags = append(tags, "scheduler:internal:agents") case config.EnableKubernetes: tags = append(tags, "scheduler:kubernetes") - case config.EnableGithub: + case config.EnableNomad: tags = append(tags, "scheduler:nomad") default: tags = append(tags, "scheduler:internal:local") diff --git a/mock/mock_gen.go b/mock/mock_gen.go index 208424fe..79408dfa 100644 --- a/mock/mock_gen.go +++ b/mock/mock_gen.go @@ -1521,6 +1521,18 @@ func (mr *MockSchedulerMockRecorder) Cancelled(arg0, arg1 interface{}) *gomock.C return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Cancelled", reflect.TypeOf((*MockScheduler)(nil).Cancelled), arg0, arg1) } +// Pause mocks base method +func (m *MockScheduler) Pause(arg0 context.Context) error { + ret := m.ctrl.Call(m, "Pause", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// Pause indicates an expected call of Pause +func (mr *MockSchedulerMockRecorder) Pause(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Pause", reflect.TypeOf((*MockScheduler)(nil).Pause), arg0) +} + // Request mocks base method func (m *MockScheduler) Request(arg0 context.Context, arg1 core.Filter) (*core.Stage, error) { ret := m.ctrl.Call(m, "Request", arg0, arg1) @@ -1534,6 +1546,18 @@ func (mr *MockSchedulerMockRecorder) Request(arg0, arg1 interface{}) *gomock.Cal return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Request", reflect.TypeOf((*MockScheduler)(nil).Request), arg0, arg1) } +// Resume mocks base method +func (m *MockScheduler) Resume(arg0 context.Context) error { + ret := m.ctrl.Call(m, "Resume", arg0) + ret0, _ := ret[0].(error) + return ret0 +} + +// Resume indicates an expected call of Resume +func (mr *MockSchedulerMockRecorder) Resume(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Resume", reflect.TypeOf((*MockScheduler)(nil).Resume), arg0) +} + // Schedule mocks base method func (m *MockScheduler) Schedule(arg0 context.Context, arg1 *core.Stage) error { ret := m.ctrl.Call(m, "Schedule", arg0, arg1) diff --git a/operator/runner/runner.go b/operator/runner/runner.go index 22c1c6e9..ca7ff7b2 100644 --- a/operator/runner/runner.go +++ b/operator/runner/runner.go @@ -169,6 +169,7 @@ func (r *Runner) Run(ctx context.Context, id int64) error { agentEnviron(r), buildEnviron(m.Build), repoEnviron(m.Repo), + stageEnviron(m.Stage), systemEnviron(m.System), linkEnviron(m.Repo, m.Build, m.System), m.Build.Params, @@ -236,6 +237,7 @@ func (r *Runner) Run(ctx context.Context, id int64) error { } secretService := secret.Combine( + secret.Encrypted(), secret.Static(m.Secrets), r.Secrets, ) diff --git a/plugin/registry/encrypted.go b/plugin/registry/encrypted.go new file mode 100644 index 00000000..34fce12d --- /dev/null +++ b/plugin/registry/encrypted.go @@ -0,0 +1,121 @@ +// Copyright 2019 Drone IO, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package registry + +import ( + "context" + "crypto/aes" + "crypto/cipher" + "encoding/base64" + "errors" + + "github.com/drone/drone-yaml/yaml" + "github.com/drone/drone/core" + "github.com/drone/drone/logger" + "github.com/drone/drone/plugin/registry/auths" +) + +// Encrypted returns a new encrypted registry credentials +// provider that sournces credentials from the encrypted strings +// in the yaml file. +func Encrypted() core.RegistryService { + return new(encrypted) +} + +type encrypted struct { +} + +func (c *encrypted) List(ctx context.Context, in *core.RegistryArgs) ([]*core.Registry, error) { + var results []*core.Registry + + for _, match := range in.Pipeline.PullSecrets { + logger := logger.FromContext(ctx). + WithField("name", match). + WithField("kind", "secret") + logger.Trace("image_pull_secrets: find encrypted secret") + + // lookup the named secret in the manifest. If the + // secret does not exist, return a nil variable, + // allowing the next secret controller in the chain + // to be invoked. + data, ok := getEncrypted(in.Conf, match) + if !ok { + logger.Trace("image_pull_secrets: no matching encrypted secret in yaml") + return nil, nil + } + + decoded, err := base64.StdEncoding.DecodeString(string(data)) + if err != nil { + logger.WithError(err).Trace("image_pull_secrets: cannot decode secret") + return nil, err + } + + decrypted, err := decrypt(decoded, []byte(in.Repo.Secret)) + if err != nil { + logger.WithError(err).Trace("image_pull_secrets: cannot decrypt secret") + return nil, err + } + + parsed, err := auths.ParseBytes(decrypted) + if err != nil { + logger.WithError(err).Trace("image_pull_secrets: cannot parse decrypted secret") + return nil, err + } + + logger.Trace("image_pull_secrets: found encrypted secret") + results = append(results, parsed...) + } + + return results, nil +} + +func getEncrypted(manifest *yaml.Manifest, match string) (data string, ok bool) { + for _, resource := range manifest.Resources { + secret, ok := resource.(*yaml.Secret) + if !ok { + continue + } + if secret.Name != match { + continue + } + if secret.Data == "" { + continue + } + return secret.Data, true + } + return +} + +func decrypt(ciphertext []byte, key []byte) (plaintext []byte, err error) { + block, err := aes.NewCipher(key[:]) + if err != nil { + return nil, err + } + + gcm, err := cipher.NewGCM(block) + if err != nil { + return nil, err + } + + if len(ciphertext) < gcm.NonceSize() { + return nil, errors.New("malformed ciphertext") + } + + return gcm.Open(nil, + ciphertext[:gcm.NonceSize()], + ciphertext[gcm.NonceSize():], + nil, + ) +} diff --git a/plugin/secret/encrypted.go b/plugin/secret/encrypted.go new file mode 100644 index 00000000..5270fa36 --- /dev/null +++ b/plugin/secret/encrypted.go @@ -0,0 +1,119 @@ +// Copyright 2019 Drone IO, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package secret + +import ( + "context" + "crypto/aes" + "crypto/cipher" + "encoding/base64" + "errors" + + "github.com/drone/drone-yaml/yaml" + "github.com/drone/drone/core" + "github.com/drone/drone/logger" +) + +// Encrypted returns a new encrypted Secret controller. +func Encrypted() core.SecretService { + return new(encrypted) +} + +type encrypted struct { +} + +func (c *encrypted) Find(ctx context.Context, in *core.SecretArgs) (*core.Secret, error) { + logger := logger.FromContext(ctx). + WithField("name", in.Name). + WithField("kind", "secret") + + // lookup the named secret in the manifest. If the + // secret does not exist, return a nil variable, + // allowing the next secret controller in the chain + // to be invoked. + data, ok := getEncrypted(in.Conf, in.Name) + if !ok { + logger.Trace("secret: encrypted: no matching secret") + return nil, nil + } + + // if the build event is a pull request and the source + // repository is a fork, the secret is not exposed to + // the pipeline, for security reasons. + if in.Repo.Private == false && + in.Build.Event == core.EventPullRequest && + in.Build.Fork != "" { + logger.Trace("secret: encrypted: restricted from forks") + return nil, nil + } + + decoded, err := base64.StdEncoding.DecodeString(string(data)) + if err != nil { + logger.WithError(err).Trace("secret: encrypted: cannot decode") + return nil, err + } + + decrypted, err := decrypt(decoded, []byte(in.Repo.Secret)) + if err != nil { + logger.WithError(err).Trace("secret: encrypted: cannot decrypt") + return nil, err + } + + logger.Trace("secret: encrypted: found matching secret") + + return &core.Secret{ + Name: in.Name, + Data: string(decrypted), + }, nil +} + +func getEncrypted(manifest *yaml.Manifest, match string) (data string, ok bool) { + for _, resource := range manifest.Resources { + secret, ok := resource.(*yaml.Secret) + if !ok { + continue + } + if secret.Name != match { + continue + } + if secret.Data == "" { + continue + } + return secret.Data, true + } + return +} + +func decrypt(ciphertext []byte, key []byte) (plaintext []byte, err error) { + block, err := aes.NewCipher(key[:]) + if err != nil { + return nil, err + } + + gcm, err := cipher.NewGCM(block) + if err != nil { + return nil, err + } + + if len(ciphertext) < gcm.NonceSize() { + return nil, errors.New("malformed ciphertext") + } + + return gcm.Open(nil, + ciphertext[:gcm.NonceSize()], + ciphertext[gcm.NonceSize():], + nil, + ) +} diff --git a/plugin/secret/encrypted_test.go b/plugin/secret/encrypted_test.go new file mode 100644 index 00000000..69a03023 --- /dev/null +++ b/plugin/secret/encrypted_test.go @@ -0,0 +1,15 @@ +// Copyright 2019 Drone IO, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package secret diff --git a/scheduler/kube/kube.go b/scheduler/kube/kube.go index a642faa3..74ef68ca 100644 --- a/scheduler/kube/kube.go +++ b/scheduler/kube/kube.go @@ -109,7 +109,7 @@ func (s *kubeScheduler) Schedule(ctx context.Context, stage *core.Stage) error { GenerateName: name, Namespace: s.namespace(), Annotations: map[string]string{ - "io.drone": "true", + "io.drone": "true", "io.drone.stage.created": time.Unix(stage.Created, 0).String(), "io.drone.stage.scheduled": time.Now().String(), "io.drone.stage.id": fmt.Sprint(stage.ID), @@ -201,6 +201,14 @@ func (s *kubeScheduler) Stats(_ context.Context) (interface{}, error) { return nil, errors.New("not implemented") } +func (s *kubeScheduler) Pause(context.Context) error { + return errors.New("not implemented") +} + +func (s *kubeScheduler) Resume(context.Context) error { + return errors.New("not implemented") +} + func (s *kubeScheduler) namespace() string { namespace := s.config.Namespace if namespace == "" { diff --git a/scheduler/kube/kube_oss.go b/scheduler/kube/kube_oss.go index 6fab9dda..7632a4bd 100644 --- a/scheduler/kube/kube_oss.go +++ b/scheduler/kube/kube_oss.go @@ -48,3 +48,11 @@ func (noop) Cancelled(context.Context, int64) (bool, error) { func (noop) Stats(context.Context) (interface{}, error) { return nil, nil } + +func (noop) Pause(context.Context) error { + return nil +} + +func (noop) Resume(context.Context) error { + return nil +} diff --git a/scheduler/nomad/nomad.go b/scheduler/nomad/nomad.go index 78dc83f7..07732399 100644 --- a/scheduler/nomad/nomad.go +++ b/scheduler/nomad/nomad.go @@ -111,7 +111,7 @@ func (s *nomadScheduler) Schedule(ctx context.Context, stage *core.Stage) error }, }, Meta: map[string]string{ - "io.drone": "true", + "io.drone": "true", "io.drone.stage.created": time.Unix(stage.Created, 0).String(), "io.drone.stage.scheduled": time.Now().String(), "io.drone.stage.id": fmt.Sprint(stage.ID), @@ -206,6 +206,14 @@ func (s *nomadScheduler) Stats(context.Context) (interface{}, error) { return nil, errors.New("not implemented") } +func (s *nomadScheduler) Pause(context.Context) error { + return errors.New("not implemented") +} + +func (s *nomadScheduler) Resume(context.Context) error { + return errors.New("not implemented") +} + // stringToPtr returns the pointer to a string func stringToPtr(str string) *string { return &str diff --git a/scheduler/nomad/nomad_oss.go b/scheduler/nomad/nomad_oss.go index f8c756bb..0f4af18d 100644 --- a/scheduler/nomad/nomad_oss.go +++ b/scheduler/nomad/nomad_oss.go @@ -48,3 +48,11 @@ func (noop) Cancelled(context.Context, int64) (bool, error) { func (noop) Stats(context.Context) (interface{}, error) { return nil, nil } + +func (noop) Pause(context.Context) error { + return nil +} + +func (noop) Resume(context.Context) error { + return nil +} diff --git a/service/license/nolimit.go b/service/license/nolimit.go index 8370f236..80d0a6ba 100644 --- a/service/license/nolimit.go +++ b/service/license/nolimit.go @@ -16,8 +16,12 @@ package license -// DefaultLicense is an empty license with no restrictions. -var DefaultLicense = &License{Kind: LicenseFoss} +import ( + "github.com/drone/drone/core" +) -func Trial(string) *License { return nil } -func Load(string) (*License, error) { return DefaultLicense, nil } +// DefaultLicense is an empty license with no restrictions. +var DefaultLicense = &core.License{Kind: core.LicenseFoss} + +func Trial(string) *core.License { return nil } +func Load(string) (*core.License, error) { return DefaultLicense, nil } diff --git a/store/repos/repos.go b/store/repos/repos.go index 80669967..f6c9be52 100644 --- a/store/repos/repos.go +++ b/store/repos/repos.go @@ -55,7 +55,11 @@ func (s *repoStore) ListLatest(ctx context.Context, id int64) ([]*core.Repositor "user_id": id, "repo_active": true, } - query, args, err := binder.BindNamed(queryRepoWithBuild, params) + stmt := queryRepoWithBuild + if s.db.Driver() == db.Postgres { + stmt = queryRepoWithBuildPostgres + } + query, args, err := binder.BindNamed(stmt, params) if err != nil { return err } @@ -431,6 +435,18 @@ WHERE repo_id = :repo_id AND repo_version = :repo_version_old ` +// TODO(bradrydzewski) this query needs performance tuning. +// one approach that is promising is the ability to use the +// repo_counter (latest build number) to join on the build +// table. +// +// FROM repos LEFT OUTER JOIN builds ON ( +// repos.repo_id = builds.build_repo_id AND +// builds.build_number = repos.repo_counter +// ) +// INNER JOIN perms ON perms.perm_repo_uid = repos.repo_uid +// + const queryRepoWithBuild = queryColsBulds + ` FROM repos LEFT OUTER JOIN builds ON build_id = ( SELECT build_id FROM builds @@ -440,7 +456,18 @@ FROM repos LEFT OUTER JOIN builds ON build_id = ( ) INNER JOIN perms ON perms.perm_repo_uid = repos.repo_uid WHERE perms.perm_user_id = :user_id -ORDER BY repo_slug ASC; +ORDER BY repo_slug ASC +` + +const queryRepoWithBuildPostgres = queryColsBulds + ` +FROM repos LEFT OUTER JOIN builds ON build_id = ( + SELECT DISTINCT ON (build_repo_id) build_id FROM builds + WHERE builds.build_repo_id = repos.repo_id + ORDER BY build_repo_id, build_id DESC +) +INNER JOIN perms ON perms.perm_repo_uid = repos.repo_uid +WHERE perms.perm_user_id = :user_id +ORDER BY repo_slug ASC ` const queryRepoWithBuildAll = queryColsBulds + ` @@ -454,7 +481,6 @@ LIMIT 25; const queryRepoWithBuildIncomplete = queryColsBulds + ` FROM repos -INNER JOIN perms ON perms.perm_repo_uid = repos.repo_uid INNER JOIN builds ON builds.build_repo_id = repos.repo_id WHERE EXISTS ( SELECT stage_id @@ -465,12 +491,3 @@ WHERE EXISTS ( ORDER BY build_id DESC LIMIT 50; ` - -// const queryRepoWithBuildIncompleteOld = queryColsBulds + ` -// FROM repos -// INNER JOIN perms ON perms.perm_repo_uid = repos.repo_uid -// INNER JOIN builds ON builds.build_repo_id = repos.repo_id -// WHERE builds.build_status IN ('pending', 'running') -// ORDER BY build_id DESC -// LIMIT 50; -// ` diff --git a/version/version.go b/version/version.go index 13f4e9ab..986d9420 100644 --- a/version/version.go +++ b/version/version.go @@ -29,7 +29,7 @@ var ( // VersionPatch is for backwards-compatible bug fixes. VersionPatch int64 // VersionPre indicates prerelease. - VersionPre = "rc.6" + VersionPre = "" // VersionDev indicates development branch. Releases will be empty string. VersionDev string ) diff --git a/version/version_test.go b/version/version_test.go index 5afffee5..2ab6533f 100644 --- a/version/version_test.go +++ b/version/version_test.go @@ -9,7 +9,7 @@ package version import "testing" func TestVersion(t *testing.T) { - if got, want := Version.String(), "1.0.0-rc.6"; got != want { + if got, want := Version.String(), "1.0.0"; got != want { t.Errorf("Want version %s, got %s", want, got) } }