Automatic Program Corrector Backend is a RESTful back-end server built with Python's FastAPI framework. It provides functionality that allows for automatically generating unit test cases for uploaded files. Data is persisted in a MySQL database.
- Make sure Python 3.6+ is installed on your machine, as well as pip. Instructions on how to install pip
Running Pynguin in a docker environment
Prerequisite: have docker installed on your machine.
-
Make sure pynguin is in the home directory
cd ~ git clone https://github.com/se2p/pynguin.git
-
Create input, output, and package directories. Create package/package.txt
cd ~/pynguin mkdir input output package touch package/package.txt
-
Create input, output, and package volumes
docker volume create input docker volume create output docker volume create package # run "docker volume ls" to check that volumes got created successfully
-
Containerize the app by running the Makefile script
make # make docker # OR RUN THE BELOW INSTEAD docker build \ -t $(IMAGE):$(VERSION) . \ -f ./docker/Dockerfile --no-cache
-
Check your docker Image container Tag for Pynguin container
docker image ls # output would be something like the below
REPOSITORY TAG IMAGE ID CREATED SIZE appname latest a4962c112cd9 6 days ago 169MB pynguin 9ccbdc17 203050f9142a 6 days ago 153MB hello-app latest 518ae29ba4ea 6 days ago 169MB ubuntu latest a457a74c9aaa 3 weeks ago 65.6MB
-
Run Pynguin in docker container ( for testing on our terminal/CMD_PROMPT)
docker run \ -v ~/pynguin/input:/input:ro \ -v ~/pynguin/output:/output \ -v ~/pynguin/package:/package:ro pynguin:<DOCKER_IMAGE_TAG> --project-path /input \ --output-path /output \ --module-name PYTHON_FILE_NAME -v
-
Create a virtual environment and activate it by executing the following commands:
cd APC_backend # navigate to project directory pip install virtualenv virtualenv env # create a virtual environment source env/bin/activate # activate the virtual environment
-
To install the required dependencies, execute the following command:
pip install -r requirements.txt # installs required dependencies
-
From APC_backend directory, run the following command:
mkdir input output
-
Create a root user account. Note down your host name, user, and password
-
Import the database.sql file from MySQL Workbench Server settings.
- To create .env file to store the server's environment variables, execute the following commands:
touch .env # creates .env file
vim .env # use vim or open the .env file in a code editor
- Set the values for the following host, user, and password keys:
host=HOST_NAME # typically host is localhost
user=USER_NAME
password=PASSWORD
db=DB_NAME
- In file PynguinAPI.sh, set the DOCKER_IMAGE_TAG variable to the docker image tag for Pynguin container
# ...
DOCKER_IMAGE_TAG="<PYNGUIN_DOCKER_IMAGE_TAG>"
# ...
- To run the app, execute the following command on your terminal:
uvicorn main:app --reload # note on this method of running the server.
# The server automatically reloads when a change is done in the back-end code
# An alternative way is to run the main.py Python file --> python3 main.py
- Notes:
-
The server automatically runs on http://localhost:8000
-
To access the API documentation (both documentations provide the same functionaltiy, one might just have a preference):
a. Swagger API Documentation: http://localhost:8000/docs
b. ReDoc Documentation: http://localhost:8000/redoc
-
Unzip to install:
unzip /path/to/ngrok.zip
-
Connect your account:
./ngrok authtoken <token>
-
To start a HTTP tunnel forwarding to your local port PORT_NUMBER, run this next:
./ngrok http PORT_NUMBER
- note: To call fetch() API from the front-end when testing locally we need to sign our backend with an SSL/TLS certificate marking it secure (https). An easy way to do that is by using ngrok!