diff --git a/configuration/pipelines/build.groovy b/configuration/pipelines/build.groovy index e10aa31..22c1d29 100644 --- a/configuration/pipelines/build.groovy +++ b/configuration/pipelines/build.groovy @@ -27,6 +27,10 @@ String get_application_version() { "${pom.version}-b${env.BUILD_NUMBER}" } +String executeShellScript( String shellPath, String arg1 = '', String arg2 = '', String arg3 = '', String arg4 = '' ) { + sh "./${shellPath} ${arg1} ${arg2} ${arg3} ${arg4}" +} + try { timestamps { node ("${env.SLAVE_LABEL}") { @@ -44,7 +48,7 @@ try { usernameVariable: 'DOCTL_USERNAME' )] ) { - sh "doctl auth init --access-token '${DOCTL_TOKEN}'" + sh "doctl auth init --access-token ${DOCTL_TOKEN}" sh "doctl kubernetes cluster kubeconfig save cryptosky-kubernetes-cluster-production" } } @@ -64,18 +68,16 @@ try { stage('Build Image') { mvn 'clean package -DskipTests' - sh "sed -i 's/REPOSITORY/${env.DOCKER_REPOSITORY}/g' configuration/kubernetes/deployment.yaml" - sh "sed -i 's/IMAGE/${env.APPLICATION_NAME}:${env.APPLICATION_VERSION}/g' configuration/kubernetes/deployment.yaml" - sh "sed -i 's/RESOURCE_NAME/${env.APPLICATION_NAME}/g' configuration/kubernetes/deployment.yaml" - sh "sed -i 's/LABEL/${env.APPLICATION_LABEL}/g' configuration/kubernetes/deployment.yaml" - - sh "sed -it 's/RESOURCE_NAME/${env.APPLICATION_NAME}/g' configuration/kubernetes/service.yaml" - sh "sed -it 's/LABEL/${env.APPLICATION_LABEL}/g' configuration/kubernetes/service.yaml" + executeShellScript("configuration/kubernetes/mapVarsToConfigs.sh", + env.DOCKER_REPOSITORY, + env.APPLICATION_NAME, + env.APPLICATION_VERSION, + env.APPLICATION_LABEL) } stage('Tag Repository') { - withDockerServer([uri: "tcp://registry.cryptosky.me:4243"]) { + withDockerServer([uri: "${env.DOCKER_REPOSITORY_TCP}"]) { withDockerRegistry([credentialsId: 'Registry', url: "${env.DOCKER_REPOSITORY_URL}"]) { def image = docker.build("${env.DOCKER_REPOSITORY}/db-gateway:${env.APPLICATION_VERSION}") image.push() diff --git a/configuration/scripts/deployToKubernetes.sh b/configuration/scripts/deployToKubernetes.sh new file mode 100644 index 0000000..20d602b --- /dev/null +++ b/configuration/scripts/deployToKubernetes.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash + diff --git a/configuration/scripts/mapVarsToConfigs.sh b/configuration/scripts/mapVarsToConfigs.sh new file mode 100644 index 0000000..94a8400 --- /dev/null +++ b/configuration/scripts/mapVarsToConfigs.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +DOCKER_REPOSITORY=$1 +APPLICATION_NAME=$2 +APPLICATION_VERSION=$3 +APPLICATION_LABEL=$4 + +sh "sed -i 's/REPOSITORY/${DOCKER_REPOSITORY}/g' configuration/kubernetes/deployment.yaml" +sh "sed -i 's/IMAGE/${APPLICATION_NAME}:${APPLICATION_VERSION}/g' configuration/kubernetes/deployment.yaml" +sh "sed -i 's/RESOURCE_NAME/${APPLICATION_NAME}/g' configuration/kubernetes/deployment.yaml" +sh "sed -i 's/LABEL/${APPLICATION_LABEL}/g' configuration/kubernetes/deployment.yaml" + +sh "sed -it 's/RESOURCE_NAME/${APPLICATION_NAME}/g' configuration/kubernetes/service.yaml" +sh "sed -it 's/LABEL/${APPLICATION_LABEL}/g' configuration/kubernetes/service.yaml" \ No newline at end of file