Coder Social home page Coder Social logo

software-resources / codespaces-multi-dev-container Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codespaces-contrib/codespaces-multi-dev-container

0.0 0.0 0.0 61 KB

License: MIT License

Shell 38.58% PowerShell 47.99% Batchfile 1.46% Dockerfile 11.97%

codespaces-multi-dev-container's Introduction

Using GitHub Codespaces with Multiple Development Containers

Visual Studio Code Remote - Containers supports the idea of connecting to multiple containers in the same source tree. There is even a pattern if you are using Docker Compose for your configuration. Unfortunately GitHub Codespaces does not currently support attaching a second window to a different container in the same Codespaces. However, the fact that the same technology is used in both Remote - Containers and Codespaces allows you to use the Remote - Containers extension with a codespace to achieve the same goal with some subtle tweaks.

This repository includes a script that you can use to connect to multiple containers via the GitHub CLI and the Remote - Containers extension. Any dev container configuration files can be in sub-folders rather than the repository root.

Codespaces will ultimately have first class support for this pattern, so this is a workaround given current limitations.

Setup

  1. Install VS Code (stable) locally.
  2. Install the GitHub CLI locally.
  3. Install an OpenSSH client and configure an SSH key for use with GitHub.

Using this sample

  1. Create a codespace from this repository if you do not already have one. You can do this using the GitHub CLI as follows:

    gh codespace create --repo codespaces-contrib/codespaces-multi-dev-container

    Note the name of the codespace. If you have an existing codespace you want to use instead, you can find out its name by running:

    gh codespace list
  2. Next, copy codespace-remote-ssh-connect.sh (macOS / Linux) or codespace-remote-ssh-connect.ps1 and codespace-remote-ssh-connect.cmd (Windows) to your local machine.

  3. In a local terminal, use the script to set up a connection to the codespace. For example, on macOS / Linux (replacing <codespace-name> with the name from step 1):

    bash codespace-remote-ssh-connect.sh <codespace-name>

    ... or on Windows, use PowerShell/Command Prompt (not WSL) as follows:

    .\codespace-remote-ssh-connect.cmd <codespace-name>
  4. In the new Remote - SSH VS Code window that appears, start a new VS Code terminal.

  5. Run the following for each folder with a dev container you want to open:

    code <folder name>

    For example:

    code codespaces-multi-dev-container/container-1-src
    code codespaces-multi-dev-container/container-2-src
  6. In each new window, click the "Reopen in Container" button in the notification that appears.

  7. After everything is up and running, use each window as you would normally.

Adapting the sample for your own use

To adapt for your own use:

  1. Make a copy of the appropriate codespace-remote-ssh-connect-*.* files on your local machine in a spot where you can use them. (You can optionally place them in other repositories to share with others, but this is not required).
  2. You do not need a custom container configuration in the root of your repository for this model to work. However, if your repository has a .devcontainer folder or .devcontainer.json file in the root of the repository with a custom image or Dockerfile, make sure the docker-in-docker is included.
  3. Add your actual dev container configuration files to sub-folders in the repository rather than the repository root.
  4. Use the script as described above to access them.

TODOs

There are few to-dos for this sample:

  1. Cache VS Code Server between development containers to avoid having to download it multiple times.
  2. Look for ways to further reduce steps.

codespaces-multi-dev-container's People

Contributors

chuxel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.