|
| 1 | +# This workflow will install Python dependencies, build the latest models as containers, and push to the registry the resulting containers |
| 2 | +# TODO: Use cache for caching the docker images, to speed up the build |
| 3 | +# TODO: Can we have the dependencies stored somehow (predownloaded, a custom image, a container registry, our artifact server...) so this will always be reproduceable? |
| 4 | +# TODO: Can we have some kind of Bill Of Materials of the resulting image? What packages are in there? What python "modules" ? Code version of monai? |
| 5 | + |
| 6 | +name: build_and_push_models |
| 7 | + |
| 8 | +# This is triggered manually. It could be changed to be triggered by new pushed tags. |
| 9 | +on: workflow_dispatch |
| 10 | + |
| 11 | +# Version could be infered from the new tag if this was triggered by a new tag push |
| 12 | +# FIXME: Python version could be inferred with "python --version" run inside the containers, and CP is the python version without '.' |
| 13 | +# FIXME: wheel name could be dynamically generated, by for example use "ls" on the download folder |
| 14 | +# ARM environment variables are used by the terraform azure provider for authentication using a client secret. |
| 15 | +# See https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/service_principal_client_secret |
| 16 | +# https://github.com/Azure-Samples/terraform-github-actions/blob/main/.github/workflows/tf-plan-apply.yml |
| 17 | +env: |
| 18 | + ARM_CLIENT_ID: "${{ secrets.AZURE_CLIENT_ID }}" |
| 19 | + ARM_SUBSCRIPTION_ID: "${{ secrets.AZURE_SUBSCRIPTION_ID }}" |
| 20 | + ARM_TENANT_ID: "${{ secrets.AZURE_TENANT_ID }}" |
| 21 | + ARM_CLIENT_SECRET: "${{ secrets.AZURE_CLIENT_SECRET }}" |
| 22 | + VERSION: "0.6.0" |
| 23 | + PYTHON_VERSION: "3.8" |
| 24 | + CP_VERSION: "38" |
| 25 | + DOCKER_IMAGE_TAG : "latest" |
| 26 | + APP_IMAGE_NAME : "simple_app" |
| 27 | + PLATFORM : "x64-workstation" |
| 28 | + DOCKER_IMAGE_NAME : "simple_app-x64-workstation-dgpu-linux-amd64-latest" |
| 29 | + DOCKER_IMAGE_NAME_SHORT: "simple_app-x64-workstation-dgpu-linux-amd64" |
| 30 | + REGISTRY: ghcr.io |
| 31 | + IMAGE_NAME: ${{ github.repository }} |
| 32 | + APP: "examples/apps/simple_imaging_app" |
| 33 | + |
| 34 | +jobs: |
| 35 | + do: |
| 36 | + runs-on: ubuntu-latest |
| 37 | + permissions: |
| 38 | + contents: read |
| 39 | + packages: write |
| 40 | + steps: |
| 41 | + - uses: actions/checkout@v2 |
| 42 | + - name: Disclaimers |
| 43 | + run: | |
| 44 | + echo "!!! WARNING !!! This is a hackweek project, not meant for production or clinical usage, does not have any kind of guarantee, use at your own risk.https://hackweek.opensuse.org/23/projects/package-monai-machine-learning-models-for-medical-applications. !!! WARNING !!!" |
| 45 | + # Install the latest version of the Terraform CLI |
| 46 | + - name: Show disc space |
| 47 | + run: df -h |
| 48 | + - name: Setup Terraform |
| 49 | + uses: hashicorp/setup-terraform@v2 |
| 50 | + with: |
| 51 | + terraform_wrapper: false |
| 52 | + - name: Initialize a new Terraform working directory |
| 53 | + run: terraform init |
| 54 | + - name: Check Terraform configuration files format |
| 55 | + run: terraform fmt -check |
| 56 | + - name: Generate unique SSH Key |
| 57 | + run: ssh-keygen -t rsa -f /tmp/ssh_id_gh -N "" |
| 58 | + - name: Terraform Apply |
| 59 | + run: terraform apply -auto-approve |
| 60 | + - name: Get IP address |
| 61 | + run: echo "AZURE_IPADDRESS=$(terraform output | grep instance_public_ip | cut -d\" -f2)" >> $GITHUB_ENV |
| 62 | + - name: Output ip address |
| 63 | + run: echo "AZURE_IPADDRESS=$AZURE_IPADDRESS" |
| 64 | + - name: Test connection |
| 65 | + # We use StrictHostKeyChecking=no to accept the SSH fingerprint on the first connection |
| 66 | + run: ssh -i /tmp/ssh_id_gh -o StrictHostKeyChecking=no adminuser@$AZURE_IPADDRESS "sudo uname -a" |
| 67 | + - name: Add fixed libseccomp package |
| 68 | + run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "sudo zypper ar -G https://download.opensuse.org/repositories/home:/jordimassaguerpla:/branches:/openSUSE:/Leap:/15.5:/Update/pool-leap-15.5/home:jordimassaguerpla:branches:openSUSE:Leap:15.5:Update.repo && sudo zypper ref && sudo zypper -n install --from home_jordimassaguerpla_branches_openSUSE_Leap_15.5_Update --allow-vendor-change libseccomp" |
| 69 | + - name: Install Deps |
| 70 | + run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "sudo zypper ar -G https://developer.download.nvidia.com/compute/cuda/repos/opensuse15/x86_64/ nvidia && sudo zypper ref && sudo zypper --non-interactive install patch python39 docker-buildx nvidia-container-toolkit nvidia-computeG05 cuda-cudart-devel-11-0 libyaml-cpp0_6 && wget -c https://bootstrap.pypa.io/get-pip.py && python3.9 get-pip.py && python3.9 --version" |
| 71 | + - name: Setup Nvidia container |
| 72 | + run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "sudo usermod -G docker,video adminuser && sudo nvidia-ctk runtime configure --runtime=docker && sudo nvidia-ctk runtime configure --runtime=containerd && sudo systemctl start docker && sudo systemctl start containerd && sudo sed -e \"s/user = \\\"\\\"/user = \\\"adminuser:video\\\"/g \" -i /etc/nvidia-container-runtime/config.toml && sudo modprobe nvidia" |
| 73 | + - name: Check nvidia |
| 74 | + run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "sudo systemctl start docker && nvidia-smi && docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi" |
| 75 | + - name: Install Monai Deploy Sdk and Holoscan |
| 76 | + run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "python3.9 -m pip install monai-deploy-app-sdk holoscan" |
| 77 | + - name: Fix Holoscan |
| 78 | + run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} 'cd /home/adminuser/.local/lib/python3.9/site-packages/holoscan/lib ; to_link=$(ls libholoscan_*.so*);for i in $to_link; do name=$(echo $i | cut -d. -f1); ln -sv $name.so.$VERSION $name.so.0;done' |
| 79 | + - name: Copy holoscan patch |
| 80 | + run: scp -i /tmp/ssh_id_gh .github/workflows/142be17d7563c3499b548dae913cabd7b8242f78.patch adminuser@${AZURE_IPADDRESS}:/home/adminuser/.local/lib/python3.9/site-packages/holoscan |
| 81 | + - name: Patch Holoscan |
| 82 | + run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "cd /home/adminuser/.local/lib/python3.9/site-packages/holoscan; patch -p3 < 142be17d7563c3499b548dae913cabd7b8242f78.patch" |
| 83 | + - name: Make work dir |
| 84 | + run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "mkdir /home/adminuser/work" |
| 85 | + - name: Download wheels |
| 86 | + run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "cd /home/adminuser/work && python3.9 -m pip download --no-deps --python-version=$PYTHON_VERSION holoscan==$VERSION && python3.9 -m pip download --no-deps monai-deploy-app-sdk==$VERSION" |
| 87 | + - name: Copy example code |
| 88 | + run: scp -i /tmp/ssh_id_gh -r * adminuser@${AZURE_IPADDRESS}:/home/adminuser/work |
| 89 | + - name: Monai Deploy package |
| 90 | + run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "mkdir /home/adminuser/work/output && cd /home/adminuser/work && monai-deploy package --no-cache /home/adminuser/work/$APP -c /home/adminuser/work/$APP/app.yaml -t $APP_IMAGE_NAME:$DOCKER_IMAGE_TAG --platform $PLATFORM -l DEBUG --holoscan-sdk-file=/home/adminuser/work/holoscan-$VERSION-cp$CP_VERSION-cp$CP_VERSION-manylinux2014_x86_64.whl --monai-deploy-sdk-file=/home/adminuser/work/monai_deploy_app_sdk-$VERSION-py3-none-any.whl --platform-config dgpu --gid 1000 --output /home/adminuser/work/output" |
| 91 | + - name: Size of docker image |
| 92 | + run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "du -hs /home/adminuser/work/output/*" |
| 93 | + - name: Compress docker image |
| 94 | + run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "cd /home/adminuser/work/output && gzip $DOCKER_IMAGE_NAME.tar" |
| 95 | + - name: Size of docker image |
| 96 | + run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "du -hs /home/adminuser/work/output/*" |
| 97 | + - name: Show disc space |
| 98 | + run: df -h |
| 99 | + - name: Load docker image |
| 100 | + run: ssh -i /tmp/ssh_id_gh adminuser@${AZURE_IPADDRESS} "cat /home/adminuser/work/output/$DOCKER_IMAGE_NAME.tar.gz" | docker load |
| 101 | + - name: Log in to the Container registry |
| 102 | + uses: docker/login-action@v3 |
| 103 | + with: |
| 104 | + registry: ${{ env.REGISTRY }} |
| 105 | + username: ${{ github.actor }} |
| 106 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 107 | + - name: Tag Docker image |
| 108 | + run: docker tag $DOCKER_IMAGE_NAME_SHORT:$DOCKER_IMAGE_TAG $REGISTRY/$IMAGE_NAME/$DOCKER_IMAGE_NAME_SHORT:$DOCKER_IMAGE_TAG |
| 109 | + - name: Push Docker image |
| 110 | + run: docker push $REGISTRY/$IMAGE_NAME/$DOCKER_IMAGE_NAME_SHORT:$DOCKER_IMAGE_TAG |
| 111 | + - name: Terraform Destroy |
| 112 | + if: ${{ always() }} |
| 113 | + run: terraform destroy -auto-approve |
0 commit comments