|
|
|
@ -3,22 +3,33 @@ from sys import stdout
|
|
|
|
|
from pkg_resources import resource_string
|
|
|
|
|
from os import chmod
|
|
|
|
|
import yaml
|
|
|
|
|
from .domain import Build
|
|
|
|
|
from .python_util import execute
|
|
|
|
|
|
|
|
|
|
class ResourceApi():
|
|
|
|
|
|
|
|
|
|
class ProjectRepository:
|
|
|
|
|
def get_build(self, project) -> Build:
|
|
|
|
|
return project.get_property("devops_build")
|
|
|
|
|
|
|
|
|
|
def set_build(self, project, build: Build):
|
|
|
|
|
project.set_property("devops_build", build)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ResourceApi:
|
|
|
|
|
def read_resource(self, path: str) -> bytes:
|
|
|
|
|
return resource_string(__name__, path)
|
|
|
|
|
|
|
|
|
|
class FileApi():
|
|
|
|
|
|
|
|
|
|
class FileApi:
|
|
|
|
|
def clean_dir(self, directory: str):
|
|
|
|
|
execute('rm -rf ' + directory, shell=True)
|
|
|
|
|
execute('mkdir -p ' + directory, shell=True)
|
|
|
|
|
execute("rm -rf " + directory, shell=True)
|
|
|
|
|
execute("mkdir -p " + directory, shell=True)
|
|
|
|
|
|
|
|
|
|
def cp_force(self, src: str, target_dir: str):
|
|
|
|
|
execute('cp -f ' + src + '* ' + target_dir, shell=True)
|
|
|
|
|
execute("cp -f " + src + "* " + target_dir, shell=True)
|
|
|
|
|
|
|
|
|
|
def cp_recursive(self, src: str, target_dir: str):
|
|
|
|
|
execute('cp -r ' + src + ' ' + target_dir, shell=True)
|
|
|
|
|
execute("cp -r " + src + " " + target_dir, shell=True)
|
|
|
|
|
|
|
|
|
|
def write_data_to_file(self, path: Path, data: bytes):
|
|
|
|
|
with open(path, "w", encoding="utf-8") as output_file:
|
|
|
|
@ -29,37 +40,56 @@ class FileApi():
|
|
|
|
|
yaml.dump(data, output_file)
|
|
|
|
|
chmod(path, 0o600)
|
|
|
|
|
|
|
|
|
|
class DockerApi():
|
|
|
|
|
|
|
|
|
|
class DockerApi:
|
|
|
|
|
def image(self, name: str, path: Path):
|
|
|
|
|
execute('docker build -t ' + name +
|
|
|
|
|
' --file ' + path + '/image/Dockerfile '
|
|
|
|
|
+ path + '/image', shell=True)
|
|
|
|
|
execute(
|
|
|
|
|
"docker build -t "
|
|
|
|
|
+ name
|
|
|
|
|
+ " --file "
|
|
|
|
|
+ path
|
|
|
|
|
+ "/image/Dockerfile "
|
|
|
|
|
+ path
|
|
|
|
|
+ "/image",
|
|
|
|
|
shell=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def drun(self, name: str):
|
|
|
|
|
execute('docker run -it --entrypoint="" ' +
|
|
|
|
|
name + ' /bin/bash', shell=True)
|
|
|
|
|
execute('docker run -it --entrypoint="" ' + name + " /bin/bash", shell=True)
|
|
|
|
|
|
|
|
|
|
def dockerhub_login(self, username: str, password: str):
|
|
|
|
|
execute('docker login --username ' + username +
|
|
|
|
|
' --password ' + password, shell=True)
|
|
|
|
|
execute(
|
|
|
|
|
"docker login --username " + username + " --password " + password,
|
|
|
|
|
shell=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def dockerhub_publish(self, name: str, username: str, tag=None):
|
|
|
|
|
if tag is not None:
|
|
|
|
|
execute('docker tag ' + name + ' ' + username +
|
|
|
|
|
'/' + name + ':' + tag, shell=True)
|
|
|
|
|
execute('docker push ' + username +
|
|
|
|
|
'/' + name + ':' + tag, shell=True)
|
|
|
|
|
execute('docker tag ' + name + ' ' + username +
|
|
|
|
|
'/' + name + ':latest', shell=True)
|
|
|
|
|
execute('docker push ' + username +
|
|
|
|
|
'/' + name + ':latest', shell=True)
|
|
|
|
|
execute(
|
|
|
|
|
"docker tag " + name + " " + username + "/" + name + ":" + tag,
|
|
|
|
|
shell=True,
|
|
|
|
|
)
|
|
|
|
|
execute("docker push " + username + "/" + name + ":" + tag, shell=True)
|
|
|
|
|
execute(
|
|
|
|
|
"docker tag " + name + " " + username + "/" + name + ":latest", shell=True
|
|
|
|
|
)
|
|
|
|
|
execute("docker push " + username + "/" + name + ":latest", shell=True)
|
|
|
|
|
|
|
|
|
|
def test(self, name: str, path: Path):
|
|
|
|
|
execute('docker build -t ' + name + '-test ' +
|
|
|
|
|
'--file ' + path + '/test/Dockerfile '
|
|
|
|
|
+ path + '/test', shell=True)
|
|
|
|
|
execute(
|
|
|
|
|
"docker build -t "
|
|
|
|
|
+ name
|
|
|
|
|
+ "-test "
|
|
|
|
|
+ "--file "
|
|
|
|
|
+ path
|
|
|
|
|
+ "/test/Dockerfile "
|
|
|
|
|
+ path
|
|
|
|
|
+ "/test",
|
|
|
|
|
shell=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ExecutionApi():
|
|
|
|
|
class ExecutionApi:
|
|
|
|
|
def execute(command: str, dry_run=False):
|
|
|
|
|
output = ""
|
|
|
|
|
if dry_run:
|
|
|
|
|