diff --git a/configuration/kubernetes/deployment.yaml b/configuration/kubernetes/deployment.yaml index 9f7dfc0..c80d13b 100644 --- a/configuration/kubernetes/deployment.yaml +++ b/configuration/kubernetes/deployment.yaml @@ -72,4 +72,4 @@ spec: memory: 256Mi restartPolicy: Always imagePullSecrets: - - name: $KUBERNETES_SECRET_NAME \ No newline at end of file + - name: registry-secret \ No newline at end of file diff --git a/configuration/pipelines/build.groovy b/configuration/pipelines/build.groovy index 5b9eaf2..fff701c 100644 --- a/configuration/pipelines/build.groovy +++ b/configuration/pipelines/build.groovy @@ -46,87 +46,80 @@ def deploy( Integer replicas ) { } try { -// timestamps { - node ("${env.SLAVE_LABEL}") { - stage('Initialise') { - checkout([$class: 'GitSCM', branches: [[name: 'master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'Github', url: 'https://github.com/andyjk15/db-gateway.git']]]) + timestamps { + node ("${env.SLAVE_LABEL}") { + stage('Initialise') { + checkout([$class: 'GitSCM', branches: [[name: 'master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'Github', url: 'https://github.com/andyjk15/db-gateway.git']]]) - env.APPLICATION_VERSION = get_application_version() + env.APPLICATION_VERSION = get_application_version() - mvn '--version' + mvn '--version' - withCredentials( - [usernamePassword( - credentialsId: 'doctl', - passwordVariable: 'DOCTL_TOKEN', - usernameVariable: 'DOCTL_USERNAME' - )] - ) { - sh "doctl auth init --access-token '${DOCTL_TOKEN}'" - sh "doctl kubernetes cluster kubeconfig save cryptosky-kubernetes-cluster-production" - } - } - - stage('Build Artifact') { - mvn 'compile' - } - - stage('Test Artifact') { - try { - mvn 'verify -DskipUTs -DskipTests' - } finally { - mvn 'test' - } - } - - 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" - } - - stage('Tag Repository') { - - 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() - def latest = docker.build("${env.DOCKER_REPOSITORY}/db-gateway:latest") - latest.push() + withCredentials( + [usernamePassword( + credentialsId: 'doctl', + passwordVariable: 'DOCTL_TOKEN', + usernameVariable: 'DOCTL_USERNAME' + )] + ) { + sh "doctl auth init --access-token '${DOCTL_TOKEN}'" + sh "doctl kubernetes cluster kubeconfig save cryptosky-kubernetes-cluster-production" } } -// } -// withCredentials( -// [usernamePassword( -// credentialsId: env.BITBUCKET_CREDENTIALS_ID, -// passwordVariable: 'GIT_PASSWORD', -// usernameVariable: 'GIT_USERNAME' -// )] -// ) { -// sh "git tag ${env.APPLICATION_VERSION}" -// sh "git push https://${GIT_USERNAME}:${GIT_PASSWORD}@${env.GIT_REPOSITORY_PATH} ${env.APPLICATION_VERSION}" -// } - } - stage('Deploy') { - sh "kubectl apply -f configuration/kubernetes/deployment.yaml" - sh "kubectl apply -f configuration/kubernetes/service.yaml" + stage('Build Artifact') { + mvn 'compile' + } - sh "kubectl get pods" -// kubernetesDeploy configs: '**/configuration/kubernetes/*.yaml', -// deleteResource: true, -// dockerCredentials: [[credentialsId: 'Registry', url: "${env.DOCKER_REPOSITORY_URL}"]], -// kubeConfig: [path: ''], -// kubeconfigId: 'Kubernetes', -//// secretName: '', -// ssh: [sshCredentialsId: '*', sshServer: ''], -// textCredentials: [certificateAuthorityData: '', clientCertificateData: '', clientKeyData: '', serverUrl: 'https://'] + stage('Test Artifact') { + try { + mvn 'verify -DskipUTs -DskipTests' + } finally { + mvn 'test' + } + } + + 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" + } + + stage('Tag Repository') { + + 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() + def latest = docker.build("${env.DOCKER_REPOSITORY}/db-gateway:latest") + latest.push() + } + } + // } + // withCredentials( + // [usernamePassword( + // credentialsId: env.BITBUCKET_CREDENTIALS_ID, + // passwordVariable: 'GIT_PASSWORD', + // usernameVariable: 'GIT_USERNAME' + // )] + // ) { + // sh "git tag ${env.APPLICATION_VERSION}" + // sh "git push https://${GIT_USERNAME}:${GIT_PASSWORD}@${env.GIT_REPOSITORY_PATH} ${env.APPLICATION_VERSION}" + // } + } + + stage('Deploy') { + sh "kubectl apply -f configuration/kubernetes/deployment.yaml" + sh "kubectl apply -f configuration/kubernetes/service.yaml" + + sh "kubectl get pods" + } } } } catch ( exception ) {