VisualStudio Code is an amazing tool. It supports containerized development in so many different ways, and the documents can be confusing. These are instructions for setting up a working containerized dev environment, by attaching VSCode to a running container.
At a high level, here’s how it works.
docker build --tag rampdev -f Dockerfile.dev .
This will build the docker image with all its dependencies except the ramp modules. This allows you to pip install from source inside the running container, and then to do development.
docker run -it --rm --gpus=all -v /home/carolyn/ramp-code:/tf/ramp-code -v /home/carolyn/ramp-code:/tf/ramp-code -p 8888:8888 rampdev bash
You should replace /home/carolyn with your RAMP_HOME path on your own host machine. Note that /home/carolyn is the RAMP_HOME directory on my server, and /tf is RAMP_HOME in the container.
This will open a bash shell in the rampdev container, in the /tf directory.
cd ramp-code pip install -e .
This will give you a development-ready installation of the ramp modules in your container, from the code you’ve mounted into the container.
You’ll then attach to the same container with VisualStudio Code, using its Remote-Containers extension (you’ll need to be running the container as root in order for VSCode to install itself into the container). Any changes you make to the code base in the process of debugging will be picked up by the debugger.
Start Visual Studio code (assuming it is already installed on your machine: here is the link for installation on Ubuntu)
In VSCode, Open Settings > Extensions (‘Settings’ is the little gear icon on the extreme left panel, at the bottom); select, install, and enable the Remote – Containers extension. The little green icon will appear on the VS Code window at the lower left, as seen below.
Click on the little green icon, and a menu of Remote-Containers commands will come up. Select ‘Attach to Running Container’, and select the rampdev container you started (there is usually only one running at a time anyway).
The green icon at the lower left will now show that you’re attached to the container you selected. Go to the VSCode File Explorer at the top of the panel on the left, and open the ‘/ramp-code’ directory. You are ready to debug!
Select a script to debug from the /tf/ramp-code/scripts directory
Place a debug breakpoint next to any line in the script as you normally would in any debugger. The red dot should appear to the left, as shown below. If it doesn’t appear, you may need to install the ‘Python’ extension (or VSCode may prompt you to do so).
From the top menu, select Run > Start Debugging. The script will run, and should stop when it hits your breakpoint. All the imports should work without any exceptions being thrown.