Enforce environment variable configuration for Docker entrypoint
CI / Go Tests (push) Successful in 12s
CI / Build (push) Successful in 11s
Format / gofmt (push) Successful in 6s
Release Artifacts / Validate release tag (push) Successful in 2s
Release Artifacts / Build and release executables (push) Successful in 16s
Release Artifacts / Build and release Docker image (push) Successful in 26s
CI / Go Tests (push) Successful in 12s
CI / Build (push) Successful in 11s
Format / gofmt (push) Successful in 6s
Release Artifacts / Validate release tag (push) Successful in 2s
Release Artifacts / Build and release executables (push) Successful in 16s
Release Artifacts / Build and release Docker image (push) Successful in 26s
- Updated `docker-entrypoint.sh` to disallow custom command-line arguments, requiring configuration through `SCRATCHBOX_*` environment variables. - Modified `README.md` to clarify that custom container commands are not supported and to reflect the new entrypoint behavior. - Enhanced `main_test.go` to validate failure when required environment variables are not set. - Added a function in `server.go` to print startup environment variables, ensuring visibility of configuration during server initialization.
This commit is contained in:
@@ -139,9 +139,30 @@ func TestMainProcessEnvSuccess(t *testing.T) {
|
||||
"SCRATCHBOX_STORAGE_DATA_DIR="+filepath.Join(tmp, "data"),
|
||||
"SCRATCHBOX_SECURITY_ALLOWED_IPS=",
|
||||
)
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("helper process failed: %v, output=%s", err, string(out))
|
||||
}
|
||||
if !strings.Contains(string(out), "[scratchbox] --env startup variables:") {
|
||||
t.Fatalf("helper output missing env startup header, output=%q", string(out))
|
||||
}
|
||||
if !strings.Contains(string(out), "SCRATCHBOX_SERVER_LISTEN_ADDR=127.0.0.1:0") {
|
||||
t.Fatalf("helper output missing expected env var, output=%q", string(out))
|
||||
}
|
||||
}
|
||||
|
||||
func TestMainProcessEnvWithoutScratchboxVarsFails(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cmd := exec.Command(os.Args[0], "-test.run=TestMainHelperProcess")
|
||||
cmd.Dir = repoRoot(t)
|
||||
cmd.Env = []string{
|
||||
"GO_WANT_MAIN_HELPER=1",
|
||||
"MAIN_HELPER_MODE=env-no-vars",
|
||||
}
|
||||
if err := cmd.Run(); err == nil {
|
||||
t.Fatalf("expected helper process failure when --env has no SCRATCHBOX_* vars")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServerConfigAndEnvMutuallyExclusive(t *testing.T) {
|
||||
@@ -256,6 +277,10 @@ func TestMainHelperProcess(t *testing.T) {
|
||||
os.Args = []string{"scratchbox", "server", "--env"}
|
||||
main()
|
||||
os.Exit(0)
|
||||
case "env-no-vars":
|
||||
os.Args = []string{"scratchbox", "server", "--env"}
|
||||
main()
|
||||
os.Exit(0)
|
||||
case "storage-fail":
|
||||
cfgPath := os.Getenv("MAIN_HELPER_CONFIG")
|
||||
os.Args = []string{"scratchbox", "server", "--config", cfgPath}
|
||||
|
||||
Reference in New Issue
Block a user