diff --git a/.dockeringore b/.dockeringore new file mode 100644 index 0000000..c13ca3f --- /dev/null +++ b/.dockeringore @@ -0,0 +1,2 @@ +* +!release/ diff --git a/.drone.yml b/.drone.yml index 61ac7c7..513874f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -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 ] diff --git a/.github/issue_template.md b/.github/issue_template.md new file mode 100644 index 0000000..d2ebe9a --- /dev/null +++ b/.github/issue_template.md @@ -0,0 +1,9 @@ + diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..5eb6578 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,7 @@ + diff --git a/.gitignore b/.gitignore index 11c1d94..80f22a9 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ _testmain.go *.exe *.test *.prof + release/ coverage.out drone-webhook diff --git a/Dockerfile b/Dockerfile index 68557f2..6ea23d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 -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"] diff --git a/Dockerfile.arm b/Dockerfile.arm index 95d4db1..2583f60 100644 --- a/Dockerfile.arm +++ b/Dockerfile.arm @@ -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 -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"] \ No newline at end of file +ENTRYPOINT ["/bin/drone-webhook"] diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 index 1dcea4b..a1d41b2 100644 --- a/Dockerfile.arm64 +++ b/Dockerfile.arm64 @@ -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 -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"] \ No newline at end of file +ENTRYPOINT ["/bin/drone-webhook"] diff --git a/Dockerfile.windows b/Dockerfile.windows index c551a37..0dadad6 100644 --- a/Dockerfile.windows +++ b/Dockerfile.windows @@ -1,8 +1,6 @@ FROM microsoft/nanoserver:latest MAINTAINER Drone.IO Community -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" ] \ No newline at end of file +ENTRYPOINT [ "/bin/drone-webhook" ] diff --git a/README.md b/README.md index e344814..e42cdd0 100644 --- a/README.md +++ b/README.md @@ -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 ``` - - - - - - diff --git a/main.go b/main.go index a1dfea1..4d5efc7 100644 --- a/main.go +++ b/main.go @@ -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"), diff --git a/plugin.go b/plugin.go index 83e76b6..01dd395 100644 --- a/plugin.go +++ b/plugin.go @@ -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