Skip to content

Commit 5db91ec

Browse files
committed
initial GitHub Codespace support
1 parent 02750a1 commit 5db91ec

File tree

5 files changed

+158
-0
lines changed

5 files changed

+158
-0
lines changed

misc/turbobob-codespace/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM alpine:latest AS builder
2+
3+
RUN apk add --no-cache curl
4+
5+
RUN curl --fail --location --no-progress-meter --output /usr/local/bin/bob https://function61.com/go/turbobob-latest-stable-linux-amd64 && chmod +x /usr/local/bin/bob
6+
7+
8+
FROM alpine:latest
9+
10+
# git = used by GitHub codespaces
11+
# docker-cli = needed by Bob to launch sibling build containers from this "main container"
12+
RUN apk add --no-cache git docker-cli
13+
14+
COPY --from=builder /usr/local/bin/bob /usr/local/bin/bob
15+
16+
COPY init-bob-devcontainer.sh /usr/bin/init-bob-devcontainer.sh
17+
18+
COPY vscode-resources/launch.json vscode-resources/tasks.json /

misc/turbobob-codespace/README.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
turbobob-codespace
2+
==================
3+
4+
Produces a [dev container](https://containers.dev/) specifically intended to enable integrating a repo with
5+
[GitHub Codespaces](https://github.com/features/codespaces).
6+
7+
Goals
8+
9+
- Integrate as many low-hanging fruit features as possible from Turbo Bob with GitHub Codespaces with minimal changes to concrete repos.
10+
11+
Non-goals:
12+
13+
- Work as a standalone dev container outside of GitHub Codespaces context.
14+
15+
16+
Architecture
17+
------------
18+
19+
```mermaid
20+
flowchart TD
21+
subgraph "Codespaces VM"
22+
dockerd
23+
ghbootstrap[GitHub Codespaces bootstrap]
24+
25+
user
26+
27+
subgraph "Workspace files"
28+
vscodeconf[VSCode conf]
29+
30+
buildtask[task: build = $ bob build]
31+
end
32+
end
33+
34+
subgraph "container: turbobob-codespace"
35+
initbobdevcontainer[init-bob-devcontainer.sh]
36+
37+
bobbuild[$ bob build]
38+
end
39+
40+
subgraph "Bob-managed containers"
41+
subgraph "buildkit-golang"
42+
gobuild[$ go build]
43+
end
44+
end
45+
46+
ghbootstrap -- launch container, invoke --> initbobdevcontainer
47+
48+
initbobdevcontainer -- writes dynamically --> vscodeconf
49+
50+
vscodeconf -- defines --> buildtask
51+
52+
bobbuild -. launch container .-> dockerd
53+
user -- build --> buildtask -- invokes --> bobbuild -- run actual build --> gobuild
54+
55+
```
56+
57+
58+
Use from concrete repo
59+
----------------------
60+
61+
Define `.devcontainer/devcontainer.json`:
62+
63+
```json
64+
{
65+
"$schema": "https://raw.githubusercontent.com/devcontainers/spec/main/schemas/devContainer.schema.json",
66+
"name": "Turbo Bob",
67+
"image": "ghcr.io/function61/turbobob-codespace:latest",
68+
// needed for at least mount command done by `init-bob-devcontainer.sh`
69+
"privileged": true,
70+
// for some reason the mount args given here do not work if given in the `mounts` field
71+
"runArgs": [
72+
// to be able to copy Bob to host-side
73+
"--mount=type=bind,source=/,destination=/host"
74+
],
75+
// prepares the container so it can succesfully launch sibling containers from Bob.
76+
// think of this as adapter for Bob running inside devcontainer.
77+
"onCreateCommand": ["/usr/bin/init-bob-devcontainer.sh"],
78+
"mounts": [
79+
"type=bind,source=/var/run/docker.sock,destination=/var/run/docker.sock"
80+
]
81+
}
82+
```
83+
84+
85+
Build
86+
-----
87+
88+
```shell
89+
docker buildx build -t ghcr.io/function61/turbobob-codespace:latest . --push
90+
```
91+
92+
Resources
93+
---------
94+
95+
- https://github.com/qdm12/godevcontainer/blob/master/.devcontainer/devcontainer.json
96+
- https://github.com/devcontainers/images/blob/main/src/go/.devcontainer/devcontainer.json
97+
- https://github.com/qdm12/godevcontainer/blob/master/.devcontainer/devcontainer.json
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh -eu
2+
3+
# Bob maps this from host-side to new containers it launches so we must copy it to host
4+
cp /usr/local/bin/bob /host/usr/local/bin/bob
5+
6+
# Bob integration to VSCode's launch config
7+
mkdir .vscode
8+
cp /launch.json /tasks.json .vscode/
9+
10+
# Bob writes stuff under /tmp which it then maps to inside Bob-spawned build containers
11+
mount --bind /host/tmp /tmp
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Build (fast)",
6+
"command": "bob build --uncommitted --fast",
7+
"request": "launch",
8+
"type": "node-terminal"
9+
},
10+
{
11+
"name": "Build",
12+
"command": "bob build --uncommitted",
13+
"request": "launch",
14+
"type": "node-terminal"
15+
}
16+
]
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "Build",
6+
"type": "shell",
7+
"command": "bob build --uncommitted --fast",
8+
"problemMatcher": [],
9+
"group": {
10+
"kind": "build",
11+
"isDefault": true
12+
}
13+
}
14+
]
15+
}

0 commit comments

Comments
 (0)