diff --git a/webhook/Dockerfile b/webhook/Dockerfile index 370d78b..2b3b06d 100644 --- a/webhook/Dockerfile +++ b/webhook/Dockerfile @@ -2,22 +2,20 @@ # Dockerfile for webhook # +FROM golang:alpine AS build +ENV CGO_ENABLED=0 +ENV GOOS=linux +ENV GOARCH=amd64 +WORKDIR /go/bin +RUN apk add --no-cache git +RUN go get -d -v github.com/adnanh/webhook +RUN go build --ldflags '-s -extldflags "-static"' -i -o webhook github.com/adnanh/webhook + FROM alpine MAINTAINER kev - -RUN set -xe \ - && apk add -U bash \ - coreutils \ - curl \ - jq \ - && rm -rf /var/cache/apk/* - -COPY ./webhook /usr/local/bin/ - -WORKDIR /scripts -VOLUME /scripts - +RUN apk add --no-cache bash coreutils curl jq +COPY --from=build /go/bin/webhook /usr/local/bin/ +VOLUME /etc/webhook EXPOSE 9000 - ENTRYPOINT ["webhook"] -CMD ["-help"] +CMD ["-header", "Access-Control-Allow-Origin=*", "-hooks", "/etc/webhook/hooks.json", "-verbose"] diff --git a/webhook/Makefile b/webhook/Makefile deleted file mode 100644 index 6f33bed..0000000 --- a/webhook/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -.PHONY: webhook - -export CGO_ENABLED=0 -export GOPATH = /tmp/go -export GOOS = linux -export GOARCH = amd64 - -webhook: - go get -d github.com/adnanh/webhook - go build --ldflags '-s -extldflags "-static"' -i -o webhook github.com/adnanh/webhook - -clean: - rm -rf $(GOPATH) - rm -f webhook diff --git a/webhook/README.md b/webhook/README.md index ce027b8..d0cfd63 100644 --- a/webhook/README.md +++ b/webhook/README.md @@ -7,64 +7,53 @@ webhook to easily create HTTP endpoints (hooks) on your server, which you can use to execute configured commands. -## Build Binary - -To build a docker image from scratch, we need to build static linked binary. - -```bash -$ go get -d github.com/adnanh/webhook -$ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -installsuffix cgo -ldflags '-s -extld ld -extldflags -static' -a -x -o webhook github.com/adnanh/webhook -$ file webhook -``` - ## Directory Tree ``` ~/fig/webhook/ ├── docker-compose.yml -└── scripts/ +└── data/ ├── hooks.json └── test.sh* (executable) ``` docker-compose.yml -``` +```yaml webhook: image: vimagick/webhook - command: -hooks hooks.json -verbose ports: - "9000:9000" volumes: - - "./scripts:/scripts" + - "./data:/etc/webhook" restart: always ``` hooks.json -``` +```json [ { "id": "test", - "execute-command": "/scripts/test.sh", - "command-working-directory": "/scripts" + "execute-command": "/etc/webhook/test.sh", + "command-working-directory": "/etc/webhook" } ] ``` test.sh -``` +```bash #!/bin/bash echo 'hello world' ``` ## Up and Running -``` +```bash $ cd ~/fig/webhook/ -$ chmod +x scripts/test.sh +$ chmod +x data/test.sh $ docker-compose up -d Creating webhook_webhook_1... diff --git a/webhook/data/hooks.json b/webhook/data/hooks.json new file mode 100644 index 0000000..851e2ef --- /dev/null +++ b/webhook/data/hooks.json @@ -0,0 +1,7 @@ +[ + { + "id": "test", + "execute-command": "/etc/webhook/test.sh", + "command-working-directory": "/etc/webhook" + } +] diff --git a/webhook/scripts/test.sh b/webhook/data/test.sh old mode 100644 new mode 100755 similarity index 96% rename from webhook/scripts/test.sh rename to webhook/data/test.sh index 985e2ad..7e979d2 --- a/webhook/scripts/test.sh +++ b/webhook/data/test.sh @@ -1,3 +1,2 @@ #!/bin/bash echo 'hello world' - diff --git a/webhook/docker-compose.yml b/webhook/docker-compose.yml index f411622..6a34fa5 100644 --- a/webhook/docker-compose.yml +++ b/webhook/docker-compose.yml @@ -1,8 +1,7 @@ webhook: image: vimagick/webhook - command: -hooks hooks.json -verbose ports: - "9000:9000" volumes: - - "./scripts:/scripts" + - "./data:/etc/webhook" restart: always diff --git a/webhook/scripts/hooks.json b/webhook/scripts/hooks.json deleted file mode 100644 index c8f7855..0000000 --- a/webhook/scripts/hooks.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "id": "test", - "execute-command": "/scripts/test.sh", - "command-working-directory": "/scripts" - } -] diff --git a/webhook/webhook b/webhook/webhook deleted file mode 100755 index dd95759..0000000 Binary files a/webhook/webhook and /dev/null differ