Torus is Attending Korea Blockchain Week 2019

The Torus Team will be heading to Seoul to attend Korea Blockchain Week 2019 and host several ancillary events. Our first collaborative event with Binance Labs and Block Crafters VC, the Game Oasis…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Automated dev workflow for using Data Science VM on Azure

tl;dr; I put together a bunch of scripts on Github that let you deploy a VM from your command line as well as sync code from your local directory to the VM easily to be able to use local IDE and git but execute on the powerful remote machine. Perfect for Data Science applications based around jupyter notebook.

Being prone to over-engineering 🙄 my side projects I started my journey of automating my VM workflow with the following goals:

It creates several resources:

* sorry if I did not explain those correctly tbh I am not 💯% sure I understand correctly what they do either 😊

This are the created resources
Variables in the Terraform recipe

The easiest way to change the variable values is to config.auto.tfvars file that contains all the variable names and their description as well.

config.auto.tfvars

You might see the following error when trying to run the Terraform script without having read this far.

Terraform error due to missing license agreement

After successfully signing the license terms you should see the following output in your shell

Once the license terms are signed you can initialize Terraform using terraform init and then can run terraform apply to bring up the infrastructure resources on azure. It may take up 5~10 minutes to fully provision the virtual machine.

After running it you may notice two new files being created. Both contain a link to the created virtual machine. .vm-ip contains the public IP address that was created and will be used to SSH into the machine. .vm-id is the Azure Resource ID of your virtual machine and is a unique identifier that we will use to start/stop the machine later. Both are plain text files and only contain one line, feel free to check them out. The machine is now up and running and you can work with it.

Before doing any work you might want to upload some bootstrap code onto the virtual machine — or you just want to run an existing jupyter notebook there. Again the Github repository holds a small script that will help you do this (works out of the box on Mac/Unix machines otherwise you need to install make and rsync first).

Place the Makefile into the working directory of your code and make sure to update the PATH definitions to the two files mentioned at the end of the last chapter containing the details of the newly created virtual machine. If you had the Terraform script in a subfolder named infra there is nothing to do. Otherwise you should either copy over the two files into such a directory or modify the PATH definition in the Makefile.

Use make syncup in your working directory (where you placed the Makefile) to sync your local directory content onto the remote machine. You can see the command that is being executed and what the remote directory will be named. In my case it is ~/work/AIND-RNN which is one of my Nanodegree projects. You can also see that the command automatically ignores all files that are defined in your .gitignore which means anything you do not want to version will also not be copied around. This is especially useful for artifacts created during neural net training processes.

Output of make syncup

Let’s assume that your project also holds a Jupyter notebook you want to execute on the remote machine and access from your local browser. You could also use a similar process to execute ANY kind of script on the remote machine.

Starting jupyter notebook on the VM

The Jupyter notebook process started above is linked to the lifecycle of the interactive shell that we opened with the SSH connection. Closing the SSH connection will kill the Jupyter server as well. All your code should still be there as Jupyter regularly saves to disk but your python kernel will be gone and all the memory objects (state of notebook execution) will be lost. You will need to execute the notebook again from beginning after you SSH again into the machine and start Jupyter up.

After you did some changes and you want to git commit like a good developer you need to get those changes you did on the virtual machine to your local development environment. You can do this using make syncdown which will copy all changed remote files onto your local working directory — again only those under git version control.

Copy remote changes to local filesystem

The Makefile comes with three commands for managing the state of the virtual machine itself. They all require the unique Azure Resource ID located in the .vm-id to select the correct VM in your Azure subscription:

make stop will stop stop the virtual machine AND deallocate the resources which will significantly reduce the costs as you only pay for the disks that hold your data.

make start tells Azure to allocate new resources and spawn up the virtual machine again

make status will tell you if the virtual machine is up or not

Virtual Machine start/status/stop

The screenshot shows you how long stopping and starting the VM might take. However as soon as you see the CLI saying Running \ you can shut down your local machine as Azure started deallocating your resources.

If you are afraid of the bill that might come flying in if you miss stopping the virtual machine you should take a closer look at the auto shutdown features that Azure offers you. It lets you specify a time at which the VM will automatically shut down every day.

Well I hope you liked this article and found some helpful tips. The general workflow can also be done with AWS machines but the Terraform template will look different. Feel free to submit a PR to my Repo and I will add the option to also use AWS resources.

Here is another look at all the commands you can use🧙‍♀️

/andreas

Add a comment

Related posts:

I need help for WordPress Plugin for Online course Scheduling

Features of scheduling courses 1. Teacher and student login 2. Course schedule by teacher like php 3. Display only for php students 4. Push notification of events

Wyoming

I have a bit more leeway writing this than something like a proper record review or even a feature for a magazine. This is sort of a feature, but not really; it’s about Kanye as an artist generally…

Neurotech is shedding new light on visual impairments

February is AMD awareness month. No, it is not the chip manufacturer. AMD refers to Age-related Macular Degeneration. About 39 million people worldwide live with some form of degenerative disease…