Supporting pushing a container from the gradle file

This commit is contained in:
R. Tyler Croy 2017-04-19 21:50:18 -07:00
parent 0c6c425706
commit 020fa2fd17
No known key found for this signature in database
GPG Key ID: 1426C7DC3F51E16F
2 changed files with 22 additions and 15 deletions

19
Jenkinsfile vendored
View File

@ -12,8 +12,8 @@ node('docker') {
timestamps {
deleteDir()
checkout scm
docker.image('java:8-alpine').inside {
sh './gradlew --no-daemon --info war'
docker.image('java:8-alpine').inside('-v /var/run/docker.sock:/var/run/docker.sock') {
sh './gradlew --no-daemon --info'
archiveArtifacts artifacts: 'build/libs/*.war', fingerprint: true
}
}
@ -28,21 +28,12 @@ node('docker') {
}
}
def container
stage('Prepare Container') {
timestamps {
sh 'git rev-parse HEAD > GIT_COMMIT'
shortCommit = readFile('GIT_COMMIT').take(6)
def imageTag = "${env.BUILD_ID}-build${shortCommit}"
echo "Creating the container ${imageName}:${imageTag}"
container = docker.build("${imageName}:${imageTag}")
}
}
/* Assuming we're not inside of a pull request or multibranch pipeline */
if (!(env.CHANGE_ID || env.BRANCH_NAME)) {
stage('Publish container') {
timestamps { container.push() }
docker.image('java:8-alpine').inside('-v /var/run/docker.sock:/var/run/docker.sock') {
sh './gradlew --no-daemon --info push'
}
}
}
}

View File

@ -2,6 +2,7 @@ buildscript {
repositories { jcenter() }
dependencies {
classpath 'com.bmuschko:gradle-docker-plugin:3.0.6'
classpath 'org.ajoberstar:gradle-git:1.7.1'
}
}
@ -10,6 +11,14 @@ apply plugin: 'jetty'
apply plugin: 'maven'
apply plugin: 'war'
apply plugin: 'com.bmuschko.docker-remote-api'
apply plugin: 'org.ajoberstar.grgit'
import org.ajoberstar.grgit.Grgit
String containerVersion = Grgit.open('.')?.head()?.abbreviatedId
if (System.env.BUILD_ID) {
containerVersion = "${System.env.BUILD_ID}-${containerVersion}"
}
group = 'org.jenkins-ci'
description = 'User self-service account management app'
@ -56,6 +65,13 @@ war {
task container(type: com.bmuschko.gradle.docker.tasks.image.DockerBuildImage) {
description 'Build the account-app container'
inputDir projectDir
tag 'jenkinsciinfra/account-app'
tag "jenkinsciinfra/account-app:${containerVersion}"
dependsOn war
}
task pushContainer(type: com.bmuschko.gradle.docker.tasks.image.DockerPushImage) {
description 'Publish the account-app container'
imageName 'jenkinsciinfra/account-app'
tag containerVersion
dependsOn container
}