Skip to content

Commit

Permalink
Merge pull request #38 from RuggedPOD/update-dev-env
Browse files Browse the repository at this point in the history
Update dev environement
  • Loading branch information
ggiamarchi authored Sep 15, 2016
2 parents 4cd7ede + 9d79e76 commit 902db69
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 27 deletions.
163 changes: 141 additions & 22 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,184 @@
$script = <<SCRIPT
set -ex
sudo apt-get update
sudo apt-get install -y apache2 apache2-dev python-dev python-pip libxml2-dev \
libxslt1-dev zlib1g-dev libffi-dev libssl-dev git
##################################################################
### SSH Config
##################################################################
mod_wsgi_version=4.4.21
cd /tmp
wget https://github.com/GrahamDumpleton/mod_wsgi/archive/${mod_wsgi_version}.tar.gz
tar xvzf ${mod_wsgi_version}.tar.gz
cd mod_wsgi-${mod_wsgi_version}
./configure && make && sudo make install
cd
rm -rf /tmp/mod_wsgi-${mod_wsgi_version}
sudo bash -c 'echo "LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so" > /etc/apache2/mods-available/wsgi.load'
mkdir -p $HOME/.ssh
cat > $HOME/.ssh/config <<EOF
Host *
StrictHostKeyChecking no
EOF
sudo a2enmod proxy_http
sudo a2enmod rewrite
sudo a2enmod proxy_wstunnel
sudo a2enmod ssl
sudo a2enmod wsgi
##################################################################
### Apt update
##################################################################
sudo apt-get update
##################################################################
### Generate Self signed certificate
##################################################################
cert=/etc/ssl/certs/ruggedpod
sudo openssl req -nodes -newkey rsa:2048 -keyout ${cert}.key -out ${cert}.csr \
-subj "/C=FR/ST=Paris/L=Paris/O=OCP/OU=RuggedPOD/CN=admin.ruggedpod"
sudo openssl x509 -req -days 365 -in ${cert}.csr -signkey ${cert}.key -out ${cert}.crt
##################################################################
### Install tools
##################################################################
sudo apt-get install -y --force-yes git tcpdump bridge-utils jq curl build-essential
##################################################################
### Install DHCP server
##################################################################
sudo apt-get install -y --force-yes dnsmasq
sudo mkdir -p /tftp/pxe/pxelinux.cfg
sudo mkdir -p /var/www/pxe
sleep 5 # Dnsmasq startup can cause temporary network issue during a short time
# Wait to avoid any problem
##################################################################
### Install Docker
##################################################################
curl -s 'https://sks-keyservers.net/pks/lookup?op=get&search=0xee6d536cf7dc86e2d7d56f59a178ac6c6238f52e' | sudo apt-key add --import
echo "deb https://packages.docker.com/1.11/apt/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt-get update
sudo apt-get install -y --force-yes linux-headers-3.13.0-85-generic \
apt-transport-https \
linux-image-extra-virtual \
docker-engine
sudo usermod -aG docker vagrant
sudo bash -c 'echo "DOCKER_OPTS=\\\"-H unix:// -H tcp://0.0.0.0:2375\\\"" > /etc/default/docker'
sudo service docker restart
##################################################################
### Wait for docker deamon to be ready
##################################################################
set +e
while true ; do
sleep 1
sudo docker info
if [ $? -eq 0 ] ; then
break
fi
done
set -e
##################################################################
### Build Docker image for blade emulation
##################################################################
sudo docker build -t blade:latest /vagrant/dev
##################################################################
### Run four containers to emulate the four blades
##################################################################
for i in 1 2 3 4 ; do
sudo docker run -d --restart=always --name blade${i} blade:latest
done
##################################################################
### Install Apache + System dependencies for python app
##################################################################
sudo apt-get install -y --force-yes apache2 python-dev python-pip libxml2-dev \
libxslt1-dev zlib1g-dev libffi-dev libssl-dev
##################################################################
### Apache configuration
##################################################################
sudo a2enmod proxy_http
sudo a2enmod rewrite
sudo a2enmod proxy_wstunnel
sudo a2enmod ssl
sudo rm -f /etc/apache2/ports.conf /etc/apache2/sites-enabled/*
sudo ln -s /vagrant/apache/ports.conf /etc/apache2/ports.conf
sudo ln -s /vagrant/apache/ruggedpod-vhost.conf /etc/apache2/sites-enabled/ruggedpod-vhost.conf
##################################################################
### Install RuggedPOD API
##################################################################
cd /opt/ruggedpod-api
sudo pip install -r test-requirements.txt
sudo pip install -e .
sudo pip uninstall -y rpi.gpio
sudo bash -c 'echo "from ruggedpod_api.server import app as application" > /var/www/ruggedpod.wsgi'
sed -i "s/profile: production/profile: development/" conf.yaml
curl -sSL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y git nodejs build-essential
##################################################################
### Install NodeJS (for RuggedPOD serial web console)
##################################################################
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo npm install -g bower
sudo npm install -g grunt-cli
##################################################################
### Fetch web application dependencies
##################################################################
cd /vagrant
sudo rm -rf web/packages
bower install
##################################################################
### Fetch serial web console dependencies
##################################################################
cd /vagrant/serial
sudo chown -R vagrant: /home/vagrant/.npm
sudo rm -rf node_modules
npm install --no-bin-links
npm install
sed -i "s/screen-safe/screen-mock/" config.json
##################################################################
### Setup startup script
##################################################################
sudo tee /etc/rc.local > /dev/null << EOL
#!/bin/bash
cd /vagrant/serial
npm start >> /var/log/ruggedpod-serial-terminal.log 2>&1 &
nohup npm start >> /var/log/ruggedpod-serial-terminal.log &
service apache2 restart
cd /opt/ruggedpod-api
nohup python ruggedpod_api/server.py --debug >> /var/log/ruggedpod-api.log 2>&1 &
EOL
sudo chmod a+x /etc/rc.local
Expand Down
7 changes: 3 additions & 4 deletions apache/ruggedpod-vhost.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
ProxyPass /serial http://localhost:9000
ProxyPassReverse /serial http://localhost:9000

ProxyPass /api http://localhost:5000
ProxyPassReverse /api http://localhost:5000

RewriteEngine on
RewriteCond %{QUERY_STRING} transport=polling
RewriteRule /(.*)$ http://localhost:9000/$1 [P]

ProxyRequests off
ProxyPass /socket.io/ ws://localhost:9000/socket.io/
ProxyPassReverse /socket.io/ ws://localhost:9000/socket.io/

WSGIDaemonProcess ruggedpod user=vagrant group=vagrant processes=1 threads=20
WSGIScriptAlias /api /var/www/ruggedpod.wsgi
WSGIProcessGroup ruggedpod
</VirtualHost>
12 changes: 12 additions & 0 deletions dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM ubuntu:14.04

RUN set -ex && \
apt-get update && \
apt-get install -y --force-yes openssh-server

RUN mkdir /root/.ssh

ADD keys/blade.pub /root/.ssh/authorized_keys

RUN mkdir /var/run/sshd
CMD ["/usr/sbin/sshd", "-D"]
27 changes: 27 additions & 0 deletions dev/keys/blade
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAnMTI+fXVH1XvSa6nLGzYaRfmwpiSrXbs4KT6mLhxpjLDX00t
OGeMKGN9R9mG/yVPE228BrH48TXRHyaQzK7rylp8fD0o+unt6x/o8Kcgo4RWYRwR
RrZSUgUBNv0heE7Zxg+rE5gib17eIKjWBQ4YWFOBnANHP7QJonr5l8ECZvwkPYze
Sax0M5u1fz/8c5vcFx9m1vw+vxkw7Oq7nV7hvNFViDJl5/9oInYs14axZFJPwZbw
cwQGjoBQLEVCk0u178NxviDSWsHC81jC5rHxber2w7iVFGKHqkjBrE9A3HXxAYig
SYLnmYfX9+afEmiCo7PeVvGXWoLrox1qxV61kwIDAQABAoIBAFz8mF0zhOOeXF3v
G7fNJBxKEhVQ3IfJp72j/gSCOt8i8yHfLDhtqwP150Sr8Vf78EiM6V9rR0cD7fO1
M2RFSRTw0S/8MweJpBa4Cbpc145GG9pkBJdV48REtbDBOo4a7y988bOgpKQ8uDLV
EoVTE/uoJJO+mg9eIezfVpa95Efiz2WfHm2ZfGyCXItHYmPQk1U2+vWEnlY/vU6m
mQll7G3UKBBECzrbAIoBfJL2qQxqw94dNXkcxYVyJKynwDgkRiq2BAiuEUym5xz5
NFUsJmJK8Mt99uFjvPWguYK6eYi+k/mUKlGIuDrBH28UuOiKbY9MxxAs/KlQvK7U
ueNkJIkCgYEAz/z3wpKGnPp0RC+lha4l8E01zC8RmxC4QnSGW/T6TfT33CkE3Ll9
9X0HCWgvjcOS4W8bdgytE3/PYSprwcFN9zBWcn8UaXmbJWcfa65zpjX63e8deS0T
oO8YKbMtWkEVXom1h1gD9IKTx+vU4VIQenqIMvU0WJwqmwReMDkQhE8CgYEAwPUC
iIzPVTK/bG1FkLQzPB0w+Ha5rUHmp2w+DD7JjEtmB7jisBb5Vct96Z4QNMazlpf3
SFWVm1RyjfUT010+9bKaPc+dHuLZPJ2qwUcIAxc2T8BI06NT/weLdBr0tYROrKoS
R6S4qQg0vPS49iXzODsD4+6krpw4/ns92dNKdX0CgYEAwX28XNYFx3o0uc59tUya
3OBngQn03gaC9MgEyv2v8uBHyhia/mDObpge+MBlJQRh27mKmZsXVMGdgu59Cuaz
ipf8hE33BlzsWbKDB6Fm06T6OoeeKsIltZ1ZJEodkg5kO+vu5feazli/9MhP5kJ7
NAZUONvnE9xMwqQgn8omtH8CgYBWJ4+gBK82bVhHQ2sCN1OBDc+lwO0azQf9zTjP
IuG/AJNn80dUNI3Tnu5zdx3pUqcxIF1LMNuB5WzYsYrOnx3TepGf86lF9yfkBsoN
TnfnWV/osARUauLARlAf4UFOIus18SIEVyoUXxOdIu/LCBrXCpKsHQvu4tYX2lM9
hTgDyQKBgCZpyzw8RgV91rp51omc75TMJgHtrKD/q43zNx1hwYaQJx1do1tpKvPN
yJ6ZDGPEFOK+7BuAMdI5ZjYSci6N88fKEnuo495FGn8GuMrlUOn15X4O6OTEMrGn
YNarqP2+UXX50/GvsQB2nvrUfBAvRyrto5el00dBlurtiFBs9Hjs
-----END RSA PRIVATE KEY-----
1 change: 1 addition & 0 deletions dev/keys/blade.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCcxMj59dUfVe9JrqcsbNhpF+bCmJKtduzgpPqYuHGmMsNfTS04Z4woY31H2Yb/JU8TbbwGsfjxNdEfJpDMruvKWnx8PSj66e3rH+jwpyCjhFZhHBFGtlJSBQE2/SF4TtnGD6sTmCJvXt4gqNYFDhhYU4GcA0c/tAmievmXwQJm/CQ9jN5JrHQzm7V/P/xzm9wXH2bW/D6/GTDs6rudXuG80VWIMmXn/2gidizXhrFkUk/BlvBzBAaOgFAsRUKTS7Xvw3G+INJawcLzWMLmsfFt6vbDuJUUYoeqSMGsT0DcdfEBiKBJgueZh9f35p8SaIKjs95W8ZdaguujHWrFXrWT vagrant@vagrant-ubuntu-trusty-64
2 changes: 1 addition & 1 deletion serial/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"express": "4.12.2",
"log4js": "0.6.22",
"pty.js": "0.2.5",
"pty.js": "0.3.1",
"socket.io": "1.3.5",
"term.js": "0.0.4",
"underscore": "1.8.2"
Expand Down

0 comments on commit 902db69

Please sign in to comment.