Skip to content

Commit

Permalink
base dir
Browse files Browse the repository at this point in the history
  • Loading branch information
mafredri committed Nov 5, 2024
1 parent c8b451f commit 23af808
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 88 deletions.
4 changes: 2 additions & 2 deletions docs/env-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
| `--git-ssh-private-key-path` | `ENVBUILDER_GIT_SSH_PRIVATE_KEY_PATH` | | Path to an SSH private key to be used for Git authentication. If this is set, then GIT_SSH_PRIVATE_KEY_BASE64 cannot be set. |
| `--git-ssh-private-key-base64` | `ENVBUILDER_GIT_SSH_PRIVATE_KEY_BASE64` | | Base64 encoded SSH private key to be used for Git authentication. If this is set, then GIT_SSH_PRIVATE_KEY_PATH cannot be set. |
| `--git-http-proxy-url` | `ENVBUILDER_GIT_HTTP_PROXY_URL` | | The URL for the HTTP proxy. This is optional. |
| `--workspace-folder` | `ENVBUILDER_WORKSPACE_FOLDER` | | The path to the workspace folder that will be built. This is optional. Defaults to `[workspaces folder]/[name]` where name is the name of the repository or `empty`. |
| `--workspaces-folder` | `ENVBUILDER_WORKSPACES_FOLDER` | `/workspaces` | The path under which workspaces will be placed when workspace folder option is not given. |
| `--workspace-folder` | `ENVBUILDER_WORKSPACE_FOLDER` | | The path to the workspace folder that will be built. This is optional. Defaults to `[workspace base dir]/[name]` where name is the name of the repository or `empty`. |
| `--workspace-base-dir` | `ENVBUILDER_WORKSPACE_BASE_DIR` | `/workspaces` | The path under which workspaces will be placed when workspace folder option is not given. |
| `--ssl-cert-base64` | `ENVBUILDER_SSL_CERT_BASE64` | | The content of an SSL cert file. This is useful for self-signed certificates. |
| `--export-env-file` | `ENVBUILDER_EXPORT_ENV_FILE` | | Optional file path to a .env file where envbuilder will dump environment variables from devcontainer.json and the built container image. |
| `--post-start-script-path` | `ENVBUILDER_POST_START_SCRIPT_PATH` | | 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. |
Expand Down
6 changes: 3 additions & 3 deletions options/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ func (o *Options) SetDefaults() {
if o.Filesystem == nil {
o.Filesystem = chmodfs.New(osfs.New("/"))
}
if o.WorkspacesFolder == "" {
o.WorkspacesFolder = "/workspaces"
if o.WorkspaceBaseDir == "" {
o.WorkspaceBaseDir = "/workspaces"
}
if o.WorkspaceFolder == "" {
o.WorkspaceFolder = DefaultWorkspaceFolder(o.WorkspacesFolder, o.GitURL)
o.WorkspaceFolder = DefaultWorkspaceFolder(o.WorkspaceBaseDir, o.GitURL)
}
if o.BinaryPath == "" {
o.BinaryPath = "/.envbuilder/bin/envbuilder"
Expand Down
140 changes: 70 additions & 70 deletions options/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,111 +16,111 @@ func TestDefaultWorkspaceFolder(t *testing.T) {
t.Parallel()

successTests := []struct {
name string
workspacesFolder string
gitURL string
expected string
name string
baseDir string
gitURL string
expected string
}{
{
name: "HTTP",
workspacesFolder: "/workspaces",
gitURL: "https://github.com/coder/envbuilder.git",
expected: "/workspaces/envbuilder",
name: "HTTP",
baseDir: "/workspaces",
gitURL: "https://github.com/coder/envbuilder.git",
expected: "/workspaces/envbuilder",
},
{
name: "SSH",
workspacesFolder: "/workspaces",
gitURL: "[email protected]:coder/envbuilder.git",
expected: "/workspaces/envbuilder",
name: "SSH",
baseDir: "/workspaces",
gitURL: "[email protected]:coder/envbuilder.git",
expected: "/workspaces/envbuilder",
},
{
name: "username and password",
workspacesFolder: "/workspaces",
gitURL: "https://username:[email protected]/coder/envbuilder.git",
expected: "/workspaces/envbuilder",
name: "username and password",
baseDir: "/workspaces",
gitURL: "https://username:[email protected]/coder/envbuilder.git",
expected: "/workspaces/envbuilder",
},
{
name: "trailing",
workspacesFolder: "/workspaces",
gitURL: "https://github.com/coder/envbuilder.git/",
expected: "/workspaces/envbuilder",
name: "trailing",
baseDir: "/workspaces",
gitURL: "https://github.com/coder/envbuilder.git/",
expected: "/workspaces/envbuilder",
},
{
name: "trailing-x2",
workspacesFolder: "/workspaces",
gitURL: "https://github.com/coder/envbuilder.git//",
expected: "/workspaces/envbuilder",
name: "trailing-x2",
baseDir: "/workspaces",
gitURL: "https://github.com/coder/envbuilder.git//",
expected: "/workspaces/envbuilder",
},
{
name: "no .git",
workspacesFolder: "/workspaces",
gitURL: "https://github.com/coder/envbuilder",
expected: "/workspaces/envbuilder",
name: "no .git",
baseDir: "/workspaces",
gitURL: "https://github.com/coder/envbuilder",
expected: "/workspaces/envbuilder",
},
{
name: "trailing no .git",
workspacesFolder: "/workspaces",
gitURL: "https://github.com/coder/envbuilder/",
expected: "/workspaces/envbuilder",
name: "trailing no .git",
baseDir: "/workspaces",
gitURL: "https://github.com/coder/envbuilder/",
expected: "/workspaces/envbuilder",
},
{
name: "fragment",
workspacesFolder: "/workspaces",
gitURL: "https://github.com/coder/envbuilder.git#feature-branch",
expected: "/workspaces/envbuilder",
name: "fragment",
baseDir: "/workspaces",
gitURL: "https://github.com/coder/envbuilder.git#feature-branch",
expected: "/workspaces/envbuilder",
},
{
name: "fragment-trailing",
workspacesFolder: "/workspaces",
gitURL: "https://github.com/coder/envbuilder.git/#refs/heads/feature-branch",
expected: "/workspaces/envbuilder",
name: "fragment-trailing",
baseDir: "/workspaces",
gitURL: "https://github.com/coder/envbuilder.git/#refs/heads/feature-branch",
expected: "/workspaces/envbuilder",
},
{
name: "fragment-trailing no .git",
workspacesFolder: "/workspaces",
gitURL: "https://github.com/coder/envbuilder/#refs/heads/feature-branch",
expected: "/workspaces/envbuilder",
name: "fragment-trailing no .git",
baseDir: "/workspaces",
gitURL: "https://github.com/coder/envbuilder/#refs/heads/feature-branch",
expected: "/workspaces/envbuilder",
},
{
name: "space",
workspacesFolder: "/workspaces",
gitURL: "https://github.com/coder/env%20builder.git",
expected: "/workspaces/env builder",
name: "space",
baseDir: "/workspaces",
gitURL: "https://github.com/coder/env%20builder.git",
expected: "/workspaces/env builder",
},
{
name: "Unix path",
workspacesFolder: "/workspaces",
gitURL: "/repo",
expected: "/workspaces/repo",
name: "Unix path",
baseDir: "/workspaces",
gitURL: "/repo",
expected: "/workspaces/repo",
},
{
name: "Unix subpath",
workspacesFolder: "/workspaces",
gitURL: "/path/to/repo",
expected: "/workspaces/repo",
name: "Unix subpath",
baseDir: "/workspaces",
gitURL: "/path/to/repo",
expected: "/workspaces/repo",
},
{
name: "empty",
workspacesFolder: "/workspaces",
gitURL: "",
expected: "/workspaces/empty",
name: "empty",
baseDir: "/workspaces",
gitURL: "",
expected: "/workspaces/empty",
},
{
name: "non default workspaces folder",
workspacesFolder: "/foo",
gitURL: "https://github.com/coder/envbuilder.git",
expected: "/foo/envbuilder",
name: "non default workspaces folder",
baseDir: "/foo",
gitURL: "https://github.com/coder/envbuilder.git",
expected: "/foo/envbuilder",
},
{
name: "non default workspaces folder empty git URL",
workspacesFolder: "/foo",
gitURL: "",
expected: "/foo/empty",
name: "non default workspaces folder empty git URL",
baseDir: "/foo",
gitURL: "",
expected: "/foo/empty",
},
}
for _, tt := range successTests {
t.Run(tt.name, func(t *testing.T) {
dir := options.DefaultWorkspaceFolder(tt.workspacesFolder, tt.gitURL)
dir := options.DefaultWorkspaceFolder(tt.baseDir, tt.gitURL)
require.Equal(t, tt.expected, dir)
})
}
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestOptions_SetDefaults(t *testing.T) {
IgnorePaths: []string{"/var/run", "/product_uuid", "/product_name"},
Filesystem: chmodfs.New(osfs.New("/")),
GitURL: "",
WorkspacesFolder: "/workspaces",
WorkspaceBaseDir: "/workspaces",
WorkspaceFolder: "/workspaces/empty",
WorkingDirBase: "/.envbuilder",
BinaryPath: "/.envbuilder/bin/envbuilder",
Expand Down
14 changes: 7 additions & 7 deletions options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ type Options struct {
// GitHTTPProxyURL is the URL for the HTTP proxy. This is optional.
GitHTTPProxyURL string
// WorkspaceFolder is the path to the workspace folder that will be built.
// This is optional. Defaults to `[workspaces folder]/[name]` where name is
// This is optional. Defaults to `[workspace base dir]/[name]` where name is
// the name of the repository or "empty".
WorkspaceFolder string
// WorkspacesFolder is the path under which workspaces will be placed when
// WorkspaceBaseDir is the path under which workspaces will be placed when
// workspace folder option is not given.
WorkspacesFolder string
WorkspaceBaseDir string
// SSLCertBase64 is the content of an SSL cert file. This is useful for
// self-signed certificates.
SSLCertBase64 string
Expand Down Expand Up @@ -400,13 +400,13 @@ func (o *Options) CLI() serpent.OptionSet {
Env: WithEnvPrefix("WORKSPACE_FOLDER"),
Value: serpent.StringOf(&o.WorkspaceFolder),
Description: "The path to the workspace folder that will be built. " +
"This is optional. Defaults to `[workspaces folder]/[name]` where " +
"This is optional. Defaults to `[workspace base dir]/[name]` where " +
"name is the name of the repository or `empty`.",
},
{
Flag: "workspaces-folder",
Env: WithEnvPrefix("WORKSPACES_FOLDER"),
Value: serpent.StringOf(&o.WorkspacesFolder),
Flag: "workspace-base-dir",
Env: WithEnvPrefix("WORKSPACE_BASE_DIR"),
Value: serpent.StringOf(&o.WorkspaceBaseDir),
Default: "/workspaces",
Description: "The path under which workspaces will be placed when " +
"workspace folder option is not given.",
Expand Down
12 changes: 6 additions & 6 deletions options/testdata/options.golden
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ OPTIONS:
--verbose bool, $ENVBUILDER_VERBOSE
Enable verbose logging.

--workspace-folder string, $ENVBUILDER_WORKSPACE_FOLDER
The path to the workspace folder that will be built. This is optional.
Defaults to `[workspaces folder]/[name]` where name is the name of the
repository or `empty`.

--workspaces-folder string, $ENVBUILDER_WORKSPACES_FOLDER (default: /workspaces)
--workspace-base-dir string, $ENVBUILDER_WORKSPACE_BASE_DIR (default: /workspaces)
The path under which workspaces will be placed when workspace folder
option is not given.

--workspace-folder string, $ENVBUILDER_WORKSPACE_FOLDER
The path to the workspace folder that will be built. This is optional.
Defaults to `[workspace base dir]/[name]` where name is the name of
the repository or `empty`.

0 comments on commit 23af808

Please sign in to comment.