1 Commits

Author SHA1 Message Date
74103cc401 ads 2016-09-30 18:22:13 -04:00
5 changed files with 18 additions and 77 deletions

View File

@ -1,88 +1,52 @@
#!/bin/bash #!/bin/bash
name="$1" name="$1"
sshURL="$2" 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" nodePort=`./random_port.py`
eval "$(ssh-agent -s)" eval "$(ssh-agent -s)"
ssh-add /root/.ssh/id_github_rsa ssh-add /root/.ssh/id_github_rsa
mkdir $workingPath mkdir /var/www/gitwrapper/$name
cd $workingPath cd /var/www/gitwrapper/$name
chmod 777 . chmod 777 .
echo `pwd` echo `pwd`
DJANGO_SETTINGS_MODULE=project.settings.prod DJANGO_SETTINGS_MODULE=project.settings.prod
export 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 . 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 ./scripts/setup.sh
source env/bin/activate
cp /var/www/local_settings.py project/settings/local_settings.py cp /var/www/local_settings.py project/settings/local_settings.py
echo "BRANCH='$name'" >> 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" # set up project from prod, load database
git checkout prod git checkout prod
python3 manage.py createcachetable ./manage.py createcachetable
python3 manage.py migrate ./manage.py migrate
python3 manage.py loaddata /var/www/django.json ./manage.py loaddata /var/www/django.json
echo "checking out to $name for set up"
git checkout $name git checkout $name
./scripts/setup.sh ./scripts/setup.sh
python3 manage.py collectstatic --noinput # python3 manage.py collectstatic --noinput
python3 manage.py migrate ./manage.py migrate
chmod 777 db.sqlite3 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"
# set up apache vhost
echo "<VirtualHost *:80>" > /etc/apache2/sites-enabled/$name.conf echo "<VirtualHost *:80>" > /etc/apache2/sites-enabled/$name.conf
echo " ServerName $name.staging.bytedev.co" >> /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 " Alias /static /var/www/gitwrapper/$name/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 " 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 " WSGIProcessGroup $name" >> /etc/apache2/sites-enabled/$name.conf
echo " WSGIScriptAlias / $workingPath/project/wsgi.py" >> /etc/apache2/sites-enabled/$name.conf echo " WSGIScriptAlias / /var/www/gitwrapper/$name/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 echo "</VirtualHost>" >> /etc/apache2/sites-enabled/$name.conf
/usr/sbin/service apache2 reload /usr/sbin/service apache2 restart
exit 0 exit 0

View File

@ -1,17 +1,10 @@
#!/bin/bash #!/bin/bash
name="$1" name="$1"
sshURL="$2" 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 -rf /var/www/gitwrapper/$name
rm /etc/apache2/sites-enabled/$name.conf rm /etc/apache2/sites-enabled/$name.conf
/usr/sbin/service apache2 restart /usr/sbin/service apache2 restart
exit 0 exit 0

View File

@ -10,21 +10,18 @@ var install_dir = '/var/www/gitwrapper/'
var calls = { var calls = {
create: function(req, res, name, sshURL){ create: function(req, res, name, sshURL){
console.log("create =========================");
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 });
}); });
}, },
update: function(req, res, name, sshURL){ update: function(req, res, name, sshURL){
console.log("update =========================");
return exec('bash /var/www/gitdeploy/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); console.log(err, stdout, stderr);
return res.json({ title: stdout }); return res.json({ title: stdout });
}); });
}, },
delete: function(req, res, name, sshURL){ delete: function(req, res, name, sshURL){
console.log("delete =========================");
return exec('bash /var/www/gitdeploy/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); console.log(err, stdout, stderr);
return res.json({ title: stdout }); return res.json({ title: stdout });

0
test Normal file
View File

View File

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