Skip to content
This repository was archived by the owner on Apr 28, 2020. It is now read-only.

Commit e75ab79

Browse files
authored
Add support for project-defined extensions (#126)
* Add support for project-defined extension Resolves #97 * fixup! Add support for project-defined extension * Refactor images to have common parent base * fixup! fixup! Add support for project-defined extension * fixup! fixup! fixup! Add support for project-defined extension * fixup! fixup! fixup! fixup! Add support for project-defined extension
1 parent b0380e4 commit e75ab79

File tree

19 files changed

+93
-26
lines changed

19 files changed

+93
-26
lines changed

.sail/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ ENV GO111MODULE=off
99
RUN wget -O /tmp/hugo.deb https://github.com/gohugoio/hugo/releases/download/v0.55.4/hugo_extended_0.55.4_Linux-64bit.deb && \
1010
sudo dpkg -i /tmp/hugo.deb && \
1111
rm -f /tmp/hugo.deb
12+
13+
RUN installext peterjausovec.vscode-docker

images/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ In order for the Sail images to have lower maintenance and minimal language
99
specific knowledge, each language image is based on the open source community image
1010
and expanded upon to add any Sail dependencies.
1111

12+
## Base Image
13+
14+
The `base` directory is where the initial base image is created. Any dependencies or configuration
15+
that needs to be used in every image should be added to this image.
16+
1217
## Extending Community Images
1318

1419
Most community language images have an image based on buildpack-deps:stretch. Since we

images/Dockerfile renamed to images/base/Dockerfile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM %BASE
1+
FROM buildpack-deps:cosmic
22

33
RUN apt-get update && apt-get install -y \
44
vim \
@@ -20,14 +20,11 @@ RUN locale-gen en_US.UTF-8
2020
# configured in /etc/default/locale so we need to set it manually.
2121
ENV LC_ALL=en_US.UTF-8
2222

23-
LABEL share.ssh="~/.ssh:~/.ssh"
24-
2523
# Download in code-server into path. sail will typically override the binary
2624
# anyways, but it's nice to have this during the build pipepline so we can
2725
# install extensions.
2826
RUN wget -O /usr/bin/code-server https://codesrv-ci.cdr.sh/latest-linux && \
2927
chmod +x /usr/bin/code-server
3028

31-
RUN adduser --gecos '' --disabled-password user && \
32-
echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/nopasswd
33-
USER user
29+
30+
ADD installext /usr/bin/installext

images/base/installext

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
set -e
3+
4+
code-server --extensions-dir ~/.vscode/extensions --install-extension $1

images/buildlang.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -eu
44
LANG_IMG_NAME=$1
55

66
COMM_DOCKERFILE=./Dockerfile.comm
7-
COMM_FROM=buildpack-deps:cosmic
7+
COMM_FROM=sail-base
88
COMM_IMG_NAME=$LANG_IMG_NAME-comm
99

1010
# Build our community base image.
@@ -13,7 +13,7 @@ COMM_IMG_NAME=$LANG_IMG_NAME-comm
1313
# location, so we need to backout to access buildfrom.sh.
1414
../buildfrom.sh $COMM_DOCKERFILE $COMM_FROM $COMM_IMG_NAME
1515

16-
BASE_DOCKERFILE=../Dockerfile
16+
BASE_DOCKERFILE=../ubuntu-dev/Dockerfile
1717
BASE_IMG_NAME=$LANG_IMG_NAME-base
1818

1919
# Add the ubuntu-dev base on top.

images/main.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ LANG_IMAGES=(
1313
ubuntu-dev-openjdk12
1414
)
1515

16-
# Build our base image for non language specific environments.
16+
# Build the base for all images.
17+
pushd base
18+
docker build -t sail-base --label com.coder.sail.base_image=sail-base .
19+
popd
20+
21+
# Build our base ubuntu-dev image for non language specific environments.
1722
pushd $BASE_IMAGE
1823
./buildpush.sh
1924
popd
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
FROM %BASE
22

33
# This technically has no effect until #35 is resolved.
4-
RUN code-server --install-extension ms-vscode.cpptools
4+
RUN installext ms-vscode.cpptools

images/ubuntu-dev-go/Dockerfile.lang

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ADD install_go_tools.sh /tmp/
44
RUN bash /tmp/install_go_tools.sh
55

66
# This technically has no effect until #35 is resolved.
7-
RUN code-server --install-extension ms-vscode.go
7+
RUN installext ms-vscode.go
88

99
LABEL share.go_mod "~/go/pkg/mod:~/go/pkg/mod"
1010
LABEL project_root "~/go/src/"

images/ubuntu-dev-node12/Dockerfile.lang

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ RUN npm install -g typescript
1616
LABEL share.go_mod "~/.cache/yarn/v4:~/.cache/yarn/v4"
1717

1818
# This technically has no effect until #35 is resolved.
19-
RUN code-server --install-extension dbaeumer.vscode-eslint
20-
RUN code-server --install-extension ms-vscode.vscode-typescript-tslint-plugin
19+
RUN installext dbaeumer.vscode-eslint
20+
RUN installext ms-vscode.vscode-typescript-tslint-plugin
2121

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM %BASE
22

33
# This technically has no effect until #35 is resolved.
4-
RUN code-server --install-extension redhat.java
5-
RUN code-server --install-extension vscjava.vscode-java-debug
4+
RUN installext redhat.java
5+
RUN installext vscjava.vscode-java-debug
66

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM %BASE
22

33
# This technically has no effect until #35 is resolved.
4-
RUN code-server --install-extension ms-python.python
4+
RUN installext ms-python.python
55

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM %BASE
22

33
# This technically has no effect until #35 is resolved.
4-
RUN code-server --install-extension ms-python.python
4+
RUN installext ms-python.python
55

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM %BASE
22

33
# This technically has no effect until #35 is resolved.
4-
RUN code-server --install-extension rebornix.Ruby
5-
RUN code-server --install-extension castwide.solargraph
4+
RUN installext rebornix.Ruby
5+
RUN installext castwide.solargraph

images/ubuntu-dev/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM %BASE
2+
3+
LABEL share.ssh="~/.ssh:~/.ssh"
4+
5+
RUN adduser --gecos '' --disabled-password user && \
6+
echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/nopasswd
7+
USER user
8+
9+
RUN mkdir -p ~/.vscode/extensions

images/ubuntu-dev/buildpush.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#!/bin/bash
22
set -eu
33

4-
DOCKERFILE=../Dockerfile
5-
FROM=buildpack-deps:cosmic
4+
DOCKERFILE=Dockerfile
5+
FROM=sail-base
66
IMAGE_NAME=codercom/ubuntu-dev
77

8-
98
../buildfrom.sh $DOCKERFILE $FROM $IMAGE_NAME
109
../push.sh $IMAGE_NAME

runner.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,13 @@ func (r *runner) constructCommand(projectDir string) string {
148148
// We want the code-server logs to be available inside the container for easy
149149
// access during development, but also going to stdout so `docker logs` can be used
150150
// to debug a failed code-server startup.
151+
//
152+
// We start code-server such that extensions installed through the UI are placed in the host's extension dir.
151153
cmd := fmt.Sprintf(`set -euxo pipefail || exit 1
152154
cd %v
153155
code-server --host %v --port %v \
154-
--data-dir ~/.config/Code --extensions-dir ~/.vscode/extensions --allow-http --no-auth 2>&1 | tee %v
155-
`, projectDir, containerAddr, containerPort, containerLogPath)
156+
--data-dir ~/.config/Code --extensions-dir %v --extra-extensions-dir ~/.vscode/extensions --allow-http --no-auth 2>&1 | tee %v
157+
`, projectDir, containerAddr, containerPort, hostExtensionsDir, containerLogPath)
156158
if r.testCmd != "" {
157159
cmd = r.testCmd + "\n exit 1"
158160
}
@@ -225,6 +227,8 @@ func (r *runner) addHatMount(mounts []mount.Mount, labels map[string]string) []m
225227
})
226228
}
227229

230+
const hostExtensionsDir = "~/.vscode/host-extensions"
231+
228232
func (r *runner) mounts(mounts []mount.Mount, image string) ([]mount.Mount, error) {
229233
// Mount in VS Code configs.
230234
mounts = append(mounts, mount.Mount{
@@ -235,7 +239,7 @@ func (r *runner) mounts(mounts []mount.Mount, image string) ([]mount.Mount, erro
235239
mounts = append(mounts, mount.Mount{
236240
Type: "bind",
237241
Source: "~/.vscode/extensions",
238-
Target: "~/.vscode/extensions",
242+
Target: hostExtensionsDir,
239243
})
240244

241245
mounts = mountGUI(mounts)

site/content/docs/concepts/labels.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
type="docs"
33
title="Labels"
44
browser_title="Sail - Docs - Labels"
5-
section_order=1
5+
section_order=3
66
+++
77

88
Sail makes extensive use of Docker labels to maintain state and to allow users to fully configure
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
+++
2+
type="docs"
3+
title="Project-defined Extensions"
4+
browser_title="Sail - Docs - Project-defined Extensions"
5+
section_order=2
6+
+++
7+
8+
Installing VS Code extensions through your Sail Dockerfile is dead-simple.
9+
10+
In your Dockerfile, call `installext <extension ID>`.
11+
12+
For example:
13+
14+
```Dockerfile
15+
FROM ubuntu-dev
16+
RUN installext vscodevim.vim
17+
```
18+
19+
20+
**`ubuntu-dev` or `ubuntu-dev-*` must be your image's base for `installext` to be available.**
21+
22+
---
23+
24+
_Tip: Find an extension's ID at it's marketplace page:_
25+
26+
![Extension ID in VS Code](/extension-id.png)
27+
28+
29+
## Under The Hood
30+
31+
`code-server` is started with two extension directories:
32+
33+
- `~/.vscode/extensions` contains extensions for the specific environment.
34+
- `~/.vscode/host-extensions` is bind-mounted in from `~/.vscode/extensions` on
35+
the host.
36+
37+
This ensures that
38+
39+
1. Projects can specify their extensions.
40+
1. Users continue using the extensions that they installed through native
41+
VS Code.
42+

site/static/extension-id.png

78.1 KB
Loading

0 commit comments

Comments
 (0)