You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge pull request #2 from MirkoZETA/feature/cloud-run-deployment
Implemented Cloud Run instead of Kubernetes plus new functionalities:
- New endpoint `/help`.
- New networks and bitrates alternatives.
- New algorithms alternative ExactFit.
- Implemented K route parameter.
- Separated Jobs in YML file.
- Updated README.
Flask-based backend API for integrating the FlexNetSim C++ library, powering the web application deployed at [www.in-progress.com](www.in-progress.com). While unofficial, it serves as a bridge between the simulation engine and the web interface.
3
+
Flask-based backend API for integrating the FlexNetSim C++ library, powering the web application.
4
4
5
5
## Prerequisites
6
6
7
7
* Python 3.9 or higher
8
8
* g++ (GNU C++ Compiler)
9
9
* Docker (for containerization)
10
-
* Google Cloud SDK (for deployment to GKE) -> In progress.
11
-
* A Google Cloud Project with Google Kubernetes Engine (GKE) and Google Container Registry (GCR) enabled -> In progress.
10
+
* Google Cloud SDK (for deployment to Cloud Run)
11
+
* A Google Cloud Project with Cloud Run API enabled.
12
12
13
13
## Getting Started (Local Development)
14
14
15
15
1.**Clone the repository:**
16
16
```bash
17
-
git clone [repository-url]
17
+
git clone <repository-url># Replace <repository-url> with your repository URL
18
18
cd flask-simulation-backend
19
19
```
20
20
@@ -36,14 +36,34 @@ Flask-based backend API for integrating the FlexNetSim C++ library, powering the
36
36
```
37
37
The backend will be accessible at `http://127.0.0.1:5000`.
38
38
39
-
5. **Send simulation requests using `curl` or a frontend application:**
40
-
Example `curl` request with minimal parameters (defaults applied):
**Example `curl`request with all parameters specified:**
66
+
```bash
47
67
curl -X POST -H "Content-Type: application/json" \
48
68
-d '{
49
69
"algorithm": "FirstFit",
@@ -56,7 +76,27 @@ Flask-based backend API for integrating the FlexNetSim C++ library, powering the
56
76
"bitrate": "bitrate" -> (filename in the ./bitrates folder)
57
77
}' \
58
78
http://127.0.0.1:5000/run_simulation
79
+
```
80
+
81
+
**Response**:
82
+
- 200 OK: Simulation executed successfully. The response body will be a JSON object with the following structure:
83
+
```JSON
84
+
{
85
+
"output": "string", // Simulation output results
86
+
"error": "string" // Empty string if no errors
87
+
}
59
88
```
89
+
- 400 Bad Request: Indicates an error in the request, such as missing or invalid parameters. The response body will be a JSON object with an `"error"` field describing the issue.
90
+
- 500 Internal Server Error: Indicates a server-side error, either during compilation or simulation execution. The response body will be a JSON object with `"error"` and "details" fields providing more information about the error.
91
+
92
+
### `/help` (GET)
93
+
94
+
This endpoint provides detailed information about the `/run_simulation` endpoint, including the expected request structure, parameters, allowed values, and response formats.
95
+
96
+
**Request**:
97
+
```bash
98
+
curl http://127.0.0.1:5000/help
99
+
```
60
100
61
101
## Dockerization
62
102
@@ -74,77 +114,54 @@ To stop:
74
114
docker stop fns-api
75
115
```
76
116
77
-
## Docs: GCloud Deployment Configuration
117
+
## GCloud Deployment Configuration
78
118
79
-
For detailed step-by-step instructions on configuring Google Cloud (GCloud) aspects such as Kubernetes Cluster creation, Artifact Registry, Service Account creation, and IAM policy binding, please refer to the following video tutorial:
119
+
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:
80
120
81
121
[GCloud Configuration Video Tutorial](https://www.youtube.com/watch?v=KQUKDiBz3IA)
82
122
83
-
This video will guide you through the necessary configurations in the Google Cloud Console to prepare your project forKubernetes deployments using GitHub Actions.
123
+
This video will guide you through the necessary configurations in the Google Cloud Console to prepare your project forCloud Run deployments using GitHub Actions.
84
124
85
125
**Key Reminders from the Video &for Successful Deployment:**
86
126
87
-
***Keep Track of Docker Image Name, Project ID, and Kubernetes Cluster Name:** Note these down during the video configuration, as you will need them in subsequent steps and for your GitHub Actions workflow.
127
+
***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.
88
128
***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.
89
129
90
-
**Post-Configuration Steps (using `gcloud` and `kubectl`):**
130
+
**Post-Configuration Steps (using `gcloud` and `cloud-run`):**
91
131
92
-
1. **Create a Kubernetes Cluster in GCloud:**
132
+
1. Activate necessary apis:
93
133
94
-
* Navigate to the Kubernetes Engine section in your Google Cloud Console.
95
-
* Click **Create Cluster**.
96
-
* Choose a cluster name (e.g., `flex-net-sim-cluster`). **Remember this name.**
97
-
* Select a region for your cluster (e.g., `us-central1`).
98
-
* For the purpose of this guide, you can use the default settings for node pools, networking, and other configurations, or adjust them based on your specific needs.
99
-
* Click **Create** to create the cluster. It will take a few minutes for the cluster to be provisioned.
134
+
*`gcloud services enable run.googleapis.com`
100
135
101
-
2. **Set IAM Policy Binding (using `gcloud`):**
136
+
2. Create cloud run service:
137
+
* Navigate to the Cloud Run section in your Google Cloud Console.
138
+
* Create a **Service**.
139
+
* Select *Use an inline editor to create a function*.
140
+
* Set a name, in this case*fns-api-cloud-run* will be used.
141
+
* Note down the Endpoint URL, because it will the defaul url for the API.
142
+
* Select the authetification preferences.
143
+
* Create.
102
144
103
-
Replace `<YOUR-GOOGLE-PROJECT-ID>` and `<SERVICE_ACCOUNT_EMAIL>` with your actual Google Cloud Project ID and the Service Account Email you noted down.
145
+
3. Update access of service accounts to cloud run resources:
Replace `<CLUSTER-NAME>` and `<YOUR-GOOGLE-PROJECT-ID>` with your Kubernetes Cluster Name and Google Cloud Project ID. Ensure the region is set to `us-central1`.
The command will fetch the cluster credentials and configure `kubectl` to use them. You should see output similar to:
118
-
119
-
```
120
-
Fetching cluster endpoint and auth data.
121
-
kubeconfig entry generated for<CLUSTER-NAME>.
122
-
```
154
+
gcloud iam service-accounts add-iam-policy-binding "<YOUR_PROJECT_NUMBER>-compute@developer.gserviceaccount.com" --member="serviceAccount:<SERVICE_ACCOUNT_EMAIL>" --role="roles/iam.serviceAccountActor"
155
+
```
123
156
124
-
4. **Verify `kubectl` Configuration and Service Deployment (using `kubectl`):**
157
+
4. **Test the Deployed API (using `curl`):**
125
158
126
-
After the commandis successful, verify your `kubectl` configuration and check for the `fns-api-service`:
159
+
Use the `curl`commandwith the `ENDPOINT-URL` you obtained from the previous steps to testyour deployed API. Replace `YOUR-ENDPOINT-URL` with the actual `ENDPOINT-URL`.
127
160
128
161
```bash
129
-
kubectl get service fns-api-service
130
-
```
131
-
132
-
If the service is correctly deployed (after your GitHub Actions workflow runs), it should display information about your service, including the `EXTERNAL-IP`.
Use the `curl`command with the `EXTERNAL-IP` you obtained from the previous step to test your deployed API. Replace `<YOUR-EXTERNAL-IP>` with the actual `EXTERNAL-IP`.
Remember that depending on the authetification preferences you might need to authetificate to send request to the Endpoint just created.
149
166
150
-
**Remember**: These GCloud configurations, along with the repository's `gke-cd.yml` GitHub Actions workflow and correctly configured GitHub secrets, are essential for successful automated deployment of your FlexNetSim-API application to Google Cloud Kubernetes Engine.
167
+
**Remember**: These GCloud configurations, along with the repository's `gke-cd.yml` GitHub Actions workflow and correctly configured GitHub secrets, are essential for successful automated deployment of your FlexNetSim-API application to Google Cloud Run.
0 commit comments