chore: add src and pipiline

This commit is contained in:
Jesús Pérez Lorenzo 2021-06-23 06:20:26 +01:00
parent 13f7ba49bf
commit ee313c14b1
15 changed files with 423 additions and 0 deletions

35
src/Dockerfile Normal file
View file

@ -0,0 +1,35 @@
# Dockerfile for https://github.com/adnanh/webhook
FROM docker.io/golang:alpine3.13 AS build
MAINTAINER Almir Dzinovic <almir@dzinovic.net>
WORKDIR /go/src/github.com/adnanh/webhook
ENV WEBHOOK_VERSION 2.8.0
RUN apk add --update -t build-deps curl libc-dev gcc libgcc
RUN curl -L --silent -o webhook.tar.gz https://github.com/adnanh/webhook/archive/${WEBHOOK_VERSION}.tar.gz && \
tar -xzf webhook.tar.gz --strip 1 && \
go get -d && \
go build -o /usr/local/bin/webhook && \
apk del --purge build-deps && \
rm -rf /var/cache/apk/* && \
rm -rf /go
#iputils-ping \
# install \
#jinja2 \
FROM docker.io/alpine:3.13
RUN apk add --update \
bash \
vim \
git \
openssh \
curl \
jq \
python3 \
cmd:pip3 &&\
pip3 install jinja2 && \
curl -fSL https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl && \
chmod +x /usr/local/bin/kubectl
COPY --from=build /usr/local/bin/webhook /usr/local/bin/webhook
WORKDIR /etc/webhook
VOLUME ["/etc/webhook"]
EXPOSE 9000
ENTRYPOINT ["/usr/local/bin/webhook"]

21
src/LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016 Almir Dzinovic
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

32
src/README.md Normal file
View file

@ -0,0 +1,32 @@
[Webhook](https://github.com/adnanh/webhook/) Dockerized
=================
## Running webhook in Docker
The simplest usage of [almir/webhook](https://hub.docker.com/r/almir/webhook/) image is for one to host the hooks JSON file on their machine and mount the directory in which those are kept as a volume to the Docker container:
```shell
docker run -d -p 9000:9000 -v /dir/to/hooks/on/host:/etc/webhook --name=webhook \
almir/webhook -verbose -hooks=/etc/webhook/hooks.json -hotreload
```
Another method of using this Docker image is to create a simple `Dockerfile`:
```docker
FROM almir/webhook
COPY hooks.json.example /etc/webhook/hooks.json
```
This `Dockerfile` and `hooks.json.example` files should be placed inside the same directory. After that run `docker build -t my-webhook-image .` and then start your container:
```shell
docker run -d -p 9000:9000 --name=webhook my-webhook-image -verbose -hooks=/etc/webhook/hooks.json -hotreload
```
Additionally, one can specify the parameters to be passed to [webhook](https://github.com/adnanh/webhook/) in `Dockerfile` simply by adding one more line to the previous example:
```docker
FROM almir/webhook
COPY hooks.json.example /etc/webhook/hooks.json
CMD ["-verbose", "-hooks=/etc/webhook/hooks.json", "-hotreload"]
```
Now, after building your Docker image with `docker build -t my-webhook-image .`, you can start your container by running just:
```shell
docker run -d -p 9000:9000 --name=webhook my-webhook-image
```

34
src/_Dockerfile Normal file
View file

@ -0,0 +1,34 @@
# Dockerfile for https://github.com/adnanh/webhook
FROM golang:alpine3.13 AS build
MAINTAINER Almir Dzinovic <almir@dzinovic.net>
WORKDIR /go/src/github.com/adnanh/webhook
ENV WEBHOOK_VERSION 2.8.0
RUN apk add --update -t build-deps curl libc-dev gcc libgcc
RUN curl -L --silent -o webhook.tar.gz https://github.com/adnanh/webhook/archive/${WEBHOOK_VERSION}.tar.gz && \
tar -xzf webhook.tar.gz --strip 1 && \
go get -d && \
go build -o /usr/local/bin/webhook && \
apk del --purge build-deps && \
rm -rf /var/cache/apk/* && \
rm -rf /go
#iputils-ping \
# install \
#jinja2 \
FROM alpine:3.13
RUN apk add --update \
bash \
vim \
git \
openssh \
curl \
jq \
python3 && \
pip3 install jinja2 && \
curl -fSL https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl && \
chmod +x /usr/local/bin/kubectl
COPY --from=build /usr/local/bin/webhook /usr/local/bin/webhook
WORKDIR /etc/webhook
VOLUME ["/etc/webhook"]
EXPOSE 9000
ENTRYPOINT ["/usr/local/bin/webhook"]

View file

@ -0,0 +1,8 @@
### Using this script
Add `update-repo.sh` script to your `crontab`, like this:
```shell
./update-repo.sh --user someuser --password somepassword --write-crontab
```
This will add a `crontab` entry for the script to execute every five minutes. In case you're not using `crontab` or you want to change the execution frequency you can always add it manually.

View file

@ -0,0 +1,65 @@
#!/bin/bash
set -o pipefail
# Set path to this script
SCRIPTPATH=$(readlink -f "$(dirname "$(readlink -f ${0})")")
# Get stript's name
SCRIPTNAME=$(basename ${0})
check_and_update() {
# Get inside the git repo directory
cd ${SCRIPTPATH}/.. || exit
# Get the branch currently used
CURBRANCH=$(git rev-parse --abbrev-ref HEAD)
# Get latest updates to the repo
git fetch --all && \
git reset --hard origin/${CURBRANCH}
# Get latest release of webhook and release used in this repo
LATEST_RELEASE=$(curl -s https://api.github.com/repos/adnanh/webhook/releases/latest | grep tag_name | awk -F ': "' '{ print $2 }' | awk -F '",' '{ print $1 }')
LOCAL_RELEASE=$(grep "^ENV.*WEBHOOK_VERSION" ${SCRIPTPATH}/../Dockerfile | awk '{ print $NF }')
# Compare releases and update Dockerfile in case they differ
if [[ "${LOCAL_RELEASE}" != "${LATEST_RELEASE}" ]] && [[ -n ${LATEST_RELEASE} ]]; then
sed -i "s/WEBHOOK_VERSION ${LOCAL_RELEASE}/WEBHOOK_VERSION ${LATEST_RELEASE}/g" ${SCRIPTPATH}/../Dockerfile
git commit -am "- bump webhook version to ${LATEST_RELEASE}"
git push origin ${CURBRANCH} && \
curl -s -X POST -H "Content-Type: application/json" \
-d '{"tag_name":"'${LATEST_RELEASE}'","target_commitish":"'${CURBRANCH}'","name":"webhook '${LATEST_RELEASE}'","body":"Release for webhook version '${LATEST_RELEASE}'.","draft":false,"prerelease":false}' \
https://${GITHUB_USER}:${GITHUB_PASS}@api.github.com/repos/${GITHUB_USER}/docker-webhook/releases
fi
}
argmissing() {
echo "Usage: $0 --user GITHUB_USERNAME --password GITHUB_PASSWORD [--write-crontab]"
echo
echo "Switches:"
echo -e "\t--user\t\t\tSpecify GitHub username - required."
echo -e "\t--password\t\tSpecify GitHub password - required."
echo -e "\t--write-crontab\t\tAdd crontab entry for this script - optional."
echo
echo "Examples:"
echo -e "\t$0 --user someuser --password somepassword"
echo -e "\t$0 --user someuser --password somepassword --write-crontab"
exit 1
}
# Translate script arguments to variables
GITHUB_USER=$(echo "$@" | awk -F "--user " '{ print $2 }' | awk '{ print $1 }')
GITHUB_PASS=$(echo "$@" | awk -F "--password " '{ print $2 }' | awk '{ print $1 }')
if [[ -z ${GITHUB_USER} ]] || [[ -z ${GITHUB_PASS} ]]; then
argmissing
else
if [[ -n $(echo "$@" | grep "\-\-write-crontab") ]]; then
if [[ -z $(crontab -l | grep ${SCRIPTNAME}) ]]; then
echo "Crontab entry is being created."
crontab -l | { cat; echo -e "# Check for webhook releases every five minutes\n*/5 * * * * ${SCRIPTPATH}/${SCRIPTNAME} --user ${GITHUB_USER} --password ${GITHUB_PASS} > /dev/null"; } | crontab -
else
echo "Crontab entry already exists."
fi
fi
check_and_update
fi
exit 0

2
src/create.sh Executable file
View file

@ -0,0 +1,2 @@
#!/bin/bash
podman build -t webhook:2.8.0 .