diff --git a/.drone.jsonnet b/.drone.jsonnet index 710c706c..4c7791d7 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -23,11 +23,11 @@ local mounts = [ # defines a pipeline step that builds and publishes # a docker image to a docker remote registry. -local docker(name, os, arch) = { +local docker(name, image, os, arch) = { name: "publish_" + name, image: "plugins/docker", settings: { - repo: "drone/" + name, + repo: "drone/" + image, auto_tag: true, auto_tag_suffix: os + "-" + arch, username: { from_secret: "docker_username" }, @@ -45,6 +45,7 @@ local manifest(name) = { name: name, image: "plugins/manifest:1", settings: { + auto_tag: true, ignore_missing: true, spec: "docker/manifest." + name + ".tmpl", username: { from_secret: "docker_username" }, @@ -85,9 +86,9 @@ local pipeline(name, os, arch) = { event: [ "push", "tag" ], }, }, - docker("agent", os, arch), - docker("controller", os, arch), - docker("server", os, arch), + docker("agent", "agent", os, arch), + docker("controller", "controller", os, arch), + docker("server", "drone", os, arch), ], }; @@ -99,7 +100,7 @@ local pipeline(name, os, arch) = { kind: "pipeline", name: "manifest", steps: [ - manifest("server"), + manifest("drone"), manifest("agent"), manifest("controller"), ], diff --git a/.drone.script b/.drone.script new file mode 100644 index 00000000..9fb7dfad --- /dev/null +++ b/.drone.script @@ -0,0 +1,110 @@ +def main(): + return [ + pipeline('linux-amd64', 'linux', 'amd64'), + pipeline('linux-arm64', 'linux', 'arm64'), + pipeline('linux-arm', 'linux', 'arm'), + 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, + 'image': 'plugins/docker', + 'settings': { + 'repo': repo, + 'auto_tag': True, + 'auto_tag_suffix': '%s-%s' % (os, arch), + 'username': 'drone', + 'password': { 'from_secret': 'docker_password' }, + 'dockerfile': 'docker/Dockerfile.%s.%s.%s' % (name, os, arch), + }, + 'when': { + 'event': [ 'push', 'tag' ], + }, + } + + +# 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': 'drone', + 'password': { 'from_secret': 'docker_password' }, + }, + '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', + 'image': 'golang:1.11', + '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): + return { + 'name': 'build', + 'image': 'golang:1.11', + 'commands': [ + 'go build -ldflags \"-extldflags \\\\\"-static\\\\\"\" -o release/%s/%s/drone-server github.com/drone/drone/cmd/drone-server' % (os, arch), + 'CGO_ENABLED=0 go build -o release/%s/%s/drone-agent github.com/drone/drone/cmd/drone-agent' % (os, arch), + 'CGO_ENABLED=0 go build -o release/%s/%s/drone-controller github.com/drone/drone/cmd/drone-controller' % (os, arch), + ] + } + +# 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', + 'name': 'default', + 'platform': { + 'os': os, + 'arch': arch, + }, + 'steps': [ + test_step(), + build_step(os, arch), + docker_step('drone', os, arch), + docker_step('agent', os, arch), + docker_step('controller', os, arch), + ], + } + +# defines a pipeline that updates the docker manifest +# for the architecture-specific images previously published +# to dockerhub. +def manifest(): + return { + 'kind': 'pipeline', + 'name': 'manifest', + 'steps': [ + manifest_step('server'), + manifest_step('agent'), + manifest_step('controller'), + ], + 'depends_on': [ + 'linux-amd64', + 'linux-arm64', + 'linux-arm', + ], + } diff --git a/.drone.yml b/.drone.yml index 14d6a2da..316418d4 100644 --- a/.drone.yml +++ b/.drone.yml @@ -69,7 +69,7 @@ steps: dockerfile: docker/Dockerfile.server.linux.amd64 password: from_secret: docker_password - repo: drone/server + repo: drone/drone username: from_secret: docker_username when: @@ -152,7 +152,7 @@ steps: dockerfile: docker/Dockerfile.server.linux.arm password: from_secret: docker_password - repo: drone/server + repo: drone/drone username: from_secret: docker_username when: @@ -235,7 +235,7 @@ steps: dockerfile: docker/Dockerfile.server.linux.arm64 password: from_secret: docker_password - repo: drone/server + repo: drone/drone username: from_secret: docker_username when: @@ -256,13 +256,14 @@ platform: arch: amd64 steps: -- name: server +- name: drone image: plugins/manifest:1 settings: + auto_tag: true ignore_missing: true password: from_secret: docker_password - spec: docker/manifest.server.tmpl + spec: docker/manifest.drone.tmpl username: from_secret: docker_username when: @@ -273,6 +274,7 @@ steps: - name: agent image: plugins/manifest:1 settings: + auto_tag: true ignore_missing: true password: from_secret: docker_password @@ -287,6 +289,7 @@ steps: - name: controller image: plugins/manifest:1 settings: + auto_tag: true ignore_missing: true password: from_secret: docker_password diff --git a/.github/code_of_conduct.md b/.github/code_of_conduct.md new file mode 100644 index 00000000..63481f40 --- /dev/null +++ b/.github/code_of_conduct.md @@ -0,0 +1,3 @@ +## Drone Community Code of Conduct + +Drone follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md). diff --git a/cmd/drone-server/bootstrap/bootstrap.go b/cmd/drone-server/bootstrap/bootstrap.go index 1086212f..bfcdc3bc 100644 --- a/cmd/drone-server/bootstrap/bootstrap.go +++ b/cmd/drone-server/bootstrap/bootstrap.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 bootstrap @@ -10,8 +20,8 @@ import ( "time" "github.com/dchest/uniuri" - "github.com/drone/drone/logger" "github.com/drone/drone/core" + "github.com/drone/drone/logger" "github.com/sirupsen/logrus" ) diff --git a/go.sum b/go.sum index 346321f3..7e9e6693 100644 --- a/go.sum +++ b/go.sum @@ -89,6 +89,8 @@ github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uP github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-retryablehttp v0.0.0-20180718195005-e651d75abec6 h1:qCv4319q2q7XKn0MQbi8p37hsJ+9Xo8e6yojA73JVxk= github.com/hashicorp/go-retryablehttp v0.0.0-20180718195005-e651d75abec6/go.mod h1:fXcdFsQoipQa7mwORhKad5jmDCeSy/RCGzWA08PO0lM= +github.com/hashicorp/go-rootcerts v1.0.0 h1:ueI78wUjYExhCvMLow4icJnayNNFRgy0d9EGs/a1T44= +github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/nomad v0.0.0-20190125003214-134391155854 h1:L7WhLZt2ory/kQWxqkMwOiBpIoa4BWoadN7yx8LHEtk= diff --git a/handler/api/acl/acl.go b/handler/api/acl/acl.go index 0153151a..e76b3121 100644 --- a/handler/api/acl/acl.go +++ b/handler/api/acl/acl.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 acl diff --git a/handler/api/acl/check.go b/handler/api/acl/check.go index 3fd657f3..ecaad538 100644 --- a/handler/api/acl/check.go +++ b/handler/api/acl/check.go @@ -1,17 +1,27 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 acl import ( "net/http" + "github.com/drone/drone/core" "github.com/drone/drone/handler/api/errors" "github.com/drone/drone/handler/api/render" "github.com/drone/drone/handler/api/request" "github.com/drone/drone/logger" - "github.com/drone/drone/core" "github.com/go-chi/chi" "github.com/sirupsen/logrus" diff --git a/handler/api/acl/repo.go b/handler/api/acl/repo.go index e45ebb2f..2f614d4f 100644 --- a/handler/api/acl/repo.go +++ b/handler/api/acl/repo.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 acl @@ -8,11 +18,11 @@ import ( "net/http" "time" + "github.com/drone/drone/core" "github.com/drone/drone/handler/api/errors" "github.com/drone/drone/handler/api/render" "github.com/drone/drone/handler/api/request" "github.com/drone/drone/logger" - "github.com/drone/drone/core" "github.com/go-chi/chi" "github.com/sirupsen/logrus" diff --git a/handler/api/auth/auth.go b/handler/api/auth/auth.go index b8a328ec..e002c160 100644 --- a/handler/api/auth/auth.go +++ b/handler/api/auth/auth.go @@ -1,15 +1,25 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 auth import ( "net/http" + "github.com/drone/drone/core" "github.com/drone/drone/handler/api/request" "github.com/drone/drone/logger" - "github.com/drone/drone/core" ) // HandleAuthentication returns an http.HandlerFunc middlewrae that authenticates diff --git a/handler/api/errors/errors.go b/handler/api/errors/errors.go index e0939195..e599daf7 100644 --- a/handler/api/errors/errors.go +++ b/handler/api/errors/errors.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 errors diff --git a/handler/api/render/render.go b/handler/api/render/render.go index 0aa7a000..077ecaaf 100644 --- a/handler/api/render/render.go +++ b/handler/api/render/render.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 render diff --git a/handler/api/repos/builds/cancel.go b/handler/api/repos/builds/cancel.go index 811d55ce..b1257232 100644 --- a/handler/api/repos/builds/cancel.go +++ b/handler/api/repos/builds/cancel.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 builds diff --git a/handler/api/repos/builds/find.go b/handler/api/repos/builds/find.go index d7056e3c..6e115d7a 100644 --- a/handler/api/repos/builds/find.go +++ b/handler/api/repos/builds/find.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 builds @@ -8,8 +18,8 @@ import ( "net/http" "strconv" - "github.com/drone/drone/handler/api/render" "github.com/drone/drone/core" + "github.com/drone/drone/handler/api/render" "github.com/go-chi/chi" ) diff --git a/handler/api/repos/builds/latest.go b/handler/api/repos/builds/latest.go index ac564c0c..886cbac1 100644 --- a/handler/api/repos/builds/latest.go +++ b/handler/api/repos/builds/latest.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 builds @@ -8,8 +18,8 @@ import ( "fmt" "net/http" - "github.com/drone/drone/handler/api/render" "github.com/drone/drone/core" + "github.com/drone/drone/handler/api/render" "github.com/go-chi/chi" ) diff --git a/handler/api/repos/builds/list.go b/handler/api/repos/builds/list.go index 3d417421..3a47fee1 100644 --- a/handler/api/repos/builds/list.go +++ b/handler/api/repos/builds/list.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 builds @@ -8,9 +18,9 @@ import ( "net/http" "strconv" + "github.com/drone/drone/core" "github.com/drone/drone/handler/api/render" "github.com/drone/drone/logger" - "github.com/drone/drone/core" "github.com/go-chi/chi" ) diff --git a/handler/api/repos/builds/retry.go b/handler/api/repos/builds/retry.go index 2e9c202b..f4bd7aed 100644 --- a/handler/api/repos/builds/retry.go +++ b/handler/api/repos/builds/retry.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 builds @@ -8,9 +18,9 @@ import ( "net/http" "strconv" + "github.com/drone/drone/core" "github.com/drone/drone/handler/api/render" "github.com/drone/drone/handler/api/request" - "github.com/drone/drone/core" "github.com/go-chi/chi" ) diff --git a/handler/api/repos/chown.go b/handler/api/repos/chown.go index 6c2bc4e5..bca3f08d 100644 --- a/handler/api/repos/chown.go +++ b/handler/api/repos/chown.go @@ -7,10 +7,10 @@ package repos import ( "net/http" + "github.com/drone/drone/core" "github.com/drone/drone/handler/api/render" "github.com/drone/drone/handler/api/request" "github.com/drone/drone/logger" - "github.com/drone/drone/core" "github.com/go-chi/chi" ) diff --git a/handler/api/repos/disable.go b/handler/api/repos/disable.go index 1157dc07..f66ca3cd 100644 --- a/handler/api/repos/disable.go +++ b/handler/api/repos/disable.go @@ -1,15 +1,25 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 repos 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/go-chi/chi" ) diff --git a/handler/api/repos/enable.go b/handler/api/repos/enable.go index 354314a0..5991a6c6 100644 --- a/handler/api/repos/enable.go +++ b/handler/api/repos/enable.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 repos diff --git a/handler/api/repos/find.go b/handler/api/repos/find.go index c6b659ad..79171a5d 100644 --- a/handler/api/repos/find.go +++ b/handler/api/repos/find.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 repos diff --git a/handler/api/repos/secrets/create.go b/handler/api/repos/secrets/create.go index fdf9f2a0..c163fa20 100644 --- a/handler/api/repos/secrets/create.go +++ b/handler/api/repos/secrets/create.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 secrets @@ -8,8 +18,8 @@ import ( "encoding/json" "net/http" - "github.com/drone/drone/handler/api/render" "github.com/drone/drone/core" + "github.com/drone/drone/handler/api/render" "github.com/go-chi/chi" ) diff --git a/handler/api/repos/secrets/delete.go b/handler/api/repos/secrets/delete.go index d6dd58b9..4fddb326 100644 --- a/handler/api/repos/secrets/delete.go +++ b/handler/api/repos/secrets/delete.go @@ -1,14 +1,24 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 secrets import ( "net/http" - "github.com/drone/drone/handler/api/render" "github.com/drone/drone/core" + "github.com/drone/drone/handler/api/render" "github.com/go-chi/chi" ) diff --git a/handler/api/repos/secrets/find.go b/handler/api/repos/secrets/find.go index 4af26a83..b86a41cd 100644 --- a/handler/api/repos/secrets/find.go +++ b/handler/api/repos/secrets/find.go @@ -1,14 +1,24 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 secrets import ( "net/http" - "github.com/drone/drone/handler/api/render" "github.com/drone/drone/core" + "github.com/drone/drone/handler/api/render" "github.com/go-chi/chi" ) diff --git a/handler/api/repos/secrets/list.go b/handler/api/repos/secrets/list.go index 9daa25f9..60c3d167 100644 --- a/handler/api/repos/secrets/list.go +++ b/handler/api/repos/secrets/list.go @@ -1,14 +1,24 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 secrets import ( "net/http" - "github.com/drone/drone/handler/api/render" "github.com/drone/drone/core" + "github.com/drone/drone/handler/api/render" "github.com/go-chi/chi" ) diff --git a/handler/api/repos/secrets/update.go b/handler/api/repos/secrets/update.go index 3751ff2a..10503e97 100644 --- a/handler/api/repos/secrets/update.go +++ b/handler/api/repos/secrets/update.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 secrets @@ -8,8 +18,8 @@ import ( "encoding/json" "net/http" - "github.com/drone/drone/handler/api/render" "github.com/drone/drone/core" + "github.com/drone/drone/handler/api/render" "github.com/go-chi/chi" ) diff --git a/handler/api/repos/update.go b/handler/api/repos/update.go index 9b50638f..7577f928 100644 --- a/handler/api/repos/update.go +++ b/handler/api/repos/update.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 repos @@ -8,10 +18,10 @@ import ( "encoding/json" "net/http" + "github.com/drone/drone/core" "github.com/drone/drone/handler/api/render" "github.com/drone/drone/handler/api/request" "github.com/drone/drone/logger" - "github.com/drone/drone/core" "github.com/go-chi/chi" ) diff --git a/handler/api/user/activity.go b/handler/api/user/activity.go index 511478fe..cdd668ba 100644 --- a/handler/api/user/activity.go +++ b/handler/api/user/activity.go @@ -1,16 +1,26 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 user import ( "net/http" + "github.com/drone/drone/core" "github.com/drone/drone/handler/api/render" "github.com/drone/drone/handler/api/request" "github.com/drone/drone/logger" - "github.com/drone/drone/core" ) // HandleRecent returns an http.HandlerFunc that write a json-encoded diff --git a/handler/api/user/find.go b/handler/api/user/find.go index c3102db0..e8607f18 100644 --- a/handler/api/user/find.go +++ b/handler/api/user/find.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 user diff --git a/handler/api/user/repos.go b/handler/api/user/repos.go index 3c85a8d9..d79c071b 100644 --- a/handler/api/user/repos.go +++ b/handler/api/user/repos.go @@ -1,16 +1,26 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 user import ( "net/http" + "github.com/drone/drone/core" "github.com/drone/drone/handler/api/render" "github.com/drone/drone/handler/api/request" "github.com/drone/drone/logger" - "github.com/drone/drone/core" ) // HandleRepos returns an http.HandlerFunc that write a json-encoded diff --git a/handler/api/user/sync.go b/handler/api/user/sync.go index 0481a828..9250aff5 100644 --- a/handler/api/user/sync.go +++ b/handler/api/user/sync.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 user @@ -8,10 +18,10 @@ import ( "context" "net/http" + "github.com/drone/drone/core" "github.com/drone/drone/handler/api/render" "github.com/drone/drone/handler/api/request" "github.com/drone/drone/logger" - "github.com/drone/drone/core" ) // HandleSync returns an http.HandlerFunc synchronizes and then diff --git a/handler/api/user/token.go b/handler/api/user/token.go index aeb1d951..dd8d9dba 100644 --- a/handler/api/user/token.go +++ b/handler/api/user/token.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 user @@ -8,9 +18,9 @@ import ( "net/http" "github.com/dchest/uniuri" + "github.com/drone/drone/core" "github.com/drone/drone/handler/api/render" "github.com/drone/drone/handler/api/request" - "github.com/drone/drone/core" ) type userWithToken struct { diff --git a/handler/api/user/update.go b/handler/api/user/update.go index 97e560b0..7d91bea2 100644 --- a/handler/api/user/update.go +++ b/handler/api/user/update.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 user @@ -8,10 +18,10 @@ import ( "encoding/json" "net/http" + "github.com/drone/drone/core" "github.com/drone/drone/handler/api/render" "github.com/drone/drone/handler/api/request" "github.com/drone/drone/logger" - "github.com/drone/drone/core" ) // HandleUpdate returns an http.HandlerFunc that processes an http.Request diff --git a/server/server.go b/server/server.go index b17c3688..d1da662b 100644 --- a/server/server.go +++ b/server/server.go @@ -2,6 +2,8 @@ // Use of this source code is governed by the Drone Non-Commercial License // that can be found in the LICENSE file. +// +build !oss + package server import ( diff --git a/server/server_oss.go b/server/server_oss.go new file mode 100644 index 00000000..26e26958 --- /dev/null +++ b/server/server_oss.go @@ -0,0 +1,53 @@ +// 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. + +// +build oss + +package server + +import ( + "context" + "net/http" + + "golang.org/x/sync/errgroup" +) + +// A Server defines parameters for running an HTTP server. +type Server struct { + Acme bool + Addr string + Cert string + Key string + Host string + Handler http.Handler +} + +// ListenAndServe initializes a server to respond to HTTP network requests. +func (s Server) ListenAndServe(ctx context.Context) error { + var g errgroup.Group + s1 := &http.Server{ + Addr: s.Addr, + Handler: s.Handler, + } + g.Go(func() error { + select { + case <-ctx.Done(): + return s1.Shutdown(ctx) + } + }) + g.Go(func() error { + return s1.ListenAndServe() + }) + return g.Wait() +} diff --git a/service/content/cache/contents.go b/service/content/cache/contents.go index 4e1d652b..3ca16c0a 100644 --- a/service/content/cache/contents.go +++ b/service/content/cache/contents.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 cache diff --git a/service/content/content.go b/service/content/content.go index 5fee43e8..c17aded3 100644 --- a/service/content/content.go +++ b/service/content/content.go @@ -17,6 +17,7 @@ package contents import ( "context" "strings" + "time" "github.com/drone/drone/core" "github.com/drone/go-scm/scm" @@ -60,7 +61,7 @@ func (s *service) Find(ctx context.Context, user *core.User, repo, commit, ref, Token: user.Token, Refresh: user.Refresh, }) - content, _, err := s.client.Contents.Find(ctx, repo, path, commit) + content, err := s.findRetry(ctx, repo, path, commit) if err != nil { return nil, err } @@ -69,3 +70,21 @@ func (s *service) Find(ctx context.Context, user *core.User, repo, commit, ref, Hash: []byte{}, }, nil } + +// helper function attempts to get the yaml configuration file +// with backoff on failure. This may be required due to eventual +// consistency issues with the github datastore. +func (s *service) findRetry(ctx context.Context, repo, path, commit string) (content *scm.Content, err error) { + for i := 0; i < 3; i++ { + content, _, err = s.client.Contents.Find(ctx, repo, path, commit) + // if no error is returned we can exit immediately. + if err == nil { + return + } + // wait a few seconds before retry. according to github + // support 30 seconds total should be enough time. we + // try 3 x 15 seconds, giving a total of 45 seconds. + time.Sleep(time.Second * 15) + } + return +} diff --git a/service/hook/parser/parse.go b/service/hook/parser/parse.go index 5748efa7..c7285843 100644 --- a/service/hook/parser/parse.go +++ b/service/hook/parser/parse.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 parser diff --git a/service/syncer/syncer.go b/service/syncer/syncer.go index 8bd7d82e..be9d0257 100644 --- a/service/syncer/syncer.go +++ b/service/syncer/syncer.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 syncer diff --git a/service/syncer/util.go b/service/syncer/util.go index 70482e2f..a445044d 100644 --- a/service/syncer/util.go +++ b/service/syncer/util.go @@ -1,6 +1,16 @@ -// Copyright 2019 Drone.IO Inc. All rights reserved. -// Use of this source code is governed by the Drone Non-Commercial License -// that can be found in the LICENSE file. +// 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 syncer diff --git a/service/token/renew.go b/service/token/renew.go index 7ae702ff..0b402ddd 100644 --- a/service/token/renew.go +++ b/service/token/renew.go @@ -2,6 +2,8 @@ // Use of this source code is governed by the Drone Non-Commercial License // that can be found in the LICENSE file. +// +build !oss + package token import ( diff --git a/service/token/renew_oss.go b/service/token/renew_oss.go new file mode 100644 index 00000000..660ce029 --- /dev/null +++ b/service/token/renew_oss.go @@ -0,0 +1,37 @@ +// 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. + +// +build oss + +package token + +import ( + "context" + + "github.com/drone/drone/core" + + "github.com/drone/go-scm/scm/transport/oauth2" +) + +type renewer struct { +} + +// Renewer returns a new Renewer. +func Renewer(refresh *oauth2.Refresher, store core.UserStore) core.Renewer { + return &renewer{} +} + +func (r *renewer) Renew(ctx context.Context, user *core.User, force bool) error { + return nil // no-op +} diff --git a/service/token/renew_test.go b/service/token/renew_test.go index 98129552..5ea70647 100644 --- a/service/token/renew_test.go +++ b/service/token/renew_test.go @@ -2,4 +2,6 @@ // Use of this source code is governed by the Drone Non-Commercial License // that can be found in the LICENSE file. +// +build !oss + package token