This tutorial will show how to connect to a remote server such as Alta using VS Code, setup the development container environment, and use what it has to offer!
If you run into any issues during this tutorial, please ask for help in the PSTAT Research Computing Users Google Group!
ctrl
/β + shift
+ x
shortcut.To run your code remotely you will first need to connect to a remote server such as Alta. For more information about available computing servers, checkout this wiki entry.
With our VS Code extensions, remote connections are made simple:
<NetID>
with your own NetID:ssh <NetID>@alta.pstat.ucsb.edu
C:\Users\<your_username>\.ssh\config
(Windows) or ~/.ssh/config
(MacOS/Linux).Now that you are connected to a server, we can set up the development container!
<project-name>
with the name of your project/directory you wish to create:copier copy gh:UCSB-PSTAT/devcontainer-template <project-name>
π€ What is the name of your project? (Must be unique and use lowercase, dashes -, underscores _ ONLY) my-awesome-project π€ What language(s) will you use in this project? R π€ Do you want to install Visual Studio Code extensions for Jupyter notebooks using R? Yes π€ Install RStudio Server? This is optional if using VS Code and R extensions for development. Yes π€ Install Quarto? Quarto is optional publishing system compatible with R. Yes π€ Do you want to include example files? Yes Copying from template version 1.1.0 create . create .devcontainer create .devcontainer/Dockerfile create .devcontainer/devcontainer.json create README.md create example.Rmd create .copier-answers.yml
<project-name>
with the name of your project/directory you created):tree -a <project-name>
<project-name> βββ .copier-answers.yml βββ .devcontainer β βββ devcontainer.json β βββ Dockerfile βββ example.Rmd βββ example-R.qmd βββ README.md
Although you can edit files directly in VS Code, it may be more preferable to utilize more specialized tools such as RStudio to edit files such as Qmd/Rmd. This requires us to access Jupyterhub.
This method will install packages immediately in your container but will
not
get added to your container configuration files for reproducibility by others.
To install packages using the Anaconda distribution use the mamba
command. This follows the same syntax as conda
but runs a lot faster. To install packages using PyPI, it is sufficient to use pip
.
$> mamba install numpy=1.26 ... $> pip install scikit-ntk==1.1.3
This method will build your container with these packages pre-installed. If you share your configuration files with someone else, they will be able to reproduce your installation with no additional steps.
You will need to rebuild your container to install packages this way!
To install Python packages in a reproducible way, you will need to add them to your Dockerfile. Simply add the package name underneath the comment for Anaconda/Pip packages followed by a β\'.
For example, here I am adding a Anaconda distribution package scikit-learn
(using conda/mamba commands):
And here, I am adding a PyPI package scikit-ntk
(using pip command):
This method will install packages immediately in your container but will
not
get added to your container configuration files for reproducibility by others.
For R, any of your favorite commands for package installation should function out of the box (install.packages(...)
being the most common). This can be run in 3 ways:
$> R -e βinstall.packages("ggplot2")'
This method will build your container with these packages pre-installed. If you share your configuration files with someone else, they will be able to reproduce your installation with no additional steps.
You will need to rebuild your container to install packages this way!
To install R packages in a reproducible way, you will need to add them to your Dockerfile. You will need to add packages using this type of command underneath the comment for R packages followed by a β&& \':
R -e βinstall.packages("ggplot2")' && \
For example, here I am adding the dplyr
package:
If your language specific packages have additional system related requirements, the easiest way to install them is to directly add them to the Dockerfile found in the .devcontainer directory of your project as shown below:
Here I am installing an additional package called "neofetch". Make sure that each package is on its own separate line and ends with a backslash!
If you wish to clone/push/pull/create repositories, you will need to use GitHub CLI to login while inside the container. This can be done using the gh auth login
command. During the steps select:
Once completed, you will now be able to manage GitHub repositories using HTTPS.
If you wish to create a repository on your GitHub account for your freshly minted project container use the following commands:
cd /home/jovyan/work/ git init git add * git commit -m "first commit" git branch -M main
cd /home/jovyan/my-awesome-project gh repo create
To get more familiar with how your container works consider the following sets of tutorials: