commit
f831addb5e
2
bin/www
2
bin/www
@ -12,7 +12,7 @@ var http = require('http');
|
||||
* Get port from environment and store in Express.
|
||||
*/
|
||||
|
||||
var port = normalizePort(process.env.PORT || '3180');
|
||||
var port = normalizePort(process.env.PORT || '3000');
|
||||
app.set('port', port);
|
||||
|
||||
/**
|
||||
|
46
create.sh
Normal file
46
create.sh
Normal file
@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
|
||||
name="$1"
|
||||
sshURL="$2"
|
||||
|
||||
eval "$(ssh-agent -s)"
|
||||
ssh-add /root/.ssh/id_github_rsa
|
||||
mkdir /var/www/gitwrapper/$name
|
||||
cd /var/www/gitwrapper/$name
|
||||
echo `pwd`
|
||||
|
||||
DJANGO_SETTINGS_MODULE=project.settings.prod
|
||||
export DJANGO_SETTINGS_MODULE=project.settings.prod
|
||||
|
||||
git clone $sshURL .
|
||||
virtualenv env
|
||||
source env/bin/activate
|
||||
pip install -r requirements.txt
|
||||
cp /var/www/local_settings.py project/settings/local_settings.py
|
||||
echo "BRANCH = '$name'" >> project/settings/local_settings.py
|
||||
|
||||
python manage.py createcachetable
|
||||
python3 manage.py migrate
|
||||
python3 manage.py loaddata "/var/www/django.json"
|
||||
|
||||
git checkout $name
|
||||
|
||||
pip install -r requirements.txt
|
||||
|
||||
python3 manage.py collectstatic --noinput
|
||||
python3 manage.py migrate
|
||||
chmod 777 .
|
||||
chmod 777 db.sqlite3
|
||||
|
||||
echo "<VirtualHost *:80>" > /etc/apache2/sites-enabled/$name.conf
|
||||
echo " ServerName $name.staging.bytedev.co" >> /etc/apache2/sites-enabled/$name.conf
|
||||
echo " Alias /static /var/www/gitwrapper/$name/staticfiles" >> /etc/apache2/sites-enabled/$name.conf
|
||||
echo " WSGIDaemonProcess $name python-path=/var/www/gitwrapper/$name:/var/www/gitwrapper/$name/env:/var/www/gitwrapper/$name/env/lib/python3.5/site-packages" >> /etc/apache2/sites-enabled/$name.conf
|
||||
echo " WSGIProcessGroup $name" >> /etc/apache2/sites-enabled/$name.conf
|
||||
echo " WSGIScriptAlias / /var/www/gitwrapper/$name/project/wsgi.py" >> /etc/apache2/sites-enabled/$name.conf
|
||||
echo "</VirtualHost>" >> /etc/apache2/sites-enabled/$name.conf
|
||||
|
||||
|
||||
service apache2 restart
|
||||
|
||||
exit 0
|
10
delete.sh
Normal file
10
delete.sh
Normal file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
name="$1"
|
||||
sshURL="$2"
|
||||
|
||||
rm -rf /var/www/gitwrapper/$name
|
||||
rm /etc/apache2/sites-enabled/$name.conf
|
||||
|
||||
service apache2 reload
|
||||
|
||||
exit 0
|
@ -1,15 +1,47 @@
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
var exec = require('child_process').exec;
|
||||
var fs = require('fs');
|
||||
/* GET home page. */
|
||||
|
||||
var install_dir = '/var/www/gitwrapper/'
|
||||
|
||||
|
||||
|
||||
var calls = {
|
||||
create: function(req, res, name, sshURL){
|
||||
return exec('bash /var/www/gitdeploy/create.sh '+name+' '+sshURL, function(err, stdout, stderr){
|
||||
|
||||
return res.json({ title: 'Express' });
|
||||
});
|
||||
},
|
||||
update: function(req, res, name, sshURL){
|
||||
return exec('bash /var/www/gitdeploy/update.sh '+name+' '+sshURL, function(err, stdout, stderr){
|
||||
|
||||
return res.json({ title: 'Express' });
|
||||
});
|
||||
},
|
||||
delete: function(req, res, name, sshURL){
|
||||
return exec('bash /var/www/gitdeploy/delete.sh '+name+' '+sshURL, function(err, stdout, stderr){
|
||||
|
||||
return res.json({ title: 'Express' });
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
router.all('/', function(req, res, next) {
|
||||
if(req.headers['x-github-event'] === 'push'){
|
||||
if(req.body.ref === "refs/heads/master"){
|
||||
console.log('time to update master!');
|
||||
exec('/var/www/gitwrapperdeploy.sh', console.log, console.log);
|
||||
}
|
||||
}
|
||||
res.render('index', { title: 'Express' });
|
||||
var event = req.headers['x-github-event'];
|
||||
var call = (req.body.created && 'create') ||
|
||||
(req.body.deleted && 'delete') ||
|
||||
'update';
|
||||
|
||||
var name = req.body.ref.replace('refs/heads/', '');
|
||||
var sshURL = req.body.repository.ssh_url;
|
||||
if(call === 'update' && !fs.existsSync('/var/www/gitwrapper/'+name)) call = 'create';
|
||||
|
||||
return calls[call](req, res, name, sshURL);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
24
update.sh
Normal file
24
update.sh
Normal file
@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
name="$1"
|
||||
sshURL="$2"
|
||||
|
||||
eval "$(ssh-agent -s)"
|
||||
ssh-add /root/.ssh/id_github_rsa
|
||||
DJANGO_SETTINGS_MODULE=project.settings.prod
|
||||
export DJANGO_SETTINGS_MODULE=project.settings.prod
|
||||
cd /var/www/gitwrapper/$name
|
||||
|
||||
source env/bin/activate
|
||||
|
||||
git stash
|
||||
git pull --force origin $name
|
||||
pip install -r requirements.txt
|
||||
|
||||
python3 manage.py collectstatic --noinput
|
||||
python3 manage.py migrate
|
||||
|
||||
chmod 777 .
|
||||
chmod 777 db.sqlite3
|
||||
service apache2 reload
|
||||
|
||||
exit 0
|
Loading…
x
Reference in New Issue
Block a user