Skip to content
Snippets Groups Projects

Add pre commit

Merged Bo-Chun Chen requested to merge louistw/account-app:feat-pre-commit into master
1 file
+ 28
28
Compare changes
  • Side-by-side
  • Inline
+ 28
28
# Introduction
# Introduction
This is a flask application that leverages [RabbitMQ](https://www.rabbitmq.com/) and [Celery](https://docs.celeryproject.org/en/latest/getting-started/introduction.html)
This is a flask application that leverages [RabbitMQ](https://www.rabbitmq.com/) and [Celery](https://docs.celeryproject.org/en/latest/getting-started/introduction.html)
to asynchronously create a Cheaha user account. Currently the project is being developed on an Openstack cluster.
to asynchronously create a Cheaha user account. Currently the project is being developed on an Openstack cluster.
# Project Setup
# Project Setup
To clone this repo use the command:
To clone this repo use the command:
```
```
$ git clone https://gitlab.rc.uab.edu/mmoo97/flask_user_reg.git
$ git clone https://gitlab.rc.uab.edu/mmoo97/flask_user_reg.git
$ cd flask_user_reg
$ cd flask_user_reg
```
```
## Prerequisites
## Prerequisites
### Setup a Virtual Environment
### Setup a Virtual Environment
- Ensure you have created a [virtual environment](https://docs.python.org/3/library/venv.html)
- Ensure you have created a [virtual environment](https://docs.python.org/3/library/venv.html)
called `venv` setup running python3.
called `venv` setup running python3.
- Note, this project requires a virtual environment running __python3__ (__3.6.8__ in this case).
- Note, this project requires a virtual environment running __python3__ (__3.6.8__ in this case).
- Create this by navigating to you home directory via typing `$ cd` and entering the following commands:<br>
- Create this by navigating to you home directory via typing `$ cd` and entering the following commands:<br>
```
```
$ python3 -m venv ~/venv
$ python3 -m venv ~/venv
$ source ~/venv
$ source ~/venv
```
```
- Upon Activation, you should see the prompt update accordingly:
- Upon Activation, you should see the prompt update accordingly:
```
```
[centos@ood ~]$ <------Old Prompt
[centos@ood ~]$ <------Old Prompt
@@ -46,7 +46,7 @@ $ pip install -r requirements.txt
@@ -46,7 +46,7 @@ $ pip install -r requirements.txt
- #### Mac/Linux
- #### Mac/Linux
- `$ brew update`
- `$ brew update`
- `$ brew install rabbitmq`
- `$ brew install rabbitmq`
- it is recommended that you add the following line to your `.bash_profile`:
- it is recommended that you add the following line to your `.bash_profile`:
`export PATH=$PATH:/usr/local/opt/rabbitmq/sbin`.
`export PATH=$PATH:/usr/local/opt/rabbitmq/sbin`.
- Start server using the command `$ rabbitmq-server`. (Note, this implementation assumes RabbitMQ is running on localhost on standard port 5672)
- Start server using the command `$ rabbitmq-server`. (Note, this implementation assumes RabbitMQ is running on localhost on standard port 5672)
- #### Windows
- #### Windows
@@ -56,13 +56,13 @@ $ pip install -r requirements.txt
@@ -56,13 +56,13 @@ $ pip install -r requirements.txt
- First, import signing key using `$ rpm --import https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc`
- First, import signing key using `$ rpm --import https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc`
- Next, install Erlang using `$ yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm`
- Next, install Erlang using `$ yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm`
- Finally, install RabbitMq using `$ yum install rabbitmq-server-3.8.2-1.el8.noarch.rpm`
- Finally, install RabbitMq using `$ yum install rabbitmq-server-3.8.2-1.el8.noarch.rpm`
- The server is not started as a daemon by default when the RabbitMQ server package is installed. To start the
- The server is not started as a daemon by default when the RabbitMQ server package is installed. To start the
daemon by default when the system boots, as an administrator run: `$ chkconfig rabbitmq-server on`.
daemon by default when the system boots, as an administrator run: `$ chkconfig rabbitmq-server on`.
- As an administrator, start and stop the server as usual: <br/>`/sbin/service rabbitmq-server start`
- As an administrator, start and stop the server as usual: <br/>`/sbin/service rabbitmq-server start`
<br/> `/sbin/service rabbitmq-server stop`
<br/> `/sbin/service rabbitmq-server stop`
- Add the user "reggie" using the command `$ rabbitmqctl add_user reggie reggie`.
- Add the user "reggie" using the command `$ rabbitmqctl add_user reggie reggie`.
- The current configuration assumes the following username password combination. To change the password, type
- The current configuration assumes the following username password combination. To change the password, type
`$ rabbitmqctl change_password reggie <new_password>`.
`$ rabbitmqctl change_password reggie <new_password>`.
- Note that rabbitmqctl may require sudo permissions and that changing the password will require a password
- Note that rabbitmqctl may require sudo permissions and that changing the password will require a password
change in the credentials within `test_producer.py` and `base_consumer.py` as well.
change in the credentials within `test_producer.py` and `base_consumer.py` as well.
# Run Project
# Run Project
@@ -75,11 +75,11 @@ $ pip install -r requirements.txt
@@ -75,11 +75,11 @@ $ pip install -r requirements.txt
2. Locate Floating Ip for each instance: <br>
2. Locate Floating Ip for each instance: <br>
![Research Computing Network](/docs/images/rc-network%20.png)<br>
![Research Computing Network](/docs/images/rc-network%20.png)<br>
According to this diagram of the network infrastructure, the IP Addresses that you will need to
According to this diagram of the network infrastructure, the IP Addresses that you will need to
connect to in order to ssh into each machine will be `164.111.161.xxx` where
connect to in order to ssh into each machine will be `164.111.161.xxx` where
`.xxx` is the last octet of your assigned Floating IP Addresses shown below.<br>
`.xxx` is the last octet of your assigned Floating IP Addresses shown below.<br>
![Floating IP Addresses](/docs/images/floating_ips.png)<br>
![Floating IP Addresses](/docs/images/floating_ips.png)<br>
Note that these numbers will typically vary depending on factors in the provisioning
Note that these numbers will typically vary depending on factors in the provisioning
process.
process.
3. SSH into each machine: <br>
3. SSH into each machine: <br>
@@ -90,21 +90,21 @@ $ pip install -r requirements.txt
@@ -90,21 +90,21 @@ $ pip install -r requirements.txt
```
```
4. Drop Firewall: <br>
4. Drop Firewall: <br>
Currently, the firewall prevents us from connecting to our soon to be running flask app.
Currently, the firewall prevents us from connecting to our soon to be running flask app.
To check if the firewall is active, type: <br>
To check if the firewall is active, type: <br>
`$ sudo systemctl status firewalld` <br>
`$ sudo systemctl status firewalld` <br>
In the case the firewall is still active, type: <br>
In the case the firewall is still active, type: <br>
`$ sudo systemctl stop firewalld` <br>
`$ sudo systemctl stop firewalld` <br>
In the case you need to turn the firewall back on, type: <br>
In the case you need to turn the firewall back on, type: <br>
`sudo systemctl start firewalld`
`sudo systemctl start firewalld`
5. Edit Security Rules: <br>
5. Edit Security Rules: <br>
Lastly, we want to make sure that our network it open to run on our flask application
Lastly, we want to make sure that our network it open to run on our flask application
which runs on `localhost:5000` by default. Modify your __Default__ security group to
which runs on `localhost:5000` by default. Modify your __Default__ security group to
reflect the following rules: <br>
reflect the following rules: <br>
![Security Rules](/docs/images/security_rules.png) <br>
![Security Rules](/docs/images/security_rules.png) <br>
The main takeaway/modification in these rules is that traffic is allowed in and out of port 5000.
The main takeaway/modification in these rules is that traffic is allowed in and out of port 5000.
## 2. Initialize RabbitMQ
## 2. Initialize RabbitMQ
Make sure that you are running rabbitmq via the command `sudo rabbitmq server`.
Make sure that you are running rabbitmq via the command `sudo rabbitmq server`.
@@ -120,7 +120,7 @@ $ python base_consumer.py ohpc
@@ -120,7 +120,7 @@ $ python base_consumer.py ohpc
You will notice that the script is awaiting a message to display.
You will notice that the script is awaiting a message to display.
To produce a message, run the following on the ood node terminal session:
To produce a message, run the following on the ood node terminal session:
```
```
$ python test_producer.py ohpc
$ python test_producer.py ohpc
```
```
You should now see that the message has been sent and displayed on the ohpc node.
You should now see that the message has been sent and displayed on the ohpc node.
@@ -129,7 +129,7 @@ You should now see that the message has been sent and displayed on the ohpc node
@@ -129,7 +129,7 @@ You should now see that the message has been sent and displayed on the ohpc node
In order to execute our tasks asychronously, we create a celery worker using the fllowing: <br>
In order to execute our tasks asychronously, we create a celery worker using the fllowing: <br>
`$ celery -A tasks worker --loglevel=info --concurrency=4 1> ~/celery.out 2> ~/celery.err &` <br><br>
`$ celery -A tasks worker --loglevel=info --concurrency=4 1> ~/celery.out 2> ~/celery.err &` <br><br>
In this case, the `celery -A tasks worker --loglevel=info --concurrency=4` portion of the command
In this case, the `celery -A tasks worker --loglevel=info --concurrency=4` portion of the command
is what is initiating the worker and the remainder serves to write the stdout and stderr to two separate files
is what is initiating the worker and the remainder serves to write the stdout and stderr to two separate files
located in the home directory and to run the process in the background. <br>
located in the home directory and to run the process in the background. <br>
@@ -138,15 +138,15 @@ Simply type `$ python run.py` <br>
@@ -138,15 +138,15 @@ Simply type `$ python run.py` <br>
Alternatively, type `$ python run.py > ~/flask.out 2> ~/flask.err &` to run the process in the background
Alternatively, type `$ python run.py > ~/flask.out 2> ~/flask.err &` to run the process in the background
and output to files in the home directory.
and output to files in the home directory.
## 6. Check Job status
## 6. Check Job status
If all goes well, you should have your processes running in the background. Check the status of these by typing
If all goes well, you should have your processes running in the background. Check the status of these by typing
`$ jobs`. You should now see the something similar to the following: <br>
`$ jobs`. You should now see the something similar to the following: <br>
```
```
(venv) [centos@ood flask_user_reg]$ jobs
(venv) [centos@ood flask_user_reg]$ jobs
[1]- Running celery -A tasks worker --loglevel=info --concurrency=4 > ~/celery.out 2> ~/celery.err &
[1]- Running celery -A tasks worker --loglevel=info --concurrency=4 > ~/celery.out 2> ~/celery.err &
[2]+ Running python run.py > ~/server.out 2> ~/server.err &
[2]+ Running python run.py > ~/server.out 2> ~/server.err &
(venv) [centos@ood flask_user_reg]$
(venv) [centos@ood flask_user_reg]$
```
```
## 7. Connect to Server
## 7. Connect to Server
@@ -157,5 +157,5 @@ address bar replacing `.xxx` with the final octet of the __OOD__ node. You shoul
@@ -157,5 +157,5 @@ address bar replacing `.xxx` with the final octet of the __OOD__ node. You shoul
- Fill out the form and hit "Submit"
- Fill out the form and hit "Submit"
- You should see an overlay signifying the account is being created. After 5 seconds it should disappear and signify the account creation has been successful.
- You should see an overlay signifying the account is being created. After 5 seconds it should disappear and signify the account creation has been successful.
- You can now enter the command `kill %1 %2` to terminate the celery worker and the flask server.
- You can now enter the command `kill %1 %2` to terminate the celery worker and the flask server.
- You can view the output/errors of either the worker and flask server by opening `flask.out`, `flask.err`,
- You can view the output/errors of either the worker and flask server by opening `flask.out`, `flask.err`,
`celery.out`, or `celery.err`.
`celery.out`, or `celery.err`.
Loading