diff --git a/.github/workflows/CUDA_Build1.yaml b/.github/workflows/CUDA_Build1.yaml index 12a13af..ae99f07 100644 --- a/.github/workflows/CUDA_Build1.yaml +++ b/.github/workflows/CUDA_Build1.yaml @@ -2,6 +2,20 @@ name: CUDA Build1 on: workflow_dispatch: # Manually trigger the workflow + +env: + RESOURCE_GROUP: "my_test" + CLUSTER_NAME: "myAKSCluster" + ACR_NAME: "test1repo" + NODE_COUNT: 1 + NODE_VM_SIZE: "Standard_NV6ads_A10_v5" + ENABLE_CLUSTER_AUTOSCALER: true + MIN_COUNT: 1 + MAX_COUNT: 1 + MAX_PODS: 30 + LOCATION: "centralindia" + KUBERNETES_VERSION: "1.28.5" + #on: # push: # branches: @@ -52,7 +66,7 @@ jobs: with: azcliversion: latest inlineScript: | - result=$(az aks show --resource-group my_test --name myAKSCluster 2>/dev/null | jq -r '.id') + result=$(az aks show --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME 2>/dev/null | jq -r '.id') exit_code=$? if [ $exit_code -ne 0 ]; then echo "Error executing az aks show command. Exit code: $exit_code" @@ -73,9 +87,19 @@ jobs: azcliversion: latest inlineScript: | if [ "${{steps.check-aks.outputs.cluster_exists}}" != "true" ]; then - az aks create --resource-group my_test --name myAKSCluster --node-count 1 --node-vm-size Standard_NV6ads_A10_v5 --enable-cluster-autoscaler --min-count 1 --max-count 1 --max-pods 30 --location centralindia --kubernetes-version 1.28.5 --generate-ssh-keys + az aks create --resource-group $RESOURCE_GROUP \ + --name $CLUSTER_NAME \ + --node-count $NODE_COUNT \ + --node-vm-size $NODE_VM_SIZE \ + --enable-cluster-autoscaler $ENABLE_CLUSTER_AUTOSCALER \ + --min-count $MIN_COUNT \ + --max-count $MAX_COUNT \ + --max-pods $MAX_PODS \ + --location $LOCATION \ + --kubernetes-version $KUBERNETES_VERSION \ + --generate-ssh-keys else - echo "AKS cluster is present" + echo "AKS $CLUSTER_NAME cluster is present in Azure" fi - name: Get AKS Credentials @@ -84,28 +108,28 @@ jobs: azcliversion: latest inlineScript: | if [ "${{steps.check-aks.outputs.cluster_exists}}" != "true" ]; then - AKS_ID=$(az aks show --resource-group my_test --name myAKSCluster --query id -o tsv) + AKS_ID=$(az aks show --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --query id -o tsv) az role assignment create --role "AcrPull" --assignee ${{ secrets.AZURE_CLIENT_ID }} --scope $AKS_ID > /dev/null - az aks update --resource-group my_test --name myAKSCluster --attach-acr test1repo > /dev/null + az aks update --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --attach-acr $ACR_NAME > /dev/null fi az account set --subscription ${{ secrets.AZURE_SUBSCRIPTION_ID }} - az aks get-credentials --resource-group my_test --name myAKSCluster --overwrite-existing + az aks get-credentials --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --overwrite-existing - name: Build and deploy nn_backend run: | - docker build ./NN_backend -t test1repo.azurecr.io/nn_backend:${GITHUB_RUN_NUMBER} - docker push test1repo.azurecr.io/nn_backend:${GITHUB_RUN_NUMBER} + docker build ./NN_backend -t ${ACR_NAME}.azurecr.io/nn_backend:${GITHUB_RUN_NUMBER} + docker push ${ACR_NAME}.azurecr.io/nn_backend:${GITHUB_RUN_NUMBER} - name: Build and deploy react_app run: | - docker build ./react_app -t test1repo.azurecr.io/react_app:${GITHUB_RUN_NUMBER} - docker push test1repo.azurecr.io/react_app:${GITHUB_RUN_NUMBER} + docker build ./react_app -t ${ACR_NAME}.azurecr.io/react_app:${GITHUB_RUN_NUMBER} + docker push ${ACR_NAME}.azurecr.io/react_app:${GITHUB_RUN_NUMBER} - uses: azure/setup-kubectl@v3 - uses: azure/aks-set-context@v2.0 with: - resource-group: my_test - cluster-name: myAKSCluster + resource-group: ${{ env.RESOURCE_GROUP }} + cluster-name: ${{ env.CLUSTER_NAME }} - name: Deploy NVIDIA DaemonSet to AKS @@ -120,8 +144,8 @@ jobs: - name: Replace placeholders in Kubernetes YAML files run: | cd k8s - sed -i "s|image: test1repo.azurecr.io/react_app:\$imageTag|image: test1repo.azurecr.io/react_app:${GITHUB_RUN_NUMBER}|" react_app_Deployment.yaml - sed -i "s|image: test1repo.azurecr.io/nn_backend:\$imageTag|image: test1repo.azurecr.io/nn_backend:${GITHUB_RUN_NUMBER}|" nn_backend_Deployment.yaml + sed -i "s|image: \$acr_name.azurecr.io/react_app:\$imageTag|image: ${ACR_NAME}.azurecr.io/react_app:${GITHUB_RUN_NUMBER}|" react_app_Deployment.yaml + sed -i "s|image: \$acr_name.azurecr.io/nn_backend:\$imageTag|image: ${ACR_NAME}.azurecr.io/nn_backend:${GITHUB_RUN_NUMBER}|" nn_backend_Deployment.yaml # kubectl set image -f deployment.template.yml react-app=test1repo.azurecr.io/react_app:$imageTag --local -o yaml > react_app_Deployment.yaml # sed -i 's|${{ github.run_number }}|'"$GITHUB_RUN_NUMBER"'|g' react_app_Deployment.yaml # echo "github.run_number ${{ github.run_number }} " diff --git a/k8s/nn_backend_Deployment.yaml b/k8s/nn_backend_Deployment.yaml index e74a6c5..af93c44 100644 --- a/k8s/nn_backend_Deployment.yaml +++ b/k8s/nn_backend_Deployment.yaml @@ -14,7 +14,7 @@ spec: spec: containers: - name: nn-backend - image: test1repo.azurecr.io/nn_backend:$imageTag # Replace with your image name + image: $acr_name.azurecr.io/nn_backend:$imageTag # Replace with your image name #command: ["bash", "-c", "nvidia-smi && tail -f /dev/null"] ports: - containerPort: 8080 diff --git a/k8s/react_app_Deployment.yaml b/k8s/react_app_Deployment.yaml index a49d88f..9775595 100644 --- a/k8s/react_app_Deployment.yaml +++ b/k8s/react_app_Deployment.yaml @@ -15,7 +15,7 @@ spec: dnsPolicy: ClusterFirst containers: - name: react-app - image: test1repo.azurecr.io/react_app:$imageTag # Replace with your image name + image: $acr_name.azurecr.io/react_app:$imageTag # Replace with your image name ports: - containerPort: 3000 resources: