Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
6ce5f44a02 | |||
1b856f261f | |||
3072ebe966 | |||
c3293e1ec4 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -28,5 +28,3 @@ node_modules
|
||||
|
||||
# Debug log from npm
|
||||
npm-debug.log
|
||||
|
||||
settings.json
|
||||
|
55
app.js
55
app.js
@ -1,26 +1,10 @@
|
||||
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');
|
||||
'use strict';
|
||||
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
|
||||
var app = express();
|
||||
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);
|
||||
app.use(express.json());
|
||||
app.use('/', require('./routes/index'));
|
||||
|
||||
// catch 404 and forward to error handler
|
||||
app.use(function(req, res, next) {
|
||||
@ -29,29 +13,16 @@ app.use(function(req, res, next) {
|
||||
next(err);
|
||||
});
|
||||
|
||||
// error handlers
|
||||
|
||||
// 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
|
||||
// error handler
|
||||
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
|
||||
res.status(err.status || 500);
|
||||
res.render('error', {
|
||||
message: err.message,
|
||||
error: {}
|
||||
});
|
||||
console.dir(err)
|
||||
res.json({message: err.message});
|
||||
});
|
||||
|
||||
|
||||
module.exports = app;
|
||||
|
88
create.sh
88
create.sh
@ -1,88 +0,0 @@
|
||||
#!/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
17
delete.sh
@ -1,17 +0,0 @@
|
||||
#!/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
|
@ -6,12 +6,7 @@
|
||||
"start": "node ./bin/www"
|
||||
},
|
||||
"dependencies": {
|
||||
"body-parser": "~1.13.2",
|
||||
"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"
|
||||
"express": "^4.16.4",
|
||||
"forever": "^0.15.3"
|
||||
}
|
||||
}
|
@ -1,16 +1,40 @@
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
var exec = require('child_process').exec;
|
||||
'use strict';
|
||||
|
||||
const router = require('express').Router();
|
||||
|
||||
const {exec} = require('child_process');
|
||||
var fs = require('fs');
|
||||
/* GET home page. */
|
||||
|
||||
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 = {
|
||||
create: function(req, res, name, sshURL){
|
||||
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){
|
||||
console.log(err, stdout, stderr);
|
||||
return res.json({ title: stdout });
|
||||
@ -39,12 +63,16 @@ router.all('/', function(req, res, next) {
|
||||
var call = (req.body.created && 'create') ||
|
||||
(req.body.deleted && 'delete') ||
|
||||
'update';
|
||||
console.log(req.body);
|
||||
|
||||
var name = req.body.ref.replace('refs/heads/', '');
|
||||
var branch = 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);
|
||||
console.log('branch', branch, 'sshURL', sshURL)
|
||||
// if(call === 'update' && !fs.existsSync('/var/wres.locals.messageww/gitwrapper/'+name)) call = 'create';
|
||||
|
||||
|
||||
// return calls[call](req, res, branch, sshURL);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
@ -1,10 +0,0 @@
|
||||
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
|
||||
name="$1"
|
||||
sshURL="$2"
|
||||
install_dir="$3"
|
||||
workingPath=/var/www/gitwrapper/$name
|
||||
|
||||
eval "$(ssh-agent -s)"
|
||||
ssh-add /root/.ssh/id_github_rsa
|
||||
cd $install_dir
|
||||
cd $workingPath
|
||||
|
||||
|
||||
DJANGO_SETTINGS_MODULE=project.settings.prod
|
||||
@ -31,8 +31,8 @@ nodePort=`cat env/nodePort`
|
||||
export NODEPORT=$nodePort
|
||||
export djangoURL="http://$name.staging.bytedev.co"
|
||||
|
||||
forever stop $install_dir/node_rtc/app.js
|
||||
forever start $install_dir/node_rtc/app.js
|
||||
forever stop $workingPath/node_rtc/app.js
|
||||
forever start $workingPath/node_rtc/app.js
|
||||
|
||||
/usr/sbin/service apache2 restart
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user