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

Ansible Deployment. #54

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
109 changes: 58 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,68 @@
# movie_radio
simple radio page, that will play stream from Icecast server

#####to install project on clean VM:
(Python related stuff)
###to install project on clean VM:
#####Step 1 — Installing Ansible
Add the Ansible PPA and refresh your system's package index, install the ansible
by typing the following commands:

```
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt-get update
$ sudo apt-get install ansible
```

#####Step 2 — Configuring Ansible Hosts
Open the file with root privileges like this:

```
$ sudo vi /etc/ansible/hosts
```

Add the following configuration:

```
1. sudo apt-get install git
2. sudo apt-get install python-pip
next line is for working python 3 terminal interpreter
3. sudo apt-get install libreadline-dev
SSL related dev libs
4. sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libsqlite3-dev
5. sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus
6. sudo apt-get install libffi-dev
7. Install python >=3.5 (see Install Python Section)
8. pip install virtualenv
9. virtualenv -p python3.5 env
Activate virtual env
10.source env/bin/activate
11.pip install -r requirments.txt
[barmaglot]
your_server_ip
```
#####Install python(if not already installed)
In case if you do not have Python 3.5:

In case if you use local connection set:

```
[barmaglot]
127.0.0.1 ansible_connection=local
```

Make sure that you have ssh connection to host that was specified
and test connection via ansible:

```
wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tar.xz
tar xf Python-3.5.1.tar.xz
cd Python-3.5.1
./configure
make
make altinstall
$ sudo ssh your_server_ip
$ ansible -m ping all
```

#####Step 3 — Install Python3.5(if not already installed)
In case if you do not have Python 3.5:

#####to install project on clean VM:
(JS related stuff)
```
$ cd ansible
$ ansible-playbook -s playbooks/install_python.yml --ask-sudo-pass
>>>
Please enter the app_dir: `project_root`/movie_radio
```

#####Step 4 — Run Building Env Playlist
For building environment

```
1. sudo apt-get install nodejs
2. sudo apt-get install npm
3. npm install
4. ln -s /usr/bin/nodejs /usr/bin/node
5. ./build_js.sh
$ cd ansible
$ ansible-playbook -s playbooks/system_packages.yml --ask-sudo-pass
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think bin/install_python3_5.sh file that is requires for this playbook is missing from this branch

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, you are right!

>>>
Please enter the virtualenv_dir: `path_to_virtual_env`
Please enter the app_dir: `project_root`/movie_radio
```
(to omit issue with /usr/bin/env: node: No such file or directory)

#####Install icecast2 server

