68 Commits
oldway ... node

Author SHA1 Message Date
e119234161 node 2016-10-01 22:01:27 -04:00
d85ba96a41 node 2016-10-01 21:58:20 -04:00
ca2132f372 node 2016-10-01 21:49:14 -04:00
6b280d357a node 2016-10-01 21:46:30 -04:00
e974481688 node 2016-10-01 21:42:10 -04:00
7819cdda0d node 2016-10-01 21:28:24 -04:00
38a592e29e node 2016-10-01 21:19:17 -04:00
1c3901af27 node 2016-10-01 18:40:55 -04:00
73e46f0ce9 node 2016-10-01 17:32:25 -04:00
560629e5bb node 2016-10-01 16:51:56 -04:00
f1b329b7d7 node 2016-10-01 16:45:27 -04:00
a0811cc7cc node 2016-10-01 16:39:18 -04:00
ea34a46d75 node 2016-10-01 16:22:34 -04:00
b0b73cdb45 node 2016-10-01 16:13:27 -04:00
7be2696c71 node 2016-10-01 16:01:35 -04:00
ece6c19ca3 node 2016-10-01 15:37:05 -04:00
bc1bb7fea2 node 2016-10-01 15:23:01 -04:00
28160bb7eb node 2016-10-01 14:47:51 -04:00
0cfb5e54f9 node 2016-10-01 14:36:30 -04:00
bfba08b1db node 2016-10-01 14:21:34 -04:00
847407beee node 2016-10-01 00:48:22 -04:00
7437a9fe3b node 2016-10-01 00:38:00 -04:00
7fc8010a60 node 2016-10-01 00:34:00 -04:00
2f3dacb569 node 2016-10-01 00:27:46 -04:00
e0963c1c29 node 2016-10-01 00:16:40 -04:00
3a060d5477 asd 2016-09-30 21:55:38 -04:00
994a3297c9 asd 2016-09-30 21:38:10 -04:00
5fef77b61f asd 2016-09-30 20:13:13 -04:00
b1a9be254b asd 2016-09-30 19:43:18 -04:00
f9b14cb38d asd 2016-09-30 19:32:21 -04:00
591d5249cf asd 2016-09-30 19:24:20 -04:00
7f65e0a420 asd 2016-09-30 19:05:42 -04:00
ee40dcc7f6 asd 2016-09-30 19:04:20 -04:00
67a7f77599 stuff 2016-09-30 18:57:12 -04:00
6a27b88465 naming error 2016-09-30 18:18:19 -04:00
d91df030be new work flow 1 2016-09-30 17:54:31 -04:00
2d027afa29 Update create.sh 2016-09-16 14:15:59 -04:00
27afb67a17 stuff 2016-06-17 01:19:20 -04:00
61af6f62b6 stuff 2016-06-17 01:05:53 -04:00
3ff71a5114 stuff 2016-06-17 00:31:13 -04:00
84ad1d92ec stuff 2016-06-17 00:13:03 -04:00
721e94e1e8 stuff 2016-06-16 23:56:31 -04:00
06c0e8b9dd Merge pull request #2 from wmantly/branches
stuff
2016-06-16 23:51:22 -04:00
749e8d537c stuff 2016-06-16 23:47:32 -04:00
f831addb5e Merge pull request #1 from wmantly/branches
Branches
2016-06-16 23:25:40 -04:00
0fba8f8fbe stuff 2016-06-16 23:24:01 -04:00
290b1f1fef stuff 2016-06-16 23:17:43 -04:00
045d14a867 stuff 2016-06-16 23:13:25 -04:00
6693101f58 stuff 2016-06-16 22:54:37 -04:00
157f9ad718 stuff 2016-06-16 22:52:04 -04:00
ad1c8e7205 stuff 2016-06-16 22:51:16 -04:00
307856f969 stuff 2016-06-16 22:34:19 -04:00
b827c91fae stuff 2016-06-16 22:27:22 -04:00
e26e8f8305 stuff 2016-06-16 22:26:50 -04:00
f2eaa29339 stuff 2016-06-16 21:00:05 -04:00
e1ce7c148c stuff 2016-06-16 20:56:32 -04:00
4256321462 stuff 2016-06-16 20:55:30 -04:00
b48e243cc6 stuff 2016-06-16 20:47:23 -04:00
8c7beea59b stuff 2016-06-16 19:35:10 -04:00
e31aaedf27 stuff 2016-06-16 19:30:22 -04:00
46bdac5aa8 stuff 2016-06-16 19:07:58 -04:00
00b474a071 stuff 2016-06-16 19:05:19 -04:00
7b8d7b439a stuff 2016-06-16 19:02:40 -04:00
5865000330 stuff 2016-06-16 18:58:15 -04:00
208395bb47 stuff 2016-06-16 18:56:04 -04:00
ffef2a59c3 stuff 2016-06-16 18:53:26 -04:00
260881acd7 stuff 2016-06-16 18:49:32 -04:00
b54d5533c9 first 2016-06-16 18:37:44 -04:00
7 changed files with 175 additions and 15 deletions

View File

