Skip to content

Commit

Permalink
ci: add nginx verify
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcossIC committed Nov 24, 2024
1 parent e130ae9 commit 68e6b58
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 24 deletions.
71 changes: 51 additions & 20 deletions .github/workflows/mainServer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,63 +59,90 @@ jobs:
with:
cluster_name: ${{ secrets.GKE_CLUSTER_NAME }}
location: ${{ secrets.GCLOUD_REGION }}

# 5. Instalar Helm
- name: Install Helm
working-directory: ./server
run: |
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
# 5. Agregar dinamicamente BACKEND_SA_KEY
# 6. Instalar Nginx Ingress Controller
- name: Install Nginx Ingress Controller
working-directory: ./server
run: |
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm upgrade --install ingress-nginx ingress-nginx/ingress-nginx \
--namespace ingress-nginx \
--create-namespace \
--set controller.service.type=LoadBalancer
# 7. Agregar dinamicamente BACKEND_SA_KEY
- name: Create service account key file
working-directory: ./server/apps/uploadGCould
run: echo "${{ secrets.GCC_BACKEND_SA_KEY }}" > ./gccKey.json

# 6. Autenticarse con Artifact Registry
# 8. Autenticarse con Artifact Registry
- name: Authenticate with Artifact Registry
working-directory: ./server
run: gcloud auth configure-docker $GCLOUD_REGION-docker.pkg.dev

# 6.5. Valido el accedo a Artifact Registry
# 8.5. Valido el accedo a Artifact Registry
- name: Validate Docker authentication
run: docker login $GCLOUD_REGION-docker.pkg.dev

# 7. Construir la imagen Docker para User Service
# 9. Construir la imagen Docker para User Service
- name: Users Service - Build Docker image
working-directory: ./server
run: docker build --progress plain --build-arg JWT_SECRET=${{ secrets.JWT_SECRET }} --build-arg SMTP_USER=${{ secrets.SMTP_USER }} --build-arg SMTP_PASS=${{ secrets.SMTP_PASS }} --build-arg SMTP_HOST=${{ secrets.SMTP_HOST }} --build-arg SMTP_PORT=${{ secrets.SMTP_PORT }} --build-arg SMTP_SECURE=${{ secrets.SMTP_SECURE }} --build-arg GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }} --build-arg GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }} --build-arg GOOGLE_CALLBACK_URL=${{ secrets.GOOGLE_CALLBACK_URL }} --build-arg DATABASE_URL=${{ secrets.DATABASE_URL }} --build-arg DATABASE_URL_UNPOOLED=${{ secrets.DATABASE_URL_UNPOOLED }} --build-arg PGHOST=${{ secrets.PGHOST }} --build-arg PGHOST_UNPOOLED=${{ secrets.PGHOST_UNPOOLED }} --build-arg PGUSER=${{ secrets.PGUSER }} --build-arg PGDATABASE=${{ secrets.PGDATABASE }} --build-arg PGPASSWORD=${{ secrets.PGPASSWORD }} --build-arg POSTGRES_URL=${{ secrets.POSTGRES_URL }} --build-arg POSTGRES_URL_NON_POOLING=${{ secrets.POSTGRES_URL_NON_POOLING }} --build-arg POSTGRES_USER=${{ secrets.POSTGRES_USER }} --build-arg POSTGRES_HOST=${{ secrets.POSTGRES_HOST }} --build-arg POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} --build-arg POSTGRES_DATABASE=${{ secrets.POSTGRES_DATABASE }} --build-arg POSTGRES_URL_NO_SSL=${{ secrets.POSTGRES_URL_NO_SSL }} --build-arg POSTGRES_PRISMA_URL=${{ secrets.POSTGRES_PRISMA_URL }} -f ./apps/users/Dockerfile -t ${{ secrets.GCLOUD_REGION }}-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT_ID }}/klowhub-server/${{ env.USERS_SERVICE_NAME }}:${{ github.sha }} ./apps/users


# 8. Construir la imagen Docker para Courses Service
# 10. Construir la imagen Docker para Courses Service
- name: Courses Service - Build Docker image
working-directory: ./server
run: docker build --progress plain --build-arg MONGO_URI=${{ secrets.MONGO_URI }} --build-arg JWT_SECRET=${{ secrets.JWT_SECRET }} -f ./apps/courses/Dockerfile -t ${{ secrets.GCLOUD_REGION }}-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT_ID }}/klowhub-server/${{ env.COURSE_SERVICE_NAME }}:${{ github.sha }} ./apps/courses

# 8. Construir la imagen Docker para Gateway Service
# 11. Construir la imagen Docker para Gateway Service
- name: Gateway Service - Build Docker image
working-directory: ./server
run: docker build --progress plain --build-arg FRONTEND_URL=${{ secrets.FRONTEND_URL }} --build-arg JWT_SECRET=${{ secrets.JWT_SECRET }} -f ./apps/gateway/Dockerfile -t ${{ secrets.GCLOUD_REGION }}-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT_ID }}/klowhub-server/${{ env.GATEWAY_SERVICE_NAME }}:${{ github.sha }} ./apps/gateway