###Install icecast2 server
server is being installed from Xiph repo's because Ubuntu one don't always have latest version.
```
sudo sh -c "echo deb http://download.opensuse.org/repositories/multimedia:/xiph/xUbuntu_14.04/ ./ >>/etc/apt/sources.list.d/icecast.list"
Expand All @@ -59,14 +76,14 @@ sudo apt-get install icecast2
(default icecast config is here /etc/icecast2/icecast.xml)


#####Production related
###Production related
Run Ansible Production playbook

```
1. sudo apt-get install nginx
2. setup nginx conf file in sites-available(and simlink to sites enabled)
3. sudo apt-get install supervisor
$ ansible-playbook -s playbooks/production.yml --ask-sudo-pass
```

#####Setup Mongo DB
###Setup Mongo DB
```
sudo touch /etc/apt/sources.list.d/mongodb-org-3.2.list
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse"
Expand All @@ -80,22 +97,12 @@ In case if you have issues with encoding:
export LC_ALL=C
```



#####Setup Nginx

```
```

...
#####Setup Supervisor
...

To run project in dev env

```
python app.py
$ ./bin/run_radio.sh
```

#####TODO:
- add setup of streaming
- add setup on production
Expand Down
22 changes: 22 additions & 0 deletions ansible/playbooks/install_python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- hosts: barmaglot

vars_prompt:

- name: app_dir
prompt: "Please enter the app_dir"
private: no

tasks:

- debug:
msg: "Running playbook as {{ lookup('env', 'USER') }} ..."

- name: Install Python
sudo: yes
sudo_user: "{{ lookup('env', 'USER') }}"
command: chdir={{ app_dir }} sh bin/install_python3_5.sh >> dev_build.log
register: install_stdout

- debug:
msg: "{{ install_stdout.stdout }}"
16 changes: 16 additions & 0 deletions ansible/playbooks/production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- hosts: barmaglot
tasks:
- name: Install NGINX
sudo: yes
apt: pkg=nginx state=installed update_cache=true
notify:
- Start Nginx

- name: Install Supervisor
sudo: yes
apt: pkg=supervisor state=installed update_cache=true

handlers:
- name: Start Nginx
service: name=nginx state=started
85 changes: 85 additions & 0 deletions ansible/playbooks/system_packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
- hosts: barmaglot

vars_prompt:

- name: virtualenv_dir
prompt: "Please enter the virtualenv_dir"
private: no

- name: app_dir
prompt: "Please enter the app_dir"
private: no

tasks:

- name: Install Git
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small issue - you will not be able to install git from ansible playbook because at that moment you should already have git as you clone this repo :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

sudo: yes
apt: pkg=git state=installed update_cache=true

- name: Install Python-Pip
sudo: yes
apt: pkg=python-pip state=installed update_cache=true

- name: Install GNU Readline Library
sudo: yes
apt: pkg=libreadline-dev state=installed update_cache=true

- name: Install System-Packages
sudo: yes
action: apt pkg={{item}} state=installed
with_items:
- make
- build-essential
- libssl-dev
- zlib1g-dev
- libbz2-dev
- libsqlite3-dev

- name: Install Python-System-Packages
sudo: yes
action: apt pkg={{item}} state=installed
with_items:
- build-essential
- python-dev
- python-setuptools
- python-pip
- python-smbus

- name: Install Foreign Function Interface library
sudo: yes
apt: pkg=libffi-dev state=installed update_cache=true

- name: Install Virtual Env
sudo: yes
apt: pkg=virtualenv state=installed update_cache=true
notify:
- Initiate virtualenv
- Install requirements

- name: Install NodeJS
sudo: yes
apt: pkg=nodejs state=installed update_cache=true

- name: Install NPM
sudo: yes
apt: pkg=npm state=installed update_cache=true
notify:
- Install NPM packages
- Building Webpack Dev build

handlers:
- name: Initiate virtualenv
command: virtualenv {{ virtualenv_dir }} -p python3.5 creates="{{ virtualenv_dir }}"

- name: Install requirements
pip:
requirements={{ app_dir }}/requirements.txt
executable={{ virtualenv_dir }}/bin/pip3

- name: Install NPM packages
npm:
path={{ app_dir }}

- name: Building Webpack Dev build
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think build output log files should be added to gitignore

shell: cd {{ app_dir }}; sh {{ app_dir }}/build_js.sh >> dev_build_js.log
29 changes: 0 additions & 29 deletions bin/build_project.sh

This file was deleted.

32 changes: 32 additions & 0 deletions bin/install_python3_5.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
Copy link
Owner

@wolendranh wolendranh Feb 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ntodosiychuk btw:I found out that we can completely replace bash with ansible, at least for Python installation:)
I will fill in pull request this week end.
spoiler:D :

    tasks:
      - name: get&unpack Python
        sudo: yes
        sudo_user: "{{ lookup('env', 'USER') }}"
        unarchive:
          src: https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tar.xz
          dest: {{ app_dir }}
          remote_src: True

      - name: compile Python
        sudo: yes
        sudo_user: "{{ lookup('env', 'USER') }}"
        command: chdir={{ app_dir }}/Python-3.5.1 {{ item }}
        with_items:
          - ./configure

something in this style


./

PYTHON_ARCHIVE=Python-3.5.1.tar.xz
PYTHON_DIR=Python-3.5.1
FTP_SOURCE=https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tar.xz

echo "Starting install python 3.5..."


if [ ! -f $PYTHON_ARCHIVE ]
# skip downloading if archive already exists
then
echo "$PYTHON_ARCHIVE not found! Will try to download..."
echo "Downloading..."
wget $FTP_SOURCE
[ $CODE -ne 0 ] && exit $CODE
fi


echo "Unpacking $PYTHON_ARCHIVE package..."
tar xf $PYTHON_ARCHIVE
[ $CODE -ne 0 ] && exit $CODE

echo "Installion..."


cd $PYTHON_DIR
./configure
sudo make
sudo make altinstall