Blame view

kea_testing.groovy 5.62 KB
a7a0d7905   George Vlahavas   Add initial Jenki...
1
2
3
4
5
6
7
8
9
10
  /**
  * Jenkinsfile to deploy multiple Docker containers based on docker-compose into a DEV server and run any test.
  * This pipeline will run the Docker containers, execute the tests and then stop and remove the containers from the DEV  
  * server automatically.
  **/
  
  
  pipeline {
  
    agent any
097a24e19   George Vlahavas   Fix whitespace
11
      environment {
a7a0d7905   George Vlahavas   Add initial Jenki...
12
13
14
        // Keep as is the following two lines
        PRIVATE_REGISTRY = "https://registry.curex-project.eu:443/curex-local/"
        ARTIFACTORY_URL = "registry.curex-project.eu:443/curex-local/"
cfd27a3cb   George Vlahavas   Add back all tests
15
16
        HOST_IP = "116.203.166.220"
        DEPLOYMENT_HOST = "${HOST_IP}:2376"
a7a0d7905   George Vlahavas   Add initial Jenki...
17
        DEPLOYMENT_HOST_CREDENTIALS = "vm2-creds"
fb793d4ad   George Vlahavas   Revert "Revert "A...
18
19
        
        // KEA specific
35edb5121   George Vlahavas   Quote variables
20
21
22
        APP_NAME = "KEA"
        APP_ENV = "production"
        APP_DEBUG = "true"
cfd27a3cb   George Vlahavas   Add back all tests
23
        APP_URL = "http://${HOST_IP}"
fa1611371   George Vlahavas   Add KIBANA_PORT a...
24
25
26
  
        KIBANA_PORT = "5611"
        GRAFANA_PORT = "3001"
fb793d4ad   George Vlahavas   Revert "Revert "A...
27
        
35edb5121   George Vlahavas   Quote variables
28
        LOG_CHANNEL = "stack"
fb793d4ad   George Vlahavas   Revert "Revert "A...
29
        
35edb5121   George Vlahavas   Quote variables
30
31
32
33
34
35
        DB_CONNECTION = "pgsql"
        DB_HOST = "timescaledb"
        DB_PORT = "5432"
        DB_DATABASE = "kea"
        DB_USERNAME = "postgres"
        DB_PASSWORD = "postgres"
fb793d4ad   George Vlahavas   Revert "Revert "A...
36
        
35edb5121   George Vlahavas   Quote variables
37
38
39
40
41
        BROADCAST_DRIVER = "log"
        CACHE_DRIVER = "file"
        QUEUE_CONNECTION = "sync"
        SESSION_DRIVER = "file"
        SESSION_LIFETIME = "120"
fb793d4ad   George Vlahavas   Revert "Revert "A...
42
        
35edb5121   George Vlahavas   Quote variables
43
        JWT_TTL = "1440"
fb793d4ad   George Vlahavas   Revert "Revert "A...
44
        
35edb5121   George Vlahavas   Quote variables
45
46
47
        ELASTICSEARCH_HOST = "elasticsearch"
        ELASTICSEARCH_PORT = "9200"
        ELASTICSEARCH_SCHEME = "http"
fb793d4ad   George Vlahavas   Revert "Revert "A...
48
        
35edb5121   George Vlahavas   Quote variables
49
50
51
52
53
        MQTT_HOST = "mosquitto"
        MQTT_PORT = "1883"
        MQTT_DEBUG = "false"
        MQTT_QOS = "0"
        MQTT_RETAIN = "0"
fb793d4ad   George Vlahavas   Revert "Revert "A...
54
        
35edb5121   George Vlahavas   Quote variables
55
56
57
58
        MLTD_HOST = "mltd"
        MLTD_PORT = "5000"
        OD_HOST = "od"
        OD_PORT = "9091"
a7a0d7905   George Vlahavas   Add initial Jenki...
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
      }
  
    stages {
             
      stage('Checkout the source code') {
        steps {
          checkout scm
        }
      }
      
    
      stage('Deploy Docker containers in DEV server') {
        steps {
          script {
            docker.withServer("$DEPLOYMENT_HOST", "$DEPLOYMENT_HOST_CREDENTIALS") {
              docker.withRegistry("$PRIVATE_REGISTRY" , 'artifactory') {
a7a0d7905   George Vlahavas   Add initial Jenki...
75
76
                echo 'Deploying the specified Docker containers in DEV server'
                sh 'sh deploy.sh'
a7a0d7905   George Vlahavas   Add initial Jenki...
77
78
79
80
81
              }
            }
          }
        }
      }
097a24e19   George Vlahavas   Fix whitespace
82
83
  
      stage('Run tests') {
a7a0d7905   George Vlahavas   Add initial Jenki...
84
85
        steps {
          script {
f7afd8ea9   George Vlahavas   Add a simple test
86
87
88
            echo '*************'
            echo '*** TESTS ***'
            echo '*************'
a7a0d7905   George Vlahavas   Add initial Jenki...
89
            /* Here do your tests */
21b0aad19   George Vlahavas   Wait a bit more
90
            sleep 90
f7afd8ea9   George Vlahavas   Add a simple test
91
            try {
686bf5b89   George Vlahavas   Add tests KEA_F00...
92
              String testName = "KEA_F001"
f58964f4c   George Vlahavas   Remove port from ...
93
              String url = "$APP_URL:13880"
f7afd8ea9   George Vlahavas   Add a simple test
94
95
96
97
              String responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' $url -o /dev/null", returnStdout: true)
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
cfd27a3cb   George Vlahavas   Add back all tests
98
99
              testName = "KEA_F004"
              url = "mqtt://${HOST_IP}:1883/test"
e53becc12   George Vlahavas   Replace parens wi...
100
              responseCode = sh(label: testName, script: "sleep 2 ; curl -d 1 $url & OUT=`curl -m 4 -s $url` ; echo $OUT", returnStdout: true)
cfd27a3cb   George Vlahavas   Add back all tests
101
102
103
104
              if (responseCode != 'test1') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
              testName = "KEA_F005"
8f78eca8a   George Vlahavas   Escape dollar sign
105
              responseCode = sh(label: testName, script: "docker exec -ti kea_timescaledb psql -l -U postgres | grep -q kea ; echo \$?", returnStdout: true)
cfd27a3cb   George Vlahavas   Add back all tests
106
107
108
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
55bf5645f   George Vlahavas   Move F004 and F00...
109
110
111
112
113
114
115
116
117
118
119
120
              testName = "KEA_F002"
              url = "$APP_URL:13880/components/od"
              responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' $url -o /dev/null", returnStdout: true)
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
              testName = "KEA_F003"
              url = "$APP_URL:13880/components/mltd"
              responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' $url -o /dev/null", returnStdout: true)
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
cfd27a3cb   George Vlahavas   Add back all tests
121
122
123
124
125
126
127
128
129
130
131
132
133
              testName = "KEA_F006"
              url = "$APP_URL:3001"
              responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' $url -o /dev/null", returnStdout: true)
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
              testName = "KEA_F007"
              url = "$APP_URL:5611"
              responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' $url -o /dev/null", returnStdout: true)
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
              testName = "KEA_F008"
55bf5645f   George Vlahavas   Move F004 and F00...
134
              url = "$APP_URL:13880/components/ceptd"
a440995cf   George Vlahavas   Move KEA_F003 to ...
135
136
137
138
              responseCode = sh(label: testName, script: "curl -m 10 -sLI -w '%{http_code}' $url -o /dev/null", returnStdout: true)
              if (responseCode != '200') {
                error("$testName: Returned status code = $responseCode when calling $url")
              }
f7afd8ea9   George Vlahavas   Add a simple test
139
140
141
142
            } catch (ignored) {
              currentBuild.result = 'FAILURE'
              echo "KEA Deployment Tests failed"
            }
a7a0d7905   George Vlahavas   Add initial Jenki...
143
144
145
          }
        }
      }
097a24e19   George Vlahavas   Fix whitespace
146
      stage('Stop and remove the Docker containers in DEV server') {
a7a0d7905   George Vlahavas   Add initial Jenki...
147
148
149
150
        steps {
          script {
            docker.withServer("$DEPLOYMENT_HOST", "$DEPLOYMENT_HOST_CREDENTIALS") {
              docker.withRegistry("$PRIVATE_REGISTRY" , 'artifactory') {
6b0c5116d   George Vlahavas   Comment out delet...
151
                //echo 'Stop and remove the specified Docker containers from the DEV server'
5d461aebf   George Vlahavas   Delete containers...
152
                sh 'sh delete.sh'
a7a0d7905   George Vlahavas   Add initial Jenki...
153
154
155
156
157
158
              
              }
            }
          }
        }
      }
a7a0d7905   George Vlahavas   Add initial Jenki...
159
160
    }
  }
097a24e19   George Vlahavas   Fix whitespace
161