115 lines
3.4 KiB
Groovy
115 lines
3.4 KiB
Groovy
#!/usr/bin/env groovy
|
|
|
|
env.APPLICATION_NAME = 'db-gateway'
|
|
env.APPLICATION_LABEL = 'gateways'
|
|
env.GIT_BRANCH = 'master'
|
|
env.GIT_REPOSITORY_PATH = "github.com/andyjk15/${env.APPLICATION_NAME}.git"
|
|
env.GIT_REPOSITORY_URL = "https://${env.GIT_REPOSITORY_PATH}"
|
|
env.GITHUB_CREDENTIALS_ID = 'Registry'
|
|
env.DOCKER_REPOSITORY = 'registry.cryptosky.me'
|
|
env.DOCKER_REPOSITORY_URL = "https://${env.DOCKER_REPOSITORY}"
|
|
|
|
env.NAMESPACE = 'production'
|
|
env.SLAVE_LABEL = "cryptosky-aio-build"
|
|
|
|
env.CPU_REQUESTS = '1'
|
|
env.CPU_LIMIT = '2'
|
|
env.RAM_REQUEST = '500MiB'
|
|
env.RAM_LIMIT = '1Gi'
|
|
|
|
def mvn( String gloals ) {
|
|
sh "mvn -s configuration/settings.xml --show-version --batch-mode ${gloals}"
|
|
}
|
|
|
|
String get_application_version() {
|
|
pom = readMavenPom file: 'pom.xml'
|
|
"${pom.version}-b${env.BUILD_NUMBER}"
|
|
}
|
|
|
|
@NonCPS
|
|
def applyResource(String environment, String resourcePath, Map<String, Object> parameters) {
|
|
String command = "kubectl apply --filename ${resourcePath}"
|
|
parameters.each { String key, Object value ->
|
|
command += " --param=${key}='${value}'"
|
|
}
|
|
command += "| oc --namespace ${environment} apply --filename -"
|
|
|
|
sh "${command}"
|
|
}
|
|
|
|
def updateBuildResources(String environment) {
|
|
Map<String, Object> buildConfigParameters = [
|
|
RESOURCE_NAME : env.APPLICATION_NAME,
|
|
APP_LABEL : env.APPLICATION_LABEL,
|
|
DOCKER_REGISTRY: env.DOCKER_REGISTRY,
|
|
IMAGE_VERSION : env.APPLICATION_VERSION
|
|
]
|
|
|
|
applyResource(environment, 'configuration/templates/build-config.yaml', buildConfigParameters)
|
|
}
|
|
|
|
def deploy( Integer replicas ) {
|
|
// rollout latest
|
|
// get rollout status
|
|
|
|
// set triggers
|
|
}
|
|
|
|
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']]])
|
|
|
|
env.APPLICATION_VERSION = get_application_version()
|
|
|
|
mvn '--version'
|
|
sh "java -version"
|
|
sh "python3 --version"
|
|
}
|
|
|
|
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/BUILD_NUMBER/${env.APPLICATION_VERSION}/g' configuration/deploy-config.yaml"
|
|
// Update build config for kubernetes
|
|
// Update Service yaml for kubernetes
|
|
// Update route yaml for kubernetes
|
|
|
|
// Run kubernetes start-build
|
|
}
|
|
|
|
stage('Deploy') {
|
|
// Update/map secret.yaml if needed
|
|
|
|
|
|
deploy( 1 )
|
|
}
|
|
|
|
stage('Tag Repository') {
|
|
|
|
withDockerServer([uri: "tcp://registry.cryptosky.me:4243"]) {
|
|
withDockerRegistry([credentialsId: 'Registry', url: "${env.DOCKER_REPOSITORY_URL}"]) {
|
|
def image = docker.build("${env.DOCKER_REPOSITORY}/db-gateway:${env.APPLICATION_VERSION}")
|
|
image.push()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch ( exception ) {
|
|
throw exception
|
|
}
|