Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhargavoza1 committed Mar 28, 2024
1 parent 8a6fb7b commit fb046b1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 16 deletions.
52 changes: 38 additions & 14 deletions .github/workflows/CUDA_Build1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 }} "
Expand Down
2 changes: 1 addition & 1 deletion k8s/nn_backend_Deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion k8s/react_app_Deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit fb046b1

Please sign in to comment.