|
| 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 |
0 commit comments