-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathpython.js
More file actions
59 lines (53 loc) · 1.54 KB
/
Copy pathpython.js
File metadata and controls
59 lines (53 loc) · 1.54 KB
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
const fs = require('fs')
const util = require('util')
const path = require('path')
const readFile = util.promisify(fs.readFile)
module.exports = {
name: 'python',
detect: options => {
return fs.existsSync(path.join(options.target, 'requirements.txt'))
},
dockerfile: ({ entrypoint, ports }) => {
if (fs.existsSync(entrypoint)) entrypoint = 'python ' + entrypoint
return [
'FROM python:3',
'WORKDIR /app',
'ARG ENV=production',
'RUN apt-get update && apt-get install -yqq inotify-tools',
'COPY requirements.txt ./',
'RUN pip install --no-cache-dir -r requirements.txt',
'COPY . .',
entrypoint
? `CMD [${entrypoint
.split(' ')
.map(e => `"${e}"`)
.join(', ')}]`
: ''
].join('\n')
},
artifact: (env, image) => {
return {
image,
sync: {},
docker: { buildArgs: { ENV: env } }
}
},
matchModules: async function (modules, options) {
const matchedModules = []
let requirementsFile = ''
try {
requirementsFile = (
await readFile(path.join(options.target, './requirements.txt'))
).toString()
} catch (err) {}
const dependencies = requirementsFile.split('\n')
for (let i = 0; i < dependencies.length; i++) {
const dep = dependencies[i].split(' ')[0]
const mod = modules.find(mod => {
return mod.languages && mod.languages[this.name] && mod.languages[this.name].includes(dep)
})
if (mod) matchedModules.push(mod)
}
return matchedModules
}
}