|
1 | | -# Flex Net Sim Backend API - Development and Deployment Instructions |
| 1 | +# Flex Net Sim API - Development Guide |
2 | 2 |
|
3 | | -This document is for developers who want to set up, develop, and deploy the Flex Net Sim Backend API. |
| 3 | +This guide helps developers set up, test, and deploy the Flex Net Sim Backend API. |
4 | 4 |
|
5 | 5 | ## Prerequisites |
6 | 6 |
|
7 | | -* Python 3.9 or higher |
8 | | -* g++ (GNU C++ Compiler) |
9 | | -* Docker (for containerization) |
10 | | -* Google Cloud SDK (for deployment to Google Cloud Run) |
11 | | -* A Google Cloud Project with Cloud Run API enabled. |
| 7 | +* Python 3.9+ |
| 8 | +* g++ (GNU C++ Compiler) |
| 9 | +* Docker (for containerization) |
| 10 | +* A Google Cloud Project with Cloud Run API enabled |
| 11 | + |
| 12 | +## Local Development Setup |
| 13 | + |
| 14 | +1. **Clone the repository:** |
| 15 | + ```bash |
| 16 | + git clone https://github.com/MirkoZETA/FlexNetSim-API.git |
| 17 | + cd FlexNetSim-API |
| 18 | + ``` |
| 19 | + |
| 20 | +2. **Set up Python environment:** |
| 21 | + ```bash |
| 22 | + # Create virtual environment |
| 23 | + python3 -m venv .venv |
| 24 | + |
| 25 | + # Activate (Linux/macOS) |
| 26 | + source .venv/bin/activate |
| 27 | + |
| 28 | + # Activate (Windows) |
| 29 | + .venv\Scripts\activate |
| 30 | + |
| 31 | + # Install dependencies |
| 32 | + pip install -r requirements.txt |
| 33 | + ``` |
| 34 | + |
| 35 | +3. **Run the application:** |
| 36 | + ```bash |
| 37 | + flask --app backend run |
| 38 | + ``` |
| 39 | + The API will be available at `http://127.0.0.1:5000`. |
| 40 | + |
| 41 | +4. **Test the API:** |
| 42 | + ```bash |
| 43 | + # Test help endpoint |
| 44 | + curl http://127.0.0.1:5000/help |
| 45 | + |
| 46 | + # Test simulation endpoint |
| 47 | + curl -X POST -H "Content-Type: application/json" -d '{}' http://127.0.0.1:5000/run_simulation |
| 48 | + ``` |
| 49 | + |
| 50 | +## Testing |
| 51 | + |
| 52 | +Run the test suite to ensure code quality: |
12 | 53 |
|
13 | | -## Getting Started (Local Development) |
14 | | - |
15 | | -1. **Clone the repository:** |
16 | | - ```bash |
17 | | - git clone [https://github.com/MirkoZETA/FlexNetSim-API.git](https://github.com/MirkoZETA/FlexNetSim-API.git) |
18 | | - cd flask-simulation-backend |
19 | | - ``` |
20 | | - |
21 | | -2. **Create a Python virtual environment (recommended):** |
22 | | - ```bash |
23 | | - python3 -m venv .venv |
24 | | - ``` |
25 | | - |
26 | | - On Linux/macOS: |
27 | | - ```bash |
28 | | - source .venv/bin/activate |
29 | | - ``` |
30 | | - |
31 | | - On Windows |
32 | | - ```bash |
33 | | - .venv\Scripts\activate |
34 | | - ``` |
35 | | -3. **Install Python dependencies:** |
36 | | - ```bash |
37 | | - pip install -r requirements.txt |
38 | | - ``` |
39 | | - |
40 | | -4. **Run the Flask backend:** |
41 | | - ```bash |
42 | | - flask --app backend run |
43 | | - ``` |
44 | | - The backend will be accessible at `http://127.0.0.1:5000`. |
45 | | - |
46 | | -5. **Test**: |
47 | | - ```bash |
48 | | - curl http://127.0.0.1:5000/help |
49 | | - ``` |
50 | | - or |
51 | | - ```bash |
52 | | - curl -X POST -H "Content-Type: application/json" -d '{}' http://127.0.0.1:5000/run_simulation |
53 | | - ``` |
| 54 | +```bash |
| 55 | +pytest --cov=backend tests/ |
| 56 | +``` |
54 | 57 |
|
55 | | -### Dockerization |
| 58 | +## Docker Deployment |
56 | 59 |
|
57 | | -To build the Docker image: |
| 60 | +Build and run the Docker container locally: |
58 | 61 |
|
59 | 62 | ```bash |
| 63 | +# Build image |
60 | 64 | docker build -t fns-api . |
| 65 | + |
| 66 | +# Run container |
| 67 | +docker run -p 5000:5000 fns-api |
61 | 68 | ``` |
62 | 69 |
|
63 | | -## GCloud Deployment Configuration |
| 70 | +## Google Cloud Deployment Configuration |
64 | 71 |
|
65 | | -As a prerequisite is mandatory to apply the following steps to the GCloud project for the docker image build and upload to artifacts, and also service account creation and IAM policy binding: |
| 72 | +The following steps are required to configure your Google Cloud project for deployment. These steps focus solely on the Google Cloud setup, not the GitHub Actions workflow configuration. |
66 | 73 |
|
67 | 74 | [GCloud Configuration Video Tutorial](https://www.youtube.com/watch?v=KQUKDiBz3IA) |
68 | 75 |
|
69 | | -This video will guide you through the necessary configurations in the Google Cloud Console to prepare your project for Cloud Run deployments using GitHub Actions. |
| 76 | +**Note: This video demonstrates only the Google Cloud Console configurations.** The YAML workflow files shown in the video may be outdated and are not necessary for current deployments. |
| 77 | + |
| 78 | +Follow the Google Cloud setup steps from the video, focusing on: |
| 79 | + |
| 80 | +* Creating a project |
| 81 | +* Setting up Docker repositories |
| 82 | +* Creating service accounts |
| 83 | +* Configuring permissions |
70 | 84 |
|
71 | | -**Key Reminders from the Video & for Successful Deployment:** |
| 85 | +**Key Information to Record During Setup:** |
72 | 86 |
|
73 | | -* **Keep Track of Docker Image Name, Project ID:** Note these down during the video configuration, as you will need them in subsequent steps and for your GitHub Actions workflow. |
74 | | -* **Service Account Email:** Ensure you create a Service Account as shown in the video and securely download and store the JSON key file. You'll also need to note the Service Account's email address. |
| 87 | +* **Docker Image Name and Project ID:** Note these for your deployment process |
| 88 | +* **Service Account Email:** Create a Service Account, download its JSON key file, and record the email address |
75 | 89 |
|
76 | | -**Post-Configuration Steps (using `gcloud` and `cloud-run`):** |
| 90 | +**Post-Configuration Steps (using `gcloud` CLI):** |
77 | 91 |
|
78 | 92 | 1. Activate necessary apis: |
79 | 93 |
|
|
0 commit comments