Skip to content

Commit

Permalink
Merge pull request #11 from v3io/DEVOPS-203-jenkinsfile
Browse files Browse the repository at this point in the history
DEVOPS-203 Jenkinsfile
  • Loading branch information
gkirok authored Dec 12, 2018
2 parents 7a56999 + 8d0cd93 commit e16a6ac
Showing 1 changed file with 51 additions and 10 deletions.
61 changes: 51 additions & 10 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
label = "${UUID.randomUUID().toString()}"
BUILD_FOLDER = "/go"
expired=240
quay_user = "iguazio"
quay_credentials = "iguazio-prod-quay-credentials"
docker_user = "iguaziodocker"
docker_credentials = "iguazio-prod-docker-credentials"
artifactory_user = "k8s"
artifactory_url = "iguazio-prod-artifactory-url"
artifactory_credentials = "iguazio-prod-artifactory-credentials"
git_project = "tsdb-nuclio"
git_project_user = "v3io"
git_deploy_user = "iguazio-prod-git-user"
Expand Down Expand Up @@ -52,7 +58,8 @@ spec:
node("${git_project}-${label}") {
withCredentials([
usernamePassword(credentialsId: git_deploy_user, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME'),
string(credentialsId: git_deploy_user_token, variable: 'GIT_TOKEN')
string(credentialsId: git_deploy_user_token, variable: 'GIT_TOKEN'),
string(credentialsId: artifactory_url, variable: 'ARTIFACTORY_URL')
]) {
def AUTO_TAG
def TAG_VERSION
Expand Down Expand Up @@ -82,7 +89,7 @@ spec:
}
}

if ( TAG_VERSION != null && TAG_VERSION.length() > 0 && PUBLISHED_BEFORE < 240 ) {
if ( TAG_VERSION != null && TAG_VERSION.length() > 0 && PUBLISHED_BEFORE < expired ) {
stage('prepare sources') {
container('jnlp') {
sh """
Expand All @@ -92,29 +99,63 @@ spec:
}
}

stage('build in dood') {
stage('build tsdb-ingest in dood') {
container('docker-cmd') {
sh """
cd ${BUILD_FOLDER}/src/github.com/v3io/${git_project}/functions/ingest
docker build . --tag tsdb-ingest:latest --tag ${docker_user}/tsdb-ingest:${TAG_VERSION}
docker build . --tag tsdb-ingest:${TAG_VERSION} --tag ${docker_user}/tsdb-ingest:${TAG_VERSION} --tag ${docker_user}/tsdb-ingest:latest --tag quay.io/${quay_user}/tsdb-ingest:${TAG_VERSION} --tag quay.io/${quay_user}/tsdb-ingest:latest --tag ${ARTIFACTORY_URL}/${artifactory_user}/tsdb-ingest:${TAG_VERSION} --tag ${ARTIFACTORY_URL}/${artifactory_user}/tsdb-ingest:latest
"""
}
}

stage('build tsdb-query in dood') {
container('docker-cmd') {
sh """
cd ${BUILD_FOLDER}/src/github.com/v3io/${git_project}/functions/query
docker build . --tag tsdb-query:latest --tag ${docker_user}/tsdb-query:${TAG_VERSION}
docker build . --tag tsdb-query:${TAG_VERSION} --tag ${docker_user}/tsdb-query:${TAG_VERSION} --tag ${docker_user}/tsdb-query:latest --tag quay.io/${quay_user}/tsdb-query:${TAG_VERSION} --tag quay.io/${quay_user}/tsdb-query:latest --tag ${ARTIFACTORY_URL}/${artifactory_user}/tsdb-query:${TAG_VERSION} --tag ${ARTIFACTORY_URL}/${artifactory_user}/tsdb-query:latest
"""
}
}

stage('push to hub') {
container('docker-cmd') {
withDockerRegistry([credentialsId: docker_credentials, url: ""]) {
sh "docker push ${docker_user}/tsdb-ingest:${TAG_VERSION}"
sh "docker push ${docker_user}/tsdb-query:${TAG_VERSION}"
withDockerRegistry([credentialsId: docker_credentials, url: "https://index.docker.io/v1/"]) {
sh "docker push docker.io/${docker_user}/tsdb-ingest:${TAG_VERSION};"
sh "docker push docker.io/${docker_user}/tsdb-ingest:latest;"
sh "docker push docker.io/${docker_user}/tsdb-query:${TAG_VERSION};"
sh "docker push docker.io/${docker_user}/tsdb-query:latest;"
}
}
}

stage('push to quay') {
container('docker-cmd') {
withDockerRegistry([credentialsId: quay_credentials, url: "https://quay.io/api/v1/"]) {
sh "docker push quay.io/${quay_user}/tsdb-ingest:${TAG_VERSION}"
sh "docker push quay.io/${quay_user}/tsdb-ingest:latest"
sh "docker push quay.io/${quay_user}/tsdb-query:${TAG_VERSION}"
sh "docker push quay.io/${quay_user}/tsdb-query:latest"
}
}
}

stage('push to artifactory') {
container('docker-cmd') {
withDockerRegistry([credentialsId: artifactory_credentials, url: "https://${ARTIFACTORY_URL}/api/v1/"]) {
sh "docker push ${ARTIFACTORY_URL}/${artifactory_user}/tsdb-ingest:${TAG_VERSION}"
sh "docker push ${ARTIFACTORY_URL}/${artifactory_user}/tsdb-ingest:latest"
sh "docker push ${ARTIFACTORY_URL}/${artifactory_user}/tsdb-query:${TAG_VERSION}"
sh "docker push ${ARTIFACTORY_URL}/${artifactory_user}/tsdb-query:latest"
}
}
}

stage('update release status') {
sh "release_id=\$(curl -H \"Content-Type: application/json\" -H \"Authorization: token ${GIT_TOKEN}\" -X GET https://api.github.com/repos/${git_project_user}/${git_project}/releases/tags/v${TAG_VERSION} | python -c 'import json,sys;obj=json.load(sys.stdin);print obj[\"id\"]'); curl -v -H \"Content-Type: application/json\" -H \"Authorization: token ${GIT_TOKEN}\" -X PATCH https://api.github.com/repos/${git_project_user}/${git_project}/releases/\${release_id} -d '{\"prerelease\": false}'"
}
} else {
stage('warning') {
if (PUBLISHED_BEFORE >= 240) {
if (PUBLISHED_BEFORE >= expired) {
echo "Tag too old, published before $PUBLISHED_BEFORE minutes."
} else if (AUTO_TAG.startsWith("Autorelease")) {
echo "Autorelease does not trigger this job."
Expand All @@ -125,4 +166,4 @@ spec:
}
}
}
}
}

0 comments on commit e16a6ac

Please sign in to comment.