Giter Club home page Giter Club logo

apc_backend's Introduction

APC_Backend

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.


Configuring the Server

  1. 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.

  1. Make sure pynguin is in the home directory

    cd ~
    git clone https://github.com/se2p/pynguin.git
  2. Create input, output, and package directories. Create package/package.txt

    cd ~/pynguin
    mkdir input output package
    touch package/package.txt
  3. 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
  4. 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
    	  
  5. 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

  6. 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

Creating a Virtual Environment

  1. 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
  2. To install the required dependencies, execute the following command:

    pip install -r requirements.txt # installs required dependencies
    

Create required directories

  1. From APC_backend directory, run the following command:

    mkdir input output

Setting Up the Database

  1. Download MySQL Community Server and MySQL Workbench

  2. Create a root user account. Note down your host name, user, and password

  3. Import the database.sql file from MySQL Workbench Server settings.


Setting Up the .env file

  1. 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 
  1. 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

Set the DOCKER_IMAGE_TAG variable in PynguinAPI.sh for Unix Machines (MacOS and Linux Distros)

  1. 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>"
# ...

Running the Server

  1. 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
  1. Notes:

Testing Locally using Ngrok

  1. Download ngrok

  2. Unzip to install:

    unzip /path/to/ngrok.zip
  3. Connect your account:

    ./ngrok authtoken <token>
  4. 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!

apc_backend's People

Contributors

jawadsrour20 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.