Skip to content

Commit

Permalink
Merge pull request #45 from No-Country-simulation/main
Browse files Browse the repository at this point in the history
base backend , compare main, update
  • Loading branch information
Orlandoc0107 authored Nov 25, 2024
2 parents e16eac5 + 4b42ed8 commit b6ba65c
Show file tree
Hide file tree
Showing 21 changed files with 159 additions and 41 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/mainClient.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@ jobs:
run: |
docker push $GCLOUD_REGION-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT_ID }}/klowhubnext-client/klowhub-client:${{ github.sha }}
# 6.5. Limpiar imágenes antiguas
- name: Cleanup Old Images
working-directory: ./client
run: |
TAGS=$(gcloud container images list-tags \
${{ secrets.GCLOUD_REGION }}-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT_ID }}/klowhubnext-client/klowhub-client \
--format='get(tags)' \
--sort-by=~TIMESTAMP)
TOTAL_IMAGES=$(echo "$TAGS" | wc -l)
if [ $TOTAL_IMAGES -gt 2 ]; then
TO_DELETE=$((TOTAL_IMAGES - 2))
echo "Found $TOTAL_IMAGES images, keeping 2, deleting $TO_DELETE"
echo "$TAGS" | tail -n $TO_DELETE | while read TAG; do
if [ ! -z "$TAG" ]; then
echo "Deleting image with tag: $TAG"
gcloud container images delete \
"${{ secrets.GCLOUD_REGION }}-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT_ID }}/klowhubnext-client/klowhub-client:$TAG" \
--quiet
fi
done
fi
# 7. Desplegar a Cloud Run
- name: Deploy to Cloud Run
working-directory: ./client
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/mainServer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
GATEWAY_SERVICE_PORT: 3000
UPLOAD_SERVICE_NAME: klowhub-upload-api
UPLOAD_SERVICE_PORT: 3003
MAX_IMAGES_TO_KEEP: 2
MAX_IMAGES_TO_KEEP: 1
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -293,7 +293,4 @@ jobs:
DEPLOY_NAME="${DEPLOY_INFO#*/}"
echo "Setting revision history limit for $DEPLOY_NAME"
kubectl patch deployment $DEPLOY_NAME -n $NAMESPACE -p '{"spec": {"revisionHistoryLimit": 2}}'
kubectl rollout status deployment/$DEPLOY_NAME -n $NAMESPACE
echo "Current revision history for $DEPLOY_NAME:"
kubectl rollout history deployment/$DEPLOY_NAME -n $NAMESPACE
done
1 change: 0 additions & 1 deletion server/api/check-deploy.rest

This file was deleted.

3 changes: 3 additions & 0 deletions server/api/check-gateway-deploy.rest
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Check Gateway Deploy
GET http://34.111.85.215/gateway/hello
Content-Type: application/json
3 changes: 3 additions & 0 deletions server/api/check-gateway-local.rest
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Check Gateway Local
GET http://localhost:3000/gateway/hello
Content-Type: application/json
14 changes: 13 additions & 1 deletion server/apps/gateway/protos/upload.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
syntax = "proto3";

package googlecloudstorage;
package googlecloudstorage; // Este será el paquete común para ambos servicios

// Servicio PubSub
service PubSubService {
rpc Test (TestRequest) returns (TestResponse);
}

message TestRequest {}

message TestResponse {
string message = 1;
}

// Servicio GoogleCloudStorage
service GoogleCloudStorageService {
rpc UploadFile (UploadFileRequest) returns (UploadFileResponse);
}
Expand Down
2 changes: 2 additions & 0 deletions server/apps/gateway/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { AuthModule } from './auth/auth.module';
import { UploadModule } from './upload/upload.module';
import { CoursesModule } from './courses/courses.module';
import { PubSubModule } from './pubsub/pubsub.module';
import { GatewayController } from './gateway.controller';
@Module({
imports: [AuthModule, UploadModule, CoursesModule,PubSubModule],
controllers: [GatewayController],
})
export class AppModule {}
2 changes: 1 addition & 1 deletion server/apps/gateway/src/gateway.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Controller, Get } from '@nestjs/common';

@Controller('gateway')
export class GatewayController {
@Get()
@Get("/hello")
getHello(): string {
return 'Hello from Gateway!';
}
Expand Down
3 changes: 2 additions & 1 deletion server/apps/gateway/src/gateway.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Module } from '@nestjs/common';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { AuthController } from './auth/auth.controllers';
import { UploadController } from './upload/upload.controllers';
import { join } from "path";
import * as dotenv from 'dotenv';
dotenv.config();

