diff --git a/hooks/jira-hook b/hooks/jira-hook new file mode 100644 index 0000000..70684d6 --- /dev/null +++ b/hooks/jira-hook @@ -0,0 +1,33 @@ +#!/bin/bash +CLIENTHOOKURL="https://raw.githubusercontent.com/egovenrments/CIOps/master/hooks/jira-hook" +read -p "Enter Your Local Git Workspace Path : " GIT_CHECKOUT_PATH +GITWORKINGDIR=$(realpath ${GIT_CHECKOUT_PATH}) +read -p "Enter Your Jira Project Key : " X +if [ ! -d ${GITWORKINGDIR} ] +then + echo "[ Error ] ${GITWORKINGDIR} directory does not exists, please enter the complete path of the git workspace." + exit 1 +fi +if [ ! -d ${GITWORKINGDIR}/.git ] +then + echo "[ Error ] ${GITWORKINGDIR} is not a git repository." + exit 1 +else + originUrl=`git --git-dir=${GITWORKINGDIR}/.git config --get remote.origin.url` + REPO_BARE_NAME=`echo ${originUrl} | awk -F '/' {'print \$NF'}` +fi +echo "Remote Repository : ${originUrl}" +echo "[ Info ] Enforcing the hooks policy, Please wait..." +rm -rf ${GITWORKINGDIR}/.git/hooks/commit-msg +wget -q -O ${GITWORKINGDIR}/.git/hooks/commit-msg ${CLIENTHOOKURL} +if [ $? != 0 ] +then + echo "[ Error ] Unable to apply the hooks to ${GITWORKINGDIR}, please check the permission ..." + echo "Please contact your DevOps team." + rm -rf ${GITWORKINGDIR}/.git/hooks/commit-msg > /dev/null 2>&1 + exit 1; +else + chmod +x ${GITWORKINGDIR}/.git/hooks/commit-msg + sed -i "4,5 s/WAP/$X/" ${GITWORKINGDIR}/.git/hooks/commit-msg + echo "[ Success ] Hooks has been applied for ${GIT_CHECKOUT_PATH}" +fi diff --git a/hooks/pre-commit.sh b/hooks/pre-commit.sh new file mode 100644 index 0000000..deeb468 --- /dev/null +++ b/hooks/pre-commit.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# hook identifies jira ids in branch names, adds on more goodies if we are a hotifx or release branch and attempts to prevent blank commit messages...although this needs a bit more work... + + +COMMIT_FILE=$1 +COMMIT_MSG=$(cat $1) + +#First and foremost check whether the commit message is blank. if so then abort the commit. strip any spaces out too +#this one only works at present when someone tries to do git commit -m "" or git commit -m " " +#if anyone uses tools such as sourcetree, then these GUIs typically present a prompt...eg. "do you want to commit wihtout a message" and pass in optional attributes to git commit to allow this. + +if [[ -z "${COMMIT_MSG// }" ]]; then + echo "You cannot have an empty commit message. Please enter something meaningful!" + exit 1 +fi + + +#if we get to this point then prepend different things onto our commit message... +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) +#CURRENT_BRANCH="hotfix/jira-123" + +##try identify a jira ticket number, and also uppercase it +JIRA_ID=$(echo "$CURRENT_BRANCH" | tr 'a-z' 'A-Z' | grep -Eo "[A-Z]+-[0-9]+") +HOTFIX_ID=$(echo "$CURRENT_BRANCH" | tr 'a-z' 'A-Z' | grep -Eo "HOTFIX") +RELEASE_ID=$(echo "$CURRENT_BRANCH" | tr 'a-z' 'A-Z' | grep -Eo "RELEASE") + +#if we have no jira then use current branch name instead +if [ [-z "$JIRA_ID"] ];then + JIRA_ID=$CURRENT_BRANCH +fi + + +if [ ! -z "$HOTFIX_ID" ]; then + echo "[$JIRA_ID] [HOTFIX]: $COMMIT_MSG" > $COMMIT_FILE + echo "JIRA ID '$JIRA_ID' AND HOTFIX, matched in current branch name, prepended BOTH to commit message." + +elif [ ! -z "$RELEASE_ID" ]; then + echo "[$JIRA_ID] [RELEASE]: $COMMIT_MSG" > $COMMIT_FILE + echo "RELEASE branch found. '[RELEASE]' prepended to commit message." + +elif [[ ! -z "$JIRA_ID" ]]; then + echo "[$JIRA_ID]: $COMMIT_MSG" > $COMMIT_FILE + echo "JIRA ID '$JIRA_ID', matched in current branch name, prepended to commit message. (Use --no-verify to skip)" + +else + echo "[$CURRENT_BRANCH]: $COMMIT_MSG" > $COMMIT_FILE +fi diff --git a/vars/buildPipeline.groovy b/vars/buildPipeline.groovy index 909ea9e..50744b6 100644 --- a/vars/buildPipeline.groovy +++ b/vars/buildPipeline.groovy @@ -29,18 +29,18 @@ spec: valueFrom: secretKeyRef: name: jenkins-credentials - key: gitReadAccessToken + key: gitReadAccessToken volumeMounts: - name: jenkins-docker-cfg mountPath: /root/.docker - name: kaniko-cache - mountPath: /cache + mountPath: /cache resources: requests: memory: "1792Mi" cpu: "750m" limits: - memory: "3954Mi" + memory: "4080Mi" cpu: "1500m" - name: git image: docker.io/egovio/builder:2-64da60a1-version_script_update-NA @@ -52,7 +52,7 @@ spec: - name: kaniko-cache persistentVolumeClaim: claimName: kaniko-cache-claim - readOnly: true + readOnly: true - name: jenkins-docker-cfg projected: sources: @@ -66,7 +66,7 @@ spec: node(POD_LABEL) { def scmVars = checkout scm - String REPO_NAME = env.REPO_NAME ? env.REPO_NAME : "docker.io/upyogio"; + String REPO_NAME = env.REPO_NAME ? env.REPO_NAME : "docker.io/{{DOCKER_ACCOUNT}}"; String GCR_REPO_NAME = "asia.gcr.io/digit-egov"; def yaml = readYaml file: pipelineParams.configFile; List jobConfigs = ConfigParser.parseConfig(yaml, env); @@ -127,7 +127,7 @@ spec: --destination=${image} \ --destination=${gcr_image} \ --no-push=${noPushImage} \ - --cache-repo=upyogio/cache/cache + --cache-repo={{DOCKER_ACCOUNT}}/cache/cache """ echo "${image} and ${gcr_image} pushed successfully!!" } @@ -142,7 +142,7 @@ spec: --snapshotMode=time \ --destination=${image} \ --no-push=${noPushImage} \ - --cache-repo=upyogio/cache/cache + --cache-repo={{DOCKER_ACCOUNT}}/cache/cache """ echo "${image} pushed successfully!" } diff --git a/vars/deployer.groovy b/vars/deployer.groovy index 316b1b2..4b6b854 100644 --- a/vars/deployer.groovy +++ b/vars/deployer.groovy @@ -13,10 +13,8 @@ spec: command: - cat tty: true - env: - - name: "GOOGLE_APPLICATION_CREDENTIALS" - value: "/var/run/secret/cloud.google.com/service-account.json" - volumeMounts: + env: + volumeMounts: - name: kube-config mountPath: /root/.kube resources: @@ -26,7 +24,7 @@ spec: limits: memory: "256Mi" cpu: "200m" - volumes: + volumes: - name: kube-config secret: secretName: "${pipelineParams.environment}-kube-config" diff --git a/vars/jobBuilder.groovy b/vars/jobBuilder.groovy index 3fc5385..beba5e9 100644 --- a/vars/jobBuilder.groovy +++ b/vars/jobBuilder.groovy @@ -29,7 +29,7 @@ spec: name: jenkins-credentials key: dockerPassword - name: DOCKER_NAMESPACE - value: upyogio + value: {{DOCKER_ACCOUNT}} - name: DOCKER_GROUP_NAME value: dev resources: