6
6
import os
7
7
__author__ = 'peter'
8
8
9
- PROJECT_NAME = 'saftims-hr '
9
+ PROJECT_NAME = 'shikafa '
10
10
VERSION = '0.1'
11
11
VIRT_DIR = "deb-build"
12
12
DEBIAN_PROJECT_DEP = "python,build-essential,python-dev,libmysqlclient-dev," \
16
16
SRC_DIR = os .path .dirname (os .path .abspath (__file__ ))
17
17
BUILD_DIR = os .path .join (SRC_DIR , VIRT_DIR )
18
18
19
- try :
20
- SSH_PEM_FILE = os .getenv ('SAFSMS_PEM_FILE' )
21
- except KeyError :
22
- local ('echo could not get path variable for pem file' )
23
- abort ('Add SAFSME_PEM_FILE location var to system path. Aborting operation ...' )
24
-
25
- env .roledefs = {
26
- "flexisaf" : [
"[email protected] " ],
27
- }
28
-
29
- env .key_filename = SSH_PEM_FILE
30
-
31
-
32
- def get_client_name_from_host (host_ip ):
33
- host_name = "staging"
34
- for k , v in env .roledefs .items ():
35
- try :
36
- if host_ip == v [0 ].split ('@' )[1 ]:
37
- host_name = k
38
- break
39
- except IndexError :
40
- continue
41
- return host_name
42
-
43
-
44
-
45
- def set_project_for_dist ():
46
- with settings (warn_only = True ):
47
- if os .path .exists (BUILD_DIR ):
48
- local ('rm -'
49
- 'r %s' % BUILD_DIR )
50
- local ("mkdir %s" % BUILD_DIR )
51
- else :
52
- local ("mkdir %s" % BUILD_DIR )
53
19
54
20
55
21
def remove_old_build ():
56
22
with settings (warn_only = True ):
57
23
local ("rm -r build" )
58
24
local ("rm -r dist" )
59
25
local ("rm *.deb" )
60
- local ("rm -r SAFTIMS_HR .egg-info" )
26
+ local ("rm -r SHINKAFA .egg-info" )
61
27
62
28
63
- def run_create_js_dist ():
64
- """
65
- Use Node and Npm to bundle all our js and saas
66
- file and put then inside our static folder, which
67
- will be collected when django run it own
68
- collect static command, and serve by Nginx
69
- """
70
- with settings (warn_only = True ):
71
- install_js_dep = local ("npm install" )
72
- dist_cmd = local ("npm run dist" )
73
- if install_js_dep .failed or dist_cmd .failed :
74
- abort ("Fail create js bundle" )
75
- print ("Bundling and minifying of JS completed" )
76
29
77
30
78
31
@@ -110,26 +63,6 @@ def build_docker_image():
110
63
print ("Docker image build successful" )
111
64
112
65
113
- def zip_docker_image ():
114
- """
115
- Since we are using docker for running the application
116
- This task is responsible for bundling the whole docker image
117
- into a tar ball which be later shipped to the client
118
-
119
- Benefit of this is that the client dont need to do a docker
120
- build as all the layers and container are already packed in
121
- the tar ball, so instead the client just load the container
122
- of the tar ball and start ruuning the new instance of the
123
- docker build
124
- Also deployment and start up time is faster as no need to
125
- start running and installing dependencies
126
- """
127
- with settings (warn_only = True ):
128
- gun_zip_task = local ("docker save flexisaf/shinkafa:latest | gzip -c > shinkafa.tgz" )
129
- if gun_zip_task .failed :
130
- abort (red ("Failed to backup docker image" ))
131
- else :
132
- print green ("Task creating gun zip executed successfully" )
133
66
134
67
135
68
@task ()
@@ -156,55 +89,46 @@ def start_docker_process(docker_host="staging"):
156
89
mode and always restart the docker container if for
157
90
any reason the process inside crashes
158
91
"""
159
- host_machine_pwd = run ('pwd' )
160
- host_log_directory = os .path .join (host_machine_pwd , 'webapp/log/shinkafa' )
92
+ host_machine_pwd = local ('echo $HOME' )
93
+ host_log_directory = '/home/ubuntu/webapp/log/shinkafa'
94
+ # host_log_directory = os.path.join(host_machine_pwd, 'webapp/log/shinkafa')
161
95
# check if there is a log directory on the host machine
162
96
if not exists (host_log_directory ):
163
97
# then create the log directory
164
- run ("mkdir -p %s" % host_log_directory )
98
+ local ("mkdir -p %s" % host_log_directory )
165
99
docker_tag = "flexisaf/shinkafa:latest"
166
100
client_db_name = "shinkafa_" + docker_host
167
- secret_key = "not-so_secret_right%%%$$$09 "
168
- docker_env = "-e DB_NAME='%s' -e CLIENT_S3_FOLDER='%s' -e SECRET_KEY='%s'" % (client_db_name , docker_host , secret_key )
169
- run ("docker run %s --name=shinkafa --detach=true --restart=always --publish=80:80 --volume=%s:%s %s"
101
+ secret_key = "your_secrete393939_key_here_please "
102
+ docker_env = "-e DB_NAME='%s' -e CLIENT_S3_FOLDER='%s' -e SECRET_KEY='%s'" % (client_db_name , docker_host ,secret_key )
103
+ local ("docker run %s --name=shinkafa --detach=true --restart=always --publish=80:80 --volume=%s:%s %s"
170
104
% (docker_env , host_log_directory , DOCKER_LOG_DIR , docker_tag ))
171
105
172
106
173
107
@task ()
174
108
def stop_container ():
175
- run ("docker stop shinkafa" )
109
+ local ("docker stop shinkafa" )
176
110
177
111
178
112
@task ()
179
113
def start_container ():
180
- run ("docker start shinkafa" )
114
+ local ("docker start shinkafa" )
181
115
182
116
183
117
@task ()
184
118
def restart_container ():
185
- run ("docker restart shinkafa" )
119
+ local ("docker restart shinkafa" )
186
120
187
121
188
- def send_compress_docker_to_remote ():
189
- """
190
- Send our compressed docker image to the
191
- the remote instances that was specified
192
- """
193
- with settings (colorize_errors = True ):
194
- put ('shinkafa.tgz' , '~/' )
195
-
196
122
197
123
@task ()
198
124
def start_build_pipeline ():
199
125
remove_old_build ()
200
126
package_tar ()
201
127
copy_tar_to_docker_folder ()
202
128
build_docker_image ()
203
- zip_docker_image ()
204
129
205
130
206
131
@task ()
207
- @roles (["flexisaf" ])
208
132
def ship_docker ():
209
133
"""
210
134
Ship the compressed docker image to the host machine
@@ -214,19 +138,10 @@ def ship_docker():
214
138
and offload the tar ball on the production
215
139
machine which then start the docker process
216
140
"""
217
- send_compress_docker_to_remote ()
218
- # offload the compressed docker image on the remote and use docker load to add it
219
- with settings (warn_only = True ):
220
- docker_load = run ("gunzip -c shinkafa.tgz | docker load" )
221
- if docker_load .failed : # during unziping did the process failed on
222
- pass # this machine if so just pass and continue to other machine
223
-
224
141
with settings (warn_only = True , colorize_error = True ):
225
142
# check if this is the first time we are loading this docker on the machine
226
- docker_restart = run ("docker restart shinkafa" )
143
+ docker_restart = local ("docker restart shinkafa" )
227
144
if docker_restart .failed :
228
- print (red ("Docker process restarted, Starting a new process" ))
145
+ print (red ("Docker process restarted, failed Starting a new process" ))
229
146
# only start a new docker process if there is no current process running
230
- start_docker_process (docker_host = get_client_name_from_host (env .host )) # start a new docker process
231
-
232
-
147
+ start_docker_process (docker_host = "shinkafa" ) # start a new docker process
0 commit comments