diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..595c065f --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,117 @@ +label = "${UUID.randomUUID().toString()}" +BUILD_FOLDER = "/go" +expired=240 +git_project = "app-resource-scaler" +git_project_user = "v3io" +git_deploy_user_token = "iguazio-prod-git-user-token" +git_deploy_user_private_key = "iguazio-prod-git-user-private-key" + +podTemplate(label: "${git_project}-${label}", yaml: """ +apiVersion: v1 +kind: Pod +metadata: + name: "${git_project}-${label}" + labels: + jenkins/kube-default: "true" + app: "jenkins" + component: "agent" +spec: + shareProcessNamespace: true + containers: + - name: jnlp + image: jenkins/jnlp-slave + resources: + limits: + cpu: 1 + memory: 2Gi + requests: + cpu: 1 + memory: 2Gi + volumeMounts: + - name: go-shared + mountPath: /go + - name: docker-cmd + image: docker + command: [ "/bin/sh", "-c", "--" ] + args: [ "apk add make; while true; do sleep 30; done;" ] + volumeMounts: + - name: docker-sock + mountPath: /var/run + - name: go-shared + mountPath: /go + volumes: + - name: docker-sock + hostPath: + path: /var/run + - name: go-shared + emptyDir: {} +""" +) { + node("${git_project}-${label}") { + withCredentials([ + string(credentialsId: git_deploy_user_token, variable: 'GIT_TOKEN') + ]) { + def TAG_VERSION + def DOCKER_TAG_VERSION + pipelinex = library(identifier: 'pipelinex@DEVOPS-204-pipelinex', retriever: modernSCM( + [$class: 'GitSCMSource', + credentialsId: git_deploy_user_private_key, + remote: "git@github.com:iguazio/pipelinex.git"])).com.iguazio.pipelinex + multi_credentials=[pipelinex.DockerRepo.ARTIFACTORY_IGUAZIO, pipelinex.DockerRepo.DOCKER_HUB, pipelinex.DockerRepo.QUAY_IO] + + common.notify_slack { + stage('get tag data') { + container('jnlp') { + TAG_VERSION = github.get_tag_version(TAG_NAME) + DOCKER_TAG_VERSION = github.get_docker_tag_version(TAG_NAME) + PUBLISHED_BEFORE = github.get_tag_published_before(git_project, git_project_user, "${TAG_VERSION}", GIT_TOKEN) + + echo "$TAG_VERSION" + echo "$PUBLISHED_BEFORE" + } + } + + if (TAG_VERSION != null && TAG_VERSION.length() > 0 && PUBLISHED_BEFORE < expired) { + stage('prepare sources') { + container('jnlp') { + dir("${BUILD_FOLDER}/src/github.com/v3io/${git_project}") { + git(changelog: false, credentialsId: git_deploy_user_private_key, poll: false, url: "git@github.com:${git_project_user}/${git_project}.git") + sh("git checkout ${TAG_VERSION}") + } + } + } + + stage("build ${git_project} in dood") { + container('docker-cmd') { + dir("${BUILD_FOLDER}/src/github.com/v3io/${git_project}") { + sh("SCALER_TAG=${DOCKER_TAG_VERSION} SCALER_REPOSITORY='' make build") + } + } + } + + stage('push') { + container('docker-cmd') { + dockerx.images_push_multi_registries(["autoscaler:${DOCKER_TAG_VERSION}", "dlx:${DOCKER_TAG_VERSION}"], multi_credentials) + } + } + + stage('update release status') { + container('jnlp') { + github.update_release_status(git_project, git_project_user, "${TAG_VERSION}", GIT_TOKEN) + } + } + } else { + stage('warning') { + if (PUBLISHED_BEFORE >= expired) { + currentBuild.result = 'ABORTED' + error("Tag too old, published before $PUBLISHED_BEFORE minutes.") + } else { + currentBuild.result = 'ABORTED' + error("${TAG_VERSION} is not release tag.") + } + } + } + } + } + } +} diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..c519d103 --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +SCALER_TAG ?= unstable +SCALER_REPOSITORY ?= iguazio/ + +.PHONY: build +build: dlx autoscaler + @echo Done. + +.PHONY: dlx +dlx: + docker build -f dlx/Dockerfile --tag=$(SCALER_REPOSITORY)dlx:$(SCALER_TAG) . + +.PHONY: autoscaler +autoscaler: + docker build -f autoscaler/Dockerfile --tag=$(SCALER_REPOSITORY)autoscaler:$(SCALER_TAG) .