diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..26fa3dc3 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,120 @@ +#!/usr/bin/env groovy +def isAccountChanged = true +def isCustomerChanged = true +def isDiscoveryChanged = false +def isGatewayChanged = false +node { + stage('checkout') +{ +checkout scm +} + stage('Check for CHANGELOG update') { + sshagent(['Credential Name']) { + // sh "git config --add remote.origin.fetch +refs/heads/master:refs/remotes/origin/master" + //sh "git fetch --no-tags" + List sourceChanged = sh(returnStdout: true, script: "git diff --name-only HEAD^ origin/${env.BRANCH_NAME}").split() + for (int i = 0; i < sourceChanged.size(); i++) { + echo "** Here ***" + if (sourceChanged[i].contains("account")) { + isAccountChanged = true + } + if (sourceChanged[i].contains("customer")) { + isCustomerChanged = true + } + if (sourceChanged[i].contains("discovery")) { + isDiscoveryChanged = true + } + if (sourceChanged[i].contains("gateway")) { + isGatewayChanged = true + } + } + + } + } + } +def micro() { + stage('checkout') { + + sh "pwd ;chmod +x script.sh" + sh "pwd ; ./script.sh " + + } + stage('scrip') { + + sh "pwd ;chmod +x scrip.sh" + sh "pwd ; ./scrip.sh " + + } + stage('checkout2') { + + sh "pwd ; chmod +x script.sh" + sh "./script.sh " + + } + stage('scrip2') { + + sh "pwd ; chmod +x scrip.sh" + sh "pwd ; ./scrip.sh " + + } +} + + stage('Test') { + if (isAccountChanged == true) { + + node{ + + dir('account-service'){ + micro() + } + } + + } + + if (isCustomerChanged == true) { + + node{ + + dir('customer-service'){ + + micro() + + } + + } + + } + + } +node { + stage('deploy staging') { + if (env.BRANCH_NAME == 'master'){ +try { + // remove the old rancher stack in case it exists, if not ignore all errors + sh 'cd stack-master && rancher-compose --url http://192.168.56.101:8080/v1/projects/1a5 --access-key B9D9EDC9AF35290AF178 --secret-key DRYbZZ96uM4mNTWWMooqrQVPXDcLm95sEGjMqBNd down' + sh 'cd stack-master && rancher-compose --url http://192.168.56.101:8080/v1/projects/1a5 --access-key B9D9EDC9AF35290AF178 --secret-key DRYbZZ96uM4mNTWWMooqrQVPXDcLm95sEGjMqBNd rm' + sleep(20) + } catch (any) {} + + // now deploy the new stack + sh 'cd stack-master && rancher-compose --url http://192.168.56.101:8080/v1/projects/1a5 --access-key B9D9EDC9AF35290AF178 --secret-key DRYbZZ96uM4mNTWWMooqrQVPXDcLm95sEGjMqBNd up -d' +} + +else { + try { + // remove the old rancher stack in case it exists, if not ignore all errors + sh 'cd stack-trunk && rancher-compose --url http://192.168.56.101:8080/v1/projects/1a5 --access-key B9D9EDC9AF35290AF178 --secret-key DRYbZZ96uM4mNTWWMooqrQVPXDcLm95sEGjMqBNd down' + sh 'cd stack-trunk && rancher-compose --url http://192.168.56.101:8080/v1/projects/1a5 --access-key B9D9EDC9AF35290AF178 --secret-key DRYbZZ96uM4mNTWWMooqrQVPXDcLm95sEGjMqBNd rm' + sleep(20) + } catch (any) {} + + + // now deploy the new stack + sh 'cd stack-trunk && rancher-compose --url http://192.168.56.101:8080/v1/projects/1a5 --access-key B9D9EDC9AF35290AF178 --secret-key DRYbZZ96uM4mNTWWMooqrQVPXDcLm95sEGjMqBNd up -d' + } +} + +} + + + diff --git a/account-service/Jenkinsfile b/account-service/Jenkinsfile index e2461c86..d4a3f3fc 100644 --- a/account-service/Jenkinsfile +++ b/account-service/Jenkinsfile @@ -33,5 +33,4 @@ node { } } - -} \ No newline at end of file +} diff --git a/account-service/scrip.sh b/account-service/scrip.sh new file mode 100644 index 00000000..fbc4830c --- /dev/null +++ b/account-service/scrip.sh @@ -0,0 +1,2 @@ +#!/bin/sh +echo " yess yess account-service 2" diff --git a/account-service/script.sh b/account-service/script.sh new file mode 100644 index 00000000..fcfb6d8b --- /dev/null +++ b/account-service/script.sh @@ -0,0 +1,2 @@ +#!/bin/sh +echo " yess yess account-service" diff --git a/customer-service/scrip.sh b/customer-service/scrip.sh new file mode 100644 index 00000000..7b9d8f57 --- /dev/null +++ b/customer-service/scrip.sh @@ -0,0 +1,3 @@ + +#!/bin/sh +echo " yess yess customer-service 2 " diff --git a/customer-service/script.sh b/customer-service/script.sh new file mode 100644 index 00000000..a7d56ee9 --- /dev/null +++ b/customer-service/script.sh @@ -0,0 +1,2 @@ +#!/bin/sh +echo " yessy yess customer-service" diff --git a/stack-master/docker-compose.yml b/stack-master/docker-compose.yml new file mode 100644 index 00000000..2474d936 --- /dev/null +++ b/stack-master/docker-compose.yml @@ -0,0 +1,39 @@ +version: 2 +services: + Goauth: + image: usman/go-auth:1.8 + command: + - "-l" + - "debug" + - "run" + - "--db-host" + - "db" + - "-p" + - "9000" + labels: + + io.rancher.scheduler.affinity:host_label: branch=master + io.rancher.scheduler.affinity:container_label_soft_ne: io.rancher.stack_service.name=$${stack_name}/$${service_name} + io.rancher.container.hostname_override: container_name + db: + image: mysql + environment: + MYSQL_ROOT_PASSWORD: rootpass + MYSQL_DATABASE: messenger + MYSQL_USER: messenger + MYSQL_PASSWORD: messenger + labels: + io.rancher.scheduler.affinity:host_label: branch=master + io.rancher.scheduler.affinity:container_label_soft_ne: io.rancher.stack_service.name=$${stack_name}/$${service_name} + io.rancher.container.hostname_override: container_name + + auth-lb: + image: rancher/lb-service-haproxy:v0.6.2 + ports: + - 9000:9000/tcp + labels: + io.rancher.container.agent.role: environmentAdmin + io.rancher.container.create_agent: 'true' + io.rancher.scheduler.affinity:host_label: branch=master + io.rancher.scheduler.affinity:container_label_soft_ne: io.rancher.stack_service.name=$${stack_name}/$${service_name} + io.rancher.container.hostname_override: container_name diff --git a/stack-master/rancher-compose.yml b/stack-master/rancher-compose.yml new file mode 100644 index 00000000..84649d70 --- /dev/null +++ b/stack-master/rancher-compose.yml @@ -0,0 +1,18 @@ +version: '2' +services: + Goauth: + scale: 2 + start_on_create: true + auth-lb: + scale: 1 + start_on_create: true + lb_config: + port_rules: + - priority: 1 + protocol: http + service: Goauth + source_port: 9000 + target_port: 9000 + db: + scale: 1 + start_on_create: true diff --git a/stack-trunk/docker-compose.yml b/stack-trunk/docker-compose.yml new file mode 100644 index 00000000..f2ce5f74 --- /dev/null +++ b/stack-trunk/docker-compose.yml @@ -0,0 +1,39 @@ +version: 2 +services: + Goauth: + image: usman/go-auth:1.8 + command: + - "-l" + - "debug" + - "run" + - "--db-host" + - "db" + - "-p" + - "9000" + labels: + + io.rancher.scheduler.affinity:host_label: branch=trunk + io.rancher.scheduler.affinity:container_label_soft_ne: io.rancher.stack_service.name=$${stack_name}/$${service_name} + io.rancher.container.hostname_override: container_name + db: + image: mysql + environment: + MYSQL_ROOT_PASSWORD: rootpass + MYSQL_DATABASE: messenger + MYSQL_USER: messenger + MYSQL_PASSWORD: messenger + labels: + io.rancher.scheduler.affinity:host_label: branch=trunk + io.rancher.scheduler.affinity:container_label_soft_ne: io.rancher.stack_service.name=$${stack_name}/$${service_name} + io.rancher.container.hostname_override: container_name + + auth-lb: + image: rancher/lb-service-haproxy:v0.6.2 + ports: + - 9000:9000/tcp + labels: + io.rancher.container.agent.role: environmentAdmin + io.rancher.container.create_agent: 'true' + io.rancher.scheduler.affinity:host_label: branch=trunk + io.rancher.scheduler.affinity:container_label_soft_ne: io.rancher.stack_service.name=$${stack_name}/$${service_name} + io.rancher.container.hostname_override: container_name diff --git a/stack-trunk/rancher-compose.yml b/stack-trunk/rancher-compose.yml new file mode 100644 index 00000000..84649d70 --- /dev/null +++ b/stack-trunk/rancher-compose.yml @@ -0,0 +1,18 @@ +version: '2' +services: + Goauth: + scale: 2 + start_on_create: true + auth-lb: + scale: 1 + start_on_create: true + lb_config: + port_rules: + - priority: 1 + protocol: http + service: Goauth + source_port: 9000 + target_port: 9000 + db: + scale: 1 + start_on_create: true