Skip to content

Commit edfc726

Browse files
committed
change fabric for jenkins local deployment
1 parent b81a988 commit edfc726

File tree

8 files changed

+37
-151
lines changed

8 files changed

+37
-151
lines changed

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ RUN apt-get install python-setuptools --force-yes -y ## for python2.7 or above
2525
RUN apt-get install build-essential --force-yes -y ##
2626
RUN apt-get install python-virtualenv --force-yes -y ## virtual env
2727
RUN apt-get install python-dev --force-yes -y ## because ubuntu 14.04 does not have dev version of python 2
28-
RUN apt-get install mysql-client-core-5.6 --force-yes -y
28+
RUN apt-get install mysql-client-5.6 --force-yes -y
2929
RUN apt-get install build-essential \
3030
libmysqlclient-dev \
3131
libpq-dev \

fabfile_remote.py renamed to fabfile_jenkins.py

Lines changed: 15 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import os
77
__author__ = 'peter'
88

9-
PROJECT_NAME = 'saftims-hr'
9+
PROJECT_NAME = 'shikafa'
1010
VERSION = '0.1'
1111
VIRT_DIR = "deb-build"
1212
DEBIAN_PROJECT_DEP = "python,build-essential,python-dev,libmysqlclient-dev," \
@@ -16,63 +16,16 @@
1616
SRC_DIR = os.path.dirname(os.path.abspath(__file__))
1717
BUILD_DIR = os.path.join(SRC_DIR, VIRT_DIR)
1818

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)
5319

5420

5521
def remove_old_build():
5622
with settings(warn_only=True):
5723
local("rm -r build")
5824
local("rm -r dist")
5925
local("rm *.deb")
60-
local("rm -r SAFTIMS_HR.egg-info")
26+
local("rm -r SHINKAFA.egg-info")
6127

6228

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

7730

7831

@@ -110,26 +63,6 @@ def build_docker_image():
11063
print("Docker image build successful")
11164

11265

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

13467

13568
@task()
@@ -156,55 +89,46 @@ def start_docker_process(docker_host="staging"):
15689
mode and always restart the docker container if for
15790
any reason the process inside crashes
15891
"""
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')
16195
# check if there is a log directory on the host machine
16296
if not exists(host_log_directory):
16397
# then create the log directory
164-
run("mkdir -p %s" % host_log_directory)
98+
local("mkdir -p %s" % host_log_directory)
16599
docker_tag = "flexisaf/shinkafa:latest"
166100
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"
170104
% (docker_env, host_log_directory, DOCKER_LOG_DIR, docker_tag))
171105

172106

173107
@task()
174108
def stop_container():
175-
run("docker stop shinkafa")
109+
local("docker stop shinkafa")
176110

177111

178112
@task()
179113
def start_container():
180-
run("docker start shinkafa")
114+
local("docker start shinkafa")
181115

182116

183117
@task()
184118
def restart_container():
185-
run("docker restart shinkafa")
119+
local("docker restart shinkafa")
186120

187121

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-
196122

197123
@task()
198124
def start_build_pipeline():
199125
remove_old_build()
200126
package_tar()
201127
copy_tar_to_docker_folder()
202128
build_docker_image()
203-
zip_docker_image()
204129

205130

206131
@task()
207-
@roles(["flexisaf"])
208132
def ship_docker():
209133
"""
210134
Ship the compressed docker image to the host machine
@@ -214,19 +138,10 @@ def ship_docker():
214138
and offload the tar ball on the production
215139
machine which then start the docker process
216140
"""
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-
224141
with settings(warn_only=True, colorize_error=True):
225142
# 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")
227144
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"))
229146
# 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

jenkins_deploy_to_heroku.sh

Lines changed: 0 additions & 47 deletions
This file was deleted.

mia/templates/mia/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{% extends 'mia/base.html' %}
2+
3+
4+
{% block container %}
5+
<div>
6+
<a href="{% url 'backup_db' %}">Backup DB</a>
7+
</div>
8+
{% endblock %}

mia/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44

55

66
urlpatterns = [
7+
url(r'^$', view=views.HomePage.as_view(), name="index"),
78
url(r'^backup/$', view=views.DBBackupView.as_view(), name="backup_db")
89
]

mia/views.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
# Create your views here.
99

1010

11+
class HomePage(TemplateView):
12+
template_name = 'mia/index.html'
13+
14+
15+
1116
class DBBackupView(TemplateView):
1217
template_name = 'mia/backup.html'
1318

@@ -30,3 +35,5 @@ def post(self, request, *args, **kwargs):
3035
return response
3136
else:
3237
return render(request, template_name=self.template_name, context={})
38+
39+

pipeline.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
echo Build pipeline started....
66

7-
fab start_build_pipeline ship_docker
7+
fab start_build_pipeline ship_docker --fabfile=fabfile_jenkins

shinkafa/urls.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
"""
1616
from django.conf.urls import url, include
1717
from django.contrib import admin
18+
from mia.views import HomePage
1819

1920
urlpatterns = [
20-
url(r'^chuahaha/', admin.site.urls),
21-
url(r'^mia/', include('mia.urls'))
21+
# url(r'^chuahaha/', admin.site.urls),
22+
url(r'^internal/', include('mia.urls')),
23+
url(r'^$', view=HomePage.as_view(), name="home_page")
2224
]

0 commit comments

Comments
 (0)