Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
Build.push classmethod for handling git-push through gitosis #35
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Monroy committed Jul 26, 2013
1 parent 10d1429 commit 9e07a52
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 43 deletions.
36 changes: 36 additions & 0 deletions api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from celery.canvas import group
from django.conf import settings
from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
Expand Down Expand Up @@ -682,6 +683,41 @@ class Meta:
def __str__(self):
return '{0}-v{1}'.format(self.formation.id, self.version)

@classmethod
def push(cls, push):
"""
Process a push from a local Git server
Creates a new Build and returns the formation's
databag for processing by the git-receive hook
"""
# SECURITY:
# we assume the first part of the ssh key name
# is the authenticated user because we trust gitosis
username = push.pop('ssh_key').split('_')[0]
# retrieve the user and formation instances
user = User.objects.get(username=username)
formation = Formation.objects.get(owner=push['owner'],
id=push.pop('formation'))
# merge the push with the required model instances
push['owner'] = user
push['formation'] = formation
# create the build
new_build = cls.objects.create(**push)
# send a release signal
release_signal.send(sender=push, build=new_build,
formation=formation,
user=user)
# recalculate the formation databag including the new
# build and release
databag = formation.calculate()
# if enabled, force-converge all of the chef nodes
if settings.CONVERGE_ON_PUSH is True:
formation.converge(databag)
# return the databag object so the git-receive hook
# can tell the user about proxy URLs, etc.
return databag


@python_2_unicode_compatible
class Release(UuidAuditedModel):
Expand Down
40 changes: 0 additions & 40 deletions bin/build-release-run

This file was deleted.

20 changes: 20 additions & 0 deletions bin/deis-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/opt/deis/controller/venv/bin/python
import os
import sys
import json

if __name__ == '__main__':
# prepare pythonpath and django settings
base_path = os.path.abspath(os.path.join(__file__, '..', '..'))
sys.path.insert(0, base_path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'deis.settings'
from api import models
# deserialize the json passed on stdin
inp = sys.stdin.read()
git_push = json.loads(inp)
# process the push
databag = models.Build.push(git_push)
# print the databag json
sys.stdout.write(json.dumps(databag))
sys.stdout.flush()
sys.exit(0)
11 changes: 8 additions & 3 deletions deis/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@
}
}

# import deis-specific settings files
from .chef_settings import * # noqa @UnusedWildImport
from .celery_settings import * # noqa @UnusedWildImport

# default deis settings
CONVERGE_ON_PUSH = True

# Create a file named "local_settings.py" to contain sensitive settings data
# such as database configuration, admin email, or passwords and keys. It
# should also be used for any settings which differ between development
Expand Down Expand Up @@ -249,10 +256,8 @@
# EMAIL_HOST_USER = 'foo'
# EMAIL_HOST_PASSWORD = 'bar'

# import other settings
from .chef_settings import * # noqa @UnusedWildImport
from .celery_settings import * # noqa @UnusedWildImport
try:
from .local_settings import * # noqa @UnusedWildImport
except ImportError:
print('No deis/local_settings.py file found!')

0 comments on commit 9e07a52

Please sign in to comment.