-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.js
63 lines (56 loc) · 1.93 KB
/
deploy.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
const {sEx} = require('./utils');
const fs = require('fs');
function unzipBuild(file, out_folder){
sEx(`unzip -o -q ${file} -d ${out_folder}`);
}
function setupVenv(venv_folder){
sEx(`python3 -m venv ${venv_folder}`);
}
/**
* @param {Build} build
* */
function writeEnvFile(build){
// if(fs.existsSync(build.envFile)) return;
let contents = [];
if(build.env){
for(let [k, v] of Object.entries(build.deployment.env)){
if(typeof v !== "string" || v.indexOf('"')===-1){
if(v === null){
contents.push(`${k}=`);
}else{
contents.push(`${k}='${v}'`);
}
}else{
contents.push(`${k}="${v}"`);
}
}
}
fs.writeFileSync(build.envFile, contents.join('\n'));
}
/**
* @param {Build} build
* */
function installDependencies(build){
let pip = `${build.pythonExecutable} -m pip`;
sEx(`${pip} install -q wheel`);
sEx(`${pip} install -q -r ${build.deployPath}/requirements.txt`);
writeEnvFile(build);
console.log("requirements installed...");
sEx(`cd ${build.deployPath} && ENVIRONMENT=deploy && ${build.pythonExecutable} ${build.managementFile} collectstatic --noinput -v 0`);
}
/**
* @param {Runner} runner
* */
async function deploy(runner){
for(let build of runner.project.builds){
unzipBuild(build.buildFilePath, build.deployPath);
console.log(`${build.project.qualifiedName}:${build.qualifiedName} | build moved to deployment folder and build dir cleaned`);
if(build.isDjango){
setupVenv(build.venvFolder);
console.log(`${build.project.qualifiedName}:${build.qualifiedName} | virtual environment created. Installing dependencies...`);
installDependencies(build);
console.log(`${build.project.qualifiedName}:${build.qualifiedName} | Dependencies installed`);
}
}
}
module.exports = deploy;