initial commit
This commit is contained in:
commit
a79e0a4557
20
.drone.yml
Normal file
20
.drone.yml
Normal file
|
@ -0,0 +1,20 @@
|
|||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: golang
|
||||
commands:
|
||||
- go build
|
||||
- go test ./...
|
||||
|
||||
- name: publish
|
||||
image: plugins/docker
|
||||
settings:
|
||||
auto_tag: true
|
||||
repo: garionion/drone-yaml-server
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
.env
|
12
Dockerfile
Normal file
12
Dockerfile
Normal file
|
@ -0,0 +1,12 @@
|
|||
FROM alpine:3.6 as alpine
|
||||
RUN apk add -U --no-cache ca-certificates
|
||||
|
||||
FROM alpine:3.6
|
||||
EXPOSE 3000
|
||||
|
||||
ENV GODEBUG netdns=go
|
||||
|
||||
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
|
||||
ADD drone-yaml-server /bin/
|
||||
ENTRYPOINT ["/bin/drone-yaml-server"]
|
55
LICENSE.md
Normal file
55
LICENSE.md
Normal file
|
@ -0,0 +1,55 @@
|
|||
# Blue Oak Model License
|
||||
|
||||
Version 1.0.0
|
||||
|
||||
## Purpose
|
||||
|
||||
This license gives everyone as much permission to work with
|
||||
this software as possible, while protecting contributors
|
||||
from liability.
|
||||
|
||||
## Acceptance
|
||||
|
||||
In order to receive this license, you must agree to its
|
||||
rules. The rules of this license are both obligations
|
||||
under that agreement and conditions to your license.
|
||||
You must not do anything with this software that triggers
|
||||
a rule that you cannot or will not follow.
|
||||
|
||||
## Copyright
|
||||
|
||||
Each contributor licenses you to do everything with this
|
||||
software that would otherwise infringe that contributor's
|
||||
copyright in it.
|
||||
|
||||
## Notices
|
||||
|
||||
You must ensure that everyone who gets a copy of
|
||||
any part of this software from you, with or without
|
||||
changes, also gets the text of this license or a link to
|
||||
<https://blueoakcouncil.org/license/1.0.0>.
|
||||
|
||||
## Excuse
|
||||
|
||||
If anyone notifies you in writing that you have not
|
||||
complied with [Notices](#notices), you can keep your
|
||||
license by taking all practical steps to comply within 30
|
||||
days after the notice. If you do not do so, your license
|
||||
ends immediately.
|
||||
|
||||
## Patent
|
||||
|
||||
Each contributor licenses you to do everything with this
|
||||
software that would otherwise infringe any patent claims
|
||||
they can license or become able to license.
|
||||
|
||||
## Reliability
|
||||
|
||||
No contributor can revoke this license.
|
||||
|
||||
## No Liability
|
||||
|
||||
***As far as the law allows, this software comes as is,
|
||||
without any warranty or condition, and no contributor
|
||||
will be liable to anyone for any damages related to this
|
||||
software or this license, under any kind of legal claim.***
|
39
README.md
Normal file
39
README.md
Normal file
|
@ -0,0 +1,39 @@
|
|||
A config extension to Server to deliver drone files for repositories where you can't put a drone file in. _Please note this project requires Drone server version 1.4 or higher._
|
||||
|
||||
## Installation
|
||||
|
||||
Create a shared secret:
|
||||
|
||||
```console
|
||||
$ openssl rand -hex 16
|
||||
bea26a2221fd8090ea38720fc445eca6
|
||||
```
|
||||
|
||||
Download and run the extension:
|
||||
|
||||
```console
|
||||
$ docker run -d \
|
||||
--publish=3000:3000 \
|
||||
--env=DRONE_DEBUG=true \
|
||||
--env=DRONE_SECRET=bea26a2221fd8090ea38720fc445eca6 \
|
||||
--restart=always \
|
||||
--name=config garionion/drone-yaml-server
|
||||
```
|
||||
|
||||
Update your Drone server configuration to include the extension address and the shared secret.
|
||||
|
||||
```text
|
||||
DRONE_YAML_ENDPOINT=http://1.2.3.4:3000
|
||||
DRONE_YAML_SECRET=bea26a2221fd8090ea38720fc445eca6
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
Use the command line tools to test your extension. _This extension uses http-signatures to authorize client access and will reject unverified requests. You will be unable to test this extension using a simple curl command._
|
||||
|
||||
```text
|
||||
export DRONE_YAML_ENDPOINT=http://1.2.3.4:3000
|
||||
export DRONE_YAML_SECRET=bea26a2221fd8090ea38720fc445eca6
|
||||
|
||||
drone plugins config get <repo>
|
||||
```
|
10
go.mod
Normal file
10
go.mod
Normal file
|
@ -0,0 +1,10 @@
|
|||
module git.entr0py.de/garionion/drone-yaml-server
|
||||
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/drone/drone-go v1.0.6
|
||||
github.com/joho/godotenv v1.3.0
|
||||
github.com/kelseyhightower/envconfig v1.4.0
|
||||
github.com/sirupsen/logrus v1.4.2
|
||||
)
|
23
go.sum
Normal file
23
go.sum
Normal file
|
@ -0,0 +1,23 @@
|
|||
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/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/drone/drone-go v1.0.6 h1:YbMwEwlE3HC4InN0bT21EDvzImct5dGG1I56dSdUhjI=
|
||||
github.com/drone/drone-go v1.0.6/go.mod h1:GxyeGClYohaKNYJv/ZpsmVHtMJ7WhoT+uDaJNcDIrk4=
|
||||
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/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
||||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
|
||||
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
62
main.go
Normal file
62
main.go
Normal file
|
@ -0,0 +1,62 @@
|
|||
// Copyright 2019 the Drone Authors. All rights reserved.
|
||||
// Use of this source code is governed by the Blue Oak Model License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.entr0py.de/garionion/drone-yaml-server/plugin"
|
||||
"github.com/drone/drone-go/plugin/config"
|
||||
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// spec provides the plugin settings.
|
||||
type spec struct {
|
||||
Bind string `envconfig:"DRONE_BIND"`
|
||||
Debug bool `envconfig:"DRONE_DEBUG"`
|
||||
Secret string `envconfig:"DRONE_SECRET"`
|
||||
|
||||
// TODO replace or remove these configuration
|
||||
// parameters. They are for demo purposes only.
|
||||
Param1 string `envconfig:"DRONE_PARAM_1"`
|
||||
Param2 string `envconfig:"DRONE_PARAM_2"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
spec := new(spec)
|
||||
err := envconfig.Process("", spec)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if spec.Debug {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
}
|
||||
if spec.Secret == "" {
|
||||
logrus.Fatalln("missing secret key")
|
||||
}
|
||||
if spec.Bind == "" {
|
||||
spec.Bind = ":3000"
|
||||
}
|
||||
|
||||
handler := config.Handler(
|
||||
plugin.New(
|
||||
// TODO replace or remove these configuration
|
||||
// parameters. They are for demo purposes only.
|
||||
spec.Param1,
|
||||
spec.Param2,
|
||||
),
|
||||
spec.Secret,
|
||||
logrus.StandardLogger(),
|
||||
)
|
||||
|
||||
logrus.Infof("server listening on address %s", spec.Bind)
|
||||
|
||||
http.Handle("/", handler)
|
||||
logrus.Fatal(http.ListenAndServe(spec.Bind, nil))
|
||||
}
|
58
plugin/plugin.go
Normal file
58
plugin/plugin.go
Normal file
|
@ -0,0 +1,58 @@
|
|||
// Copyright 2019 the Drone Authors. All rights reserved.
|
||||
// Use of this source code is governed by the Blue Oak Model License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/drone/drone-go/drone"
|
||||
"github.com/drone/drone-go/plugin/config"
|
||||
)
|
||||
|
||||
// TODO replace or remove
|
||||
const defaultPipeline = `
|
||||
kind: pipeline
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: golang
|
||||
commands:
|
||||
- go build
|
||||
- go test -v
|
||||
`
|
||||
|
||||
// New returns a new config plugin.
|
||||
func New(param1, param2 string) config.Plugin {
|
||||
return &plugin{
|
||||
// TODO replace or remove these configuration
|
||||
// parameters. They are for demo purposes only.
|
||||
param1: param1,
|
||||
param2: param2,
|
||||
}
|
||||
}
|
||||
|
||||
type plugin struct {
|
||||
// TODO replace or remove these configuration
|
||||
// parameters. They are for demo purposes only.
|
||||
param1 string
|
||||
param2 string
|
||||
}
|
||||
|
||||
func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config, error) {
|
||||
// TODO replace or remove
|
||||
// this demonstrates how we can override
|
||||
// and return a custom configuration file
|
||||
if req.Repo.Namespace == "some-organization" {
|
||||
return &drone.Config{
|
||||
Data: defaultPipeline,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// return nil and Drone will fallback to
|
||||
// the standard behavior for getting the
|
||||
// configuration file.
|
||||
return nil, nil
|
||||
}
|
11
plugin/plugin_test.go
Normal file
11
plugin/plugin_test.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Copyright 2019 the Drone Authors. All rights reserved.
|
||||
// Use of this source code is governed by the Blue Oak Model License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package plugin
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestPlugin(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
Loading…
Reference in a new issue