Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mkalioby/AutoDeploy
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalioby committed Oct 11, 2016
2 parents 66ac63d + 1a147bd commit 2d6b90f
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 37 deletions.
35 changes: 21 additions & 14 deletions Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This document shows how to install autoDeploy on Ubuntu System

# Install Server

* Create an autodeploy user
```sh
# adduser --system --home /opt/autodeploy/home --shell /bin/bash autodeploy
Expand All @@ -10,43 +12,48 @@ This document shows how to install autoDeploy on Ubuntu System
```sh
# adduser autodeploy sudo
```
* Download The latest release from [github](/~https://github.com/mkalioby/AutoDeploy/releases)
* Expand the downloaded archive to '/opt/autodeploy/home'
* Copy the file in UnixConfig to /etc/sudoers.d/

* Install the Client Library
```sh
# python setup.py install
```

* Install pyCrypto
```sh
# pip install python-pycrypto
```

* Install yaml
* Install pyCrypto and pyYAML
```sh
# pip install pyyaml
# pip install python-pycrypto pyyaml
```

* Edit Server init script so that it points to installation directory

* Copy server init script to /etc/init.d
* Add the init script to the start defaults
```sh
sudo update-rc.d autodeploy-server start
# update-rc.d autodeploy-server start
```

# Install Web Application

* Install required Packages
```sh
# pip install django==1.8 django-tables2==1.0.4 django-tables2-reports
```

* Configure your database
* Edit Settings file.
* Create empty database in your DBMS.
* Create empty database in your DBMS.
* Edit Settings file in `webapp/autoDeploy/settings.py`.

* Create Database by
```sh
python manage.py migrate
$ python manage.py migrate
```
* Start Django Sever
1. Start Django Sever
```sh
python manage.py runserver IP:PORT
```

A Guide to show how to configure autodeploy Django webapp with Apache should be done.
TBD: A Guide to show how to configure autodeploy Django webapp with Apache should be done.



Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# AutoDeploy

[![StackShare](http://img.shields.io/badge/tech-stack-0690fa.svg?style=flat)](http://stackshare.io/mkalioby/autodeploy)

Buildong an automated deployment system which is similar to AWS CodeDeploy but is hostable inside enterprise.

The target is to minimize the manual prone errors of code deployment.
Expand Down
11 changes: 11 additions & 0 deletions client/autodeploy_client/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,15 @@ def getCommitsDiff(self,workdir,commit,owner=''):
for item in res.split("\n"):
if item=="" or item=="Done" : continue
result.append(item)
return result

def getChangeLog(self, workdir, since,to, owner=''):
if owner == '':
owner = Config.Owner
msg = Job.createGetChangeLog(owner, workdir, self.scm,options={"since":since,"to":to})
res = self._send(msg)
result = []
for item in res.split("\n"):
if item == "" or item == "Done": continue
result.append(item)
return result
13 changes: 13 additions & 0 deletions client/autodeploy_client/ClientJob.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ def creategetCommitsDiffMessage(owner, workdir, commit, scm,options=None):
f += '<workdir>%s</workdir>'%workdir
f += '<commit>%s</commit>'%commit

if options:
f += '<options>'
for option in options.keys():
f += "<option name='%s'>%s</option>" % (option, options[option])

f += "</options>"
f += '</job>'
return f

def createGetChangeLog(owner,workdir,scm,options=None):
sec = base64.encodestring(importKey().encrypt(owner + scm + "LIST-CHANGES", "")[0])
f = '<job owner="%s" type="%s" sec="%s" scm="%s">\n' % (owner, "LIST-CHANGES", sec, scm)
f += '<workdir>%s</workdir>' % workdir
if options:
f += '<options>'
for option in options.keys():
Expand Down
2 changes: 1 addition & 1 deletion server/Config.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[Server]
port: 4567
publicKey: /home/mohamed/autoDeploy/autoDeploy/server/client.pub
publicKey: /home/mohamed/AutoDeploy/server/client.pub

22 changes: 21 additions & 1 deletion server/Request.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,24 @@ def parseSwitchCommitJob(message):


def parseGetCommitDiff(message):
return parseSwitchCommitJob(message)
return parseSwitchCommitJob(message)

def parseGetChangeLog(message):
params = {}
optionsDict = {}
doc = xml.dom.minidom.parseString(message)
Job = doc.getElementsByTagName('job')[0]
scm = Job.getAttribute("scm")
workdir = getValue(Job, 'workdir')

requestType = Job.getAttribute('type')
owner = Job.getAttribute('owner')
options = (Job.getElementsByTagName('option'))
for option in options:
name = option.getAttribute("name")
optionsDict[name] = option.firstChild.nodeValue

print 'Recieved New Job from ' + owner + '.....'
params = {"workdir": workdir, "owner": owner, "requestType": requestType,
"scm": scm, "options": optionsDict}
return params
20 changes: 20 additions & 0 deletions server/autodeploy-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,26 @@ def HandleClient(clientsock):
if job["scm"]=="git":
gclient=git.GIT(workdir=job["workdir"])
cmd=gclient.commit_diff_cmd(commit=job["commit"])

elif req["requestType"]=="LIST-CHANGES":
job = Request.parseGetChangeLog(msg)
if job["scm"] == "git":
gclient = git.GIT(workdir=job["workdir"])
cmd = gclient.get_changelog(since=job["options"]["since"], to=job["options"]["to"])
result = []
res = Common.run(cmd)
print res
if "ERR:" in res:
Response.sendData(clientsock, res)
else:
for line in res.split("\n"):
try:
if line != "":
result.append(line.replace("*", "").strip())
except:
pass
print result
Response.sendData(clientsock, "\n".join(result))
elif req["requestType"]=="DEPLOY":
print msg
job = Request.parseDeployJob(msg)
Expand Down
3 changes: 3 additions & 0 deletions server/scm/Git.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ def switch_to_histroy_cmd(self,commit):
def commit_diff_cmd(self,commit):
Common.run(self.get_pull_cmd())
return 'git rev-list %s..HEAD'%(commit)
def get_changelog(self,since,to):
return "cd %s;git shortlog %s..%s"%(self.workdir,since,to)

29 changes: 26 additions & 3 deletions webapp/autoDeploy/autodeploy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def deploy(request):
import Common
server = Server.objects.get(name=request.session["deploy_server"])
project = Project.objects.get(name=request.session["deploy_project"])
last_Deployment=Deployment_Server.objects.filter(server=server,project=project).latest()
D= Deployment_Server()
c = Client(str(project.repo_type), server.ip, server.port)
D.project = project
Expand Down Expand Up @@ -60,14 +61,36 @@ def deploy(request):
link="http://"+server.DNS+project.deployment_link
print link
if project.emailUsers!="" or project.emailUsers!=" ":
# for user in project.emailUsers.split(","):
Common.send(project.emailUsers.replace(",",";"),"New version of %s deployed"%project.name,"Dear User,<br/> This is an automated notification that a new version of %s has been deployed at: %s"%(project.name,link),fromUser=None,cc="",bcc="",)
changes=c.getChangeLog(project.working_dir,since=last_Deployment.update_version,to=request.GET["commit"])
changes_text="<h3>Changes</h3><ul>"
found=False
for change in changes:
if change.endswith(":"): continue
changes_text+="<li>%s</li>"%change
found=True
if found:
changes_text+="</ul>"
else:
changes_text=""
Common.send(project.emailUsers.replace(",",";"),"New version of %s deployed"%project.name,"Dear User,<br/> This is an automated notification that a new version of %s has been deployed at: %s<br/>%s"%(project.name,link,changes_text),fromUser=None,cc="",bcc="",)

return HttpResponse(res+",,"+link)
else:
print "in else"
link=project.deployment_link
if project.emailUsers!="" or project.emailUsers!=" ":
Common.send(project.emailUsers.replace(",",";"),"New version of %s deployed"%project.name,"Dear User,<br/> This is an automated notification that a new version of %s has been deployed at: %s"%(project.name,link),fromUser=None,cc="",bcc="",)
changes=c.getChangeLog(project.working_dir,since=last_Deployment.update_version,to=request.GET["commit"])
changes_text="<h3>Changes</h3><ul>"
found=False
for change in changes:
if change.endswith(":"): continue
changes_text+="<li>%s</li>"%change
found=True
if found:
changes_text += "</ul>"
else:
changes_text = ""

Common.send(project.emailUsers.replace(",",";"),"New version of %s deployed"%project.name,"Dear User,<br/> This is an automated notification that a new version of %s has been deployed at: %s.<br>%s"%(project.name,link,changes_text),fromUser=None,cc="",bcc="",)
return HttpResponse(res+",,"+link)
else: return HttpResponse(res)
3 changes: 3 additions & 0 deletions webapp/autoDeploy/autodeploy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class Deployment_Server(models.Model):
project = models.ForeignKey(Project)
server = models.ForeignKey(Server)

class Meta:
get_latest_by="id"

class Plugins(models.Model):
name=models.CharField(max_length=50)
settings=models.TextField()
Expand Down
18 changes: 0 additions & 18 deletions webapp/autoDeploy/media/AutoDeploy/autodeploy.yaml

This file was deleted.

0 comments on commit 2d6b90f

Please sign in to comment.