Skip to content

Commit 330d8b9

Browse files
authored
Merge pull request #1 from MirkoZETA/develop
Develop to Main
2 parents 224f33e + 0f1c91c commit 330d8b9

File tree

3 files changed

+155
-50
lines changed

3 files changed

+155
-50
lines changed

.github/workflows/gke-cd.yml

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,33 @@
1-
name: Backend CI/CD to GKE
1+
name: Deploy FNS API
22

33
on:
44
push:
5-
branches: [ "main" ]
5+
branches:
6+
- main
67
pull_request:
7-
branches: [ "main" ]
8+
branches:
9+
- main
810

911
jobs:
10-
build-and-push-docker:
12+
deploy:
1113
name: Build and Push Docker Image
1214
runs-on: ubuntu-latest
13-
1415
steps:
15-
- name: Checkout code
16-
uses: actions/checkout@v3
17-
18-
- name: Set up Google Cloud SDK
19-
uses: google-github-actions/setup-gcloud@v1
20-
with:
21-
service_account_key: ${{ secrets.GKE_SA_KEY }} # Configure this secret in GitHub Actions
22-
project_id: ${{ secrets.GKE_PROJECT_ID }} # Configure this secret in GitHub Actions
23-
24-
- name: Enable Docker Credential Helper
25-
run: |-
26-
gcloud auth configure-docker
27-
28-
- name: Build Docker image
29-
run: |-
30-
docker build --tag gcr.io/${{ secrets.GKE_PROJECT_ID }}/mi-backend-simulacion:${GITHUB_SHA} .
3116

32-
- name: Push Docker image to GCR
33-
run: |-
34-
docker push gcr.io/${{ secrets.GKE_PROJECT_ID }}/mi-backend-simulacion:${GITHUB_SHA}
35-
36-
deploy-to-gke:
37-
name: Deploy to GKE
38-
needs: build-and-push-docker
39-
runs-on: ubuntu-latest
40-
41-
steps:
4217
- name: Checkout code
43-
uses: actions/checkout@v3
18+
uses: actions/checkout@v2
4419

45-
- name: Set up Google Cloud SDK
46-
uses: google-github-actions/setup-gcloud@v1
20+
- name: Set up Google CLoud CLI
21+
uses: google-github-actions/setup-gcloud@v0
4722
with:
48-
service_account_key: ${{ secrets.GKE_SA_KEY }} # Configure this secret in GitHub Actions
49-
project_id: ${{ secrets.GKE_PROJECT_ID }} # Configure this secret in GitHub Actions
50-
cluster_name: tu-cluster-gke # Reemplaza with your GKE cluster name
51-
cluster_zone: tu-zona-gke # Reemplaza with your GKE cluster zone
52-
53-
- name: Get Kubernetes credentials
54-
run: |-
55-
gcloud container clusters get-credentials tu-cluster-gke --zone tu-zona-gke --project ${{ secrets.GKE_PROJECT_ID }} # Reemplaza with your cluster and zone
56-
57-
- name: Deploy to GKE (Ejemplo Básico - Necesitas Adaptar!)
58-
run: |-
59-
# This is a VERY basic example. YOU MUST ADAPT THIS TO YOUR KUBERNETES DEPLOYMENT.
60-
# Normally you would use a Kubernetes Deployment YAML file and kubectl apply -f deployment.yaml
61-
# Here, we just update the image of an existing Deployment named 'mi-backend-deployment' (example).
62-
kubectl set image deployment/mi-backend-deployment mi-backend-container=gcr.io/${{ secrets.GKE_PROJECT_ID }}/mi-backend-simulacion:${GITHUB_SHA}
23+
service_account_key: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
24+
project_id: ${{ secrets.GOOGLE_PROJECT }}
25+
export_default_credentials: true
26+
27+
- name: Build and push Docker image
28+
env:
29+
GOOGLE_PROJECT: ${{ secrets.GOOGLE_PROJECT }}
30+
run: |
31+
gcloud auth configure-docker us-central1-docker.pkg.dev
32+
docker build -t us-central1-docker.pkg.dev/$GOOGLE_PROJECT/flex-net-sim-repo/fns-api:latest .
33+
docker push us-central1-docker.pkg.dev/$GOOGLE_PROJECT/flex-net-sim-repo/fns-api:latest

