Skip to content

Commit

Permalink
Merge pull request #63 from prefeiturasp/homolog
Browse files Browse the repository at this point in the history
Atualização 10/08/2021
  • Loading branch information
anderson89marques authored Aug 11, 2021
2 parents ed2b37a + 04c8098 commit 41a62d2
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 47 deletions.
5 changes: 5 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
API_MONGO_URI=localhost:27017
FLASK_APP=api.py
# Caso tenha integração com o sentry, descomente a linha abaixo e coloque a URL
# SENTRY_URL=http://sua_url_do_sentry/2
# SENTRY_ENVIRONMENT=Development
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

109 changes: 109 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
pipeline {
environment {
branchname = env.BRANCH_NAME.toLowerCase()
kubeconfig = getKubeconf(env.branchname)
registryCredential = 'jenkins_registry'
}

agent {
node { label 'python-36-pratoaberto' }
}

options {
buildDiscarder(logRotator(numToKeepStr: '5', artifactNumToKeepStr: '5'))
disableConcurrentBuilds()
skipDefaultCheckout()
}

stages {

stage('CheckOut') {
steps { checkout scm }
}



stage('AnaliseCodigo') {
when { branch 'homolog' }
steps {
withSonarQubeEnv('sonarqube-local'){
sh 'echo "[ INFO ] Iniciando analise Sonar..." && sonar-scanner \
-Dsonar.projectKey=SME-PratoAberto-API \
-Dsonar.sources=.'
}
}
}



stage('Build') {
when { anyOf { branch 'master'; branch 'main'; branch "story/*"; branch 'development'; branch 'release'; branch 'homolog'; } }
steps {
script {
imagename1 = "registry.sme.prefeitura.sp.gov.br/${env.branchname}/pratoaberto-api"
//imagename2 = "registry.sme.prefeitura.sp.gov.br/${env.branchname}/sme-outra"
dockerImage1 = docker.build(imagename1, "-f Dockerfile .")
//dockerImage2 = docker.build(imagename2, "-f Dockerfile_outro .")
docker.withRegistry( 'https://registry.sme.prefeitura.sp.gov.br', registryCredential ) {
dockerImage1.push()
//dockerImage2.push()
}
sh "docker rmi $imagename1"
//sh "docker rmi $imagename2"
}
}
}

stage('Deploy'){
when { anyOf { branch 'master'; branch 'main'; branch 'development'; branch 'release'; branch 'homolog'; } }
steps {
script{
if ( env.branchname == 'main' || env.branchname == 'master' || env.branchname == 'homolog' || env.branchname == 'release' ) {
sendTelegram("🤩 [Deploy ${env.branchname}] Job Name: ${JOB_NAME} \nBuild: ${BUILD_DISPLAY_NAME} \nMe aprove! \nLog: \n${env.BUILD_URL}")
timeout(time: 24, unit: "HOURS") {
input message: 'Deseja realizar o deploy?', ok: 'SIM', submitter: 'kelwy_oliveira, anderson_morais, luis_zimmermann, rodolpho_azeredo'
}
withCredentials([file(credentialsId: "${kubeconfig}", variable: 'config')]){
sh('cp $config '+"$home"+'/.kube/config')
sh 'kubectl rollout restart deployment/pratoaberto-api -n sme-pratoaberto'
sh('rm -f '+"$home"+'/.kube/config')
}
}
else{
withCredentials([file(credentialsId: "${kubeconfig}", variable: 'config')]){
sh('cp $config '+"$home"+'/.kube/config')
sh 'kubectl rollout restart deployment/pratoaberto-api -n sme-pratoaberto'
sh('rm -f '+"$home"+'/.kube/config')
}
}
}
}
}
}

post {
success { sendTelegram("🚀 Job Name: ${JOB_NAME} \nBuild: ${BUILD_DISPLAY_NAME} \nStatus: Success \nLog: \n${env.BUILD_URL}console") }
unstable { sendTelegram("💣 Job Name: ${JOB_NAME} \nBuild: ${BUILD_DISPLAY_NAME} \nStatus: Unstable \nLog: \n${env.BUILD_URL}console") }
failure { sendTelegram("💥 Job Name: ${JOB_NAME} \nBuild: ${BUILD_DISPLAY_NAME} \nStatus: Failure \nLog: \n${env.BUILD_URL}console") }
aborted { sendTelegram ("😥 Job Name: ${JOB_NAME} \nBuild: ${BUILD_DISPLAY_NAME} \nStatus: Aborted \nLog: \n${env.BUILD_URL}console") }
}
}
def sendTelegram(message) {
def encodedMessage = URLEncoder.encode(message, "UTF-8")
withCredentials([string(credentialsId: 'telegramToken', variable: 'TOKEN'),
string(credentialsId: 'telegramChatId', variable: 'CHAT_ID')]) {
response = httpRequest (consoleLogResponseBody: true,
contentType: 'APPLICATION_JSON',
httpMode: 'GET',
url: 'https://api.telegram.org/bot'+"$TOKEN"+'/sendMessage?text='+encodedMessage+'&chat_id='+"$CHAT_ID"+'&disable_web_page_preview=true',
validResponseCodes: '200')
return response
}
}
def getKubeconf(branchName) {
if("main".equals(branchName)) { return "config_prd"; }
else if ("master".equals(branchName)) { return "config_prd"; }
else if ("homolog".equals(branchName)) { return "config_hom"; }
else if ("release".equals(branchName)) { return "config_hom"; }
else if ("development".equals(branchName)) { return "config_dev"; }
}
Loading

0 comments on commit 41a62d2

Please sign in to comment.