Expand Down Expand Up @@ -29,7 +30,7 @@ dotenv.config();
transport: Transport.GRPC,
options: {
package: 'googlecloudstorage',
protoPath: '../protos/upload.proto',
protoPath: join(__dirname,'../protos/upload.proto'),
url: `${process.env.UPLOAD_MICROSERVICE_HOST || "0.0.0.0"}:${process.env.UPLOAD_SERVICE_PORT || 3003}`,
},
},
Expand Down
1 change: 1 addition & 0 deletions server/apps/gateway/src/middleware/routersPublics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export const publicRoutes: string[] = [
'/auth/login',
'/auth/verifyEmail',
'/auth/resetToken',
'/gateway/hello'
];
30 changes: 0 additions & 30 deletions server/apps/gateway/src/proto/upload.proto

This file was deleted.

5 changes: 3 additions & 2 deletions server/apps/gateway/src/pubsub/pubsub.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Module } from '@nestjs/common';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { PubSubGatewayController } from './pubsub.gateway.controller';
import { PubSubGatewayService } from './pubsub.gateway.service';
import { join } from "path";

@Module({
imports: [
Expand All @@ -11,8 +12,8 @@ import { PubSubGatewayService } from './pubsub.gateway.service';
transport: Transport.GRPC,
options: {
package: 'googlecloudstorage',
protoPath: 'src/proto/upload.proto',
url: '0.0.0.0:50051',
protoPath: join(__dirname,'../../protos/upload.proto'),
url: `${process.env.UPLOAD_MICROSERVICE_HOST || "0.0.0.0"}:${process.env.UPLOAD_SERVICE_PORT || 3003}`,
},
},
]),
Expand Down
3 changes: 2 additions & 1 deletion server/apps/gateway/src/upload/upload.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Module } from '@nestjs/common';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { UploadController } from './upload.controllers';
import { join } from "path";

@Module({
imports: [
Expand All @@ -10,7 +11,7 @@ import { UploadController } from './upload.controllers';
transport: Transport.GRPC,
options: {
package: 'googlecloudstorage',
protoPath: 'src/proto/upload.proto',
protoPath: join(__dirname,'../../protos/upload.proto'),
url: `${process.env.UPLOAD_MICROSERVICE_HOST || "0.0.0.0"}:${process.env.UPLOAD_SERVICE_PORT || 3003}`,
},
},
Expand Down
7 changes: 7 additions & 0 deletions server/k8s/courses-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ spec:
image: ${GCLOUD_REGION}-docker.pkg.dev/${GCLOUD_PROJECT_ID}/klowhub-server/${COURSE_SERVICE_NAME}:${IMAGE_TAG}
ports:
- containerPort: 3002
resources:
requests:
cpu: "50m"
memory: "64Mi"
limits:
cpu: "100m"
memory: "128Mi"
env:
- name: NODE_ENV
value: "production"
Expand Down
19 changes: 19 additions & 0 deletions server/k8s/courses-hpa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: courses-hpa
namespace: courseservice
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: courses-deployment
minReplicas: 1
maxReplicas: 2
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80
7 changes: 7 additions & 0 deletions server/k8s/gateway-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ spec:
image: ${GCLOUD_REGION}-docker.pkg.dev/${GCLOUD_PROJECT_ID}/klowhub-server/${GATEWAY_SERVICE_NAME}:${IMAGE_TAG}
ports:
- containerPort: 3000
resources:
requests:
cpu: "50m"
memory: "64Mi"
limits:
cpu: "100m"
memory: "128Mi"
env:
- name: NODE_ENV
value: "production"
Expand Down
19 changes: 19 additions & 0 deletions server/k8s/gateway-hpa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: gateway-hpa
namespace: gateway
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: gateway-deployment
minReplicas: 1
maxReplicas: 2
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80
7 changes: 7 additions & 0 deletions server/k8s/upload-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ spec:
image: ${GCLOUD_REGION}-docker.pkg.dev/${GCLOUD_PROJECT_ID}/klowhub-server/${UPLOAD_SERVICE_NAME}:${IMAGE_TAG}
ports:
- containerPort: 3003
resources:
requests:
cpu: "50m"
memory: "64Mi"
limits:
cpu: "100m"
memory: "128Mi"
env:
- name: NODE_ENV
value: "production"
Expand Down
19 changes: 19 additions & 0 deletions server/k8s/upload-hpa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: upload-hpa
namespace: gcc-upload
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: klowhub-upload-api-deployment
minReplicas: 1
maxReplicas: 2
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80
7 changes: 7 additions & 0 deletions server/k8s/users-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ spec:
image: ${GCLOUD_REGION}-docker.pkg.dev/${GCLOUD_PROJECT_ID}/klowhub-server/${USERS_SERVICE_NAME}:${IMAGE_TAG}
ports:
- containerPort: 3001
resources:
requests:
cpu: "50m"
memory: "64Mi"
limits:
cpu: "100m"
memory: "128Mi"
env:
- name: NODE_ENV
value: "production"
Expand Down
19 changes: 19 additions & 0 deletions server/k8s/users-hpa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: users-hpa
namespace: userservice
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: users-deployment
minReplicas: 1
maxReplicas: 2
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80

0 comments on commit b6ba65c

Please sign in to comment.