Skip to content

Commit 5c140d2

Browse files
committed
Add devcontainer
1 parent e141933 commit 5c140d2

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

.devcontainer/Readme.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Using VSCode devcontainers
2+
3+
VSCode supports creating development environments inside of a docker container. With some light configuration, we can get a consistent development environment that is robust to changes in your local environment and also doesn't require you to install and manage dependencies on your machine.
4+
5+
### Setup
6+
7+
1. Install Docker, a tool for managing containerized VMs: https://www.docker.com
8+
- If you have Docker installed, make sure it is updated to the most recent version (there is a "Check for Updates" option in the application UI).
9+
- If installing Docker on macOS for the first time, I recommend selecting the "Advanced" installation option, specifying a "User" installation and disabling the two options below. This makes it so your Docker installation does not require root privileges for anything, which is generally nice and makes updates more seamless. This will require you telling VSCode where the `docker` executable ended up by changing the "dev.containers.dockerPath" setting (usually to something like `"/Users/<your-user-name>/.docker/bin/docker”`). You should make sure this executable exists by executing `"/<expected-path-to-docker>/docker --version”`.
10+
2. Install Visual Studio Code and the Remote Containers extensions: https://code.visualstudio.com/docs/devcontainers/tutorial
11+
3. Configure Docker by opening up the Docker application and navigating to "Settings"
12+
- Recommended settings for macOS (some of these are defaults):
13+
- General:
14+
- "Choose file sharing implementation for your containers": VirtioFS (better IO performance)
15+
- Resources:
16+
- CPUs: Allow docker to use most or all of your CPUs
17+
- Memory: Allow docker to use most or all of your memory
18+
4. Open up this repository in VSCode
19+
- VSCode has an "Install 'code' command in PATH" command which installs a helpful tool to open VSCode from the commandline (`code <path-to-this-repo>`)
20+
5. Select "Reopen in Container" in the notification that pops up
21+
- If there is no popup you can manually open the dev container by selecting "Dev Containers: Rebuild and Reopen in Container" from the command palette (Command-Shift-P on macOS)
22+
- Occasionally, after pulling from git, VSCode may prompt you to rebuild the container if the container definition has changed
23+
6. Wait for the container to be built

.devcontainer/default/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM swiftlang/swift:nightly-main-jammy
2+
3+
RUN \
4+
#
5+
# Disable apt interactive prompts for this RUN command
6+
export DEBIAN_FRONTEND="noninteractive" && \
7+
#
8+
# Update apt package list
9+
apt-get update && \
10+
#
11+
# Install sourcekit-lsp dependencies
12+
apt-get install -y \
13+
libsqlite3-dev libncurses5-dev python3 ninja-build && \
14+
#
15+
# Install swift-format
16+
apt-get install -y \
17+
curl && \
18+
mkdir /swift-format && \
19+
curl -L https://github.com/apple/swift-format/archive/refs/heads/release/5.9.tar.gz | tar xz --strip-component=1 -C /swift-format && \
20+
swift build --package-path /swift-format
21+
22+
ENV \
23+
PATH="/swift-format/.build/debug:${PATH}"
24+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Reference: https://containers.dev/implementors/json_reference/
2+
{
3+
"name": "SourceKit LSP",
4+
"dockerFile": "Dockerfile",
5+
6+
// Allow the processes in the container to attach a debugger
7+
"capAdd": [ "SYS_PTRACE" ],
8+
"securityOpt": [ "seccomp=unconfined" ],
9+
10+
"mounts": [
11+
// Use a named volume for the build products for optimal performance (https://code.visualstudio.com/remote/advancedcontainers/improve-performance?WT.mc_id=javascript-14373-yolasors#_use-a-targeted-named-volume)
12+
"source=${localWorkspaceFolderBasename}-build,target=${containerWorkspaceFolder}/build,type=volume"
13+
],
14+
"remoteEnv": {
15+
"PATH": "${containerWorkspaceFolder}/.build/bin:${containerEnv:PATH}"
16+
},
17+
"customizations": {
18+
"vscode": {
19+
"extensions": [
20+
"sswg.swift-lang",
21+
"vknabel.vscode-apple-swift-format"
22+
],
23+
"settings": {
24+
"lldb.launch.expressions": "native",
25+
"lldb.library": "/usr/lib/liblldb.so"
26+
}
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)