|
1 | 1 | # envbuilder
|
2 | 2 |
|
3 |
| -Build development environments from repositories in a container on Kubernetes, Docker, or gVisor. Allow developers to customize their environment on pre-defined infrastructure. |
| 3 | +[](https://discord.gg/coder) |
| 4 | +[](https://github.com/coder/envbuilder/releases/latest) |
| 5 | +[](https://pkg.go.dev/github.com/coder/envbuilder) |
| 6 | +[](./LICENSE) |
4 | 7 |
|
5 |
| -- Supports `devcontainer.json` and `Dockerfile` |
| 8 | +Build development environments from a Dockerfile on Docker, Kubernetes, and OpenShift. Allow developers to modify their environment in a tight feedback loop. |
| 9 | + |
| 10 | +- Supports [`devcontainer.json`](https://containers.dev/) and `Dockerfile` |
6 | 11 | - Cache image layers with registries for speedy builds
|
7 |
| -- Runs on Kubernetes, Docker, and OpenShift |
| 12 | +- Runs on Kubernetes, Docker, and OpenShift |
| 13 | + |
| 14 | +<div align="center"> |
| 15 | + <a href="#gh-light-mode-only"> |
| 16 | + <img src="./scripts/diagram-light.svg"> |
| 17 | + </a> |
| 18 | + <a href="#gh-dark-mode-only"> |
| 19 | + <img src="./scripts/diagram-dark.svg"> |
| 20 | + </a> |
| 21 | +</div> |
8 | 22 |
|
9 | 23 | ## Quickstart
|
10 | 24 |
|
11 |
| -The easiest way to play with `envbuilder` is to launch a Docker container that builds a sample image. |
| 25 | +The easiest way to get started is to run the `envbuilder` Docker container that clones a repository, builds the image from a Dockerfile, and runs the `$INIT_SCRIPT` in the freshly built container. |
| 26 | + |
| 27 | +> `/tmp/envbuilder` is used to persist data between commands for the purpose of this demo. You can change it to any directory you want. |
12 | 28 |
|
13 | 29 | ```bash
|
14 | 30 | docker run -it --rm \
|
15 |
| - -e GIT_URL=https://github.com/vercel/next.js \ |
| 31 | + -v /tmp/envbuilder:/workspaces \ |
| 32 | + -e GIT_URL=https://github.com/coder/envbuilder-starter-devcontainer \ |
| 33 | + -e INIT_SCRIPT=bash \ |
16 | 34 | ghcr.io/coder/envbuilder
|
17 | 35 | ```
|
| 36 | + |
| 37 | +Edit `.devcontainer/Dockerfile` to add `htop`: |
| 38 | + |
| 39 | +```bash |
| 40 | +$ vim .devcontainer/Dockerfile |
| 41 | +``` |
| 42 | + |
| 43 | +```diff |
| 44 | +- RUN apt-get install vim sudo -y |
| 45 | ++ RUN apt-get install vim sudo htop -y |
| 46 | +``` |
| 47 | + |
| 48 | +Exit the container, and re-run the `docker run` command... after the build completes, `htop` should exist in the container! 🥳 |
| 49 | + |
| 50 | +## Container Registry Authentication |
| 51 | + |
| 52 | +envbuilder uses Kaniko to build containers. You should [follow their instructions](https://github.com/GoogleContainerTools/kaniko#pushing-to-different-registries) to create an authentication configuration. |
| 53 | + |
| 54 | +After you have a configuration that resembles the following: |
| 55 | + |
| 56 | +```json |
| 57 | +{ |
| 58 | + "auths": { |
| 59 | + "https://index.docker.io/v1/": { |
| 60 | + "auth": "base64-encoded-username-and-password" |
| 61 | + } |
| 62 | + } |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +`base64` encode the JSON and provide it to envbuilder as the `DOCKER_CONFIG_BASE64` environment variable. |
| 67 | + |
| 68 | +## Git Authentication |
| 69 | + |
| 70 | +`GIT_USERNAME` and `GIT_PASSWORD` are environment variables to provide Git authentication for private repositories. |
| 71 | + |
| 72 | +For access token-based authentication, follow the following schema (if empty, there's no need to provide the field): |
| 73 | + |
| 74 | +| Provider | `GIT_USERNAME` | `GIT_PASSWORD` | |
| 75 | +| ------------ | -------------- | -------------- | |
| 76 | +| GitHub | [access-token] | | |
| 77 | +| GitLab | oauth2 | [access-token] | |
| 78 | +| BitBucket | x-token-auth | [access-token] | |
| 79 | +| Azure DevOps | [access-token] | | |
| 80 | + |
| 81 | +If using envbuilder inside of [Coder](https://github.com/coder/coder), you can use the `coder_git_auth` Terraform resource to automatically provide this token on workspace creation: |
| 82 | + |
| 83 | +```hcl |
| 84 | +resource "coder_git_auth" "github" { |
| 85 | + id = "github" |
| 86 | +} |
| 87 | +
|
| 88 | +resource "docker_container" "dev" { |
| 89 | + env = [ |
| 90 | + GIT_USERNAME = coder_git_auth.github.access_token, |
| 91 | + ] |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +## Layer Caching |
| 96 | + |
| 97 | +Cache layers in a container registry to speed up builds. To enable caching, [authenticate with your registry](#container-registry-authentication) and set the `CACHE_REPO` environment variable. |
| 98 | + |
| 99 | +```bash |
| 100 | +CACHE_REPO=ghcr.io/coder/repo-cache |
| 101 | +``` |
| 102 | + |
| 103 | +Each layer is stored in the registry as a separate image. The image tag is the hash of the layer's contents. The image digest is the hash of the image tag. The image digest is used to pull the layer from the registry. |
| 104 | + |
| 105 | +## devcontainer.json Support |
| 106 | + |
| 107 | +We don't support mounts, features, and many other primitives of `devcontainer.json`. We support the following: |
| 108 | + |
| 109 | +- `image` |
| 110 | +- `build` |
| 111 | +- `runArgs` |
| 112 | +- `workspaceFolder` |
0 commit comments