Skip to content

Commit

Permalink
Merge pull request #63 from stakater/add-buildah-support
Browse files Browse the repository at this point in the history
Add basic support for buildah in releaseApplication
  • Loading branch information
kahootali authored Jun 8, 2020
2 parents 2bcad7d + e1019e7 commit ff9ffd5
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/io/stakater/app/App.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
package io.stakater.app

Map configure(Map parameters = [:]) {
println "Pipeline Parameters: "
parameters.each{ k, v -> println "${k}:${v}" }

String appType = parameters.appType ?: "angular"

configureByAppType(appType, parameters)
Expand Down Expand Up @@ -96,6 +99,7 @@ def build(String appType, String version, String goal) {
def builder = new io.stakater.builder.Build()
String parsedGoal = parseGoalEnvironment(goal)

echo "TODO: build: $version , $parsedGoal"
switch(appType) {
case "angular":
builder.buildAngularApplication(version, parsedGoal)
Expand Down
2 changes: 2 additions & 0 deletions src/io/stakater/app/AppConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Map getPackageConfig(Map config) {
packageConfig.chartPackageName = ""
packageConfig.helmVersion = ""
packageConfig.dockerRepositoryURL = config.dockerRepositoryURL ?: ""
packageConfig.useBuildah = config.useBuildah ?: false
packageConfig.buildahVerifyTls = config.buildahVerifyTls ?: false

packageConfig.javaRepositoryURL = config.javaRepositoryURL ?: ""
packageConfig.publishArtifact = ! packageConfig.javaRepositoryURL.equals("")
Expand Down
1 change: 1 addition & 0 deletions src/io/stakater/builder/Build.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package io.stakater.builder

def buildMavenApplication(String version, String mavenGoal = "clean package"){
sh "mvn -version"
sh "mvn versions:set -DnewVersion=${version} -f pom.xml"
mavenGoal.split(';').each { goal ->
sh "mvn ${goal} -f pom.xml"
Expand Down
21 changes: 21 additions & 0 deletions src/io/stakater/containers/Buildah.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/groovy
package io.stakater.containers


def buildImageWithTagCustom(def imageName, def tag, def verifyTls) {
buildImageWithTagCustom(".", imageName, tag, verifyTls)
}

def buildImageWithTagCustom(def buildContext, def imageName, def tag, def verifyTls) {
sh """
buildah --storage-driver=vfs build-using-dockerfile --tls-verify=${verifyTls} --layers -f ${buildContext} -t ${imageName}:${tag} .
"""
}

def pushTagCustom(def imageName, def tag, def verifyTls) {
sh """
buildah --storage-driver=vfs push --tls-verify=${verifyTls} ${imageName}:${tag} docker://${imageName}:${tag}
"""
}

return this
19 changes: 11 additions & 8 deletions src/io/stakater/pods/Pod.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ def setToolsImage(Map parameters = [:], String image) {
parameters.podContainers.defaultContainer.image = image
}

def mountDockerSocket(Map parameters = [:]) {
setPodVolumes(parameters)
parameters.podVolumes.isDockerMount = true
}

Map setDockerConfig(Map parameters = [:]) {
mountDockerSocket(parameters)
setPodVolumes(parameters)
setDefaultContainerEnvVarsConfig(parameters)

parameters.podVolumes.isDockerConfig = true
parameters.podContainers.defaultContainer.envVarsConfig.isDocker = true
// Don't mount docker socket if useBuildah is true or isDockerMount is false
if (!parameters.get('useBuildah', false ) && parameters.get('isDockerMount', true )) {
parameters.podVolumes.isDockerMount = true
parameters.podContainers.defaultContainer.envVarsConfig.isDocker = true
}

// Don't mount docker config if isDockerConfig exists and is false
if (parameters.get('isDockerConfig', true )) {
parameters.podVolumes.isDockerConfig = true
}
return parameters
}

Expand Down
13 changes: 11 additions & 2 deletions vars/releaseApplication.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def call(body) {
Map kubernetesConfig = appConfig.getKubernetesConfig(config)

def docker = new io.stakater.containers.Docker()
def buildah = new io.stakater.containers.Buildah()
def git = new io.stakater.vc.Git()
def utils = new io.fabric8.Utils()
def chartManager = new io.stakater.charts.ChartManager()
Expand Down Expand Up @@ -96,8 +97,16 @@ def call(body) {
}

stage('Image build & push') {
docker.buildImageWithTagCustom(dockerImage, version)
docker.pushTagCustom(dockerImage, version)
if (packageConfig.useBuildah) {
echo "Using buildah to build image"
buildah.buildImageWithTagCustom(dockerImage, version, packageConfig.buildahVerifyTls)
buildah.pushTagCustom(dockerImage, version, packageConfig.buildahVerifyTls)
}
else {
echo "Using docker to build image"
docker.buildImageWithTagCustom(dockerImage, version)
docker.pushTagCustom(dockerImage, version)
}
}

stage('Package chart' ) {
Expand Down
5 changes: 4 additions & 1 deletion vars/stakaterPodTemplate.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import io.fabric8.Fabric8Commands
def call(Map parameters = [:], body) {
def flow = new Fabric8Commands()

println "StakaterPodTemplate Parameters: "
parameters.each{ k, v -> println "${k}:${v}" }

def defaultLabel = buildId('stakater-node')
def label = parameters.get('label', defaultLabel)
def serviceAccount = parameters.get('serviceAccount', 'jenkins')
Expand Down Expand Up @@ -184,7 +187,7 @@ def getStakaterPodContainers(Map parameters = [:]) {

def getStakaterPodDefaultContainer(Map parameters = [:]) {
String name = parameters.get('name', 'tools')
String image = parameters.get('image', 'stakater/pipeline-tools:v2.1.2')
String image = parameters.get('image', 'stakater/pipeline-tools:v2.1.3')
String command = parameters.get('command', '/bin/sh -c')
String args = parameters.get('args', 'cat')
Boolean privileged = parameters.get('privileged', true)
Expand Down

0 comments on commit ff9ffd5

Please sign in to comment.