Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code restructuration #15

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
c1a9f8d
Empty commit
wixyvir Aug 10, 2015
30bb961
Now using gulp
wixyvir Aug 11, 2015
320ebef
docker restructuration
wixyvir Aug 12, 2015
11bf58f
fixing nginx configuration
wixyvir Aug 12, 2015
33229f7
Using dev environment w/ docker-compose on demoinstance production do…
wixyvir Aug 25, 2015
9d1137d
adding permission fixes: when in dev, all code belongs to folder owner
wixyvir Aug 25, 2015
b036a94
setting MAINTAINER to "Loïc PORTE"
wixyvir Aug 25, 2015
17c83ee
Merge pull request #1 from pmsipilot/restructuration
wixyvir Aug 25, 2015
e258a27
updating readme
wixyvir Aug 25, 2015
e2cc004
fixing links
wixyvir Aug 25, 2015
62b520b
fixing links
wixyvir Aug 25, 2015
af5ab7a
fixing links
wixyvir Aug 25, 2015
8ffd626
Do not overwrite "type" object if you to use the "type" builtin.
wixyvir Aug 26, 2015
e7b05ff
send http exception type
wixyvir Aug 26, 2015
4fd2d3b
Merge pull request #7 from pmsipilot/fix_6_err_display
willgarcia Aug 26, 2015
550cdd1
Adding trigger in dev_demoinstance launcher to fix ownership
wixyvir Aug 27, 2015
993f809
Merge pull request #9 from pmsipilot/fix_8_ownership
wixyvir Aug 27, 2015
5ebc74f
adding Vagrantfile
wixyvir Aug 31, 2015
df50db2
Merge pull request #10 from pmsipilot/vagrantfile
willgarcia Aug 31, 2015
413c108
fix(bug): Correctif vagrantfile
Aug 31, 2015
ed8ccc3
Merge pull request #11 from pmsipilot/correctif-vagrantfile
wixyvir Sep 1, 2015
119c664
adding apt-get update to vagrant provisionning script
wixyvir Sep 10, 2015
3312d0a
Merge pull request #15 from pmsipilot/fix_vagrant
wixyvir Sep 10, 2015
685194f
bump 2.1.1
wixyvir Sep 10, 2015
da12d0f
adding network configuration item
wixyvir Sep 10, 2015
c61269f
adding doc & Readme
wixyvir Sep 10, 2015
ed8f4e2
Merge pull request #16 from pmsipilot/neutron_network
willgarcia Sep 10, 2015
c571d1d
ortho too much --> too many
chbu1983 Nov 10, 2015
43dc0ac
ortho to --> too
chbu1983 Nov 10, 2015
7bccd7a
Merge pull request #18 from pmsipilot/issue_17
willgarcia Nov 11, 2015
78c7d0f
Speedup admin loading
wixyvir Nov 9, 2016
2c7102d
Merge pull request #20 from pmsipilot/fix_admin
wixyvir Nov 9, 2016
31cf779
Add IP adress in administration pages
wixyvir Nov 9, 2016
4c4d24b
Merge pull request #21 from pmsipilot/add_ip
wixyvir Nov 10, 2016
ef7bba8
Merge pull request #22 from pmsipilot/add_forget
wixyvir Nov 10, 2016
7845372
Add a forget button, which detach the instance from demoinstance with…
wixyvir Nov 10, 2016
9e0135f
fixing home button
wixyvir Nov 10, 2016
1bc3306
Merge pull request #24 from pmsipilot/fix_homme_button
wixyvir Nov 10, 2016
21c528c
Fixing Dockerfile by updating Ubuntu
wixyvir May 21, 2018
95fccdf
Mise à jour de la charte graphique de DemoInstance
wixyvir May 21, 2018
f8333f3
Merge pull request #25 from pmsipilot/updating_graphic_chart
wixyvir May 21, 2018
5114e6b
Fixing python-novaclient version
wixyvir May 21, 2018
c94ea56
Do not verify SSL certificate (python 2.7 change)
wixyvir May 21, 2018
b8efa70
feat(admin): Display pooled instances IP
wixyvir Feb 18, 2019
df1003f
Merge pull request #27 from pmsipilot/ippool
wixyvir Feb 19, 2019
c5e0df3
Add a slack warning system before instances destruction
wixyvir Jan 14, 2020
e97819a
Prise en compte de mes propres retours
wixyvir Jan 15, 2020
20d20c2
Ajout d'un gif d'explication slack
wixyvir Jan 15, 2020
8b5667a
On sépare slack dans une autre classe
wixyvir Jan 15, 2020
c1cf35f
Merge pull request #28 from pmsipilot/add-slack-warnings
wixyvir Jan 15, 2020
397dde1
Petit correctif
wixyvir Jan 15, 2020
70b58d9
fix: Pas de support de cachounet !
wixyvir Jan 16, 2020
57a05b0
Forcing update of vendor and app.js
wixyvir Jan 16, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Vagrantfile
.vagrant
/*.ini
!config-dist.ini
Expand All @@ -10,4 +9,5 @@ web/instance_image/*
!web/instance_image/example.png
web/node_modules/
web/public
/*.sqlite
/*.sqlite
*~
40 changes: 27 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
FROM ubuntu:14.04
FROM ubuntu:16.04
MAINTAINER Loïc PORTE
RUN apt-get update && apt-get install git python python-dev\
RUN apt-get update && apt-get install -y git python python-dev\
python-pip mysql-client libmysqlclient-dev nodejs npm\
libldap2-dev libsasl2-dev libssl-dev -y
libldap2-dev libsasl2-dev libssl-dev nginx supervisor
RUN ln -s /usr/bin/nodejs /usr/bin/node
RUN npm install -g bower grunt-cli

RUN rm -rf /etc/nginx/sites-available/* /etc/nginx/sites-enabled/*

COPY ./ressources/nginx/nginx-server /etc/nginx/sites-available/default
RUN ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
RUN ln -sf /dev/stdout /var/log/nginx/access.log
RUN ln -sf /dev/stderr /var/log/nginx/error.log


RUN mkdir -p /etc/demoinstance/instance_image/
RUN mkdir /opt/demoinstance
COPY ./ /opt/demoinstance
WORKDIR /opt/demoinstance
RUN pip install -r requirements.txt
WORKDIR /opt/demoinstance/web

WORKDIR /opt/demoinstance/frontend
RUN npm install
RUN bower install --allow-root
RUN grunt
WORKDIR /opt/demoinstance/
VOLUME /opt/demoinstance/config.ini
VOLUME /opt/demoinstance/instance_image/
CMD python demo.py
RUN node_modules/gulp/bin/gulp.js


WORKDIR /opt/demoinstance/backend/
RUN pip install --upgrade pip
RUN pip install --upgrade setuptools
RUN python setup.py install

COPY ./ressources/supervisor/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]

EXPOSE 8080
117 changes: 88 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,82 @@
# Project DemoInstance
DemoInstance provides an interface to deploy instance of your project on an Openstack cloud. With this project your futur client can deploy an isolated instance for a defined time.
DemoInstance is web interface offering on-demand virtual machines instances with lifetime limits.

## Interface example
![Image of Demoinstance](https://raw.githubusercontent.com/bewiwi/DemoInstance/gh-pages/demoinstance.gif)

## Pre requisites
## Dependencies

* Python & Python devel & Python PIP
* GCC
* MySQL server / MySQL devel

## Installation
<img src="http://svgporn.com/logos/python.svg" alt="Python" width="64"> <img src="http://svgporn.com/logos/npm.svg" alt="Python" width="64"> <img src="http://svgporn.com/logos/gulp.svg" alt="Python" width="64">


* Python 2.7
* PIP
* NodeJS & NPM
* An underlying database system:
* SQLite
* MySQL

## Building and setting up

In order to use DemoInstance, you can:

* [Build](#building-and-setting-up), [configure](#configuration) and [run](#run-backend) demoinstance yourself
* [Configure](#configuration) and [use a production docker image](#run-w-docker)

### Install backend service

In order to install DemoInstance backend service:

```
# npm install -g bower
# npm install -g grunt-cli
$ git clone [email protected]:bewiwi/DemoInstance.git
$ cd DemoInstance
$ pip install -r requirement.txt
$ cd web/
$ git clone [email protected]:pmsipilot/demoinstance.git
$ cd demoinstance/backend/
$ sudo python2 ./setup.py install
```

### Prepare frontend sources

In order to prepare frontend sources:

```
$ cd frontend
$ npm install
$ bower install
$ grunt
$ cd -
$ cp config-dist.ini config.ini
$ vim config.ini
$ node_modules/gulp/bin/gulp.js
```

#### Set up web server
In this example, we'll be using [the nginx webserver](http://nginx.org/):

* Install nginx (according to your operating system documentation)
* Configure nginx virtualhost
* Restart nginx

Virtualhost example:
```
server {
listen 8080;
root /opt/demoinstance/frontend/;
index index.html;
location /api {
proxy_pass http://127.0.0.1:8081;
}
location / {
try_files $uri $uri/ =404;
}
location /instance_image/ {
alias /etc/demoinstance/instance_image/;
try_files $uri $uri/ =404;
}
}
```

* In this example, the webserver is listening on port `8080`, frontend files are stored in `/opt/demoinstance/frontend`, and backend is listening on port `8081`.
* All `/api` requests must be passed to demoinstance backend service
* `/instance_image`requests points to `/etc/demoinstance/instance_image/` in this example.
* Other requests are fulfilled with previously prepared frontend source code files.

Then, you must configure DemoInstance backend.

## Configuration

DemoInstance have a single ini config file : config.ini
Expand Down Expand Up @@ -104,8 +154,8 @@ region=regionOne
| password | No | openstack password |
| tenant | No | openstack tenant |
| url | No | openstack keystone api url |
| region | Yes | openstak region |

| region | Yes | openstack region |
| network | Yes | openstack network id |
### HTTP
```
[HTTP]
Expand Down Expand Up @@ -217,22 +267,30 @@ user_data:#cloud-config
This is defined here : http://tools.ietf.org/html/rfc822.html on LONG HEADER FIELDS section


## Run
## Run Backend
```
python demo.py
/usr/local/bin/demoinstance -c /etc/demoinstance/config.ini
```
Or

## Run w/ Docker

There is also a Docker Production-ready image: https://hub.docker.com/r/pmsipilot/demoinstance/

```
./demo.sh start
docker run -v /path/to/config/and/instance_image:/etc/demoinstance/ -i pmsipilot/demoinstance
```

* `/etc/demoinstance/` must contain:
* `config.ini` file
* `instance_image` folder with instance images

## Init script

### Redhat/Centos
Template for Centos is avaible in samples/
Just link file to /etc/init.d and maybe add it to boot sequence
Template for Centos is avaible in `ressources/rhel-init-demoinstance`.
Just link file to /etc/init.d.
```
ln -s /where/is/your/project /etc/init.d/demoinstance
chkconfig demoinstance on
```
Don't forget to add config file in /etc/sysconfig/demoinstance
```
Expand All @@ -255,11 +313,12 @@ If you want this you can do it and make me a PR
If you want to contribute you're welcome. Just create issues or make some PR.

### Dev env
A docker env was set to help you to dev. To start just configure a good config.ini and run
The development environment is built w/ Docker on top of the production-ready image, with [docker-compose](https://docs.docker.com/compose/)
```
fig up
docker-compose up
```
If you don't have docker you can directly install needed lib on your hosts, it works well to

A supervisord process will listen for changes in frontend files, and changes to backend source code will be directly applied.

### Run test
To run test just run this command on with an URL od demoinstance run with test/samples/config/config-fake.ini
Expand Down
23 changes: 23 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.box_url = "https://atlas.hashicorp.com/debian/jessie64"
config.vm.box = "debian/jessie64"

config.vm.provider :virtualbox do |v, override|
v.customize ["modifyvm", :id, "--memory", 1024]
v.customize ["modifyvm", :id, "--cpus", 1]
override.vm.synced_folder ".", "/opt/demoinstance", :id => "vagrant-root", owner: "root", group: "root", :mount_options => ["dmode=777", "fmode=777"]
end

config.vm.usable_port_range = (2200..2299)
config.vm.network "forwarded_port", guest: 8080, host: 2280, auto_correct: true
config.vm.network "forwarded_port", guest: 8081, host: 2281, auto_correct: true

config.vm.define :master do |master|
master.vm.provision "shell" do |sh|
sh.path = "ressources/vagrant_setup.sh"
end
end
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def check_auth(self, user, password):
return False

if len(res) > 1:
raise Exception("To much user returned")
raise Exception("Too many users returned")
if len(res) < 1:
raise ldap.INVALID_CREDENTIALS

Expand Down
13 changes: 7 additions & 6 deletions demo.py → backend/demoinstance/cli.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from Demo.demo_config import DemoConfig
from Demo.database import DemoData
from Demo.http import ThreadedHTTPServer, Handler
from Demo.vacuum import Vacuum
from Demo.pool import Pool
from demo_config import DemoConfig
from database import DemoData
from http import ThreadedHTTPServer, Handler
from vacuum import Vacuum
from pool import Pool
import logging
import argparse

if __name__ == '__main__':
def cli_entrypoint():
parser = argparse.ArgumentParser()
parser.add_argument('-c', help='config file', default='./config.ini')
args = parser.parse_args()
Expand All @@ -27,4 +27,5 @@
server = ThreadedHTTPServer(('0.0.0.0', config.http_port), Handler)
server.serve_forever()
except (KeyboardInterrupt, SystemExit):
logging.info("Exit signal catched")
vacuum.stop = True
3 changes: 3 additions & 0 deletions Demo/database.py → backend/demoinstance/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ class Instance(Base):
name = Column(String(255))
image_key = Column(String(255))
status = Column(String(255), nullable=False)
ip = Column(String(255), nullable=True)
launched_at = Column(types.DATETIME)
life_time = Column(types.Integer, nullable=False)
token = Column(String(255), nullable=False)
user_alerted = Column(types.Boolean, default=False)

def get_dead_time(self):
delta = (
Expand Down Expand Up @@ -68,6 +70,7 @@ class User(Base):
token = Column(String(255), primary_key=True)
login = Column(String(255), unique=True)
last_connection = Column(types.DATETIME)
slack_identifier= Column(String(255), nullable=True)

def generate_token(self):
self.token = str(uuid.uuid4())
Expand Down
Loading