I need to deploy a spring boot app (docker image) in openshift via jenkins, to achieve this I am doing the below steps,
The above two steps are completed and working, But I am struggling to deploy that docker image (which is in Artifactory registory) to openshift server via jenkins pipeline, It seems like its a common requirement but I did not find any good documentation on this, any help would be much appreciated.
There are a few solutions ranging depending on your level of commitment and level of automation DevOps integration wanted:
oc
command line tool into your Jenkins agents\slaves (usually best if you ran on machines or VMs), you can create an environment variable to hold the application name and as long as you created it with oc new-app
or similar you can execute oc import-image
followed by the ImageStream name nad it will check the docker repo tag for changes in the version hash (and if the hash changed it will update it). check here for basic token injecting to avoid password spills through git.example Jenkinsfile snippet:
pipeline {
agent { 'jenkins_slave_vm' }
environment {
SERVICE='myapp'
}
stages {
stage('build&push') {
steps {
sh "docker build -t myrepo/${SERVICE}:latest -f Dockerfile.production ."
sh "docker push myrepo/${SERVICE}:latest"
}
}
stage('deploy') {
steps {
sh "oc login --token=${OC_IMAGE_UPDATE_TOKEN}"
sh "oc import-image ${SERVICE}"
}
}
}
}
Dockerfile
configuration, S2I
or fully managed by openshift using the pipeline
method (though more complex and very platform invested compared to the other two), here's a fairly latest explanation for openshift 4.6 though existed since version 3.x as well. This method allows for a more declarative, reproducible, and in the long term consistent build strategy and is the one we at my current organization are currently using for the resource-saving and the consistency that originally came with the rise of containers.