From 1bf4bd4c88d0d58e5469d946a12c30a792a8103b Mon Sep 17 00:00:00 2001 From: syamgk Date: Fri, 13 Apr 2018 15:32:28 +0530 Subject: [PATCH] add rhel Dockerfile and modify cico script for building it --- Docker/Dockerfile | 43 +++++++++++++++++++++++ Docker/docker-entrypoint.sh | 60 ++++++++++++++++++++++++++++++++ Docker/mattermost+pmcd.sh | 40 +++++++++++++++++++++ cico_build_deploy.sh | 69 ++++++++++++++++++++++++++----------- 4 files changed, 191 insertions(+), 21 deletions(-) create mode 100644 Docker/Dockerfile create mode 100755 Docker/docker-entrypoint.sh create mode 100755 Docker/mattermost+pmcd.sh diff --git a/Docker/Dockerfile b/Docker/Dockerfile new file mode 100644 index 0000000..4e1e5f9 --- /dev/null +++ b/Docker/Dockerfile @@ -0,0 +1,43 @@ +FROM registry.devshift.net/osio-prod/base/mattermost:latest + +LABEL maintainer "Devtools " +LABEL author "Devtools " + +# Labels consumed by the build service +LABEL Component="mattermost" \ + Name="mattermost/mattermost-team-4.8.0-centos7" \ + Version="4.8.0" \ + Release="1" + +# Openshift/Kubernetes labels +LABEL io.k8s.description="Mattermost is an open source, self-hosted Slack-alternative" \ + io.k8s.display-name="Mattermost 4.8.0" \ + io.openshift.expose-services="8065/tcp:mattermost" \ + io.openshift.non-scalable="true" \ + io.openshift.tags="mattermost,slack" \ + io.openshift.min-memory="128Mi" + +ENV MATTERMOST_VERSION 4.8.0 + +RUN set -x && \ + curl -sLO https://releases.mattermost.com/${MATTERMOST_VERSION}/mattermost-team-${MATTERMOST_VERSION}-linux-amd64.tar.gz && \ + tar -xf mattermost-team-${MATTERMOST_VERSION}-linux-amd64.tar.gz -C /opt && \ + rm -f mattermost-team-${MATTERMOST_VERSION}-linux-amd64.tar.gz && \ + + mkdir /opt/mattermost/data && \ + + cp -f /opt/mattermost/config/config.json /opt/mattermost/config.json.orig && \ + + chown -R 1001 /opt/mattermost && \ + chmod 777 /opt/mattermost/data /opt/mattermost/logs + +COPY docker-entrypoint.sh / +COPY mattermost+pmcd.sh / + +USER 1001 + +EXPOSE 8065 +EXPOSE 44321 + +ENTRYPOINT ["/mattermost+pmcd.sh"] +CMD ["mattermost"] diff --git a/Docker/docker-entrypoint.sh b/Docker/docker-entrypoint.sh new file mode 100755 index 0000000..e4a0109 --- /dev/null +++ b/Docker/docker-entrypoint.sh @@ -0,0 +1,60 @@ +#!/bin/bash +MM_HOME=/opt/mattermost +MM_CONFIG=${MM_HOME}/config/config.json +MM_CONFIG_ORIG=${MM_HOME}/config.json.orig + +function updatejson() { + set -o nounset + key=$1 + value=$2 + file=$3 + jq "$key = \"$value\"" $file > ${file}.new + mv ${file}.new ${file} + echo "Set key $key in file $file" + set +o nounset +} + +if [[ ! -f $MM_CONFIG ]]; then + cp -f $MM_CONFIG_ORIG $MM_CONFIG +fi + +if [[ "$1" == "mattermost" ]]; then + if [[ -z $MM_DB_HOST ]]; then echo "MM_DB_HOST not set."; exit 1; fi + if [[ -z $MM_DB_PORT ]]; then echo "MM_DB_PORT not set."; exit 1; fi + if [[ -z $MM_DB_USER ]]; then echo "MM_DB_USER not set."; exit 1; fi + if [[ -z $MM_DB_PASS ]]; then echo "MM_DB_PASS not set."; exit 1; fi + if [[ -z $MM_DB_NAME ]]; then echo "MM_DB_NAME not set."; exit 1; fi + + echo "Updating mattermost configuration..." + updatejson ".SqlSettings.DriverName" "postgres" $MM_CONFIG + updatejson ".SqlSettings.DataSource" "postgres://${MM_DB_USER}:${MM_DB_PASS}@${MM_DB_HOST}:${MM_DB_PORT}/${MM_DB_NAME}?sslmode=disable&connect_timeout=10" $MM_CONFIG + + # Check if we want to use S3 for data storage + if [[ "$MM_USE_S3" == "true" ]]; then + if [[ -z $MM_S3_ACCESS_KEY_ID ]]; then echo "MM_S3_ACCESS_KEY_ID not set."; exit 1; fi + if [[ -z $MM_S3_SECRET_ACCESS_KEY ]]; then echo "MM_S3_SECRET_ACCESS_KEY not set."; exit 1; fi + if [[ -z $MM_S3_BUCKET ]]; then echo "MM_S3_BUCKET not set."; exit 1; fi + + MM_S3_REGION=${MM_S3_REGION:-us-east-1} + MM_S3_ENDPOINT=${MM_S3_ENDPOINT:-s3.amazonaws.com} + + updatejson ".FileSettings.DriverName" "amazons3" $MM_CONFIG + updatejson ".FileSettings.AmazonS3AccessKeyId" "${MM_S3_ACCESS_KEY_ID}" $MM_CONFIG + updatejson ".FileSettings.AmazonS3SecretAccessKey" "${MM_S3_SECRET_ACCESS_KEY}" $MM_CONFIG + updatejson ".FileSettings.AmazonS3Bucket" "${MM_S3_BUCKET}" $MM_CONFIG + updatejson ".FileSettings.AmazonS3Region" "${MM_S3_REGION}" $MM_CONFIG + updatejson ".FileSettings.AmazonS3Endpoint" "${MM_S3_ENDPOINT}" $MM_CONFIG + + fi + + while ! echo | nc -w1 $MM_DB_HOST $MM_DB_PORT > /dev/null 2>&1; do + echo "Could not connect to database at ${MM_DB_HOST}:${MM_DB_PORT}... Retrying..." + sleep 1 + done + + echo "Starting platform" + cd ${MM_HOME} + ./bin/platform +else + exec "$@" +fi diff --git a/Docker/mattermost+pmcd.sh b/Docker/mattermost+pmcd.sh new file mode 100755 index 0000000..116fb62 --- /dev/null +++ b/Docker/mattermost+pmcd.sh @@ -0,0 +1,40 @@ +#! /bin/sh + +set -eu + +# Initialize a little unprivileged pcp pmcd metrics collector +# process within this container; run this in a background subshell. +# No special signal handling or cleanup required. +( +# Setup pmcd to run in unprivileged mode of operation +. /etc/pcp.conf + +# Configure pmcd with a minimal set of DSO agents +rm -f $PCP_PMCDCONF_PATH; # start empty +echo "# Name ID IPC IPC Params File/Cmd" >> $PCP_PMCDCONF_PATH; +echo "pmcd 2 dso pmcd_init $PCP_PMDAS_DIR/pmcd/pmda_pmcd.so" >> $PCP_PMCDCONF_PATH; +echo "proc 3 dso proc_init $PCP_PMDAS_DIR/proc/pmda_proc.so" >> $PCP_PMCDCONF_PATH; +echo "linux 60 dso linux_init $PCP_PMDAS_DIR/linux/pmda_linux.so" >> $PCP_PMCDCONF_PATH; +rm -f $PCP_VAR_DIR/pmns/root_xfs $PCP_VAR_DIR/pmns/root_jbd2 $PCP_VAR_DIR/pmns/root_root $PCP_VAR_DIR/pmns/root +touch $PCP_VAR_DIR/pmns/.NeedRebuild + +# allow unauthenticated access to proc.* metrics (default is false) +export PROC_ACCESS=1 +export PMCD_ROOT_AGENT=0 + +# NB: we can't use the rc.pmcd script. It assumes that it's run as root. +cd $PCP_VAR_DIR/pmns +./Rebuild + +cd $PCP_LOG_DIR + +: "${PCP_HOSTNAME:=`hostname`}" +# possibly: filter pod name? + +# We can log in plaintext to stdout. +# pmcd is not chatty and only speaks up during errors. +exec /usr/libexec/pcp/bin/pmcd -l /dev/no-such-file -f -A -H $PCP_HOSTNAME +) & +sleep 5 # give time for pmcd's startup messages, so it doesn't intermix with keycloak's + +exec /docker-entrypoint.sh ${1+"$@"} diff --git a/cico_build_deploy.sh b/cico_build_deploy.sh index 2a9890a..10c94d3 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-team" -REGISTRY="https://registry.centos.org" -REPOSITORY="mattermost" -TEMPLATE="openshift/mattermost.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]}') - -#Check if image is in the registry -echo -e "Checking if image exists in the registry" -TAGLIST=$(curl -X GET $REGISTRY/v2/$REPOSITORY/$IMAGE/tags/list) -echo $TAGLIST | grep -w $TAG +export BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M:%S`+00:00 -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 +if [ "$TARGET" = "rhel" ]; then + IMAGE="mattermost-team" + REGISTRY="push.registry.devshift.net" + REPOSITORY="osio-prod" + TAG="latest" + + login + + 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 + # Check the existence of image on registry.centos.org + IMAGE="mattermost-team" + REGISTRY="https://registry.centos.org" + REPOSITORY="mattermost" + TEMPLATE="openshift/mattermost.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 in 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