.github/workflows/google.yml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# This workflow will build a docker container, publish it to Google Container
2+
# Registry, and deploy it to GKE when there is a push to the "main"
3+
# branch.
4+
#
5+
# To configure this workflow:
6+
#
7+
# 1. Enable the following Google Cloud APIs:
8+
#
9+
# - Artifact Registry (artifactregistry.googleapis.com)
10+
# - Google Kubernetes Engine (container.googleapis.com)
11+
# - IAM Credentials API (iamcredentials.googleapis.com)
12+
#
13+
# You can learn more about enabling APIs at
14+
# https://support.google.com/googleapi/answer/6158841.
15+
#
16+
# 2. Ensure that your repository contains the necessary configuration for your
17+
# Google Kubernetes Engine cluster, including deployment.yml,
18+
# kustomization.yml, service.yml, etc.
19+
#
20+
# 3. Create and configure a Workload Identity Provider for GitHub:
21+
# https://github.com/google-github-actions/auth#preferred-direct-workload-identity-federation.
22+
#
23+
# Depending on how you authenticate, you will need to grant an IAM principal
24+
# permissions on Google Cloud:
25+
#
26+
# - Artifact Registry Administrator (roles/artifactregistry.admin)
27+
# - Kubernetes Engine Developer (roles/container.developer)
28+
#
29+
# You can learn more about setting IAM permissions at
30+
# https://cloud.google.com/iam/docs/manage-access-other-resources
31+
#
32+
# 5. Change the values in the "env" block to match your values.
33+
34+
name: 'Build and Deploy to GKE'
35+
36+
on:
37+
push:
38+
branches:
39+
- '"main"'
40+
pull_request:
41+
branches: none
42+
43+
env:
44+
PROJECT_ID: 'flexnetsim' # TODO: update to your Google Cloud project ID
45+
GAR_LOCATION: 'us-central1' # TODO: update to your region
46+
GKE_CLUSTER: 'flex-net-sim-cluster' # TODO: update to your cluster name
47+
GKE_ZONE: 'us-central1-c' # TODO: update to your cluster zone
48+
DEPLOYMENT_NAME: 'gke-test' # TODO: update to your deployment name
49+
REPOSITORY: 'samples' # TODO: update to your Artifact Registry docker repository name
50+
IMAGE: 'static-site'
51+
WORKLOAD_IDENTITY_PROVIDER: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' # TODO: update to your workload identity provider
52+
53+
jobs:
54+
setup-build-publish-deploy:
55+
name: 'Setup, Build, Publish, and Deploy'
56+
runs-on: 'ubuntu-latest'
57+
environment: 'production'
58+
59+
permissions:
60+
contents: 'read'
61+
id-token: 'write'
62+
63+
steps:
64+
- name: 'Checkout'
65+
uses: 'actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332' # actions/checkout@v4
66+
67+
# Configure Workload Identity Federation and generate an access token.
68+
#
69+
# See https://github.com/google-github-actions/auth for more options,
70+
# including authenticating via a JSON credentials file.
71+
- id: 'auth'
72+
name: 'Authenticate to Google Cloud'
73+
uses: 'google-github-actions/auth@f112390a2df9932162083945e46d439060d66ec2' # google-github-actions/auth@v2
74+
with:
75+
workload_identity_provider: '${{ env.WORKLOAD_IDENTITY_PROVIDER }}'
76+
77+
# Authenticate Docker to Google Cloud Artifact Registry
78+
- name: 'Docker Auth'
79+
uses: 'docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567' # docker/login-action@v3
80+
with:
81+
username: 'oauth2accesstoken'
82+
password: '${{ steps.auth.outputs.auth_token }}'
83+
registry: '${{ env.GAR_LOCATION }}-docker.pkg.dev'
84+
85+
# Get the GKE credentials so we can deploy to the cluster
86+
- name: 'Set up GKE credentials'
87+
uses: 'google-github-actions/get-gke-credentials@6051de21ad50fbb1767bc93c11357a49082ad116' # google-github-actions/get-gke-credentials@v2
88+
with:
89+
cluster_name: '${{ env.GKE_CLUSTER }}'
90+
location: '${{ env.GKE_ZONE }}'
91+
92+
# Build the Docker image
93+
- name: 'Build and push Docker container'
94+
run: |-
95+
DOCKER_TAG="${GAR_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${REPOSITORY}/${IMAGE}:${GITHUB_SHA}"
96+
97+
docker build \
98+
--tag "${DOCKER_TAG}" \
99+
--build-arg GITHUB_SHA="${GITHUB_SHA}" \
100+
--build-arg GITHUB_REF="${GITHUB_REF}" \
101+
.
102+
103+
docker push "${DOCKER_TAG}"
104+
105+
# Set up kustomize
106+
- name: 'Set up Kustomize'
107+
run: |-
108+
curl -sfLo kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv5.4.3/kustomize_v5.4.3_linux_amd64.tar.gz
109+
chmod u+x ./kustomize
110+
111+
# Deploy the Docker image to the GKE cluster
112+
- name: 'Deploy to GKE'
113+
run: |-
114+
# replacing the image name in the k8s template
115+
./kustomize edit set image LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE:TAG=$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$GITHUB_SHA
116+
./kustomize build . | kubectl apply -f -
117+
kubectl rollout status deployment/$DEPLOYMENT_NAME
118+
kubectl get services -o wide

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,27 @@ This is a Flask-based backend API that runs the Flex Net Sim C++ library.
3737
The backend will be accessible at `http://127.0.0.1:5000`.
3838

3939
5. **Send simulation requests using `curl` or a frontend application:**
40-
Example `curl` request:
40+
Example `curl` request with minimal parameters (defaults applied):
4141
```bash
4242
curl -X POST -H "Content-Type: application/json" -d '{"algorithm": "FirstFit", "networkType": 1, "bitrate": "bitrate"}' [http://127.0.0.1:5000/run_simulation](http://127.0.0.1:5000/run_simulation)
4343
```
4444

45+
Example `curl` request with all parameters specified
46+
```bash
47+
curl -X POST -H "Content-Type: application/json" \
48+
-d '{
49+
"algorithm": "BestFit",
50+
"networkType": 2,
51+
"goal_connections": 50000,
52+
"confidence": 0.01,
53+
"lambda": 1.5,
54+
"mu": 8,
55+
"network": "USNet",
56+
"bitrate": "100Gbps"
57+
}' \
58+
http://127.0.0.1:5000/run_simulation
59+
```
60+
4561
## Dockerization
4662

4763
To build the Docker image:

0 commit comments

Comments
 (0)