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

View File

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

View File

@ -1,13 +1,6 @@
FROM alpine:3.6 as alpine FROM plugins/base:multiarch
RUN apk add -U --no-cache ca-certificates
FROM scratch
MAINTAINER Drone.IO Community <drone-dev@googlegroups.com> 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.version=latest
LABEL org.label-schema.vcs-url="https://github.com/drone-plugins/drone-webhook.git" 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.name="Drone Webhook"
@ -15,4 +8,4 @@ LABEL org.label-schema.vendor="Drone.IO Community"
LABEL org.label-schema.schema-version="1.0" LABEL org.label-schema.schema-version="1.0"
ADD release/linux/arm/drone-webhook /bin/ 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 FROM plugins/base:multiarch
RUN apk add -U --no-cache ca-certificates
FROM scratch
MAINTAINER Drone.IO Community <drone-dev@googlegroups.com> 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.version=latest
LABEL org.label-schema.vcs-url="https://github.com/drone-plugins/drone-webhook.git" 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.name="Drone Webhook"
@ -15,4 +8,4 @@ LABEL org.label-schema.vendor="Drone.IO Community"
LABEL org.label-schema.schema-version="1.0" LABEL org.label-schema.schema-version="1.0"
ADD release/linux/arm64/drone-webhook /bin/ 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 FROM microsoft/nanoserver:latest
MAINTAINER Drone.IO Community <drone-dev@googlegroups.com> MAINTAINER Drone.IO Community <drone-dev@googlegroups.com>
ENV GODEBUG=netdns=go
LABEL org.label-schema.version=latest LABEL org.label-schema.version=latest
LABEL org.label-schema.vcs-url="https://github.com/drone-plugins/drone-webhook.git" 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.name="Drone Webhook"
@ -10,4 +8,4 @@ LABEL org.label-schema.vendor="Drone.IO Community"
LABEL org.label-schema.schema-version="1.0" LABEL org.label-schema.schema-version="1.0"
ADD release/windows/amd64/drone-webhook /bin/ 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). 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 ### Usage
``` ```
docker run --rm \ docker run --rm \
-e PLUGIN_URLS=https://hooks.somplace.com/endpoing/... \ -e PLUGIN_URLS=https://hooks.somplace.com/endpoing/... \
-e PLUGIN_HEADERS="HEADER1=value1" \ -e PLUGIN_HEADERS="HEADER1=value1" \
-e PLUGIN_USERNAME=drone \ -e PLUGIN_USERNAME=drone \
-e PLUGIN_PASSWORD=password \ -e PLUGIN_PASSWORD=password \
-e DRONE_REPO_OWNER=octocat \ -e DRONE_REPO_OWNER=octocat \
-e DRONE_REPO_NAME=hello-world \ -e DRONE_REPO_NAME=hello-world \
-e DRONE_COMMIT_SHA=7fd1a60b01f91b314f59955a4e4d4e80d8edf11d \ -e DRONE_COMMIT_SHA=7fd1a60b01f91b314f59955a4e4d4e80d8edf11d \
-e DRONE_COMMIT_BRANCH=master \ -e DRONE_COMMIT_BRANCH=master \
-e DRONE_COMMIT_AUTHOR=octocat \ -e DRONE_COMMIT_AUTHOR=octocat \
-e DRONE_BUILD_NUMBER=1 \ -e DRONE_BUILD_NUMBER=1 \
-e DRONE_BUILD_STATUS=success \ -e DRONE_BUILD_STATUS=success \
-e DRONE_BUILD_LINK=http://github.com/octocat/hello-world \ -e DRONE_BUILD_LINK=http://github.com/octocat/hello-world \
-e DRONE_TAG=1.0.0 \ -e DRONE_TAG=1.0.0 \
plugins/webhook plugins/webhook
``` ```

31
main.go
View File

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

View File

@ -12,6 +12,11 @@ import (
"strings" "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 ( type (
Repo struct { Repo struct {
Owner string `json:"owner"` Owner string `json:"owner"`
@ -58,7 +63,6 @@ type (
) )
func (p Plugin) Exec() error { func (p Plugin) Exec() error {
var buf bytes.Buffer var buf bytes.Buffer
var b []byte var b []byte