Skip to content

Commit b5493d7

Browse files
committed
feat: auto add flags docs into the README
1 parent e3b205b commit b5493d7

File tree

3 files changed

+86
-6
lines changed

3 files changed

+86
-6
lines changed

README.md

+39-5
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ resource "kubernetes_deployment" "example" {
8585
}
8686
spec {
8787
spec {
88-
container {
88+
container {
8989
# Define the volumeMount with the pull credentials
9090
volume_mount {
9191
name = "docker-config-volume"
@@ -194,8 +194,7 @@ A sample script to pre-fetch a number of images can be viewed [here](./examples/
194194

195195
The `SETUP_SCRIPT` environment variable dynamically configures the user and init command (PID 1) after the container build process.
196196

197-
> **Note**
198-
> `TARGET_USER` is passed to the setup script to specify who will execute `INIT_COMMAND` (e.g., `code`).
197+
> **Note** > `TARGET_USER` is passed to the setup script to specify who will execute `INIT_COMMAND` (e.g., `code`).
199198
200199
Write the following to `$ENVBUILDER_ENV` to shape the container's init process:
201200

@@ -225,7 +224,6 @@ docker run -it --rm \
225224
- [`SSL_CERT_DIR`](https://go.dev/src/crypto/x509/root_unix.go#L25): Identifies which directory to check for SSL certificate files.
226225
- `SSL_CERT_BASE64`: Specifies a base64-encoded SSL certificate that will be added to the global certificate pool on start.
227226

228-
229227
# Local Development
230228

231229
Building `envbuilder` currently **requires** a Linux system.
@@ -243,4 +241,40 @@ On MacOS or Windows systems, we recommend either using a VM or the provided `.de
243241
- `build`: builds and tags `envbuilder:latest` for your current architecture.
244242
- `develop`: runs `envbuilder:latest` against a sample Git repository.
245243
- `test`: run tests.
246-
- `test-registry`: stands up a local registry for caching images used in tests.
244+
- `test-registry`: stands up a local registry for caching images used in tests.
245+
246+
<!--- PLEASE DO NOT MODIFY THIS SECTION. IT IS AUTOMATICALLY GENERATED. --->
247+
<!--- start-flags --->## Flags
248+
249+
| Flag | Env | Default | Description |
250+
| - | - | - | - |
251+
| setup-script | SETUP_SCRIPT | | SetupScript is the script to run before the init script. It runs as the root user regardless of the user specified in the devcontainer.json file. SetupScript is ran as the root user prior to the init script. It is used to configure envbuilder dynamically during the runtime. e.g. specifying whether to start systemd or tiny init for PID 1. |
252+
| init-script | INIT_SCRIPT | sleep infinity | InitScript is the script to run to initialize the workspace. |
253+
| init-command | INIT_COMMAND | /bin/sh | InitCommand is the command to run to initialize the workspace. |
254+
| init-args | INIT_ARGS | | InitArgs are the arguments to pass to the init command. They are split according to /bin/sh rules with https://github.com/kballard/go-shellquote. |
255+
| cache-repo | CACHE_REPO | | CacheRepo is the name of the container registry to push the cache image to. If this is empty, the cache will not be pushed. |
256+
| base-image-cache-dir | BASE_IMAGE_CACHE_DIR | | BaseImageCacheDir is the path to a directory where the base image can be found. This should be a read-only directory solely mounted for the purpose of caching the base image. |
257+
| layer-cache-dir | LAYER_CACHE_DIR | | LayerCacheDir is the path to a directory where built layers will be stored. This spawns an in-memory registry to serve the layers from. |
258+
| devcontainer-dir | DEVCONTAINER_DIR | | DevcontainerDir is a path to the folder containing the devcontainer.json file that will be used to build the workspace and can either be an absolute path or a path relative to the workspace folder. If not provided, defaults to `.devcontainer`. |
259+
| devcontainer-json-path | DEVCONTAINER_JSON_PATH | | DevcontainerJSONPath is a path to a devcontainer.json file that is either an absolute path or a path relative to DevcontainerDir. This can be used in cases where one wants to substitute an edited devcontainer.json file for the one that exists in the repo. |
260+
| dockerfile-path | DOCKERFILE_PATH | | DockerfilePath is a relative path to the Dockerfile that will be used to build the workspace. This is an alternative to using a devcontainer that some might find simpler. |
261+
| build-context-path | BUILD_CONTEXT_PATH | | BuildContextPath can be specified when a DockerfilePath is specified outside the base WorkspaceFolder. This path MUST be relative to the WorkspaceFolder path into which the repo is cloned. |
262+
| cache-ttl-days | CACHE_TTL_DAYS | | CacheTTLDays is the number of days to use cached layers before expiring them. Defaults to 7 days. |
263+
| docker-config-base64 | DOCKER_CONFIG_BASE64 | | DockerConfigBase64 is a base64 encoded Docker config file that will be used to pull images from private container registries. |
264+
| fallback-image | FALLBACK_IMAGE | | FallbackImage specifies an alternative image to use when neither an image is declared in the devcontainer.json file nor a Dockerfile is present. If there's a build failure (from a faulty Dockerfile) or a misconfiguration, this image will be the substitute. Set ExitOnBuildFailure to true to halt the container if the build faces an issue. |
265+
| exit-on-build-failure | EXIT_ON_BUILD_FAILURE | | ExitOnBuildFailure terminates the container upon a build failure. This is handy when preferring the FALLBACK_IMAGE in cases where no devcontainer.json or image is provided. However, it ensures that the container stops if the build process encounters an error. |
266+
| force-safe | FORCE_SAFE | | ForceSafe ignores any filesystem safety checks. This could cause serious harm to your system! This is used in cases where bypass is needed to unblock customers. |
267+
| insecure | INSECURE | | Insecure bypasses TLS verification when cloning and pulling from container registries. |
268+
| ignore-paths | IGNORE_PATHS | /var/run | IgnorePaths is a comma separated list of paths to ignore when building the workspace. |
269+
| skip-rebuild | SKIP_REBUILD | | SkipRebuild skips building if the MagicFile exists. This is used to skip building when a container is restarting. e.g. docker stop -> docker start This value can always be set to true - even if the container is being started for the first time. |
270+
| git-url | GIT_URL | | GitURL is the URL of the Git repository to clone. This is optional. |
271+
| git-clone-depth | GIT_CLONE_DEPTH | | GitCloneDepth is the depth to use when cloning the Git repository. |
272+
| git-clone-single-branch | GIT_CLONE_SINGLE_BRANCH | | GitCloneSingleBranch clones only a single branch of the Git repository. |
273+
| git-username | GIT_USERNAME | | GitUsername is the username to use for Git authentication. This is optional. |
274+
| git-password | GIT_PASSWORD | | GitPassword is the password to use for Git authentication. This is optional. |
275+
| git-http-proxy-url | GIT_HTTP_PROXY_URL | | GitHTTPProxyURL is the url for the http proxy. This is optional. |
276+
| workspace-folder | WORKSPACE_FOLDER | | WorkspaceFolder is the path to the workspace folder that will be built. This is optional. |
277+
| ssl-cert-base64 | SSL_CERT_BASE64 | | SSLCertBase64 is the content of an SSL cert file. This is useful for self-signed certificates. |
278+
| export-env-file | EXPORT_ENV_FILE | | ExportEnvFile is an optional file path to a .env file where envbuilder will dump environment variables from devcontainer.json and the built container image. |
279+
| post-start-script-path | POST_START_SCRIPT_PATH | | PostStartScriptPath is the path to a script that will be created by envbuilder based on the postStartCommand in devcontainer.json, if any is specified (otherwise the script is not created). If this is set, the specified InitCommand should check for the presence of this script and execute it after successful startup. |
280+
<!--- end-flags --->

options.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (o *Options) CLI() serpent.OptionSet {
4646
Value: serpent.StringOf(&o.SetupScript),
4747
Description: "SetupScript is the script to run before the init script. It runs as " +
4848
"the root user regardless of the user specified in the devcontainer.json " +
49-
"file.\n\nSetupScript is ran as the root user prior to the init script. " +
49+
"file. SetupScript is ran as the root user prior to the init script. " +
5050
"It is used to configure envbuilder dynamically during the runtime. e.g. " +
5151
"specifying whether to start systemd or tiny init for PID 1.",
5252
},
@@ -265,3 +265,15 @@ func (o *Options) CLI() serpent.OptionSet {
265265
},
266266
}
267267
}
268+
269+
func (o *Options) Markdown() string {
270+
cliOptions := o.CLI()
271+
mkd := "| Flag | Env | Default | Description |\n" +
272+
"| - | - | - | - |\n"
273+
274+
for _, opt := range cliOptions {
275+
mkd += "| " + opt.Flag + " | " + opt.Env + " | " + opt.Default + " | " + opt.Description + " |\n"
276+
}
277+
278+
return mkd
279+
}

scripts/docsgen/main.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"strings"
7+
8+
"github.com/coder/envbuilder"
9+
)
10+
11+
func main() {
12+
readmePath := "README.md"
13+
readmeFile, err := os.ReadFile(readmePath)
14+
if err != nil {
15+
panic("Error reading " + readmePath + " file")
16+
}
17+
readmeContent := string(readmeFile)
18+
startIndex := strings.Index(readmeContent, "<!--- start-flags --->")
19+
endIndex := strings.Index(readmeContent, "<!--- end-flags --->")
20+
if startIndex == -1 || endIndex == -1 {
21+
panic("Start or end marks not found in the file.")
22+
}
23+
24+
options := envbuilder.Options{}
25+
mkd := "## Flags\n\n" + options.Markdown()
26+
modifiedContent := readmeContent[:startIndex+len("<!--- start-flags --->")] + mkd + readmeContent[endIndex:]
27+
28+
err = os.WriteFile(readmePath, []byte(modifiedContent), 0644)
29+
if err != nil {
30+
panic(err)
31+
}
32+
33+
fmt.Println("README updated successfully with the latest flags!")
34+
}

0 commit comments

Comments
 (0)