Skip to content

Commit 29336c1

Browse files
authored
Initial version of devcontainer (#1)
Copy of original from https://github.com/microsoft/vscode-dev-containers
1 parent 978a504 commit 29336c1

File tree

8 files changed

+833
-2
lines changed

8 files changed

+833
-2
lines changed

README.md

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,65 @@
1-
# vscode-swift-devcontainer
2-
Visual Studio Code Development Container for Swift
1+
# Swift (Community)
2+
3+
## Summary
4+
5+
*Develop Swift based applications. Includes everything you need to get up and running.*
6+
7+
| Metadata | Value |
8+
|----------|-------|
9+
| *Contributors* | [0xTim](https://github.com/0xTim), [adam-fowler](https://github.com/adam-fowler), [cloudnull](https://github.com/cloudnull) |
10+
| *Categories* | Community, Languages |
11+
| *Definition type* | Dockerfile |
12+
| *Supported architecture(s)* | x86-64 |
13+
| *Works in Codespaces* | Yes |
14+
| *Container host OS support* | Linux, macOS, Windows |
15+
| *Container OS* | Debian |
16+
| *Languages, platforms* | Swift |
17+
18+
## Using this definition
19+
20+
While the definition itself works unmodified, you can select the version of Swift the container uses by updating the `VARIANT` arg in the included `devcontainer.json` (and rebuilding if you've already created the container).
21+
22+
```json
23+
"args": { "VARIANT": "4" }
24+
```
25+
26+
Given how frequently web applications use Node.js for front end code, this container also includes an optional install of Node.js. You can enable installation and change the version of Node.js installed or disable its installation by updating the `args` property in `.devcontainer/devcontainer.json`.
27+
28+
```jsonc
29+
"args": {
30+
"VARIANT": "4",
31+
"NODE_VERSION": "14" // Set to "none" to skip Node.js installation
32+
}
33+
```
34+
35+
### Adding the definition to a project or codespace
36+
37+
1. If this is your first time using a development container, please see getting started information on [setting up](https://aka.ms/vscode-remote/containers/getting-started) Remote-Containers or [creating a codespace](https://aka.ms/ghcs-open-codespace) using GitHub Codespaces.
38+
39+
2. Start VS Code and open your project folder or connect to a codespace.
40+
41+
3. Press <kbd>F1</kbd> select and **Add Development Container Configuration Files...** command for **Remote-Containers** or **Codespaces**.
42+
43+
> **Note:** If needed, you can drag-and-drop the `.devcontainer` folder from this sub-folder in a locally cloned copy of this repository into the VS Code file explorer instead of using the command.
44+
45+
4. Select this definition. You may also need to select **Show All Definitions...** for it to appear.
46+
47+
5. Finally, press <kbd>F1</kbd> and run **Remote-Containers: Reopen Folder in Container** or **Codespaces: Rebuild Container** to start using the definition.
48+
49+
## Testing the definition
50+
51+
This definition includes some test code that will help you verify it is working as expected on your system. Follow these steps:
52+
53+
1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine.
54+
2. Clone this repository.
55+
3. Start VS Code, press <kbd>F1</kbd>, and select **Remote-Containers: Open Folder in Container...**
56+
4. Select the `containers/swift` folder.
57+
5. After the folder has opened in the container, press <kbd>F5</kbd> to start the project.
58+
6. You should see "Hello, remote world!" in the Debug Console after the program executes.
59+
7. From here, you can add breakpoints or edit the contents of the `test-project` folder to do further testing.
60+
61+
## License
62+
63+
Copyright (c) Microsoft Corporation. All rights reserved.
64+
65+
Licensed under the MIT License. See [LICENSE](https://github.com/microsoft/vscode-dev-containers/blob/main/LICENSE).

src/swift/.devcontainer/Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# [Choice] Swift version: 5.5, 5.4, 5.3, 5.2, 5.1, 4.2
2+
ARG VARIANT=5.5
3+
FROM swift:${VARIANT}
4+
5+
# [Option] Install zsh
6+
ARG INSTALL_ZSH="true"
7+
# [Option] Upgrade OS packages to their latest versions
8+
ARG UPGRADE_PACKAGES="false"
9+
10+
# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies.
11+
ARG USERNAME=vscode
12+
ARG USER_UID=1000
13+
ARG USER_GID=$USER_UID
14+
COPY library-scripts/common-debian.sh /tmp/library-scripts/
15+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
16+
&& /bin/bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" \
17+
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* && rm -rf /tmp/library-scripts
18+
19+
# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
20+
ARG NODE_VERSION="none"
21+
ENV NVM_DIR=/usr/local/share/nvm
22+
ENV NVM_SYMLINK_CURRENT=true \
23+
PATH=${NVM_DIR}/current/bin:${PATH}
24+
COPY library-scripts/node-debian.sh /tmp/library-scripts/
25+
RUN bash /tmp/library-scripts/node-debian.sh "${NVM_DIR}" "${NODE_VERSION}" "${USERNAME}" \
26+
&& rm -rf /var/lib/apt/lists/* /tmp/library-scripts
27+
28+
# [Optional] Uncomment this section to install additional OS packages you may want.
29+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
30+
# && apt-get -y install --no-install-recommends <your-package-list-here>
31+
32+
# [Optional] Uncomment this line to install global node packages.
33+
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "Swift (Community)",
3+
"build": {
4+
"dockerfile": "Dockerfile",
5+
"args": {
6+
// Update the VARIANT arg to pick a Swift version
7+
"VARIANT": "5.7",
8+
// Options
9+
"NODE_VERSION": "lts/*"
10+
}
11+
},
12+
"runArgs": [
13+
"--cap-add=SYS_PTRACE",
14+
"--security-opt",
15+
"seccomp=unconfined"
16+
],
17+
18+
// Set *default* container specific settings.json values on container create.
19+
"settings": {
20+
"lldb.library": "/usr/lib/liblldb.so"
21+
},
22+
23+
// Add the IDs of extensions you want installed when the container is created.
24+
"extensions": [
25+
"sswg.swift-lang"
26+
],
27+
28+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
29+
// "forwardPorts": [],
30+
31+
// Use 'postCreateCommand' to run commands after the container is created.
32+
// "postCreateCommand": "",
33+
34+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
35+
"remoteUser": "vscode"
36+
}

0 commit comments

Comments
 (0)