Skip to content

Commit

Permalink
add Jenkinsfile (#1) (#2)
Browse files Browse the repository at this point in the history
* add Jenkinsfile, Makefile
  • Loading branch information
gkirok authored Feb 11, 2019
1 parent 1f47980 commit 2caa114
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 0 deletions.
117 changes: 117 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -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: "[email protected]: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: "[email protected]:${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.")
}
}
}
}
}
}
}
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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) .

0 comments on commit 2caa114

Please sign in to comment.