Skip to content

Commit 80265f8

Browse files
committed
Revert "fix: add preExec to Run (#368)"
This reverts commit 481e3a9.
1 parent 481e3a9 commit 80265f8

File tree

3 files changed

+2
-84
lines changed

3 files changed

+2
-84
lines changed

Diff for: cmd/envbuilder/main.go

+1-11
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ func envbuilderCmd() serpent.Command {
3737
Options: o.CLI(),
3838
Handler: func(inv *serpent.Invocation) error {
3939
o.SetDefaults()
40-
var preExec []func()
41-
defer func() { // Ensure cleanup in case of error.
42-
for _, fn := range preExec {
43-
fn()
44-
}
45-
}()
4640
o.Logger = log.New(os.Stderr, o.Verbose)
4741
if o.CoderAgentURL != "" {
4842
if o.CoderAgentToken == "" {
@@ -56,10 +50,6 @@ func envbuilderCmd() serpent.Command {
5650
if err == nil {
5751
o.Logger = log.Wrap(o.Logger, coderLog)
5852
defer closeLogs()
59-
preExec = append(preExec, func() {
60-
o.Logger(log.LevelInfo, "Closing logs")
61-
closeLogs()
62-
})
6353
// This adds the envbuilder subsystem.
6454
// If telemetry is enabled in a Coder deployment,
6555
// this will be reported and help us understand
@@ -88,7 +78,7 @@ func envbuilderCmd() serpent.Command {
8878
return nil
8979
}
9080

91-
err := envbuilder.Run(inv.Context(), o, preExec...)
81+
err := envbuilder.Run(inv.Context(), o)
9282
if err != nil {
9383
o.Logger(log.LevelError, "error: %s", err)
9484
}

Diff for: envbuilder.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ type execArgsInfo struct {
8484
// Logger is the logf to use for all operations.
8585
// Filesystem is the filesystem to use for all operations.
8686
// Defaults to the host filesystem.
87-
// preExec are any functions that should be called before exec'ing the init
88-
// command. This is useful for ensuring that defers get run.
89-
func Run(ctx context.Context, opts options.Options, preExec ...func()) error {
87+
func Run(ctx context.Context, opts options.Options) error {
9088
var args execArgsInfo
9189
// Run in a separate function to ensure all defers run before we
9290
// setuid or exec.
@@ -105,9 +103,6 @@ func Run(ctx context.Context, opts options.Options, preExec ...func()) error {
105103
}
106104

107105
opts.Logger(log.LevelInfo, "=== Running the init command %s %+v as the %q user...", opts.InitCommand, args.InitArgs, args.UserInfo.user.Username)
108-
for _, fn := range preExec {
109-
fn()
110-
}
111106

112107
err = syscall.Exec(args.InitCommand, append([]string{args.InitCommand}, args.InitArgs...), args.Environ)
113108
if err != nil {

Diff for: integration/integration_test.go

-67
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import (
2323
"testing"
2424
"time"
2525

26-
"github.com/coder/coder/v2/codersdk"
27-
"github.com/coder/coder/v2/codersdk/agentsdk"
2826
"github.com/coder/envbuilder"
2927
"github.com/coder/envbuilder/devcontainer/features"
3028
"github.com/coder/envbuilder/internal/magicdir"
@@ -60,71 +58,6 @@ const (
6058
testImageUbuntu = "localhost:5000/envbuilder-test-ubuntu:latest"
6159
)
6260

63-
func TestLogs(t *testing.T) {
64-
t.Parallel()
65-
66-
token := uuid.NewString()
67-
logsDone := make(chan struct{})
68-
69-
logHandler := func(w http.ResponseWriter, r *http.Request) {
70-
switch r.URL.Path {
71-
case "/api/v2/buildinfo":
72-
w.Header().Set("Content-Type", "application/json")
73-
_, _ = w.Write([]byte(`{"version": "v2.8.9"}`))
74-
return
75-
case "/api/v2/workspaceagents/me/logs":
76-
w.WriteHeader(http.StatusOK)
77-
tokHdr := r.Header.Get(codersdk.SessionTokenHeader)
78-
assert.Equal(t, token, tokHdr)
79-
var req agentsdk.PatchLogs
80-
err := json.NewDecoder(r.Body).Decode(&req)
81-
if err != nil {
82-
http.Error(w, err.Error(), http.StatusBadRequest)
83-
return
84-
}
85-
for _, log := range req.Logs {
86-
t.Logf("got log: %+v", log)
87-
if strings.Contains(log.Output, "Closing logs") {
88-
close(logsDone)
89-
return
90-
}
91-
}
92-
return
93-
default:
94-
t.Errorf("unexpected request to %s", r.URL.Path)
95-
w.WriteHeader(http.StatusNotFound)
96-
return
97-
}
98-
}
99-
logSrv := httptest.NewServer(http.HandlerFunc(logHandler))
100-
defer logSrv.Close()
101-
102-
// Ensures that a Git repository with a devcontainer.json is cloned and built.
103-
srv := gittest.CreateGitServer(t, gittest.Options{
104-
Files: map[string]string{
105-
"devcontainer.json": `{
106-
"build": {
107-
"dockerfile": "Dockerfile"
108-
},
109-
}`,
110-
"Dockerfile": fmt.Sprintf(`FROM %s`, testImageUbuntu),
111-
},
112-
})
113-
_, err := runEnvbuilder(t, runOpts{env: []string{
114-
envbuilderEnv("GIT_URL", srv.URL),
115-
"CODER_AGENT_URL=" + logSrv.URL,
116-
"CODER_AGENT_TOKEN=" + token,
117-
}})
118-
require.NoError(t, err)
119-
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
120-
defer cancel()
121-
select {
122-
case <-ctx.Done():
123-
t.Fatal("timed out waiting for logs")
124-
case <-logsDone:
125-
}
126-
}
127-
12861
func TestInitScriptInitCommand(t *testing.T) {
12962
t.Parallel()
13063

0 commit comments

Comments
 (0)