Skip to content

Commit fd00b06

Browse files
authored
Install swiftly into vscode-swift devcontainer (#1922)
- Pull from nightly image to always have latest deps - Install swiftly and add to bashrc to use swiftly toolchain - Add "vscode" user and password in docker file - Force always prompting for sudo password for "vscode" user to help testing askpass
1 parent d948929 commit fd00b06

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

.devcontainer/Dockerfile

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
FROM swiftlang/swift:nightly-6.2-jammy
1+
FROM swiftlang/swift:nightly-jammy
22

3+
# python3-lldb-13 is only needed for swiftly and a great dep to remove to test post-install script ;)
34
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
45
&& apt-get -q update \
56
&& apt-get -q dist-upgrade -y \
@@ -9,8 +10,11 @@ RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
910
libsqlite3-dev \
1011
libncurses5-dev \
1112
python3 \
12-
build-essential
13+
python3-lldb-13 \
14+
build-essential \
15+
sudo
1316

17+
# Install nvm / Node.js
1418
RUN mkdir -p /usr/local/nvm
1519
ENV NVM_DIR /usr/local/nvm
1620
ENV NODE_VERSION v20.19.0
@@ -21,3 +25,24 @@ ENV PATH $NODE_PATH:$PATH
2125
RUN npm -v
2226
RUN node -v
2327

28+
# Create a "vscode" user that is a sudoer
29+
RUN useradd -ms /bin/bash vscode
30+
RUN echo "vscode:vscode" | chpasswd
31+
RUN adduser vscode sudo
32+
33+
# Install swiftly
34+
USER vscode
35+
ENV SWIFTLY_HOME_DIR /home/vscode/.swiftly
36+
ENV SWIFTLY_BIN_DIR /home/vscode/.swiftly/bin
37+
ENV SWIFTLY_TOOLCHAINS_DIR /home/vscode/.swiftly/bin
38+
RUN mkdir -p $SWIFTLY_HOME_DIR
39+
RUN cd ~ && curl -O https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz && \
40+
tar zxf swiftly-$(uname -m).tar.gz && \
41+
./swiftly init --quiet-shell-followup && \
42+
. "${SWIFTLY_HOME_DIR}/env.sh" && \
43+
hash -r
44+
45+
# Use swiftly toolchain by default
46+
RUN echo "export SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> ~/.bashrc
47+
RUN echo "export SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> ~/.bashrc
48+
RUN echo '. "${SWIFTLY_HOME_DIR}/env.sh"' >> ~/.bashrc

.devcontainer/devcontainer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
"features": {
55
"ghcr.io/devcontainers/features/common-utils:2": {
66
"installZsh": "false",
7-
"username": "vscode",
8-
"userUid": "1000",
9-
"userGid": "1000",
107
"upgradePackages": "false"
118
},
129
"ghcr.io/devcontainers/features/git:1": {
@@ -35,7 +32,8 @@
3532
"source=node_modules,target=${containerWorkspaceFolder}/node_modules,type=volume"
3633
],
3734
// Use 'postCreateCommand' to run commands after the container is created.
38-
"postCreateCommand": "sudo chown vscode node_modules && npm install",
35+
// Modify /etc/sudoers.d/vscode to make sure we're always prompted for root password for testing askpass.
36+
"postCreateCommand": "sudo chown vscode node_modules && echo 'vscode ALL=(ALL:ALL) ALL' | sudo tee /etc/sudoers.d/vscode && npm install",
3937
// Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
4038
"remoteUser": "vscode"
4139
}

0 commit comments

Comments
 (0)