Skip to content

Commit

Permalink
Merge branch 'main' into stdio
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecarbs committed Jul 25, 2023
2 parents afc005b + 9cd920d commit 4334bde
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
# Install Go!
- uses: actions/setup-go@v3
with:
go-version: "~1.20"
go-version: "1.20.5"

- name: Test
run: go test ./...
21 changes: 16 additions & 5 deletions envbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,15 @@ type Options struct {
// It will override CacheRepo if both are specified.
LayerCacheDir string `env:"LAYER_CACHE_DIR"`

// DockerfilePath is a relative path to the workspace
// folder that will be used to build the workspace.
// This is an alternative to using a devcontainer
// that some might find simpler.
// DevcontainerJSONPath is a relative or absolute path to a
// devcontainer.json file. This can be used in cases where
// one wants to substitute an edited devcontainer.json file
// for the one that exists in the repo.
DevcontainerJSONPath string `env:"DEVCONTAINER_JSON_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.
DockerfilePath string `env:"DOCKERFILE_PATH"`

// DockerConfigBase64 is a base64 encoded Docker config
Expand Down Expand Up @@ -368,7 +373,13 @@ func Run(ctx context.Context, options Options) error {
// Only look for a devcontainer if a Dockerfile wasn't specified.
// devcontainer is a standard, so it's reasonable to be the default.
devcontainerDir := filepath.Join(options.WorkspaceFolder, ".devcontainer")
devcontainerPath := filepath.Join(devcontainerDir, "devcontainer.json")
devcontainerPath := options.DevcontainerJSONPath
if devcontainerPath == "" {
devcontainerPath = "devcontainer.json"
}
if !filepath.IsAbs(devcontainerPath) {
devcontainerPath = filepath.Join(devcontainerDir, devcontainerPath)
}
_, err := options.Filesystem.Stat(devcontainerPath)
if err == nil {
// We know a devcontainer exists.
Expand Down
18 changes: 10 additions & 8 deletions envbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@ func TestDefaultWorkspaceFolder(t *testing.T) {
func TestSystemOptions(t *testing.T) {
t.Parallel()
opts := map[string]string{
"INIT_SCRIPT": "echo hello",
"CACHE_REPO": "kylecarbs/testing",
"DOCKERFILE_PATH": "Dockerfile",
"FALLBACK_IMAGE": "ubuntu:latest",
"FORCE_SAFE": "true",
"INSECURE": "false",
"GIT_URL": "https://github.com/coder/coder",
"WORKSPACE_FOLDER": "/workspaces/coder",
"INIT_SCRIPT": "echo hello",
"CACHE_REPO": "kylecarbs/testing",
"DEVCONTAINER_JSON_PATH": "/tmp/devcontainer.json",
"DOCKERFILE_PATH": "Dockerfile",
"FALLBACK_IMAGE": "ubuntu:latest",
"FORCE_SAFE": "true",
"INSECURE": "false",
"GIT_URL": "https://github.com/coder/coder",
"WORKSPACE_FOLDER": "/workspaces/coder",
}
env := envbuilder.OptionsFromEnv(func(s string) (string, bool) {
return opts[s], true
})
require.Equal(t, "echo hello", env.InitScript)
require.Equal(t, "kylecarbs/testing", env.CacheRepo)
require.Equal(t, "/tmp/devcontainer.json", env.DevcontainerJSONPath)
require.Equal(t, "Dockerfile", env.DockerfilePath)
require.Equal(t, "ubuntu:latest", env.FallbackImage)
require.True(t, env.ForceSafe)
Expand Down

0 comments on commit 4334bde

Please sign in to comment.