CUDA Build1 #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CUDA Build1 | |
on: | |
workflow_dispatch: # Manually trigger the workflow | |
#on: | |
# push: | |
# branches: | |
# - main | |
# pull_request: | |
# branches: | |
# - main | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
services: | |
nn_backend: | |
image: nvidia/cuda:12.2.2-devel-ubuntu22.04 | |
ports: | |
- "8080:8080" | |
options: --privileged # Required for GPU access | |
env: | |
NVIDIA_VISIBLE_DEVICES: all | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Azure Login | |
uses: azure/login@v2 | |
with: | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
- name: Login to Azure Container Registry | |
uses: azure/docker-login@v1 | |
with: | |
login-server: test1repo.azurecr.io | |
username: ${{ secrets.ACR_USERNAME }} | |
password: ${{ secrets.ACR_PASSWORD }} | |
- id: check-aks | |
name: Check if AKS Cluster exists | |
uses: azure/CLI@v2 | |
with: | |
azcliversion: latest | |
inlineScript: | | |
result=$(az aks show --resource-group my_test --name myAKSCluster 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" | |
echo "Error message: $result" | |
echo "::error::Error executing az aks show command. Exit code: $exit_code" | |
exit $exit_code | |
fi | |
if [[ -z "$result" || "$result" == *"ResourceNotFound"* ]]; then | |
echo "cluster_exists=false" >> $GITHUB_OUTPUT | |
else | |
echo "cluster_exists=true" >> $GITHUB_OUTPUT | |
fi | |
- name: Print name | |
run: | | |
if [ "${{steps.check-aks.outputs.cluster_exists}}" != "true" ]; then | |
echo "checking value ${{steps.check-aks.outputs.cluster_exists}}" | |
else | |
echo "heyyyy" | |
fi | |
- name: Create AKS Cluster | |
uses: azure/CLI@v2 | |
with: | |
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 | |
else | |
echo "AKS cluster is present" | |
ls | |
pwd | |
fi | |
- name: Get AKS Credentials | |
uses: azure/CLI@v2 | |
with: | |
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) | |
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 | |
fi | |
az account set --subscription ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
az aks get-credentials --resource-group my_test --name myAKSCluster --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} | |
- 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} | |
- uses: azure/setup-kubectl@v3 | |
- uses: azure/aks-set-context@v2.0 | |
with: | |
resource-group: my_test | |
cluster-name: myAKSCluster | |
- name: Deploy NVIDIA DaemonSet to AKS | |
run: | | |
cd k8s | |
kubectl create namespace gpu-resources | |
kubectl apply -f nvidia-device-plugin-ds.yaml | |
- 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 | |
# 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 }} " | |
- name: Deploy APP to AKS | |
run: | | |
cd k8s | |
kubectl apply -f nn_backend_Service.yaml -f nn_backend_Deployment.yaml | |
kubectl apply -f react_app_Deployment.yaml -f react_app_Service.yaml | |