-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
142 lines (112 loc) · 5.04 KB
/
Copy pathbuild.py
File metadata and controls
142 lines (112 loc) · 5.04 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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from pybuilder.core import Author, init, use_plugin, task, depends
import os
import shutil
import subprocess
use_plugin("python.core")
use_plugin("python.install_dependencies")
use_plugin("python.distutils")
use_plugin("python.unittest")
use_plugin("python.integrationtest")
use_plugin("source_distribution")
default_task = "publish"
name = "neumann"
summary = "Neumann is Neo4j recommendation generator"
description = "Neumann is Neo4j recommendation generator"
authors = [Author("guilherme", "guilherme@vventures.asia"),
Author("jocki", "jocki@vventures.asia")]
url = "https://github.com/predictry/neumann"
version = "0.4"
def _docker_build(project, logger):
profile = project.get_property('profile')
# Creating docker staging directory
docker_dir = project.expand("$dir_target/docker")
logger.info("Creating docker staging at {0}".format(docker_dir))
shutil.rmtree(docker_dir, True)
os.mkdir(docker_dir)
# Copying Dockerfile
logger.info("Copying Dockerfile to {0}".format(docker_dir))
shutil.copy('Dockerfile', docker_dir)
artifact_file = project.expand("$dir_dist/dist/neumann-{0}.tar.gz".format(project.version))
logger.info("Copying {0} to {1}".format(artifact_file, docker_dir))
shutil.copy(artifact_file, docker_dir)
# Copying requirements.txt
requirements_file = project.expand("$basedir/requirements.txt")
logger.info("Copying {0} to {1}".format(requirements_file, docker_dir))
shutil.copy(requirements_file, docker_dir)
# Copying config files to staging directory
config_dir = project.expand("$basedir/config/{0}".format(profile))
for filename in os.listdir(project.expand(config_dir)):
full_filename = os.path.join(config_dir, filename)
if os.path.isfile(full_filename):
logger.info("Copying {0} to {1}".format(full_filename, docker_dir))
shutil.copy(full_filename, docker_dir)
# Executing docker build
logger.info("Executing docker build")
subprocess.call(["docker", "build", "-t", "predictry/neumann-{0}:{1}".format(profile, project.version), docker_dir])
def _docker_run(project, logger):
profile = project.get_property('profile')
# Deleting existing container
logger.info("Stopping container neumann")
subprocess.call(["docker", "stop", "neumann-{0}-{1}".format(profile, project.version)])
logger.info("Removing container")
subprocess.call(["docker", "rm", "-f", "neumann-{0}-{1}".format(profile, project.version)])
# Running new container
data_dir = project.expand("$basedir/$dir_target/tmp/data")
if not os.path.exists(data_dir):
os.makedirs(data_dir)
s3copy_dir = project.expand("$basedir/$dir_target/tmp/s3copy")
if not os.path.exists(s3copy_dir):
os.makedirs(s3copy_dir)
logger.info("Executing docker run with data_dir [{0}] and s3copy_dir [{1}]".format(data_dir, s3copy_dir))
subprocess.call(["docker", "run", "-d", "-P", "--name=neumann-{0}-{1}".format(profile, project.version),
"-v", "{0}:/app/data".format(data_dir), "-v", "{0}:/app/s3copy".format(s3copy_dir),
"--net=host", "predictry/neumann-{0}:{1}".format(profile, project.version)])
@task
@depends("publish")
def docker_build_dev(project, logger):
project.set_property('profile', 'dev')
_docker_build(project, logger)
@task
@depends("docker_build_dev")
def docker_run_dev(project, logger):
project.set_property('profile', 'dev')
_docker_run(project, logger)
@task
@depends("publish")
def docker_build_prod(project, logger):
project.set_property('profile', 'prod')
_docker_build(project, logger)
@task
@depends("docker_build_prod")
def docker_run_prod(project, logger):
project.set_property('profile', 'prod')
_docker_run(project, logger)
@task
@depends("docker_build_prod")
def docker_push(project, logger):
project.set_property('profile', 'prod')
profile = project.get_property('profile')
# Tag image
logger.info("Tagging image")
subprocess.call(["docker", "tag", "-f", "predictry/neumann-{0}:{1}".format(profile, project.version),
"fisher.predictry.com:5000/predictry/neumann-{0}:{1}".format(profile, project.version)])
# Push image
logger.info("Push image")
subprocess.call(["docker", "push",
"fisher.predictry.com:5000/predictry/neumann-{0}:{1}".format(profile, project.version)])
@task
def install_dev_configs(project, logger):
# Copying configuration files
target_dir = os.path.expanduser('~/.local/share/neumann/config')
if not os.path.exists(target_dir):
logger.info("Creating {0}".format(target_dir))
os.makedirs(target_dir)
config_dir = project.expand('$basedir/config/dev')
for filename in os.listdir(project.expand(config_dir)):
full_filename = os.path.join(config_dir, filename)
if os.path.isfile(full_filename):
logger.info("Copying {0} to {1}".format(full_filename, target_dir))
shutil.copy(full_filename, target_dir)
@init
def initialize(project):
project.depends_on_requirements("requirements.txt")