From b54d5533c99c0f262d1eb3779dabffc7ada646ab Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 18:37:44 -0400 Subject: [PATCH 01/23] first --- bin/www | 2 +- routes/create.sh | 38 ++++++++++++++++++++++++++++++++++ routes/index.js | 54 +++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 routes/create.sh diff --git a/bin/www b/bin/www index af073dd..1a37480 100755 --- a/bin/www +++ b/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); /** diff --git a/routes/create.sh b/routes/create.sh new file mode 100644 index 0000000..b9e3798 --- /dev/null +++ b/routes/create.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +name="$1" +sshURL="$2" + +eval "$(ssh-agent -s)" +ssh-add /root/.ssh/github_rsa +cd /var/www/gitwrapper +mkdir $name +cd $name + +git clone $sshURL . +git checkout $name +virtual env +source env/bin/activate +pip3 install -r /var/www/gitwrapper/requirements.txt > /var/www/pipinstall.log +DJANGO_SETTINGS_MODULE=project.settings.prod +export DJANGO_SETTINGS_MODULE=project.settings.prod +cp /var/www/local_settings.py project/ +echo "BRANCH = /"$name/"" >> project/local_settings.py + +python3 manage.py loaddata /var/www/django.dump +python3 manage.py collectstatic --noinput +python3 manage.py migrate +chmod 777 . +chmod 777 db.sqlite3 + +echo '' > /etc/apache2/sites-enabled/runner.conf +echo ' Alias /static /var/www/gitwrapper/$name/staticfiles' > /etc/apache2/sites-enabled/runner.conf +echo ' WSGIDaemonProcess $name python-path=/var/www/gitwrapper/$name:/var/www/gitwrapper/$name/env/lib/python3.4/site-packages' >> /etc/apache2/sites-enabled/runner.conf +echo ' WSGIProcessGroup $name' >> /etc/apache2/sites-enabled/runner.conf +echo ' WSGIScriptAlias / /var/www/gitwrapper/$name/project/wsgi.py' >> /etc/apache2/sites-enabled/runner.conf +echo '' >> /etc/apache2/sites-enabled/runner.conf + + +service apache2 restart + +# copy and make data base diff --git a/routes/index.js b/routes/index.js index 8645530..ac059f0 100644 --- a/routes/index.js +++ b/routes/index.js @@ -2,14 +2,62 @@ var express = require('express'); var router = express.Router(); var exec = require('child_process').exec; /* GET home page. */ + +var install_dir = '/var/www/gitwrapper/' + +// var shell = { +// clone: function(name, sshURL, callback){ +// return exec('git clone '+ sshURL + ' '+ install_dir + name, function(err, stdout, stderr){ +// return callback(name, stdout); +// }, +// setUpENV: function(){ + +// } +// }; + + +var calls = { + create: function(name, sshURL){ + exec('git clone '+ sshURL + ' /var/www/gitwrapper/'+ name, function(err, stdout, stderr){ + // set up virtual env + // install req file + // sync db + // run migrations + // write apache file + // reload apache + }); + }, + update: function(name, sshURL){ + // git pull + // run migrations + // install req file + // reload apache + }, + delete: function(name){ + // delete dir + // remove apache file + // reload apache + } + +}; + + router.all('/', function(req, res, next) { - if(req.headers['x-github-event'] === 'push'){ + 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; + exec('pwd', console.log); + console.log('call', call, 'event:', event, 'name:', name, 'sshURL:', sshURL) + // console.log("\n=================\n\n", req.body); +/* 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' }); + }*/ + res.json({ title: 'Express' }); }); module.exports = router; From 260881acd7e73f19713b48c336b1a2987c6d04fb Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 18:49:32 -0400 Subject: [PATCH 02/23] stuff --- routes/create.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/routes/create.sh b/routes/create.sh index b9e3798..48defb5 100644 --- a/routes/create.sh +++ b/routes/create.sh @@ -4,10 +4,10 @@ name="$1" sshURL="$2" eval "$(ssh-agent -s)" -ssh-add /root/.ssh/github_rsa -cd /var/www/gitwrapper -mkdir $name -cd $name +ssh-add /root/.ssh/id_github_rsa +mkdir /var/www/gitwrapper/$name +cd /var/www/gitwrapper/$name +echo pwd git clone $sshURL . git checkout $name @@ -25,12 +25,12 @@ python3 manage.py migrate chmod 777 . chmod 777 db.sqlite3 -echo '' > /etc/apache2/sites-enabled/runner.conf -echo ' Alias /static /var/www/gitwrapper/$name/staticfiles' > /etc/apache2/sites-enabled/runner.conf -echo ' WSGIDaemonProcess $name python-path=/var/www/gitwrapper/$name:/var/www/gitwrapper/$name/env/lib/python3.4/site-packages' >> /etc/apache2/sites-enabled/runner.conf -echo ' WSGIProcessGroup $name' >> /etc/apache2/sites-enabled/runner.conf -echo ' WSGIScriptAlias / /var/www/gitwrapper/$name/project/wsgi.py' >> /etc/apache2/sites-enabled/runner.conf -echo '' >> /etc/apache2/sites-enabled/runner.conf +echo "" > /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/lib/python3.4/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 "" >> /etc/apache2/sites-enabled/$name.conf service apache2 restart From ffef2a59c3078391a439b700d756745d6fd57ddb Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 18:53:26 -0400 Subject: [PATCH 03/23] stuff --- routes/create.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/create.sh b/routes/create.sh index 48defb5..c6dd9a0 100644 --- a/routes/create.sh +++ b/routes/create.sh @@ -7,7 +7,7 @@ eval "$(ssh-agent -s)" ssh-add /root/.ssh/id_github_rsa mkdir /var/www/gitwrapper/$name cd /var/www/gitwrapper/$name -echo pwd +echo `pwd` git clone $sshURL . git checkout $name From 208395bb47dc2c0dfd37660e8b1b5e0354ee1453 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 18:56:04 -0400 Subject: [PATCH 04/23] stuff --- routes/create.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/create.sh b/routes/create.sh index c6dd9a0..4f7129f 100644 --- a/routes/create.sh +++ b/routes/create.sh @@ -13,7 +13,7 @@ git clone $sshURL . git checkout $name virtual env source env/bin/activate -pip3 install -r /var/www/gitwrapper/requirements.txt > /var/www/pipinstall.log +pip3 install -r requirements.txt DJANGO_SETTINGS_MODULE=project.settings.prod export DJANGO_SETTINGS_MODULE=project.settings.prod cp /var/www/local_settings.py project/ From 586500033006da68377bf4716fa2ea699d23e499 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 18:58:15 -0400 Subject: [PATCH 05/23] stuff --- routes/create.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/create.sh b/routes/create.sh index 4f7129f..1ad345d 100644 --- a/routes/create.sh +++ b/routes/create.sh @@ -11,7 +11,7 @@ echo `pwd` git clone $sshURL . git checkout $name -virtual env +virtualenv env source env/bin/activate pip3 install -r requirements.txt DJANGO_SETTINGS_MODULE=project.settings.prod From 7b8d7b439afab6e5832496498850d2498fa15f0c Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 19:02:40 -0400 Subject: [PATCH 06/23] stuff --- routes/create.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/create.sh b/routes/create.sh index 1ad345d..b53426e 100644 --- a/routes/create.sh +++ b/routes/create.sh @@ -16,8 +16,8 @@ source env/bin/activate pip3 install -r requirements.txt DJANGO_SETTINGS_MODULE=project.settings.prod export DJANGO_SETTINGS_MODULE=project.settings.prod -cp /var/www/local_settings.py project/ -echo "BRANCH = /"$name/"" >> project/local_settings.py +cp /var/www/local_settings.py project/settings/local_settings.py +echo "BRANCH = '$name'" >> project/settings/local_settings.py python3 manage.py loaddata /var/www/django.dump python3 manage.py collectstatic --noinput From 00b474a0717997319f955058325ccf589c2f3564 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 19:05:19 -0400 Subject: [PATCH 07/23] stuff --- routes/create.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/routes/create.sh b/routes/create.sh index b53426e..73f8858 100644 --- a/routes/create.sh +++ b/routes/create.sh @@ -26,7 +26,8 @@ chmod 777 . chmod 777 db.sqlite3 echo "" > /etc/apache2/sites-enabled/$name.conf -echo " Alias /static /var/www/gitwrapper/$name/staticfiles" > /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/lib/python3.4/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 From 46bdac5aa8fb84dcb541a88182841b675e59b256 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 19:07:58 -0400 Subject: [PATCH 08/23] stuff --- routes/create.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/create.sh b/routes/create.sh index 73f8858..3f5ebf1 100644 --- a/routes/create.sh +++ b/routes/create.sh @@ -28,7 +28,7 @@ chmod 777 db.sqlite3 echo "" > /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/lib/python3.4/site-packages" >> /etc/apache2/sites-enabled/$name.conf +echo " WSGIDaemonProcess $name python-path=/var/www/gitwrapper/$name:/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 "" >> /etc/apache2/sites-enabled/$name.conf From e31aaedf279a9ab71257036b93bdd54a0d73acd1 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 19:30:22 -0400 Subject: [PATCH 09/23] stuff --- routes/create.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/routes/create.sh b/routes/create.sh index 3f5ebf1..1779430 100644 --- a/routes/create.sh +++ b/routes/create.sh @@ -9,17 +9,19 @@ 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 . git checkout $name virtualenv env source env/bin/activate + pip3 install -r requirements.txt -DJANGO_SETTINGS_MODULE=project.settings.prod -export DJANGO_SETTINGS_MODULE=project.settings.prod cp /var/www/local_settings.py project/settings/local_settings.py echo "BRANCH = '$name'" >> project/settings/local_settings.py -python3 manage.py loaddata /var/www/django.dump +python3 manage.py loaddata "/var/www/django.dump" python3 manage.py collectstatic --noinput python3 manage.py migrate chmod 777 . From 8c7beea59b72f2c6bff32693b4711609ee1234c0 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 19:35:10 -0400 Subject: [PATCH 10/23] stuff --- routes/create.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/create.sh b/routes/create.sh index 1779430..2e984f5 100644 --- a/routes/create.sh +++ b/routes/create.sh @@ -17,7 +17,7 @@ git checkout $name virtualenv env source env/bin/activate -pip3 install -r requirements.txt +pip install -r requirements.txt cp /var/www/local_settings.py project/settings/local_settings.py echo "BRANCH = '$name'" >> project/settings/local_settings.py @@ -30,7 +30,7 @@ chmod 777 db.sqlite3 echo "" > /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/lib/python3.5/site-packages" >> /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 "" >> /etc/apache2/sites-enabled/$name.conf From b48e243cc6db5359e737a8dbf01077e7d1e80faa Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 20:47:23 -0400 Subject: [PATCH 11/23] stuff --- routes/create.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/routes/create.sh b/routes/create.sh index 2e984f5..0e5094a 100644 --- a/routes/create.sh +++ b/routes/create.sh @@ -13,6 +13,9 @@ DJANGO_SETTINGS_MODULE=project.settings.prod export DJANGO_SETTINGS_MODULE=project.settings.prod git clone $sshURL . +python3 manage.py migrate +python3 manage.py loaddata "/var/www/django.dump" + git checkout $name virtualenv env source env/bin/activate @@ -21,7 +24,6 @@ pip install -r requirements.txt cp /var/www/local_settings.py project/settings/local_settings.py echo "BRANCH = '$name'" >> project/settings/local_settings.py -python3 manage.py loaddata "/var/www/django.dump" python3 manage.py collectstatic --noinput python3 manage.py migrate chmod 777 . From 425632146253220831b0ad943beae9eff9d03bb2 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 20:55:30 -0400 Subject: [PATCH 12/23] stuff --- routes/create.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/routes/create.sh b/routes/create.sh index 0e5094a..c764105 100644 --- a/routes/create.sh +++ b/routes/create.sh @@ -13,12 +13,14 @@ 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 + python3 manage.py migrate python3 manage.py loaddata "/var/www/django.dump" git checkout $name -virtualenv env -source env/bin/activate pip install -r requirements.txt cp /var/www/local_settings.py project/settings/local_settings.py From e1ce7c148c57060bb8ef19272af10f79c5ad03d4 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 20:56:32 -0400 Subject: [PATCH 13/23] stuff --- routes/create.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/create.sh b/routes/create.sh index c764105..15738c5 100644 --- a/routes/create.sh +++ b/routes/create.sh @@ -16,6 +16,8 @@ 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 python3 manage.py migrate python3 manage.py loaddata "/var/www/django.dump" @@ -23,8 +25,6 @@ python3 manage.py loaddata "/var/www/django.dump" git checkout $name pip install -r requirements.txt -cp /var/www/local_settings.py project/settings/local_settings.py -echo "BRANCH = '$name'" >> project/settings/local_settings.py python3 manage.py collectstatic --noinput python3 manage.py migrate From f2eaa293395155817d1d3f83c182045d483f0a30 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 21:00:05 -0400 Subject: [PATCH 14/23] stuff --- routes/create.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/routes/create.sh b/routes/create.sh index 15738c5..9a71c91 100644 --- a/routes/create.sh +++ b/routes/create.sh @@ -19,8 +19,9 @@ 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.dump" +python3 manage.py loaddata "/var/www/django" git checkout $name From e26e8f8305258dbee9bc846020b72f448ec8f604 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 22:26:50 -0400 Subject: [PATCH 15/23] stuff --- routes/create.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/create.sh b/routes/create.sh index 9a71c91..ecf928c 100644 --- a/routes/create.sh +++ b/routes/create.sh @@ -21,7 +21,7 @@ echo "BRANCH = '$name'" >> project/settings/local_settings.py python manage.py createcachetable python3 manage.py migrate -python3 manage.py loaddata "/var/www/django" +python3 manage.py loaddata "/var/www/django.json" git checkout $name From b827c91fae67f2eaba59465dbb014792bea6098b Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 22:27:22 -0400 Subject: [PATCH 16/23] stuff --- routes/create.sh => create.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename routes/create.sh => create.sh (100%) diff --git a/routes/create.sh b/create.sh similarity index 100% rename from routes/create.sh rename to create.sh From 307856f96946f40755af57c10bb415d5fae7dbee Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 22:34:19 -0400 Subject: [PATCH 17/23] stuff --- routes/index.js | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/routes/index.js b/routes/index.js index ac059f0..2ab2562 100644 --- a/routes/index.js +++ b/routes/index.js @@ -17,14 +17,9 @@ var install_dir = '/var/www/gitwrapper/' var calls = { - create: function(name, sshURL){ - exec('git clone '+ sshURL + ' /var/www/gitwrapper/'+ name, function(err, stdout, stderr){ - // set up virtual env - // install req file - // sync db - // run migrations - // write apache file - // reload apache + create: function(req, res, name, sshURL){ + return exec('bash create.sh '+name+' '+sshURL, function(err, stdout, stderr){ + return res.json({ title: 'Express' }); }); }, update: function(name, sshURL){ @@ -48,16 +43,8 @@ router.all('/', function(req, res, next) { var name = req.body.ref.replace('refs/heads/', ''); var sshURL = req.body.repository.ssh_url; - exec('pwd', console.log); - console.log('call', call, 'event:', event, 'name:', name, 'sshURL:', sshURL) - // console.log("\n=================\n\n", req.body); -/* 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.json({ title: 'Express' }); + + return calls[call](req, res, name, sshURL); }); module.exports = router; From ad1c8e7205f887af5ebecfaae15c388a4519a5f2 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 22:51:16 -0400 Subject: [PATCH 18/23] stuff --- create.sh | 2 +- delete.sh | 10 ++++++++++ routes/index.js | 25 +++++++++---------------- update.sh | 24 ++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 delete.sh create mode 100644 update.sh diff --git a/create.sh b/create.sh index ecf928c..6ee54ef 100644 --- a/create.sh +++ b/create.sh @@ -43,4 +43,4 @@ echo "" >> /etc/apache2/sites-enabled/$name.conf service apache2 restart -# copy and make data base +exit 0 diff --git a/delete.sh b/delete.sh new file mode 100644 index 0000000..aa0b6c1 --- /dev/null +++ b/delete.sh @@ -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 diff --git a/routes/index.js b/routes/index.js index 2ab2562..b2d2695 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,19 +1,12 @@ var express = require('express'); var router = express.Router(); var exec = require('child_process').exec; +var fs = require('fs'); +var fs = fs.existsSync(dir) /* GET home page. */ var install_dir = '/var/www/gitwrapper/' - -// var shell = { -// clone: function(name, sshURL, callback){ -// return exec('git clone '+ sshURL + ' '+ install_dir + name, function(err, stdout, stderr){ -// return callback(name, stdout); -// }, -// setUpENV: function(){ -// } -// }; var calls = { @@ -23,15 +16,14 @@ var calls = { }); }, update: function(name, sshURL){ - // git pull - // run migrations - // install req file - // reload apache + return exec('bash update.sh '+name+' '+sshURL, function(err, stdout, stderr){ + return res.json({ title: 'Express' }); + }); }, delete: function(name){ - // delete dir - // remove apache file - // reload apache + return exec('bash delete.sh '+name+' '+sshURL, function(err, stdout, stderr){ + return res.json({ title: 'Express' }); + }); } }; @@ -43,6 +35,7 @@ router.all('/', function(req, res, next) { 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); }); diff --git a/update.sh b/update.sh new file mode 100644 index 0000000..1d7a247 --- /dev/null +++ b/update.sh @@ -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 From 157f9ad718887e99cdf161ee3bc438d25d10f3e7 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 22:52:04 -0400 Subject: [PATCH 19/23] stuff --- routes/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/routes/index.js b/routes/index.js index b2d2695..9f71cdd 100644 --- a/routes/index.js +++ b/routes/index.js @@ -2,7 +2,6 @@ var express = require('express'); var router = express.Router(); var exec = require('child_process').exec; var fs = require('fs'); -var fs = fs.existsSync(dir) /* GET home page. */ var install_dir = '/var/www/gitwrapper/' From 6693101f58a6e9aa4335325587dbb64fcf8ce1cb Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 22:54:37 -0400 Subject: [PATCH 20/23] stuff --- routes/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/index.js b/routes/index.js index 9f71cdd..3d8f597 100644 --- a/routes/index.js +++ b/routes/index.js @@ -14,12 +14,12 @@ var calls = { return res.json({ title: 'Express' }); }); }, - update: function(name, sshURL){ + update: function(req, res, name, sshURL){ return exec('bash update.sh '+name+' '+sshURL, function(err, stdout, stderr){ return res.json({ title: 'Express' }); }); }, - delete: function(name){ + delete: function(req, res, name, sshURL){ return exec('bash delete.sh '+name+' '+sshURL, function(err, stdout, stderr){ return res.json({ title: 'Express' }); }); From 045d14a867f022347eec3882b3df0d570afd8d7b Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 23:13:25 -0400 Subject: [PATCH 21/23] stuff --- routes/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/routes/index.js b/routes/index.js index 3d8f597..1472c27 100644 --- a/routes/index.js +++ b/routes/index.js @@ -11,16 +11,19 @@ var install_dir = '/var/www/gitwrapper/' var calls = { create: function(req, res, name, sshURL){ return exec('bash create.sh '+name+' '+sshURL, function(err, stdout, stderr){ + console.log(err, stdout, stderr); return res.json({ title: 'Express' }); }); }, update: function(req, res, name, sshURL){ return exec('bash update.sh '+name+' '+sshURL, function(err, stdout, stderr){ + console.log(err, stdout, stderr); return res.json({ title: 'Express' }); }); }, delete: function(req, res, name, sshURL){ return exec('bash delete.sh '+name+' '+sshURL, function(err, stdout, stderr){ + console.log(err, stdout, stderr); return res.json({ title: 'Express' }); }); } From 290b1f1fef3585652188ace78b97c6d350bbabde Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 23:17:43 -0400 Subject: [PATCH 22/23] stuff --- routes/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/routes/index.js b/routes/index.js index 1472c27..48148bf 100644 --- a/routes/index.js +++ b/routes/index.js @@ -10,19 +10,19 @@ var install_dir = '/var/www/gitwrapper/' var calls = { create: function(req, res, name, sshURL){ - return exec('bash 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); return res.json({ title: 'Express' }); }); }, update: function(req, res, name, sshURL){ - return exec('bash update.sh '+name+' '+sshURL, function(err, stdout, stderr){ + return exec('bash /var/www/gitdeploy/update.sh '+name+' '+sshURL, function(err, stdout, stderr){ console.log(err, stdout, stderr); return res.json({ title: 'Express' }); }); }, delete: function(req, res, name, sshURL){ - return exec('bash delete.sh '+name+' '+sshURL, function(err, stdout, stderr){ + return exec('bash /var/www/gitdeploy/delete.sh '+name+' '+sshURL, function(err, stdout, stderr){ console.log(err, stdout, stderr); return res.json({ title: 'Express' }); }); From 0fba8f8fbeda6c9cae9f3c7dd7a264f9f1c0cfff Mon Sep 17 00:00:00 2001 From: William Mantly Date: Thu, 16 Jun 2016 23:24:01 -0400 Subject: [PATCH 23/23] stuff --- routes/index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/routes/index.js b/routes/index.js index 48148bf..cdf9eb2 100644 --- a/routes/index.js +++ b/routes/index.js @@ -11,19 +11,19 @@ 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: 'Express' }); }); }, 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: 'Express' }); }); }, 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: 'Express' }); }); } @@ -33,7 +33,9 @@ var calls = { 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 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;