-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·90 lines (84 loc) · 2.27 KB
/
index.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
85
86
87
88
89
90
const { join } = require('path')
const { readFileSync } = require('fs')
const { spawn } = require('child_process')
const async = require('async')
const tar = require('tar-stream')
const scrape = require('scrape-it')
const Docker = require('dockerode')
const { process: dockerfile } = require('dockerfile-template')
const template = readFileSync(
join(__dirname, 'Dockerfile.template'), 'utf8'
)
var docker = new Docker({
socketPath: '/var/run/docker.sock'
})
function versions (cb) {
scrape(
'http://www.nvidia.com/object/linux-amd64-display-archive.html',
{
all: {
listItem: '#pressRoom .pressItem',
data: {
NVIDIA_VERSION: {
selector: 'p',
convert: t => {
return t
.split('\r\n')[0]
.split('Operating')[0]
.replace('Version: ', '')
}
}
}
}
}, cb
)
}
function start (items, [ BASE, BASE_TAG, DOCKER_TAG ]) {
async.eachSeries(
items.all,
function ({ NVIDIA_VERSION }, cb) {
let TAG = `${DOCKER_TAG}:${NVIDIA_VERSION}`
console.log('* Starting:', TAG)
// start an archive for our Dockerfile template
let pack = tar.pack()
// start image build, adding our tar stream
let d = docker.buildImage(
pack,
{ t: TAG },
function(err, stream) {
if (err) return
stream.pipe(process.stdout, { end: true })
stream.on('end', function() {
console.log('* Finished:', DOCKER_TAG + NVIDIA_VERSION)
spawn('docker', ['push', TAG], {
detached: false,
stdio: [process.stdin, process.stdout, process.stderr]
})
cb()
})
}
)
// write our dockerfile template to a tar stream
let entry = pack.entry(
{ name: 'Dockerfile' },
dockerfile(template, {
BASE, BASE_TAG, NVIDIA_VERSION
}),
function (err) {
if (err) throw err
pack.finalize()
}
)
},
function (err) {
if (err) throw err
}
)
}
// get each nvidia version
versions((err, items) => {
// compile multiple base images
[
['node', '6.5.0-slim', 'nucleardreamer/node-nvidia']
].map(m => start(items, m))
})