-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner-01.js
84 lines (64 loc) · 2.68 KB
/
runner-01.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// node-http
const rp = require('request-promise')
const path = require('path')
const pusher = require('@uet/pusher')
const u = require('./helper/util')
const source = require('./source')
const p1 = require('./pipelines/01-prepare-repo')
const p2 = require('./pipelines/02-generate-env')
async function start(jobId, secret, studentRepo, mentorRepo) {
try {
// clone projects
await p1.run(studentRepo, mentorRepo)
const env_mentor = p2.run({JOB_ID: jobId, SUBMIT_SECRET: secret})
const env_student = p2.run({})
await startStudentServer(studentRepo, env_student)
await runMentorTests(mentorRepo, env_mentor)
await cleanStack(env_student, env_mentor)
console.log('--------- exit with success 🎉 -------')
} catch (err){
console.log('--------- exit with error 🙊 -------')
console.log(err.message)
pusher.settings({secret})
pusher.submit({
id: jobId,
is_pass: false,
message: err.message,
std_out: '',
})
}
}
async function startStudentServer(studentRepo, env) {
// make sure old stack is removed
await u._runBash(env + ' docker-compose -f docker-compose/runner-01/student-server-runner.yml rm -sf')
console.log('-------- clean student\'s server stack done --------')
// install node_modules
await u._runBash('cd tmp/student-repo && npm install')
// start test-server stack: nodejs + mongodb
await u._runBash(env + ' docker-compose -f docker-compose/runner-01/student-server-runner.yml up -d')
console.log('-------- start test-server done --------')
// checking test-server ready
await u._try(30, 1000, 'test-server is unhealthy', checkHealth, null)
console.log('test-server is ready')
}
async function runMentorTests(mentorRepo, env) {
// make sure old stack is removed
await u._runBash(`docker-compose -f docker-compose/runner-01/mentor-test-runner.yml rm -sf`)
console.log('-------- clean mentor\'s server stack done --------')
// install node_modules
await u._runBash('cd tmp/mentor-repo && npm install')
// start stack: nodejs
const text = await u._runBash(env + ` docker-compose -f docker-compose/runner-01/mentor-test-runner.yml up`)
console.log('text mentor bash', text)
console.log('-------- start run tests done --------')
}
async function cleanStack(env_student, env_mentor) {
await u._runBash(env_student + ' docker-compose -f docker-compose/runner-01/student-server-runner.yml rm -sf')
console.log('-------- clean student\'s server stack done --------')
await u._runBash(env_mentor + ' docker-compose -f docker-compose/runner-01/mentor-test-runner.yml rm -sf')
console.log('-------- clean mentor\'s server stack done --------')
}
async function checkHealth() {
const response = await rp('http://localhost:6001')
}
exports.start = start