# 8. Construir la imagen Docker para Upload Service
# 12. Construir la imagen Docker para Upload Service
- name: Upload Service - Build Docker image
working-directory: ./server
run: docker build --progress plain --build-arg PROJECT_ID=${{ secrets.PROJECT_ID }} --build-arg BUCKET_NAME=${{ secrets.BUCKET_NAME }} -f ./apps/uploadGCould/Dockerfile -t ${{ secrets.GCLOUD_REGION }}-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT_ID }}/klowhub-server/${{ env.UPLOAD_SERVICE_NAME }}:${{ github.sha }} ./apps/uploadGCould

# 9. Subir la imagen de User Service a Artifact Registry
# 13. Subir la imagen de User Service a Artifact Registry
- name: Users Service - Push Docker image
working-directory: ./server
run: docker push ${{ secrets.GCLOUD_REGION }}-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT_ID }}/klowhub-server/${{ env.USERS_SERVICE_NAME }}:${{ github.sha }}

# 10. Subir la imagen de Courses Service a Artifact Registry
# 14. Subir la imagen de Courses Service a Artifact Registry
- name: Courses Service - Push Docker image
working-directory: ./server
run: docker push ${{ secrets.GCLOUD_REGION }}-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT_ID }}/klowhub-server/${{ env.COURSE_SERVICE_NAME }}:${{ github.sha }}

# 10. Subir la imagen de Upload Service a Artifact Registry
# 15. Subir la imagen de Upload Service a Artifact Registry
- name: Upload Service - Push Docker image
working-directory: ./server
run: docker push ${{ secrets.GCLOUD_REGION }}-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT_ID }}/klowhub-server/${{ env.UPLOAD_SERVICE_NAME }}:${{ github.sha }}

# 11. Subir la imagen de Gateway Service a Artifact Registry
# 16. Subir la imagen de Gateway Service a Artifact Registry
- name: Gateway Service - Push Docker image
working-directory: ./server
run: docker push ${{ secrets.GCLOUD_REGION }}-docker.pkg.dev/${{ secrets.GCLOUD_PROJECT_ID }}/klowhub-server/${{ env.GATEWAY_SERVICE_NAME }}:${{ github.sha }}

# 12. Setear un .env para la susticucion de variables
# 17. Esperar a que el Ingress Controller esté listo
- name: Wait for Ingress Controller
working-directory: ./server
run: |
echo "Waiting for Ingress Controller to be ready..."
kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=300s
# 18. Setear un .env para la susticucion de variables
- name: Create env file for substitution
working-directory: ./server
run: |
Expand Down Expand Up @@ -157,7 +184,7 @@ jobs:
chmod +x .env
source .env
# 13. Sustituir variables en los manifiestos en K8s
# 19. Sustituir variables en los manifiestos en K8s
- name: Prepare and validate K8s manifests
working-directory: ./server
run: |
Expand Down Expand Up @@ -228,16 +255,20 @@ jobs:
BUCKET_NAME: ${{ secrets.BUCKET_NAME }}
MONGO_URI: ${{ secrets.MONGO_URI }}

# 14. Aplicando los manifiestos a los kubernetes
# 20. Aplicando los manifiestos a los kubernetes
- name: Apply Kubernetes manifests
working-directory: ./server
run: |
kubectl apply -f k8s-rendered/
echo "Waiting for deployments to be ready..."
kubectl wait --for=condition=available deployment/users-deployment -n userservice --timeout=300s
run: kubectl apply -f k8s-rendered/

# 21. Verificando que el Ingress este listo
- name: Verify Ingress Status
working-directory: ./server
run: |
echo "Checking Ingress status..."
kubectl get ingress -A
kubectl get svc -n ingress-nginx
# 15. Verificando que el deployment este listo
# 22. Verificando que el deployment este listo
- name: Verify deployment
working-directory: ./server
run: |
Expand Down
15 changes: 12 additions & 3 deletions server/k8s/gateway-ingress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@ kind: Ingress
metadata:
name: gateway-ingress
namespace: gateway
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/rewrite-target: /$1
nginx.ingress.kubernetes.io/use-regex: "true"
# Si necesitas SSL/TLS
# nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-methods: "PUT, GET, POST, OPTIONS, DELETE"
nginx.ingress.kubernetes.io/cors-allow-origin: "*"
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
- path: /(.*)
pathType: ImplementationSpecific
backend:
service:
name: klowhub-gateway-api
name: gateway-service
port:
number: 80
2 changes: 1 addition & 1 deletion server/k8s/gateway-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: gateway-service
namespace: gateway
spec:
type: LoadBalancer
type: ClusterIP
selector:
app: klowhub-gateway-api
ports:
Expand Down

0 comments on commit 68e6b58

Please sign in to comment.