From 47dcff47caebf9e9628467812864ef27ae0a2ee2 Mon Sep 17 00:00:00 2001 From: syamgk Date: Fri, 13 Apr 2018 12:19:40 +0530 Subject: [PATCH 1/4] add rhel builds for github integration --- github/Docker/Dockerfile | 14 ++++++++ github/Docker/config.py | 25 ++++++++++++++ github/cico_build_deploy.sh | 65 ++++++++++++++++++++++++++----------- 3 files changed, 85 insertions(+), 19 deletions(-) create mode 100644 github/Docker/Dockerfile create mode 100644 github/Docker/config.py diff --git a/github/Docker/Dockerfile b/github/Docker/Dockerfile new file mode 100644 index 0000000..e9b4bf2 --- /dev/null +++ b/github/Docker/Dockerfile @@ -0,0 +1,14 @@ +FROM registry.devshift.net/osio-prod/base/python2:latest + +# Install mattermost-integration-github +RUN pip install git+https://github.com/softdevteam/mattermost-github-integration@acb6833 + +# copy config file +COPY config.py /opt/ + +# set env variables +ENV FLASK_APP=mattermostgithub MGI_CONFIG_FILE=/opt/config.py + +EXPOSE 5000 + +CMD flask run --host=0.0.0.0 diff --git a/github/Docker/config.py b/github/Docker/config.py new file mode 100644 index 0000000..8b30eb4 --- /dev/null +++ b/github/Docker/config.py @@ -0,0 +1,25 @@ +from os import environ +from sys import exit +USERNAME = "Github" +ICON_URL = "" +reponames = [x for x in environ['REPO_NAMES'].split(',')] +hook_urls = [x for x in environ['HOOK_URLS'].split(',')] +channels = [x for x in environ['CHANNEL_NAMES'].split(',')] + +MATTERMOST_WEBHOOK_URLS = {} + +if not( len(reponames) == len(hook_urls) == len(channels)): + exit(1) + +# MATTERMOST_WEBHOOK_URLS.update( reponame : ( url, channel) +for x in xrange(len(channels)): + MATTERMOST_WEBHOOK_URLS.update({reponames[x] : (hook_urls[x], channels[x])}) + +SECRET = "" +SHOW_AVATARS = True +SERVER = { + 'hook': "/", + 'address': "0.0.0.0", + 'port': 5000, +} + diff --git a/github/cico_build_deploy.sh b/github/cico_build_deploy.sh index d51a3a3..185796c 100644 --- a/github/cico_build_deploy.sh +++ b/github/cico_build_deploy.sh @@ -6,27 +6,54 @@ set -x # Exit on error set -e -export BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M:%S`+00:00 - -# Check the existence of image on registry.centos.org -IMAGE="mattermost-github-integration" -REGISTRY="https://registry.centos.org" -REPOSITORY="mattermost" -TEMPLATE="openshift/mattermost-github.app.yaml" +function login() { + if [ -n "${DEVSHIFT_USERNAME}" -a -n "${DEVSHIFT_PASSWORD}" ]; then + docker login -u ${DEVSHIFT_USERNAME} -p ${DEVSHIFT_PASSWORD} ${REGISTRY} + else + echo "Could not login, missing credentials for the registry" + fi +} -#Find tag used by deployment template -echo -e "Scanning OpenShift Deployment Template for Image tag" -TAG=$(cat $TEMPLATE | grep -A 1 "name: IMAGE_TAG_VERSION" | grep "value:" | awk '{split($0,array,":")} END{print array[2]}') +export BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M:%S`+00:00 -#Check if image is in the registry -echo -e "Checking if image exists on the registry" -TAGLIST=$(curl -X GET $REGISTRY/v2/$REPOSITORY/$IMAGE/tags/list) -echo $TAGLIST | grep -w $TAG +if [ "$TARGET" = "rhel" ]; then + IMAGE="mattermost-github-integration" + REGISTRY="push.registry.devshift.net" + REPOSITORY="osio-prod" + TAG="latest" + + login -if [ $? -eq 0 ]; then - echo 'CICO: Image existence check successful. Ready to deploy updated app' - exit 0 + docker build ./Docker -t $REGISTRY/$REPOSITORY/$IMAGE:$TAG + docker push $REGISTRY/$REPOSITORY/$IMAGE:$TAG + if [ $? -eq 0 ]; then + echo 'CICO: Image pushed, ready to update deployed app' + exit 0 + else + echo 'CICO: Image push failed' + exit 2 + fi else - echo 'CICO: Image existence check failed. Exiting' - exit 2 + # Check the existence of image on registry.centos.org + IMAGE="mattermost-github-integration" + REGISTRY="https://registry.centos.org" + REPOSITORY="mattermost" + TEMPLATE="openshift/mattermost-github.app.yaml" + + #Find tag used by deployment template + echo -e "Scanning OpenShift Deployment Template for Image tag" + TAG=$(cat $TEMPLATE | grep -A 1 "name: IMAGE_TAG_VERSION" | grep "value:" | awk '{split($0,array,":")} END{print array[2]}') + + #Check if image is in the registry + echo -e "Checking if image exists on the registry" + TAGLIST=$(curl -X GET $REGISTRY/v2/$REPOSITORY/$IMAGE/tags/list) + echo $TAGLIST | grep -w $TAG + + if [ $? -eq 0 ]; then + echo 'CICO: Image existence check successful. Ready to deploy updated app' + exit 0 + else + echo 'CICO: Image existence check failed. Exiting' + exit 2 + fi fi From ee5363f0cbecb3a0fc9be33a85545556aa12b8c1 Mon Sep 17 00:00:00 2001 From: syamgk Date: Fri, 13 Apr 2018 12:19:50 +0530 Subject: [PATCH 2/4] add rhel builds for gitlab integration --- gitlab/Docker/Dockerfile | 9 +++++ gitlab/cico_build_deploy.sh | 66 ++++++++++++++++++++++++++----------- 2 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 gitlab/Docker/Dockerfile diff --git a/gitlab/Docker/Dockerfile b/gitlab/Docker/Dockerfile new file mode 100644 index 0000000..8951b27 --- /dev/null +++ b/gitlab/Docker/Dockerfile @@ -0,0 +1,9 @@ +FROM registry.devshift.net/osio-prod/base/python2:latest + +# Install mattermost-integration-gitlab +RUN pip install git+https://github.com/NotSqrt/mattermost-integration-gitlab@4a61a48 + +# Run the integration as a service after making sure that the webhook url variable is set +CMD if [ "${MATTERMOST_WEBHOOK_URL}" = "" ]; then echo "FAILED. MATTERMOST_WEBHOOK_URL environment variable is not set."; echo "Consult README for more information."; exit 1; fi; mattermost_gitlab "${MATTERMOST_WEBHOOK_URL}" --push --tag --icon "${MATTERMOST_ICON}" + +EXPOSE 5000 diff --git a/gitlab/cico_build_deploy.sh b/gitlab/cico_build_deploy.sh index 6cad296..71b6e69 100644 --- a/gitlab/cico_build_deploy.sh +++ b/gitlab/cico_build_deploy.sh @@ -6,27 +6,53 @@ set -x # Exit on error set -e -export BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M:%S`+00:00 - -# Check the existence of image on registry.centos.org -IMAGE="mattermost-gitlab-integration" -REGISTRY="https://registry.centos.org" -REPOSITORY="mattermost" -TEMPLATE="openshift/mattermost-gitlab.app.yaml" +function login() { + if [ -n "${DEVSHIFT_USERNAME}" -a -n "${DEVSHIFT_PASSWORD}" ]; then + docker login -u ${DEVSHIFT_USERNAME} -p ${DEVSHIFT_PASSWORD} ${REGISTRY} + else + echo "Could not login, missing credentials for the registry" + fi +} -#Find tag used by deployment template -echo -e "Scanning OpenShift Deployment Template for Image tag" -TAG=$(cat $TEMPLATE | grep -A 1 "name: IMAGE_TAG_VERSION" | grep "value:" | awk '{split($0,array,":")} END{print array[2]}') +export BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M:%S`+00:00 -#Check if image is in the registry -echo -e "Checking if image exists on the registry" -TAGLIST=$(curl -X GET $REGISTRY/v2/$REPOSITORY/$IMAGE/tags/list) -echo $TAGLIST | grep -w $TAG +if [ "$TARGET" = "rhel" ]; then + IMAGE="mattermost-gitlab-integration" + REGISTRY="push.registry.devshift.net" + REPOSITORY="osio-prod" + TAG="latest" + + login -if [ $? -eq 0 ]; then - echo 'CICO: Image existence check successful. Ready to deploy updated app' - exit 0 + docker build ./Docker -t $REGISTRY/$REPOSITORY/$IMAGE:$TAG + docker push $REGISTRY/$REPOSITORY/$IMAGE:$TAG + if [ $? -eq 0 ]; then + echo 'CICO: Image pushed, ready to update deployed app' + exit 0 + else + echo 'CICO: Image push failed' + exit 2 + fi else - echo 'CICO: Image existence check failed. Exiting' - exit 2 -fi + # Check the existence of image on registry.centos.org + IMAGE="mattermost-gitlab-integration" + REGISTRY="https://registry.centos.org" + REPOSITORY="mattermost" + TEMPLATE="openshift/mattermost-gitlab.app.yaml" + + #Find tag used by deployment template + echo -e "Scanning OpenShift Deployment Template for Image tag" + TAG=$(cat $TEMPLATE | grep -A 1 "name: IMAGE_TAG_VERSION" | grep "value:" | awk '{split($0,array,":")} END{print array[2]}') + + #Check if image is in the registry + echo -e "Checking if image exists on the registry" + TAGLIST=$(curl -X GET $REGISTRY/v2/$REPOSITORY/$IMAGE/tags/list) + echo $TAGLIST | grep -w $TAG + + if [ $? -eq 0 ]; then + echo 'CICO: Image existence check successful. Ready to deploy updated app' + exit 0 + else + echo 'CICO: Image existence check failed. Exiting' + exit 2 + fi From 69b6f60d637076e75a6f043a55ddd7c5b071b303 Mon Sep 17 00:00:00 2001 From: syamgk Date: Fri, 13 Apr 2018 12:19:59 +0530 Subject: [PATCH 3/4] add rhel builds for rss integration --- rssfeeds/Docker/Dockerfile | 12 +++++++ rssfeeds/cico_build_deploy.sh | 65 +++++++++++++++++++++++++---------- 2 files changed, 58 insertions(+), 19 deletions(-) create mode 100644 rssfeeds/Docker/Dockerfile diff --git a/rssfeeds/Docker/Dockerfile b/rssfeeds/Docker/Dockerfile new file mode 100644 index 0000000..19e2830 --- /dev/null +++ b/rssfeeds/Docker/Dockerfile @@ -0,0 +1,12 @@ +FROM registry.devshift.net/osio-prod/base/python2:latest + +# clone the upstream source repo +RUN git clone https://github.com/bitbackofen/Rss-Atom-Feed-Integration-for-Mattermost &&\ + cd Rss-Atom-Feed-Integration-for-Mattermost && git checkout 8e189eb &&\ + pip install -r requirements.txt + +RUN mv Rss-Atom-Feed-Integration-for-Mattermost/settings.py.docker Rss-Atom-Feed-Integration-for-Mattermost/settings.py + +WORKDIR Rss-Atom-Feed-Integration-for-Mattermost + +CMD python feedfetcher.py diff --git a/rssfeeds/cico_build_deploy.sh b/rssfeeds/cico_build_deploy.sh index 1fa7c2e..c1374f1 100644 --- a/rssfeeds/cico_build_deploy.sh +++ b/rssfeeds/cico_build_deploy.sh @@ -6,27 +6,54 @@ set -x # Exit on error set -e -export BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M:%S`+00:00 - -# Check the existence of image on registry.centos.org -IMAGE="mattermost-rss-integration" -REGISTRY="https://registry.centos.org" -REPOSITORY="mattermost" -TEMPLATE="openshift/mattermost-rss.app.yaml" +function login() { + if [ -n "${DEVSHIFT_USERNAME}" -a -n "${DEVSHIFT_PASSWORD}" ]; then + docker login -u ${DEVSHIFT_USERNAME} -p ${DEVSHIFT_PASSWORD} ${REGISTRY} + else + echo "Could not login, missing credentials for the registry" + fi +} -#Find tag used by deployment template -echo -e "Scanning OpenShift Deployment Template for Image tag" -TAG=$(cat $TEMPLATE | grep -A 1 "name: IMAGE_TAG_VERSION" | grep "value:" | awk '{split($0,array,":")} END{print array[2]}') +export BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M:%S`+00:00 -#Check if image is in the registry -echo -e "Checking if image exists on the registry" -TAGLIST=$(curl -X GET $REGISTRY/v2/$REPOSITORY/$IMAGE/tags/list) -echo $TAGLIST | grep -w $TAG +if [ "$TARGET" = "rhel" ]; then + IMAGE="mattermost-rss-integration" + REGISTRY="push.registry.devshift.net" + REPOSITORY="osio-prod" + TAG="latest" + + login -if [ $? -eq 0 ]; then - echo 'CICO: Image existence check successful. Ready to deploy updated app' - exit 0 + docker build ./Docker -t $REGISTRY/$REPOSITORY/$IMAGE:$TAG + docker push $REGISTRY/$REPOSITORY/$IMAGE:$TAG + if [ $? -eq 0 ]; then + echo 'CICO: Image pushed, ready to update deployed app' + exit 0 + else + echo 'CICO: Image push failed' + exit 2 + fi else - echo 'CICO: Image existence check failed. Exiting' - exit 2 + # Check the existence of image on registry.centos.org + IMAGE="mattermost-rss-integration" + REGISTRY="https://registry.centos.org" + REPOSITORY="mattermost" + TEMPLATE="openshift/mattermost-rss.app.yaml" + + #Find tag used by deployment template + echo -e "Scanning OpenShift Deployment Template for Image tag" + TAG=$(cat $TEMPLATE | grep -A 1 "name: IMAGE_TAG_VERSION" | grep "value:" | awk '{split($0,array,":")} END{print array[2]}') + + #Check if image is in the registry + echo -e "Checking if image exists on the registry" + TAGLIST=$(curl -X GET $REGISTRY/v2/$REPOSITORY/$IMAGE/tags/list) + echo $TAGLIST | grep -w $TAG + + if [ $? -eq 0 ]; then + echo 'CICO: Image existence check successful. Ready to deploy updated app' + exit 0 + else + echo 'CICO: Image existence check failed. Exiting' + exit 2 + fi fi From 9ca667292a5211726b59820e1e548201336f86ee Mon Sep 17 00:00:00 2001 From: syamgk Date: Fri, 13 Apr 2018 13:44:51 +0530 Subject: [PATCH 4/4] add rhel builds for irc integration --- irc/Docker/Dockerfile.build | 9 +++++ irc/Docker/Dockerfile.rhel | 15 ++++++++ irc/Docker/docker-entry.sh | 14 ++++++++ irc/Docker/matterbridge.toml | 22 ++++++++++++ irc/Docker/setuptoml.py | 14 ++++++++ irc/cico_build_deploy.sh | 69 ++++++++++++++++++++++++++---------- 6 files changed, 125 insertions(+), 18 deletions(-) create mode 100644 irc/Docker/Dockerfile.build create mode 100644 irc/Docker/Dockerfile.rhel create mode 100644 irc/Docker/docker-entry.sh create mode 100644 irc/Docker/matterbridge.toml create mode 100644 irc/Docker/setuptoml.py diff --git a/irc/Docker/Dockerfile.build b/irc/Docker/Dockerfile.build new file mode 100644 index 0000000..b7dfb29 --- /dev/null +++ b/irc/Docker/Dockerfile.build @@ -0,0 +1,9 @@ +FROM registry.centos.org/centos/centos:7 + +RUN yum -y install golang git + +ENV GOPATH /tmp/ + +RUN go get github.com/42wim/matterbridge && cd /tmp/src/github.com/42wim/matterbridge && \ + git checkout tags/v1.9.0 && \ + go build . diff --git a/irc/Docker/Dockerfile.rhel b/irc/Docker/Dockerfile.rhel new file mode 100644 index 0000000..e0b4a67 --- /dev/null +++ b/irc/Docker/Dockerfile.rhel @@ -0,0 +1,15 @@ +FROM registry.devshift.net/osio-prod/base/pcp:latest + +RUN mkdir -p /opt/matterbridge + +COPY . /opt/matterbridge + +RUN chown -R 1001 /opt/matterbridge && \ + chmod -R 777 /opt/matterbridge && \ + chmod +x /opt/matterbridge/docker-entry.sh + +WORKDIR /opt/matterbridge + +USER 1001 + +ENTRYPOINT ["/opt/matterbridge/docker-entry.sh"] diff --git a/irc/Docker/docker-entry.sh b/irc/Docker/docker-entry.sh new file mode 100644 index 0000000..40e1406 --- /dev/null +++ b/irc/Docker/docker-entry.sh @@ -0,0 +1,14 @@ +#!/bin/bash +config=/opt/matterbridge/matterbridge.toml +sed -Ei "s/IRC_NICK/`echo $IRC_NICK`/" $config +sed -Ei "s/MM_SERVER_NAME/`echo $MM_SERVER_NAME`/" $config +sed -Ei "s/MM_TEAM_NAME/`echo $MM_TEAM_NAME`/" $config +sed -Ei "s/MM_LOGIN/`echo $MM_LOGIN`/" $config +sed -Ei "s/MM_PASS/`echo $MM_PASS`/" $config +sed -Ei "s/NICKSERV_NICK/`echo $NICKSERV_NICK`/" $config +sed -Ei "s/NICKSERV_PASS/`echo $NICKSERV_PASS`/" $config + +python setuptoml.py +#sed -Ei "s/IRC_CHANNEL_NAME/`echo $IRC_CHANNEL_NAME`/" $config +#sed -Ei "s/MM_CHANNEL_NAME/`echo $MM_CHANNEL_NAME`/" $config +./matterbridge diff --git a/irc/Docker/matterbridge.toml b/irc/Docker/matterbridge.toml new file mode 100644 index 0000000..b4cf1ee --- /dev/null +++ b/irc/Docker/matterbridge.toml @@ -0,0 +1,22 @@ +[irc] + [irc.freenode] + Server="irc.freenode.net:6697" + UseTLS=true + SkipTLSVerify=true + Nick="IRC_NICK" + PrefixMessagesWithNick=true + ShowJoinPart=false + RemoteNickFormat="<{NICK}> " + UseSASL=true + NickServNick="NICKSERV_NICK" + NickServPassword="NICKSERV_PASS" + +[mattermost] + [mattermost.work] + Server="MM_SERVER_NAME" + Team="MM_TEAM_NAME" + Login="MM_LOGIN" + Password="MM_PASS" + PrefixMessagesWithNick=true + ShowJoinPart=false + RemoteNickFormat="[{PROTOCOL}] <{NICK}> " diff --git a/irc/Docker/setuptoml.py b/irc/Docker/setuptoml.py new file mode 100644 index 0000000..9cc154f --- /dev/null +++ b/irc/Docker/setuptoml.py @@ -0,0 +1,14 @@ +from os import environ + +irc_chan = environ['IRC_CHANNEL_NAMES'].split(",") +mm_chan = environ['MM_CHANNEL_NAMES'].split(",") +counter = 1 +o = open("matterbridge.toml",'a') +print irc_chan, mm_chan +for x,y in zip(irc_chan, mm_chan): + o.write("\n[[gateway]]\nname=\"gateway%d\"\nenable=true\n" %counter) + counter+=1 + o.write(" [[gateway.inout]]\n account=\"irc.freenode\"\n channel=\"%s\"\n" %x) + o.write(" [[gateway.inout]]\n account=\"mattermost.work\"\n channel=\"%s\"\n" %y) +o.close() + diff --git a/irc/cico_build_deploy.sh b/irc/cico_build_deploy.sh index abd2b4a..3af9cbb 100644 --- a/irc/cico_build_deploy.sh +++ b/irc/cico_build_deploy.sh @@ -6,27 +6,60 @@ set -x # Exit on error set -e -export BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M:%S`+00:00 +function login() { + if [ -n "${DEVSHIFT_USERNAME}" -a -n "${DEVSHIFT_PASSWORD}" ]; then + docker login -u ${DEVSHIFT_USERNAME} -p ${DEVSHIFT_PASSWORD} ${REGISTRY} + else + echo "Could not login, missing credentials for the registry" + fi +} -# Check the existence of image on registry.centos.org -IMAGE="matterbridge" -REGISTRY="https://registry.centos.org" -REPOSITORY="mattermost" -TEMPLATE="openshift/mattermost-irc-bridge.app.yaml" +export BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M:%S`+00:00 -#Find tag used by deployment template -echo -e "Scanning OpenShift Deployment Template for Image tag" -TAG=$(cat $TEMPLATE | grep -A 1 "name: IMAGE_TAG_VERSION" | grep "value:" | awk '{split($0,array,":")} END{print array[2]}') +if [ "$TARGET" = "rhel" ]; then + IMAGE="matterbridge" + REGISTRY="push.registry.devshift.net" + REPOSITORY="osio-prod" + TAG="latest" + BUILDER_IMAGE="matterbridge-builder" + BUILDER_CONT="matterbridge-build-container" -#Check if image is in the registry -echo -e "Checking if image exists on the registry" -TAGLIST=$(curl -X GET $REGISTRY/v2/$REPOSITORY/$IMAGE/tags/list) -echo $TAGLIST | grep -w $TAG + # build the bin on centos based container + docker build Docker -f Docker/Dockerfile.build -t BUILDER_IMAGE="matterbridge-builder" + docker run --detach=true --name ${BUILDER_CONT} -t ${BUILDER_IMAGE} /bin/tail -f /dev/null + docker cp ${BUILDER_CONT}:/tmp/src/github.com/42wim/matterbridge/matterbridge . -if [ $? -eq 0 ]; then - echo 'CICO: Image existence check successful. Ready to deploy updated app' - exit 0 + # building the final image + docker build Docker -f Docker/Dockerfile.rhel -t $REGISTRY/$REPOSITORY/$IMAGE:$TAG + docker push $REGISTRY/$REPOSITORY/$IMAGE:$TAG + if [ $? -eq 0 ]; then + echo 'CICO: Image pushed, ready to update deployed app' + exit 0 + else + echo 'CICO: Image push failed' + exit 2 + fi else - echo 'CICO: Image existence check failed. Exiting' - exit 2 + # Check the existence of image on registry.centos.org + IMAGE="matterbridge" + REGISTRY="https://registry.centos.org" + REPOSITORY="mattermost" + TEMPLATE="openshift/mattermost-irc-bridge.app.yaml" + + #Find tag used by deployment template + echo -e "Scanning OpenShift Deployment Template for Image tag" + TAG=$(cat $TEMPLATE | grep -A 1 "name: IMAGE_TAG_VERSION" | grep "value:" | awk '{split($0,array,":")} END{print array[2]}') + + #Check if image is in the registry + echo -e "Checking if image exists on the registry" + TAGLIST=$(curl -X GET $REGISTRY/v2/$REPOSITORY/$IMAGE/tags/list) + echo $TAGLIST | grep -w $TAG + + if [ $? -eq 0 ]; then + echo 'CICO: Image existence check successful. Ready to deploy updated app' + exit 0 + else + echo 'CICO: Image existence check failed. Exiting' + exit 2 + fi fi