@ -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);
/**

75
create.sh Normal file
View File

@ -0,0 +1,75 @@
#!/bin/bash
name="$1"
sshURL="$2"
nodePort=`python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()'`
workingPath=/var/www/gitwrapper/$name
echo "starting $sshURL on $name"
eval "$(ssh-agent -s)"
ssh-add /root/.ssh/id_github_rsa
mkdir $workingPath
cd $workingPath
chmod 777 .
echo `pwd`
DJANGO_SETTINGS_MODULE=project.settings.prod
export DJANGO_SETTINGS_MODULE=project.settings.prod
NODE_ENV='staging'
export NODE_ENV='staging'
export NODEPORT=$nodePort
git clone $sshURL .
./scripts/setup.sh
source env/bin/activate
cp /var/www/local_settings.py project/settings/local_settings.py
echo "BRANCH='$name'" >> project/settings/local_settings.py
echo "NODEPORT='$nodePort'" >> project/settings/local_settings.py
echo $nodePort > env/nodePort
echo "checking out to prod for set up"
git checkout prod
python3 manage.py createcachetable
python3 manage.py migrate
python3 manage.py loaddata /var/www/django.json
echo "checking out to $name for set up"
git checkout $name
./scripts/setup.sh
python3 manage.py collectstatic --noinput
python3 manage.py migrate
chmod 777 db.sqlite3
forever stop $workingPath/node_rtc/app.js
echo "starting node app on port $nodePort"
forever start $workingPath/node_rtc/app.js -l
echo "creating apache VirtualHost file"
echo "<VirtualHost *:80>" > /etc/apache2/sites-enabled/$name.conf
echo " ServerName $name.staging.bytedev.co" >> /etc/apache2/sites-enabled/$name.conf
echo " Alias /static $workingPath/staticfiles" >> /etc/apache2/sites-enabled/$name.conf
echo " WSGIDaemonProcess $name python-path=$workingPath:$workingPath/env:$workingPath/env/lib/python3.5/site-packages" >> /etc/apache2/sites-enabled/$name.conf
echo " WSGIProcessGroup $name" >> /etc/apache2/sites-enabled/$name.conf
echo " WSGIScriptAlias / $workingPath/project/wsgi.py" >> /etc/apache2/sites-enabled/$name.conf
echo " # socket.io conf" >> /etc/apache2/sites-enabled/$name.conf
echo " <Location '/socket.io'>" >> /etc/apache2/sites-enabled/$name.conf
echo " RewriteEngine On" >> /etc/apache2/sites-enabled/$name.conf
echo " RewriteCond %{REQUEST_URI} ^/socket.io/1/websocket [NC]" >> /etc/apache2/sites-enabled/$name.conf
echo " RewriteRule socket.io/(.*) ws://localhost:$nodePort/socket.io/\$1 [P,L]" >> /etc/apache2/sites-enabled/$name.conf
echo " ProxyPass http://localhost:$nodePort/socket.io" >> /etc/apache2/sites-enabled/$name.conf
echo " ProxyPassReverse http://localhost:$nodePort/socket.io" >> /etc/apache2/sites-enabled/$name.conf
echo " </Location>" >> /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
View 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
View 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)

View File

@ -1,21 +1,50 @@
var express = require('express');
var router = express.Router();
var exec = require('child_process').exec;
var fs = require('fs');
/* GET home page. */
router.all('/', function(req, res, next) {
console.log("some one is here");
if(req.headers['x-github-event'] === 'push'){
console.log("got a push!");
if(req.body.ref === "refs/heads/prod"){
console.log('time to update prod!');
exec('/var/www/gitwrapperdeploy.sh', console.log, console.log);
}
}
res.render('index', { title: 'Express' });
});
router.get('/dbdump', function(req, res, nex){
res.sendFile('/var/backups/db/djangodump.json');
var install_dir = '/var/www/gitwrapper/'
var calls = {
create: function(req, res, name, sshURL){
console.log("create =========================");
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){
console.log("update =========================");
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){
console.log("delete =========================");
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) {
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;

37
update.sh Normal file
View File

@ -0,0 +1,37 @@
#!/bin/bash
name="$1"
sshURL="$2"
workingPath=/var/www/gitwrapper/$name
eval "$(ssh-agent -s)"
ssh-add /root/.ssh/id_github_rsa
cd $workingPath
DJANGO_SETTINGS_MODULE=project.settings.prod
export DJANGO_SETTINGS_MODULE=project.settings.prod
source env/bin/activate
git stash
git pull --force origin $name
./scripts/setup.sh
source env/bin/activate
python3 manage.py collectstatic --noinput
python3 manage.py migrate
chmod 777 .
chmod 777 db.sqlite3
echo "starting node app"
NODE_ENV='staging'
export NODE_ENV='staging'
nodePort=cat env/nodePort
export NODEPORT=$nodePort
forever stop $workingPath/node_rtc/app.js
forever start $workingPath/node_rtc/app.js
/usr/sbin/service apache2 restart
exit 0

View File

@ -6,6 +6,6 @@
</head>
<body>
<h1><%= title %></h1>
<p>YO!! <%= title %></p>
<p>Welcome to <%= title %></p>
</body>
</html>