Swift devcontainer template

One of the advantages of Visual Studio Code is you can develop your project inside a docker container. If you are developing on macOS but deploying to Linux you no longer need to run your code on Linux to verify it works, you can edit, compile, run and debug your project on your Mac inside a docker container running inside VS Code.

Up until this point you could either define your container environment by hand editing a devcontainer.json file or by downloading the template for swift development managed by Microsoft.

Having the template managed by Microsoft meant their input was required (via PR review) when changes were needed to made to the template eg adding a new version of swift. Recently this changed and responsibility for the Swift devcontainer template has been moved to the SSWG. The devcontainer is now stored in the swift-server GitHub organisation.

The first thing we have done is modernise the template. We have replaced the shell scripts that original template had with the equivalent devcontainer common-utils feature. You can find out more about devcontainer features here. The original template had an option to install Node.js (a standard MS implemented across most of their templates). This has been removed as this can be done via a devcontainer feature now.

You can find the new devcontainer here GitHub - swift-server/swift-devcontainer-template: Visual Studio Code Development Container for Swift.

If you haven't used a devcontainer in VS Code before here are the steps to get up and running

  • Install Devcontainers extension
  • Press F1 to bring up the command selection menu
  • Select Dev Containers: Add Dev Container Configuration Files...
  • Select From a predefined container configuration definition...
  • Select Show All Definitions...
  • Type swift
  • Select Swift devcontainer
  • Select the version of Swift you want to run.
  • You'll then be asked if you want to add any features to your devcontainer. In general you can skip this.
  • Your devcontainer template will now be generated.
  • To start using it select Reopen in container.