forked from redhat-beyond/edison
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from knowabli/master
pull
- Loading branch information
Showing
9 changed files
with
116 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | ||
|
||
name: Python package | ||
|
||
on: | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.7] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
sudo apt-get install -y python3-pip | ||
pip3 install -r requirements.txt | ||
- name: Lint with flake8 | ||
run: | | ||
pip install flake8 | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
#Build result | ||
|
||
*.log | ||
_pycache_/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,57 @@ | ||
# Edison | ||
# Edison - Automated house managment | ||
|
||
### Overview | ||
|
||
Edison is an open-source home management system. | ||
In its core, Edison is a regular automatic home management system: it reads data from humidity and light sensors and decides when to turn on the air condition and turn on the lights in different rooms. | ||
|
||
Edison allows users to write their own house management plans. | ||
Users can share their management plans through the Edison network and users can also download and review plans from other users. | ||
|
||
Edison can also manage different sensors from different rooms with different management plans for each room. | ||
|
||
## How to spin and tear down the environment | ||
|
||
Edison makes the initial setup easy for you by including a provisioner file that runs automatically on **`vagrant up`**. | ||
You will have a fully ready-to-go work environment with a single command. | ||
|
||
### How to get started | ||
|
||
- Download the proper [VirtualBox](https://www.virtualbox.org/wiki/Downloads) and [Vagrant](https://www.vagrantup.com/downloads.html) package for your operating system and architecture. | ||
- Download Edison to your machine and then open a console window on *edison* folder. | ||
- Write **`vagrant up`** and press enter. | ||
- That's it! Your virtual machine is up and running. | ||
You can enter your virtual machine with **`vagrant ssh`**. | ||
> **Important!** In case that, after `vagrant ssh`, your virtual machine asks for a password the default password is `vagrant`. | ||
### How to save virtual machine state | ||
|
||
In order for your next **`vagrant up`** to execute quicker you should save your virtual machine state into a box file format. | ||
|
||
- If you are inside the virtual machine write **`exit`** and press enter. Now you are back on your host command line. | ||
- Write **`vagrant halt`** and press enter. | ||
> **Note:** It will shut down the running machine Vagrant is managing. | ||
- Write **`vagrant package --output box-name.box`** and press enter. You can replace *box-name* with any name you want. | ||
> **Note:** It will output your virtual machine into a box file format with .box extension. | ||
- Write **`vagrant box add box-name box-name.box`** and press enter. | ||
Make sure you replaced *box-name* with the name you have chosen on the previous step. | ||
- Edit *Vagrantfile* inside the *edison* folder. | ||
Change the following line `config.vm.box = "ubuntu/xenial64"` to `config.vm.box = "box-name"` (replace *box-name* with the name of the box you have created). | ||
- Run **`vagrant up --no-provision`** on future spins. | ||
|
||
### How to tear down the environment | ||
|
||
- If you are inside your virtual machine execute the **`exit`** command so you would get back to your host command line. | ||
- Write **`vagrant destroy -f`** and press enter. It sould terminate your virtual machine. | ||
> **Important!** If you have some unsaved work on your virtual machine your data will be lost! In order to save your data you should follow the steps we provided on **How to save virtual machine state**. | ||
## FAQ | ||
|
||
Here are some answers to some frequently asked questions: | ||
|
||
**Why does `vagrant up` take so long ?** | ||
If you don't have a box to spin your environment from, **`vagrant up`** will take longer to be done. | ||
As part of this command execution our included file `setup.sh` starts to execute and configure Edison environment inside the virtual machine. It downloads all the dependencies Edison requires to run. | ||
|
||
**What is box file format ?** | ||
Please read [box file format](https://www.vagrantup.com/docs/boxes/format.html) documentation for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Flask==1.1.1 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,20 @@ | ||
#!/bin/bash | ||
|
||
time=`TZ=Asia/Jerusalem date '+%Y%m%d_%H%M'` | ||
VAG_COMMON_DIR="/vagrant" | ||
HOME="/home/vagrant" | ||
LOG_DIR="$VAG_COMMON_DIR/log" | ||
OUTFILE="$LOG_DIR/${time}_vagrant-out.log" | ||
FLASK_APP_PY="$VAG_COMMON_DIR/flask_init.py" | ||
FLASK_EXEC="$HOME/runFlask.sh" | ||
FLASK_LOG="$LOG_DIR/flask-out.log" | ||
KILLFLASK_SCRIPT="$VAG_COMMON_DIR/killFlask.sh" | ||
FLASK_ONBOOT=false # Currently Flask On Startup feature disabled [ Not Supported ] | ||
echo "updating apt before installation" | ||
sudo apt-get update | ||
|
||
runSetup() { | ||
step=1 | ||
echo "installing python 3.7" | ||
sudo apt-get install -y python3.7 | ||
|
||
if [ ! -d $LOG_DIR ]; then | ||
mkdir $LOG_DIR | ||
else | ||
# Deleting all vagrant-out log files except for the 5 most recent | ||
cd $LOG_DIR | ||
ls -t | grep vagrant-out.log$ | tail -n +6 | xargs -d '\n' -r rm -- | ||
cd $HOME | ||
fi | ||
touch $OUTFILE | ||
echo "installing python3-pip" | ||
sudo apt-get install -y python3-pip | ||
|
||
if [ ! -e $FLASK_LOG ]; then | ||
touch $FLASK_LOG | ||
fi | ||
echo "installing PostgreSQL" | ||
sudo apt-get install -y postgresql postgresql-contrib | ||
|
||
if [ ! -e $FLASK_APP_PY ]; then | ||
echo "ERROR: Missing $FLASK_APP_PY file..." >> $OUTFILE | ||
exit 1 | ||
else | ||
chmod +x $FLASK_APP_PY | ||
fi | ||
echo "install requirements" | ||
pip3 install -r /vagrant/requirements.txt | ||
|
||
# Adding execution permission to $KILLFLASK_SCRIPT | ||
if [ -e $KILLFLASK_SCRIPT ]; then | ||
chmod +x $KILLFLASK_SCRIPT | ||
fi | ||
|
||
echo " " | ||
echo " " | ||
echo "==> Running Provision Script: $0:" | ||
echo " " | ||
echo "$((step++)). Installing Python PIP3..." | ||
sudo apt-get -yq update >> $OUTFILE 2>&1 | ||
sudo apt-get -yq install python3-pip >> $OUTFILE 2>&1 | ||
echo "" | ||
echo "$((step++)). Installing Flask..." | ||
sudo pip3 install Flask >> $OUTFILE 2>&1 | ||
|
||
# Set Flask Run On Starup: | ||
if [ $FLASK_ONBOOT == true ] && [ -e $FLASK_EXEC ]; then | ||
echo "@reboot $FLASK_EXEC >> /dev/null 2>&1 &" > temp_cron | ||
crontab temp_cron | ||
rm temp_cron | ||
fi | ||
echo " " | ||
echo "$((step++)). Initiating Flask Server..." | ||
export FLASK_APP=$FLASK_APP_PY | ||
flask run --host=0.0.0.0 >> $FLASK_LOG 2>&1 & | ||
echo " " | ||
|
||
exit 0 | ||
} | ||
|
||
(runSetup) | ||
if [ $? -eq 0 ]; then | ||
echo "Vagrant Completed Successfully!!!" | ||
exit 0 | ||
else | ||
echo "Vagrant Failed! Please see log file under $LOG_DIR" | ||
exit 1 | ||
fi | ||
echo "running flask_init.py" | ||
export FLASK_APP=/vagrant/flask_init.py | ||
python3 -m flask run --host=0.0.0.0 >> /vagrant/log.log 2>&1 & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters