Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
0f44f41031 | |||
cbf9f50050 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -28,3 +28,5 @@ node_modules
|
|||||||
|
|
||||||
# Debug log from npm
|
# Debug log from npm
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
|
|
||||||
|
settings.json
|
||||||
|
55
app.js
55
app.js
@ -1,10 +1,26 @@
|
|||||||
'use strict';
|
var express = require('express');
|
||||||
|
var path = require('path');
|
||||||
|
var favicon = require('serve-favicon');
|
||||||
|
var logger = require('morgan');
|
||||||
|
var cookieParser = require('cookie-parser');
|
||||||
|
var bodyParser = require('body-parser');
|
||||||
|
|
||||||
const express = require('express');
|
|
||||||
const app = express();
|
|
||||||
|
|
||||||
app.use(express.json());
|
var app = express();
|
||||||
app.use('/', require('./routes/index'));
|
app.settings = require('./settings.json');
|
||||||
|
// view engine setup
|
||||||
|
// app.set('views', path.join(__dirname, 'views'));
|
||||||
|
// app.set('view engine', 'ejs');
|
||||||
|
|
||||||
|
// uncomment after placing your favicon in /public
|
||||||
|
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
|
||||||
|
app.use(logger('dev'));
|
||||||
|
app.use(bodyParser.json());
|
||||||
|
app.use(bodyParser.urlencoded({ extended: false }));
|
||||||
|
app.use(cookieParser());
|
||||||
|
app.use(express.static(path.join(__dirname, 'public')));
|
||||||
|
|
||||||
|
require('./routes/index')(app);
|
||||||
|
|
||||||
// catch 404 and forward to error handler
|
// catch 404 and forward to error handler
|
||||||
app.use(function(req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
@ -13,16 +29,29 @@ app.use(function(req, res, next) {
|
|||||||
next(err);
|
next(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
// error handler
|
// error handlers
|
||||||
app.use(function(err, req, res, next) {
|
|
||||||
// set locals, only providing error in development
|
|
||||||
res.locals.message = err.message;
|
|
||||||
res.locals.error = req.app.get('env') === 'development' ? err : {};
|
|
||||||
|
|
||||||
// render the error page
|
// development error handler
|
||||||
|
// will print stacktrace
|
||||||
|
if (app.get('env') === 'development') {
|
||||||
|
app.use(function(err, req, res, next) {
|
||||||
|
res.status(err.status || 500);
|
||||||
|
res.render('error', {
|
||||||
|
message: err.message,
|
||||||
|
error: err
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// production error handler
|
||||||
|
// no stacktraces leaked to user
|
||||||
|
app.use(function(err, req, res, next) {
|
||||||
res.status(err.status || 500);
|
res.status(err.status || 500);
|
||||||
console.dir(err)
|
res.render('error', {
|
||||||
res.json({message: err.message});
|
message: err.message,
|
||||||
|
error: {}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
module.exports = app;
|
module.exports = app;
|
||||||
|
88
create.sh
Normal file
88
create.sh
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
#!/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
|
||||||
|
export djangoURL="http://$name.staging.bytedev.co"
|
||||||
|
|
||||||
|
git clone $sshURL .
|
||||||
|
|
||||||
|
echo "creating apache VirtualHost file and showing down"
|
||||||
|
|
||||||
|
echo "<VirtualHost *:80>" > /etc/apache2/sites-enabled/$name.conf
|
||||||
|
echo " ServerName $name.staging.bytedev.co" >> /etc/apache2/sites-enabled/$name.conf
|
||||||
|
echo " DocumentRoot $workingPath/static/error_pages" >> /etc/apache2/sites-enabled/$name.conf
|
||||||
|
echo "</VirtualHost>" >> /etc/apache2/sites-enabled/$name.conf
|
||||||
|
|
||||||
|
/usr/sbin/service apache2 reload
|
||||||
|
|
||||||
|
./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
|
||||||
|
chmod 777 -R .track-storage
|
||||||
|
|
||||||
|
forever stop $workingPath/node_rtc/app.js
|
||||||
|
echo "starting node app on port $nodePort"
|
||||||
|
forever start $workingPath/node_rtc/app.js
|
||||||
|
|
||||||
|
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 " RewriteEngine On" >> /etc/apache2/sites-enabled/$name.conf
|
||||||
|
echo " RewriteCond %{HTTP:UPGRADE} ^WebSocket\$ [NC]" >> /etc/apache2/sites-enabled/$name.conf
|
||||||
|
echo " RewriteCond %{HTTP:CONNECTION} Upgrade\$ [NC]" >> /etc/apache2/sites-enabled/$name.conf
|
||||||
|
echo " RewriteRule .* ws://localhost:$nodePort%{REQUEST_URI} [P]" >> /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 /socket.io http://localhost:$nodePort/socket.io" >> /etc/apache2/sites-enabled/$name.conf
|
||||||
|
echo " ProxyPassReverse /socket.io http://localhost:$nodePort/socket.io" >> /etc/apache2/sites-enabled/$name.conf
|
||||||
|
|
||||||
|
echo "</VirtualHost>" >> /etc/apache2/sites-enabled/$name.conf
|
||||||
|
|
||||||
|
/usr/sbin/service apache2 reload
|
||||||
|
|
||||||
|
exit 0
|
17
delete.sh
Normal file
17
delete.sh
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
name="$1"
|
||||||
|
sshURL="$2"
|
||||||
|
workingPath=/var/www/gitwrapper/$name
|
||||||
|
|
||||||
|
|
||||||
|
nodePort=`cat $workingPath/env/nodePort`
|
||||||
|
export NODEPORT=$nodePort
|
||||||
|
forever stop $workingPath/node_rtc/app.js
|
||||||
|
|
||||||
|
rm -rf /var/www/gitwrapper/$name
|
||||||
|
rm /etc/apache2/sites-enabled/$name.conf
|
||||||
|
|
||||||
|
|
||||||
|
/usr/sbin/service apache2 restart
|
||||||
|
|
||||||
|
exit 0
|
11
package.json
11
package.json
@ -6,7 +6,12 @@
|
|||||||
"start": "node ./bin/www"
|
"start": "node ./bin/www"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.16.4",
|
"body-parser": "~1.13.2",
|
||||||
"forever": "^0.15.3"
|
"cookie-parser": "~1.3.5",
|
||||||
|
"debug": "~2.2.0",
|
||||||
|
"ejs": "~2.3.3",
|
||||||
|
"express": "~4.13.1",
|
||||||
|
"morgan": "~1.6.1",
|
||||||
|
"serve-favicon": "~2.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,40 +1,16 @@
|
|||||||
'use strict';
|
var express = require('express');
|
||||||
|
var router = express.Router();
|
||||||
const router = require('express').Router();
|
var exec = require('child_process').exec;
|
||||||
|
|
||||||
const {exec} = require('child_process');
|
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
/* GET home page. */
|
/* GET home page. */
|
||||||
|
|
||||||
var install_dir = '/var/www/gitwrapper/'
|
var install_dir = '/var/www/gitwrapper/'
|
||||||
|
|
||||||
|
|
||||||
// function lxc_create(name, callback) {
|
|
||||||
// exec('lxc-create', [
|
|
||||||
// '-n', 'name_'+(Math.random()*100).toString().slice(-4),
|
|
||||||
// '-t' 'download', '--',
|
|
||||||
// '--dist', 'ubuntu',
|
|
||||||
// '--release', 'xenial',
|
|
||||||
// '--arch', 'amd64']
|
|
||||||
// function(err, stdout, stderr){
|
|
||||||
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
var calls = {
|
var calls = {
|
||||||
create: function(req, res, name, sshURL){
|
create: function(req, res, name, sshURL){
|
||||||
console.log("create =========================");
|
console.log("create =========================");
|
||||||
// create new container
|
|
||||||
// install git in container
|
|
||||||
// seed container with deploy key
|
|
||||||
// clone repo into container
|
|
||||||
// run <repo>/scripts/deploy/create
|
|
||||||
// add entry to proxy
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return exec('bash /var/www/gitdeploy/create.sh '+name+' '+sshURL, function(err, stdout, stderr){
|
return exec('bash /var/www/gitdeploy/create.sh '+name+' '+sshURL, function(err, stdout, stderr){
|
||||||
console.log(err, stdout, stderr);
|
console.log(err, stdout, stderr);
|
||||||
return res.json({ title: stdout });
|
return res.json({ title: stdout });
|
||||||
@ -63,16 +39,12 @@ router.all('/', function(req, res, next) {
|
|||||||
var call = (req.body.created && 'create') ||
|
var call = (req.body.created && 'create') ||
|
||||||
(req.body.deleted && 'delete') ||
|
(req.body.deleted && 'delete') ||
|
||||||
'update';
|
'update';
|
||||||
console.log(req.body);
|
|
||||||
|
|
||||||
var branch = req.body.ref.replace('refs/heads/', '');
|
var name = req.body.ref.replace('refs/heads/', '');
|
||||||
var sshURL = req.body.repository.ssh_url;
|
var sshURL = req.body.repository.ssh_url;
|
||||||
|
if(call === 'update' && !fs.existsSync('/var/www/gitwrapper/'+name)) call = 'create';
|
||||||
|
|
||||||
console.log('branch', branch, 'sshURL', sshURL)
|
return calls[call](req, res, name, sshURL);
|
||||||
// if(call === 'update' && !fs.existsSync('/var/wres.locals.messageww/gitwrapper/'+name)) call = 'create';
|
|
||||||
|
|
||||||
|
|
||||||
// return calls[call](req, res, branch, sshURL);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
10
scripts/clone.sh
Normal file
10
scripts/clone.sh
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
name="$1";
|
||||||
|
sshURL="$2";
|
||||||
|
install_dir="$3";
|
||||||
|
|
||||||
|
mkdir -p $install_dir;
|
||||||
|
cd $install_dir;
|
||||||
|
|
||||||
|
git clone $install_dir;
|
||||||
|
git fetch origin $name:$name;
|
||||||
|
exit 0;
|
@ -1,11 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
name="$1"
|
name="$1"
|
||||||
sshURL="$2"
|
sshURL="$2"
|
||||||
workingPath=/var/www/gitwrapper/$name
|
install_dir="$3"
|
||||||
|
|
||||||
eval "$(ssh-agent -s)"
|
eval "$(ssh-agent -s)"
|
||||||
ssh-add /root/.ssh/id_github_rsa
|
ssh-add /root/.ssh/id_github_rsa
|
||||||
cd $workingPath
|
cd $install_dir
|
||||||
|
|
||||||
|
|
||||||
DJANGO_SETTINGS_MODULE=project.settings.prod
|
DJANGO_SETTINGS_MODULE=project.settings.prod
|
||||||
@ -31,8 +31,8 @@ nodePort=`cat env/nodePort`
|
|||||||
export NODEPORT=$nodePort
|
export NODEPORT=$nodePort
|
||||||
export djangoURL="http://$name.staging.bytedev.co"
|
export djangoURL="http://$name.staging.bytedev.co"
|
||||||
|
|
||||||
forever stop $workingPath/node_rtc/app.js
|
forever stop $install_dir/node_rtc/app.js
|
||||||
forever start $workingPath/node_rtc/app.js
|
forever start $install_dir/node_rtc/app.js
|
||||||
|
|
||||||
/usr/sbin/service apache2 restart
|
/usr/sbin/service apache2 restart
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user