Skip to content

ci: use big runners #4990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use central tmp dir in agent
  • Loading branch information
kylecarbs committed Nov 13, 2022
commit 0144c63e6c8ee01481be3a789c152fca02af86fe
12 changes: 7 additions & 5 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const (

type Options struct {
Filesystem afero.Fs
TempDir string
ExchangeToken func(ctx context.Context) (string, error)
Client Client
ReconnectingPTYTimeout time.Duration
Expand All @@ -78,6 +79,9 @@ func New(options Options) io.Closer {
if options.Filesystem == nil {
options.Filesystem = afero.NewOsFs()
}
if options.TempDir == "" {
options.TempDir = os.TempDir()
}
if options.ExchangeToken == nil {
options.ExchangeToken = func(ctx context.Context) (string, error) {
return "", nil
Expand All @@ -93,6 +97,7 @@ func New(options Options) io.Closer {
client: options.Client,
exchangeToken: options.ExchangeToken,
filesystem: options.Filesystem,
tempDir: options.TempDir,
stats: &Stats{},
}
server.init(ctx)
Expand All @@ -104,6 +109,7 @@ type agent struct {
client Client
exchangeToken func(ctx context.Context) (string, error)
filesystem afero.Fs
tempDir string

reconnectingPTYs sync.Map
reconnectingPTYTimeout time.Duration
Expand Down Expand Up @@ -376,11 +382,7 @@ func (a *agent) runStartupScript(ctx context.Context, script string) error {
}

a.logger.Info(ctx, "running startup script", slog.F("script", script))
tempDir, err := afero.TempDir(a.filesystem, "", "")
if err != nil {
return xerrors.Errorf("create temp dir: %w", err)
}
writer, err := a.filesystem.OpenFile(filepath.Join(tempDir, "coder-startup-script.log"), os.O_CREATE|os.O_RDWR, 0o600)
writer, err := a.filesystem.OpenFile(filepath.Join(a.tempDir, "coder-startup-script.log"), os.O_CREATE|os.O_RDWR, 0o600)
if err != nil {
return xerrors.Errorf("open startup script log file: %w", err)
}
Expand Down
15 changes: 7 additions & 8 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,21 +360,20 @@ func TestAgent(t *testing.T) {

t.Run("StartupScript", func(t *testing.T) {
t.Parallel()
tempPath := filepath.Join(t.TempDir(), "content.txt")
content := "hello"
setupAgent(t, codersdk.WorkspaceAgentMetadata{
StartupScript: "echo " + content + " > " + tempPath,
content := "some output"
_, _, fs := setupAgent(t, codersdk.WorkspaceAgentMetadata{
StartupScript: "echo " + content,
}, 0)

var gotContent string
require.Eventually(t, func() bool {
content, err := os.ReadFile(tempPath)
outputPath := filepath.Join(os.TempDir(), "coder-startup-script.log")
content, err := afero.ReadFile(fs, outputPath)
if err != nil {
t.Logf("read file %q: %s", tempPath, err)
t.Logf("read file %q: %s", outputPath, err)
return false
}
if len(content) == 0 {
t.Logf("no content in %q", tempPath)
t.Logf("no content in %q", outputPath)
return false
}
if runtime.GOOS == "windows" {
Expand Down