Deployed App
: CCEEMS
- This is developed using Flask as the backend and HTML, CSS and JavaScript as the frontend.
- Python version
3.10.12
is required to build and run this application. - If you plan to deploy this in heroku, please see Heroku's supported python runtimes and stacks Heroku's Stacks & Python Support. Check the same for
AWS
as well.
-
brew install postgresql@16
brew services start postgresql@16
- add the PostgreSQL binaries directory to your PATH by adding the following line to your shell profile file (such as ~/.zshrc if you're using Zsh):
export PATH="/opt/homebrew/opt/postgresql@16/bin:$PATH"
source ~/.zshrc
- create a new database to setup local
-
$ sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' $ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - $ sudo apt-get update $ sudo apt-get -y install postgresql
-
Open a terminal window. Log in to PostgreSQL using:
psql -U postgres
Create a new user
CREATE USER <your_username> WITH PASSWORD '<your_password>';
Create a database
CREATE DATABASE <your_database>;
Provide all privileges to your user for your database
ALTER USER <your_username> WITH SUPERUSER; GRANT ALL PRIVILEGES ON DATABASE <your_database> TO <your_username>;
Type
\q
to exit
Copy this string for use in the later steps for the local setup
DATABASE_URL=postgres://<your_username>:<your_password>@localhost:5432/<your_database>
Replace <your_username>, <your_password>, and <your_database> with your chosen values
- Clone this repo using
git clone
- Install postgres and create the database and the user in your local machine following install-postgres-in-your-local
- Configure environment and configuration files:
In the terminal type this.
export FLASK_ENV=development FLASK_SECRET_KEY=test DATABASE_URL={connectionString}
- To permanently seed these values, add this command in your
bashrc
file. See this for adding variables to .bashrc
- Install the dependencies -
pip install -r requirements.txt
- Install pre-commit -
pre-commit install
- Run migrations -
flask --app main db upgrade
- Run seeds -
python seed.py
- Run the application using
flask --app main run
- Use login details -
- Username -
[email protected]
- Password -
Password@123
- Username -
- Pre-commit hooks automatically format the code using autopep8 when you do
git commit
. Additionally, please format the code to follow the pep8 standards and check your code quality.
- Clone this repo using
git clone
- Ensure the
Procfile
has the lineweb: gunicorn main:app
. This means the filemain.py
will be used to run the flask application calledapp
- Login to Heroku using
heroku login
. Verify your credentials in the browser. Useheroku -i
to login without using the browser - Create a heroku app
heroku apps:create appName
If successful the command output will show the git repo url for this app. Make a note of it, it will be in the form `https://git.heroku.com/tanmai.git - Add the heroku git branch as a
remote
to your cloned repository. In the terminal type thisgit remote add heroku [you heroku app's git url]
- Add the Postgresql addon for your app, using this link Heroku Postgress Add-on (Must be logged in to Heroku)
- Go to your app's resource page, go to Dashboard.
- Then click on your appname
- Go to the resources tab.
- Then click on Heroku Postgresql
- On this page, go to settings and click on view credentials.
Copy the database connection URI. It starts with
postgres://
- Using the terminal set the environment variables in Heroku for the flask application using this command
heroku config:set FLASK_APP=main FLASK_ENV=production FLASK_SECRET_KEY=test DATABASE_URL={your_connection_URI} --app yourHerokuAppName
- Push this repo to the heroku remote by doing
git push heroku main
. Wait for the deployment to finish. - Run the migrations in flask using this command
heroku run flask --app main db upgrade --app yourHerokuAppName
- Perform the seeding with this command
heroku run python seed.py --app yourHerokuAppName
- Type
heroku open
to open your app's homepage.
- Setup the project following the steps in steps-to-setup-in-local
- Setup the Test DB
Create another database called
test
, and grant all privileges to your user for this database. Follow the same steps Setup PSQL User Copy the connection string accordingly. - In a terminal, type this
export FLASK_ENV=test FLASK_SECRET_KEY=test DATABASE_URL_TEST={connectionURIForTestDB}
Seed the DATABASE_URL_TEST permanently into.bashrc
if required. See this How to set env variables in .bashrc - To run with coverage -
coverage run -m unittest discover -s tests
- Generate coverage report -
coverage report -m main.py config.py $(find app -name "*.py" ! -path "app/seeds/*.py")
- Setup the project following the steps in steps-to-setup-in-local
- In a terminal set these variables
export FLASK_ENV=test FLASK_SECRET_KEY=test DATABASE_URL_TEST={connectionURIForTestDB}
If you haven't seeded theDATABASE_URL_TEST
in your.bashrc
you must provide it here in the command - Run tests -
behave
- To run with coverage -
coverage run -m behave
To automatically format the code to follow the pep8 style guide, run the following command:
autopep8 --in-place --recursive app main.py seed.py
To check the code quality using pylint, run the following command:
pylint app
- If you face any issues during the setup contact one of us
- Bharath Kumar Ravichandran (
bharath[at]tamu[dot]edu
) - Tanmai Harish (
tanmai[at]tamu[dot]edu
)
- Bharath Kumar Ravichandran (