108 lines
3.0 KiB
Python
Raw Normal View History

2019-07-22 21:01:26 +03:00
# This Python file uses the following encoding: utf-8
2019-10-06 20:17:52 +03:00
from BuildBotLib.basemodule import BaseModule
2019-07-22 21:01:26 +03:00
from buildbot.plugins import secrets, util, steps
from pathlib import Path
import datetime
import os
import subprocess
from BuildBotLib.secretManager import *
2019-07-23 17:13:55 +03:00
2019-10-06 19:29:14 +03:00
class NPM(BaseModule):
2019-07-23 17:13:55 +03:00
2019-10-06 19:29:14 +03:00
def __init__(self):
BaseModule.__init__(self);
2019-07-23 17:17:08 +03:00
2019-10-06 19:29:14 +03:00
def isStopForce(self, step):
return step.getProperty('stopForce');
2019-07-22 21:01:26 +03:00
2019-10-06 19:29:14 +03:00
def isLog(self, step):
return step.getProperty('showLog');
2019-07-27 20:57:10 +03:00
2019-10-06 19:29:14 +03:00
def getFactory(self):
factory = self.getFactory();
2019-07-22 21:01:26 +03:00
2019-10-06 19:29:14 +03:00
factory.addStep(
steps.Git(
repourl=util.Interpolate('%(prop:repository)s'),
branch=util.Interpolate('%(prop:branch)s'),
mode='full',
method = 'fresh',
submodules=True,
name = 'git operations',
description = 'operations of git like pull clone fetch',
doStepIf = lambda step : not self.isStopForce(step) and not self.isLog(step),
2019-07-22 21:01:26 +03:00
2019-10-06 19:29:14 +03:00
)
);
2019-07-22 21:01:26 +03:00
2019-10-06 19:29:14 +03:00
factory.addStep(
steps.ShellCommand(
command = [
'npm',
"stop"
],
doStepIf = lambda step : (not self.isLog(step)) ,
haltOnFailure = True,
name = 'npm stop',
description = 'stop old version',
)
);
2019-07-22 21:01:26 +03:00
2019-10-06 19:29:14 +03:00
factory.addStep(
steps.ShellCommand(
command = [
'docker-compose',
"logs"
],
doStepIf = lambda step : (not self.isStopForce(step)) and self.isLog(step),
haltOnFailure = True,
name = 'docker logs',
description = 'docker logs',
)
);
factory.addStep(
steps.ShellCommand(
command = [
'npm',
"i"
],
doStepIf = lambda step : not self.isStopForce(step) and not self.isLog(step),
haltOnFailure = True,
name = 'npm install',
description = 'install all dependecies',
)
);
factory.addStep(
steps.ShellCommand(
command = [
'npm',
"run",
"start:detach"
],
doStepIf = lambda step : not self.isStopForce(step) and not self.isLog(step),
haltOnFailure = True,
name = 'npm start',
description = 'install new versio to server',
)
);
return factory
def getPropertyes(self):
return [
util.BooleanParameter(
name = 'stopForce',
label = 'Stop Force',
default = False
),
util.BooleanParameter(
name = 'showLog',
label = 'show logs of the docker',
default = False
)
]