Using a startup script to launch a pre-configured cloud environment

Anton Kovalsky
  • Updated

If the default environments available in the Application Configuration dropdown menu found in the Cloud Environments widget don't come with all of the packages you consistently need, and you'd like a more efficient way of launching a Jupyter notebook without having to install each package manually when you create a new notebook, you may want to use a startup script to streamline this process.

Not only are startup scripts good for installing packages, they're also capable of making environment changes that typically require sudo. This makes them an efficient alternative to creating custom docker images (if you're curious about doing that, check out this tutorial). While a custom docker is a great way to take a snapshot of a set of package versions to keep your environment consistent, using a startup script is quick way to add anything you need - including updated packages - to whatever docker image you're working with, whether you're using a custom docker or one of our pre-configured ones. Startup scripts are supported for both Jupyter environments and RStudio environments.

In this short tutorial, you'll see an example of a startup script, how to upload that startup script, how to find the file path you'll need to provide as a link, and how to use that link to launch your custom cloud environment.

Below is the example startup script we'll be using in this tutorial. This startup script installs the "multtest" package that's part of Bioconductor, but is not included in Terra's default R/Bioconductor environment.

Screen_Shot_2021-03-17_at_2.04.10_PM.png

We can start with a quick sanity check - let's make sure the package we're interested in isn't already part of the default environment. We'll start by opening the Cloud Environment widget and selecting the default R/Bioconductor image in the Application Configuration dropdown menu:

2021-03-17_1356.png

Before we add our custom startup script in our compute profile, we'll do our quick sanity check by trying to import that package. You should see an error saying that no such package is currently on your virtual machine:

Screen_Shot_2021-03-17_at_1.46.45_PM.png

Next, we'll add a startup script to our cloud environment, for which we'll first need a URI to use as the link. You can upload the startup script to any Google bucket, provided your workspace can access to that bucket. For the purpose of this tutorial, we've uploaded the startup script file to the dedicated workspace bucket by going to the Data tab of the workspace, selecting the "Files" section at the bottom of the lefthand menu, and clicking the "Upload" button in the bottom right.

2021-03-17_1548.png


Once the file is in our workspace bucket, go to the Google Cloud Console where you can copy the URI of your script file. You can do this either with the link to your bucket found on the right-hand side of your workspace dashboard, or by clicking the file link in the Data tab:

rstudio2.gif


Once you have this URI copied, paste that URI into the Startup Script field under the Cloud Compute Profile section of the Cloud Environment widget, and click "Upload" or "Create".

 

Screen_Shot_2021-03-17_at_3.58.17_PM.png

Once your environment is ready, you can launch a notebook. If you run the same command we attempted during the sanity check at the beginning of this tutorial, you should now be able to successfully import this package:

Screen_Shot_2021-03-17_at_1.55.53_PM.png

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.