More additions to be in sync with other plugins (#21)

* Use specific plugin versions, pull latest versions and enable a microbadger webhook

* Use the new plugins/base:multiarch image

* Write readme like it is done for other plugins

* Downcase all wording like on other plugins, move variables to correct file

* Added dockerignore file

* Added missing schema version label

* Only execute webhook on master branch

* Added issue and pull request templates

* Added blank line to gitignore
This commit is contained in:
Thomas Boerger 2017-09-02 11:34:15 +02:00 committed by Bo-Yi Wu
parent 2882e258d2
commit 4d38a477e9
12 changed files with 95 additions and 77 deletions

2
.dockeringore Normal file
View File

@ -0,0 +1,2 @@
*
!release/

View File

@ -5,12 +5,14 @@ workspace:
pipeline:
test:
image: golang:1.9
pull: true
commands:
- go vet
- go test -cover -coverprofile=coverage.out
build_linux_amd64:
image: golang:1.9
pull: true
group: build
environment:
- GOOS=linux
@ -21,6 +23,7 @@ pipeline:
build_linux_arm64:
image: golang:1.9
pull: true
group: build
environment:
- GOOS=linux
@ -31,6 +34,7 @@ pipeline:
build_linux_arm:
image: golang:1.9
pull: true
group: build
environment:
- GOOS=linux
@ -42,6 +46,7 @@ pipeline:
# build_windows_amd64:
# image: golang:1.9-nanoserver
# pull: true
# group: build
# environment:
# - GOOS=windows
@ -51,7 +56,8 @@ pipeline:
# - go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -o release/windows/amd64/drone-webhook
publish_linux_amd64:
image: plugins/docker
image: plugins/docker:17.05
pull: true
repo: plugins/webhook
tags: [ latest, 1.0.0, 1.0, 1 ]
secrets: [ docker_username, docker_password ]
@ -61,7 +67,8 @@ pipeline:
event: push
publish_linux_arm64:
image: plugins/docker
image: plugins/docker:17.05
pull: true
repo: plugins/webhook
tags: [ linux-arm64 ]
secrets: [ docker_username, docker_password ]
@ -71,7 +78,8 @@ pipeline:
event: push
publish_linux_arm:
image: plugins/docker
image: plugins/docker:17.05
pull: true
repo: plugins/webhook
tags: [ linux-arm ]
secrets: [ docker_username, docker_password ]
@ -81,7 +89,8 @@ pipeline:
event: push
# publish_windows_amd64:
# image: plugins/docker
# image: plugins/docker:17.05
# pull: true
# repo: plugins/webhook
# tags: [ windows-amd64 ]
# secrets: [ docker_username, docker_password ]
@ -89,3 +98,12 @@ pipeline:
# when:
# branch: master
# event: push
microbadger:
image: plugins/webhook:1
pull: true
secrets: [ webhook_url ]
when:
branch: master
event: push
status: [ success ]

9
.github/issue_template.md vendored Normal file
View File

@ -0,0 +1,9 @@
<!-- PLEASE READ BEFORE DELETING
Bugs or Issues? Due to the high number of false positive issues we receive,
please do not create a GitHub issue until you have discussed and verified
with community support at:
https://gitter.im/drone/drone
-->

7
.github/pull_request_template.md vendored Normal file
View File

@ -0,0 +1,7 @@
<!-- PLEASE READ BEFORE DELETING
Please discuss changes before creating pull requests.
https://gitter.im/drone/drone
-->

1
.gitignore vendored
View File

@ -22,6 +22,7 @@ _testmain.go
*.exe
*.test
*.prof
release/
coverage.out
drone-webhook

View File

@ -1,18 +1,11 @@
FROM alpine:3.6 as alpine
RUN apk add -U --no-cache ca-certificates
FROM scratch
FROM plugins/base:multiarch
MAINTAINER Drone.IO Community <drone-dev@googlegroups.com>
ENV GODEBUG=netdns=go
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
LABEL org.label-schema.version=latest
LABEL org.label-schema.vcs-url="https://github.com/drone-plugins/drone-webhook.git"
LABEL org.label-schema.name="Drone Webhook"
LABEL org.label-schema.vendor="Drone.IO Community"
LABEL org.label-schema.schema-version="1.0"
ADD release/linux/amd64/drone-webhook /bin/
ENTRYPOINT ["/bin/drone-webhook"]

View File

@ -1,13 +1,6 @@
FROM alpine:3.6 as alpine
RUN apk add -U --no-cache ca-certificates
FROM scratch
FROM plugins/base:multiarch
MAINTAINER Drone.IO Community <drone-dev@googlegroups.com>
ENV GODEBUG=netdns=go
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
LABEL org.label-schema.version=latest
LABEL org.label-schema.vcs-url="https://github.com/drone-plugins/drone-webhook.git"
LABEL org.label-schema.name="Drone Webhook"
@ -15,4 +8,4 @@ LABEL org.label-schema.vendor="Drone.IO Community"
LABEL org.label-schema.schema-version="1.0"
ADD release/linux/arm/drone-webhook /bin/
ENTRYPOINT ["/bin/drone-webhook"]
ENTRYPOINT ["/bin/drone-webhook"]

View File

@ -1,13 +1,6 @@
FROM alpine:3.6 as alpine
RUN apk add -U --no-cache ca-certificates
FROM scratch
FROM plugins/base:multiarch
MAINTAINER Drone.IO Community <drone-dev@googlegroups.com>
ENV GODEBUG=netdns=go
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
LABEL org.label-schema.version=latest
LABEL org.label-schema.vcs-url="https://github.com/drone-plugins/drone-webhook.git"
LABEL org.label-schema.name="Drone Webhook"
@ -15,4 +8,4 @@ LABEL org.label-schema.vendor="Drone.IO Community"
LABEL org.label-schema.schema-version="1.0"
ADD release/linux/arm64/drone-webhook /bin/
ENTRYPOINT ["/bin/drone-webhook"]
ENTRYPOINT ["/bin/drone-webhook"]

View File

@ -1,8 +1,6 @@
FROM microsoft/nanoserver:latest
MAINTAINER Drone.IO Community <drone-dev@googlegroups.com>
ENV GODEBUG=netdns=go
LABEL org.label-schema.version=latest
LABEL org.label-schema.vcs-url="https://github.com/drone-plugins/drone-webhook.git"
LABEL org.label-schema.name="Drone Webhook"
@ -10,4 +8,4 @@ LABEL org.label-schema.vendor="Drone.IO Community"
LABEL org.label-schema.schema-version="1.0"
ADD release/windows/amd64/drone-webhook /bin/
ENTRYPOINT [ "/bin/drone-webhook" ]
ENTRYPOINT [ "/bin/drone-webhook" ]

View File

@ -8,32 +8,39 @@
Drone plugin to send build status notifications via Webhook. For the usage information and a listing of the available options please take a look at [the docs](DOCS.md).
## Binary
## Build
Build the binary using `drone exec`:
Build the binary with the following commands:
```
go build
```
## Docker
Build the Docker image with the following commands:
```
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -tags netgo -o release/linux/amd64/drone-webhook
docker build --rm -t plugins/webhook .
```
### Usage
```
docker run --rm \
-e PLUGIN_URLS=https://hooks.somplace.com/endpoing/... \
-e PLUGIN_HEADERS="HEADER1=value1" \
-e PLUGIN_USERNAME=drone \
-e PLUGIN_PASSWORD=password \
-e DRONE_REPO_OWNER=octocat \
-e DRONE_REPO_NAME=hello-world \
-e DRONE_COMMIT_SHA=7fd1a60b01f91b314f59955a4e4d4e80d8edf11d \
-e DRONE_COMMIT_BRANCH=master \
-e DRONE_COMMIT_AUTHOR=octocat \
-e DRONE_BUILD_NUMBER=1 \
-e DRONE_BUILD_STATUS=success \
-e DRONE_BUILD_LINK=http://github.com/octocat/hello-world \
-e DRONE_TAG=1.0.0 \
plugins/webhook
docker run --rm \
-e PLUGIN_URLS=https://hooks.somplace.com/endpoing/... \
-e PLUGIN_HEADERS="HEADER1=value1" \
-e PLUGIN_USERNAME=drone \
-e PLUGIN_PASSWORD=password \
-e DRONE_REPO_OWNER=octocat \
-e DRONE_REPO_NAME=hello-world \
-e DRONE_COMMIT_SHA=7fd1a60b01f91b314f59955a4e4d4e80d8edf11d \
-e DRONE_COMMIT_BRANCH=master \
-e DRONE_COMMIT_AUTHOR=octocat \
-e DRONE_BUILD_NUMBER=1 \
-e DRONE_BUILD_STATUS=success \
-e DRONE_BUILD_LINK=http://github.com/octocat/hello-world \
-e DRONE_TAG=1.0.0 \
plugins/webhook
```

31
main.go
View File

@ -7,65 +7,60 @@ import (
"os"
)
const (
respFormat = "Webhook %d\n URL: %s\n RESPONSE STATUS: %s\n RESPONSE BODY: %s\n"
debugRespFormat = "Webhook %d\n URL: %s\n METHOD: %s\n HEADERS: %s\n REQUEST BODY: %s\n RESPONSE STATUS: %s\n RESPONSE BODY: %s\n"
)
var build string
var build = "0" // build number set at compile-time
func main() {
app := cli.NewApp()
app.Name = "Drone webhook"
app.Usage = "Drone webhook"
app.Name = "webhook plugin"
app.Usage = "webhook plugin"
app.Action = run
app.Version = fmt.Sprintf("1.0.0+%s", build)
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "method",
Usage: "Webhook method",
Usage: "webhook method",
EnvVar: "PLUGIN_METHOD",
Value: "POST",
},
cli.StringFlag{
Name: "username",
Usage: "Username for basic auth",
Usage: "username for basic auth",
EnvVar: "PLUGIN_USERNAME,WEBHOOK_USERNAME",
},
cli.StringFlag{
Name: "password",
Usage: "Password for basic auth",
Usage: "password for basic auth",
EnvVar: "PLUGIN_PASSWORD,WEBHOOK_PASSWORD",
},
cli.StringFlag{
Name: "content-type",
Usage: "Content type",
Usage: "content type",
EnvVar: "PLUGIN_CONTENT_TYPE",
Value: "application/json",
},
cli.StringFlag{
Name: "template",
Usage: "Custom template for webhook",
Usage: "custom template for webhook",
EnvVar: "PLUGIN_TEMPLATE",
},
cli.StringSliceFlag{
Name: "headers",
Usage: "Custom headers key map",
Usage: "custom headers key map",
EnvVar: "PLUGIN_HEADERS",
},
cli.StringSliceFlag{
Name: "urls",
Usage: "List of urls to perform the action on",
Usage: "list of urls to perform the action on",
EnvVar: "PLUGIN_URLS",
},
cli.BoolFlag{
Name: "debug",
Usage: "For debug information",
Usage: "enable debug information",
EnvVar: "PLUGIN_DEBUG",
},
cli.BoolFlag{
Name: "skip-verify",
Usage: "Skip ssl verification",
Usage: "skip ssl verification",
EnvVar: "PLUGIN_SKIP_VERIFY",
},
cli.StringFlag{
@ -158,8 +153,6 @@ func main() {
}
func run(c *cli.Context) error {
fmt.Printf("Drone Webhook Plugin built from %s\n", build)
plugin := Plugin{
Repo: Repo{
Owner: c.String("repo.owner"),

View File

@ -12,6 +12,11 @@ import (
"strings"
)
const (
respFormat = "Webhook %d\n URL: %s\n RESPONSE STATUS: %s\n RESPONSE BODY: %s\n"
debugRespFormat = "Webhook %d\n URL: %s\n METHOD: %s\n HEADERS: %s\n REQUEST BODY: %s\n RESPONSE STATUS: %s\n RESPONSE BODY: %s\n"
)
type (
Repo struct {
Owner string `json:"owner"`
@ -58,7 +63,6 @@ type (
)
func (p Plugin) Exec() error {
var buf bytes.Buffer
var b []byte