Skip to content

Commit 123afad

Browse files
committed
added 500.html to docker directory
1 parent 48201c7 commit 123afad

File tree

2 files changed

+46
-23
lines changed

2 files changed

+46
-23
lines changed

fabfile.py

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
abort('Add SAFSME_PEM_FILE location var to system path. Aborting operation ...')
2424

2525
env.roledefs = {
26-
"ci": ["jenkins"],
27-
"dev": ["localhost"],
28-
"flexisaf": ["ec2-user"]
26+
"flexisaf": ["[email protected]"],
2927
}
3028

3129
env.key_filename = SSH_PEM_FILE
@@ -59,9 +57,22 @@ def remove_old_build():
5957
local("rm -r build")
6058
local("rm -r dist")
6159
local("rm *.deb")
62-
local("rm -r SHINKAFA.egg-info")
60+
local("rm -r SAFTIMS_HR.egg-info")
6361

6462

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")
6576

6677

6778

@@ -145,45 +156,56 @@ def start_docker_process(docker_host="staging"):
145156
mode and always restart the docker container if for
146157
any reason the process inside crashes
147158
"""
148-
host_machine_pwd = local('echo $HOME')
149-
host_log_directory = '/home/ubuntu/webapp/log/shinkafa'
159+
host_machine_pwd = run('pwd')
160+
host_log_directory = os.path.join(host_machine_pwd, 'webapp/log/shinkafa')
150161
# check if there is a log directory on the host machine
151-
if not os.path.exists(host_log_directory):
162+
if not exists(host_log_directory):
152163
# then create the log directory
153-
local("mkdir -p %s" % host_log_directory)
164+
run("mkdir -p %s" % host_log_directory)
154165
docker_tag = "flexisaf/shinkafa:latest"
155166
client_db_name = "shinkafa_" + docker_host
156-
secret_key = "your_secrete393939_key_here_please_not_so$secret"
157-
docker_env = "-e DB_NAME='%s' -e CLIENT_S3_FOLDER='%s' -e SECRET_KEY='%s'" % (client_db_name, docker_host,secret_key)
158-
local("docker run %s --name=shinkafa --detach=true --restart=always --publish=8083:80 --volume=%s:%s %s"
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"
159170
% (docker_env, host_log_directory, DOCKER_LOG_DIR, docker_tag))
160171

161172

162173
@task()
163174
def stop_container():
164-
local("docker stop shinkafa")
175+
run("docker stop shinkafa")
165176

166177

167178
@task()
168179
def start_container():
169-
local("docker start shinkafa")
180+
run("docker start shinkafa")
170181

171182

172183
@task()
173184
def restart_container():
174-
local("docker restart shinkafa")
185+
run("docker restart shinkafa")
175186

176187

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+
177196

178197
@task()
179198
def start_build_pipeline():
180199
remove_old_build()
200+
run_create_js_dist()
181201
package_tar()
182202
copy_tar_to_docker_folder()
183203
build_docker_image()
204+
zip_docker_image()
184205

185206

186207
@task()
208+
@roles(["flexisaf"])
187209
def ship_docker():
188210
"""
189211
Ship the compressed docker image to the host machine
@@ -193,13 +215,19 @@ def ship_docker():
193215
and offload the tar ball on the production
194216
machine which then start the docker process
195217
"""
218+
send_compress_docker_to_remote()
219+
# offload the compressed docker image on the remote and use docker load to add it
220+
with settings(warn_only=True):
221+
docker_load = run("gunzip -c shinkafa.tgz | docker load")
222+
if docker_load.failed: # during unziping did the process failed on
223+
pass # this machine if so just pass and continue to other machine
224+
196225
with settings(warn_only=True, colorize_error=True):
197226
# check if this is the first time we are loading this docker on the machine
198-
docker_restart = local("docker restart shinkafa")
227+
docker_restart = run("docker restart shinkafa")
199228
if docker_restart.failed:
200-
print(red("Docker process restarted, failed Starting a new process"))
229+
print(red("Docker process restarted, Starting a new process"))
201230
# only start a new docker process if there is no current process running
202-
start_docker_process(docker_host="shinkafa") # start a new docker process
203-
231+
start_docker_process(docker_host=get_client_name_from_host(env.host)) # start a new docker process
204232

205233

setup.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323
url="http://flexisaf.net/saftims-hr-demo.html",
2424

2525
install_requires=install_requires,
26-
entry_points={
27-
'console_scripts': [
28-
'hr_setup = scripts.setuphr:main',
29-
]
30-
},
3126
classifiers=[
3227
'Private :: Dont upload to any pypi registry'
3328
]

0 commit comments

Comments
 (0)