I have tested new Visual Studio Code Remote Development feature with Azure CLI. Now you can start developing Azure CLI in a few simple steps:
- Install Visual Studio Code Insiders Edition
- Clone Azure CLI Repository
- Launch Visual Studio Code and wait for a few minutes
- Set a breakpoint and press F5
To replicate this you need do download Visual Studio Code from here:
https://code.visualstudio.com/insiders/
Clone my fork of Azure CLI repository and switch to adding-devcontainer-setup branch.
1 2 3 |
|
Then run Visual Code from cloned repository:
1
|
|
Visual Studio Code should detect that .devcontainer folder is present, and will ask whether you want to use container.
When you choose Reopen in Container, VSC will build the image from docker file, that may take a few minutes, but it will be done only once (for current folder).
When container is ready, just set a breakpoint, for instance in azure-cli/src/azure-cli/main.py and press F5.
More Details on the Container
My Dockerfile is pretty simple. As a base I used Ubuntu 16.04, and:
- Installed Python 3.6
- Cloned Azure CLI repo (just to install dependencies)
- Created virtual environment located at /env (outside Azure CLI repo)
- Installed azdev using pip
- Installed Azure CLI dependencies using azdev setup
- Made sure that /env is activated every time bash is started by Visual Studio Code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
And Configuration File
Configuration file devcontainer.json is pretty simple. It specifies Dockerfile and a path to Python interpreter inside /env.
Please note that instead of specifying dockerFile it’s possible to specify existing image.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Other Considerations
(1) It’s possible to specify existing image instead of dockerfile. If we have existing development image that would make setup even faster.
(2) Perhaps it would be a good idea to clone all azure-cli, azure-cli-dev-tools, azure-cli-extensions under workspaces. Then it should be possible to map all three of them when starting the container.
(3) Perhaps leaving azure-cli (I currently delete it) would be a good idea, this way the container could be used as a standalone dev environment with source code cloned inside.
(4) Instead of cloning azure-cli it’s possible to map external repository. I am not doing it right now, as there’s .dockerignore file that would need to be modified in order to make this solution to work, and that could affect
Documents
Development environment setup instructions:
https://github.com/Azure/azure-cli-dev-tools
About VSC Remote Development