diff --git a/Docker/Dockerfile b/Docker/Dockerfile new file mode 100644 index 0000000..83b6414 --- /dev/null +++ b/Docker/Dockerfile @@ -0,0 +1,15 @@ +FROM registry.access.redhat.com/rhel7 + +ENV MMPP_VERSION 4.4 +ENV MMPP_VERSION_MINOR .0 + +RUN cd /opt && \ + curl -L https://github.com/mattermost/mattermost-push-proxy/releases/download/v${MMPP_VERSION}/mattermost-push-proxy-${MMPP_VERSION}${MMPP_VERSION_MINOR}.tar.gz > mmpp.tar.gz && \ + tar xvf mmpp.tar.gz && rm mmpp.tar.gz + +COPY mattermost-push-proxy.json /opt/mattermost-push-proxy/config/ + +RUN chmod -R 777 /opt/mattermost-push-proxy/config/ +COPY docker-entrypoint.sh / + +ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/Docker/docker-entrypoint.sh b/Docker/docker-entrypoint.sh new file mode 100755 index 0000000..d533dd5 --- /dev/null +++ b/Docker/docker-entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/bash +MMPP_CONFIG=/opt/mattermost-push-proxy/config/mattermost-push-proxy.json + +echo "Updating mattermost-push-proxy configuration..." + +sed -Ei 's/APPLEPUSHCERT/'$APPLEPUSHCERT'/g' $MMPP_CONFIG +sed -Ei 's/APPLEPUSHPASS/'$APPLEPUSHPASS'/g' $MMPP_CONFIG + +sed -Ei 's/APPLEPUSHRNCERT/'$APPLEPUSHRNCERT'/g' $MMPP_CONFIG +sed -Ei 's/APPLEPUSHRNPASS/'$APPLEPUSHRNPASS'/g' $MMPP_CONFIG + +sed -Ei 's/GOOGLEAPIKEY/'$GOOGLEAPIKEY'/g' $MMPP_CONFIG +sed -Ei 's/GOOGLERNAPIKEY/'$GOOGLERNAPIKEY'/g' $MMPP_CONFIG + +cd /opt/mattermost-push-proxy + +/opt/mattermost-push-proxy/bin/mattermost-push-proxy diff --git a/Docker/mattermost-push-proxy.json b/Docker/mattermost-push-proxy.json new file mode 100644 index 0000000..15561d2 --- /dev/null +++ b/Docker/mattermost-push-proxy.json @@ -0,0 +1,33 @@ +{ + "ListenAddress":":8066", + "ThrottlePerSec":300, + "ThrottleMemoryStoreSize":50000, + "ThrottleVaryByHeader":"X-Forwarded-For", + "EnableMetrics": false, + "ApplePushSettings":[ + { + "Type":"apple", + "ApplePushUseDevelopment":false, + "ApplePushCertPrivate":"APPLEPUSHCERT", + "ApplePushCertPassword":"APPLEPUSHPASS", + "ApplePushTopic":"com.mattermost.Mattermost" + }, + { + "Type":"apple_rn", + "ApplePushUseDevelopment":false, + "ApplePushCertPrivate":"APPLEPUSHRNCERT", + "ApplePushCertPassword":"APPLEPUSHRNPASS", + "ApplePushTopic":"com.mattermost.react.native" + } + ], + "AndroidPushSettings":[ + { + "Type":"android", + "AndroidApiKey":"GOOGLEAPIKEY" + }, + { + "Type":"android_rn", + "AndroidApiKey":"GOOGLERNAPIKEY" + } + ] +} diff --git a/cico_build_deploy.sh b/cico_build_deploy.sh index e4ac584..3592a86 100644 --- a/cico_build_deploy.sh +++ b/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-push-proxy" -REGISTRY="https://registry.centos.org" -REPOSITORY="mattermost" -TEMPLATE="openshift/mattermost-push-proxy.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 -o -e "registry.*" | awk '{split($0,array,"/")} END{print array[3]}' | 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-push-proxy" + 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-push-proxy" + REGISTRY="https://registry.centos.org" + REPOSITORY="mattermost" + TEMPLATE="openshift/mattermost-push-proxy.app.yaml" + + #Find tag used by deployment template + echo -e "Scanning OpenShift Deployment Template for Image tag" + TAG=$(cat $TEMPLATE | grep -o -e "registry.*" | awk '{split($0,array,"/")} END{print array[3]}' | 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