Setup - Aimlackies/Reporter GitHub Wiki
The following instructions will set up a local instance of the reporter application for development.
-
Clone repository to your local machine.
git clone https://git.cardiff.ac.uk/aimlackies/reporter.git -
Create a Conda environment and install Python packages. The Conda enviroemtn is set to use Python 3.8 as, at the time of creation, that was the latest version PyTorch supported. Ensure compatibility with dependencies before upgrading.
conda create -n aimlacReporter python=3.8 conda activate aimlacReporter pip install -r requirements.txt -
Set up local MySQL server
Useful guide: https://dev.mysql.com/doc/mysql-getting-started/en/#mysql-getting-started-installing
Note: MySQL workbench is not required to use MySQL but it makes viewing database entries easier.
Note: If this system is live then ensure the password for both root and the database user is strong.
Windows:
i. Download MySQL installer and install and install MySQL server and Workbench (you do not need any other MySQL applications): https://dev.mysql.com/downloads/installer/
ii. Configure MySQL within MySQL installer so it starts on computer start-up and has a root password (note down this password)
iii. Start MySQL server command line utility
iv. Continue from
all operating systemsUnix based systems:
i. Install MySQL server and workbench for your distro / Mac OS
iii. Enable start-up on computer boot and start MySQL server now
sudo systemctl enable mysqld.service sudo systemctl start mysqld.serviceii. Find the default password for MySQL
sudo grep 'temporary password' /var/log/mysqld.logiii. Change the default password and configure MySQL server
sudo mysql_secure_installationiv. Enter MySQL interactive shell
mysql -u root -pv. Continue from
all operating systemsAll operating systems:
i. Create a user with a password (note these down)
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; # Change newuser to a username of your choosing # Change password to a password of your choosingii. Create database
CREATE DATABASE db_name; # Change db_name to a name of your choosing for the databaseiii. Grant access to the database for your user
GRANT ALL ON db_name.* TO 'newuser'@'localhost'; # Change db_name to the name you set for the database # Change newuser to the username you set for your useriv. Save changes made to mysql. You can exit MySQL once done
FLUSH PRIVILEGES; -
Set system environment variables for the Flask application. The first tells the Flask command the file to run on start-up and the second will cause the Flask application to start in development mode.
Windows:
SET FLASK_APP=reporter.py SET FLASK_ENV=developmentUnix based systems:
export FLASK_APP=reporter.py export FLASK_ENV=development -
Setup environmental variables for
config.py
For some aspects of the web application to function we will need to provide a variable value that should NOT be added to the repository. We will therefore set these up as environmental variables that the web application can access, but is not set as part of the application. To set these variables follow the corresponding steps for your operating system.Windows:
i. Open
Control Panelii. Click on the Advanced system settings link and then click
Environment Variables. Click create new variable under your users Environment Variables.iii. Set a variable for each of the following
AIMLAC_CC_MACHINE=34.72.51.59 AIMLAC_API_KEY=AIMLACkies275001901 AIMLACKIES_REPORTER_SECRET_KEY AIMLACKIES_REPORTER_SECURITY_PASSWORD_SALT AIMLACKIES_REPORTER_DATABASE_URL # AIMLACKIES_REPORTER_DATABASE_URL = mysql+pymysql://reporter_db_user:[email protected]/local_reporter # reporter_db_user = database user name # reporter_db_password = database user password # local_reporter = local database name # generate secure random varables on your local machine. This can be done use command line utilities such as `openssl rand -base64 64` # or in python with `secrets.SystemRandom().getrandbits(128)`Unix based systems:
i.
nano ~/.bash_profileii. Enter the following variables
export AIMLAC_CC_MACHINE=34.72.51.59 export AIMLAC_API_KEY=AIMLACkies275001901 export AIMLACKIES_REPORTER_SECRET_KEY= # Enter your generated secret key (e.g. openssl rand -base64 64) export AIMLACKIES_REPORTER_SECURITY_PASSWORD_SALT= # Enter your generated password salt (e.g. secrets.SystemRandom().getrandbits(128)) export AIMLACKIES_REPORTER_DATABASE_URL=mysql+pymysql://reporter_db_user:[email protected]/local_reporter # reporter_db_user = database user name # reporter_db_password = database user password # local_reporter = local database name # generate secure random varables on your local machine. This can be done use command line utilities such as `openssl rand -base64 64` # or in python with `secrets.SystemRandom().getrandbits(128)`iii. Save the variables
source ~/.bash_profile-
Initiate, create and seed your local database with a default admin user. The commands to
migrateandupgradethe database will also be used to make updates to the database schema. The default admin user will have the email[email protected]and the passwordpassword. The password should be changed straight away on a live Installation.flask db init flask db migrate flask db upgrade flask seed
-
-
Start the application.
You're done! All that is left now is to start the application and start developing!
flask run