Compare commits
35 Commits
oldway
...
teststuff3
Author | SHA1 | Date | |
---|---|---|---|
74103cc401 | |||
6a27b88465 | |||
d91df030be | |||
2d027afa29 | |||
27afb67a17 | |||
61af6f62b6 | |||
3ff71a5114 | |||
84ad1d92ec | |||
721e94e1e8 | |||
06c0e8b9dd | |||
749e8d537c | |||
f831addb5e | |||
0fba8f8fbe | |||
290b1f1fef | |||
045d14a867 | |||
6693101f58 | |||
157f9ad718 | |||
ad1c8e7205 | |||
307856f969 | |||
b827c91fae | |||
e26e8f8305 | |||
f2eaa29339 | |||
e1ce7c148c | |||
4256321462 | |||
b48e243cc6 | |||
8c7beea59b | |||
e31aaedf27 | |||
46bdac5aa8 | |||
00b474a071 | |||
7b8d7b439a | |||
5865000330 | |||
208395bb47 | |||
ffef2a59c3 | |||
260881acd7 | |||
b54d5533c9 |
2
bin/www
2
bin/www
@ -12,7 +12,7 @@ var http = require('http');
|
|||||||
* Get port from environment and store in Express.
|
* 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);
|
app.set('port', port);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
52
create.sh
Normal file
52
create.sh
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
name="$1"
|
||||||
|
sshURL="$2"
|
||||||
|
|
||||||
|
nodePort=`./random_port.py`
|
||||||
|
|
||||||
|
eval "$(ssh-agent -s)"
|
||||||
|
ssh-add /root/.ssh/id_github_rsa
|
||||||
|
mkdir /var/www/gitwrapper/$name
|
||||||
|
cd /var/www/gitwrapper/$name
|
||||||
|
chmod 777 .
|
||||||
|
echo `pwd`
|
||||||
|
|
||||||
|
DJANGO_SETTINGS_MODULE=project.settings.prod
|
||||||
|
export DJANGO_SETTINGS_MODULE=project.settings.prod
|
||||||
|
|
||||||
|
git clone $sshURL .
|
||||||
|
|
||||||
|
./scripts/setup.sh
|
||||||
|
|
||||||
|
cp /var/www/local_settings.py project/settings/local_settings.py
|
||||||
|
echo "BRANCH = '$name'" >> project/settings/local_settings.py
|
||||||
|
|
||||||
|
# set up project from prod, load database
|
||||||
|
git checkout prod
|
||||||
|
|
||||||
|
./manage.py createcachetable
|
||||||
|
./manage.py migrate
|
||||||
|
./manage.py loaddata /var/www/django.json
|
||||||
|
|
||||||
|
git checkout $name
|
||||||
|
|
||||||
|
./scripts/setup.sh
|
||||||
|
|
||||||
|
# python3 manage.py collectstatic --noinput
|
||||||
|
./manage.py migrate
|
||||||
|
chmod 777 db.sqlite3
|
||||||
|
|
||||||
|
|
||||||
|
# set up apache vhost
|
||||||
|
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
|
||||||
|
|
||||||
|
/usr/sbin/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
|
||||||
|
|
||||||
|
/usr/sbin/service apache2 restart
|
||||||
|
|
||||||
|
exit 0
|
9
random_port.py
Executable file
9
random_port.py
Executable file
@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import socket
|
||||||
|
|
||||||
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
s.bind(('', 0))
|
||||||
|
addr = s.getsockname()
|
||||||
|
print (addr[1])
|
||||||
|
s.close()
|
||||||
|
exit(0)
|
@ -1,15 +1,47 @@
|
|||||||
var express = require('express');
|
var express = require('express');
|
||||||
var router = express.Router();
|
var router = express.Router();
|
||||||
var exec = require('child_process').exec;
|
var exec = require('child_process').exec;
|
||||||
|
var fs = require('fs');
|
||||||
/* GET home page. */
|
/* 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){
|
||||||
|
console.log(err, stdout, stderr);
|
||||||
|
return res.json({ title: stdout });
|
||||||
|
});
|
||||||
|
},
|
||||||
|
update: function(req, res, name, sshURL){
|
||||||
|
return exec('bash /var/www/gitdeploy/update.sh '+name+' '+sshURL, function(err, stdout, stderr){
|
||||||
|
console.log(err, stdout, stderr);
|
||||||
|
return res.json({ title: stdout });
|
||||||
|
});
|
||||||
|
},
|
||||||
|
delete: function(req, res, name, sshURL){
|
||||||
|
return exec('bash /var/www/gitdeploy/delete.sh '+name+' '+sshURL, function(err, stdout, stderr){
|
||||||
|
console.log(err, stdout, stderr);
|
||||||
|
return res.json({ title: stdout });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
router.all('/', function(req, res, next) {
|
router.all('/', function(req, res, next) {
|
||||||
if(req.headers['x-github-event'] === 'push'){
|
var event = req.headers['x-github-event'];
|
||||||
if(req.body.ref === "refs/heads/master"){
|
var call = (req.body.created && 'create') ||
|
||||||
console.log('time to update master!');
|
(req.body.deleted && 'delete') ||
|
||||||
exec('/var/www/gitwrapperdeploy.sh', console.log, console.log);
|
'update';
|
||||||
}
|
|
||||||
}
|
var name = req.body.ref.replace('refs/heads/', '');
|
||||||
res.render('index', { title: 'Express' });
|
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;
|
module.exports = router;
|
||||||
|
26
update.sh
Normal file
26
update.sh
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
name="$1"
|
||||||
|
sshURL="$2"
|
||||||
|
|
||||||
|
# set up git to auth
|
||||||
|
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
|
||||||
|
git stash
|
||||||
|
git pull --force origin $name
|
||||||
|
|
||||||
|
./scripts/setup.sh
|
||||||
|
|
||||||
|
python3 manage.py collectstatic --noinput
|
||||||
|
python3 manage.py migrate
|
||||||
|
|
||||||
|
chmod 777 .
|
||||||
|
chmod 777 db.sqlite3
|
||||||
|
|
||||||
|
/usr/sbin/service apache2 restart
|
||||||
|
|
||||||
|
exit 0
|
Reference in New Issue
Block a user