Skip to content

Commit 7b56862

Browse files
committed
Merge branch 'main' of https://github.com/coder/coder into spike/8243-helm-ext-provisioner
2 parents bec7eb9 + b2a8446 commit 7b56862

File tree

75 files changed

+1707
-531
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1707
-531
lines changed

.github/actions/setup-go/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: |
44
inputs:
55
version:
66
description: "The Go version to use."
7-
default: "1.20.6"
7+
default: "1.20.7"
88
runs:
99
using: "composite"
1010
steps:

.github/workflows/ci.yaml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ jobs:
137137
138138
# Check for any typos
139139
- name: Check for typos
140-
uses: crate-ci/typos@v1.16.1
140+
uses: crate-ci/typos@v1.16.2
141141
with:
142142
config: .github/workflows/typos.toml
143143

@@ -224,7 +224,7 @@ jobs:
224224
with:
225225
# This doesn't need caching. It's super fast anyways!
226226
cache: false
227-
go-version: 1.20.6
227+
go-version: 1.20.7
228228

229229
- name: Install shfmt
230230
run: go install mvdan.cc/sh/v3/cmd/shfmt@v3.5.0
@@ -724,6 +724,7 @@ jobs:
724724
password: ${{ secrets.GITHUB_TOKEN }}
725725

726726
- name: Build and push Linux amd64 Docker image
727+
id: build_and_push
727728
run: |
728729
set -euxo pipefail
729730
go mod download
@@ -738,3 +739,19 @@ jobs:
738739
--version $version \
739740
--push \
740741
build/coder_linux_amd64
742+
743+
# Tag image with new package tag and push
744+
tag=$(echo "$version" | sed 's/+/-/g')
745+
docker tag ghcr.io/coder/coder-preview:main ghcr.io/coder/coder-preview:main-$tag
746+
docker push ghcr.io/coder/coder-preview:main-$tag
747+
748+
- name: Prune old images
749+
uses: vlaurin/action-ghcr-prune@v0.5.0
750+
with:
751+
token: ${{ secrets.GITHUB_TOKEN }}
752+
organization: coder
753+
container: coder-preview
754+
keep-younger-than: 7 # days
755+
keep-tags-regexes: ^pr
756+
prune-tags-regexes: ^main-
757+
prune-untagged: true

.github/workflows/release.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ env:
2828
# https://github.blog/changelog/2022-06-10-github-actions-inputs-unified-across-manual-and-reusable-workflows/
2929
CODER_RELEASE: ${{ !inputs.dry_run }}
3030
CODER_DRY_RUN: ${{ inputs.dry_run }}
31-
# For some reason, setup-go won't actually pick up a new patch version if
32-
# it has an old one cached. We need to manually specify the versions so we
33-
# can get the latest release. Never use "~1.xx" here!
34-
CODER_GO_VERSION: "1.20.6"
3531

3632
jobs:
3733
release:

.github/workflows/security.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ concurrency:
2121
group: ${{ github.workflow }}-${{ github.ref }}-security
2222
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
2323

24-
env:
25-
CODER_GO_VERSION: "1.20.6"
26-
2724
jobs:
2825
codeql:
2926
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}

cli/delete.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,19 @@ func (r *RootCmd) deleteWorkspace() *clibase.Cmd {
2222
r.InitClient(client),
2323
),
2424
Handler: func(inv *clibase.Invocation) error {
25-
_, err := cliui.Prompt(inv, cliui.PromptOptions{
26-
Text: "Confirm delete workspace?",
27-
IsConfirm: true,
28-
Default: cliui.ConfirmNo,
29-
})
25+
workspace, err := namedWorkspace(inv.Context(), client, inv.Args[0])
3026
if err != nil {
3127
return err
3228
}
3329

34-
workspace, err := namedWorkspace(inv.Context(), client, inv.Args[0])
30+
sinceLastUsed := time.Since(workspace.LastUsedAt)
31+
cliui.Infof(inv.Stderr, "%v was last used %.0f days ago", workspace.FullName(), sinceLastUsed.Hours()/24)
32+
33+
_, err = cliui.Prompt(inv, cliui.PromptOptions{
34+
Text: "Confirm delete workspace?",
35+
IsConfirm: true,
36+
Default: cliui.ConfirmNo,
37+
})
3538
if err != nil {
3639
return err
3740
}
@@ -51,7 +54,7 @@ func (r *RootCmd) deleteWorkspace() *clibase.Cmd {
5154
return err
5255
}
5356

54-
_, _ = fmt.Fprintf(inv.Stdout, "\nThe %s workspace has been deleted at %s!\n", cliui.DefaultStyles.Keyword.Render(workspace.Name), cliui.DefaultStyles.DateTimeStamp.Render(time.Now().Format(time.Stamp)))
57+
_, _ = fmt.Fprintf(inv.Stdout, "\n%s has been deleted at %s!\n", cliui.DefaultStyles.Keyword.Render(workspace.FullName()), cliui.DefaultStyles.DateTimeStamp.Render(time.Now().Format(time.Stamp)))
5558
return nil
5659
},
5760
}

cli/delete_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestDelete(t *testing.T) {
4141
assert.ErrorIs(t, err, io.EOF)
4242
}
4343
}()
44-
pty.ExpectMatch("workspace has been deleted")
44+
pty.ExpectMatch("has been deleted")
4545
<-doneChan
4646
})
4747

@@ -68,7 +68,7 @@ func TestDelete(t *testing.T) {
6868
assert.ErrorIs(t, err, io.EOF)
6969
}
7070
}()
71-
pty.ExpectMatch("workspace has been deleted")
71+
pty.ExpectMatch("has been deleted")
7272
<-doneChan
7373
})
7474

@@ -113,7 +113,7 @@ func TestDelete(t *testing.T) {
113113
assert.ErrorIs(t, err, io.EOF)
114114
}
115115
}()
116-
pty.ExpectMatch("workspace has been deleted")
116+
pty.ExpectMatch("has been deleted")
117117
<-doneChan
118118
})
119119

@@ -145,7 +145,7 @@ func TestDelete(t *testing.T) {
145145
}
146146
}()
147147

148-
pty.ExpectMatch("workspace has been deleted")
148+
pty.ExpectMatch("has been deleted")
149149
<-doneChan
150150

151151
workspace, err = client.Workspace(context.Background(), workspace.ID)

cli/exp_scaletest_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cli_test
22

33
import (
4-
"bytes"
54
"context"
65
"path/filepath"
76
"testing"
@@ -72,9 +71,10 @@ func TestScaleTestWorkspaceTraffic(t *testing.T) {
7271
"--ssh",
7372
)
7473
clitest.SetupConfig(t, client, root)
75-
var stdout, stderr bytes.Buffer
76-
inv.Stdout = &stdout
77-
inv.Stderr = &stderr
74+
pty := ptytest.New(t)
75+
inv.Stdout = pty.Output()
76+
inv.Stderr = pty.Output()
77+
7878
err := inv.WithContext(ctx).Run()
7979
require.ErrorContains(t, err, "no scaletest workspaces exist")
8080
}
@@ -98,9 +98,10 @@ func TestScaleTestDashboard(t *testing.T) {
9898
"--scaletest-prometheus-wait", "0s",
9999
)
100100
clitest.SetupConfig(t, client, root)
101-
var stdout, stderr bytes.Buffer
102-
inv.Stdout = &stdout
103-
inv.Stderr = &stderr
101+
pty := ptytest.New(t)
102+
inv.Stdout = pty.Output()
103+
inv.Stderr = pty.Output()
104+
104105
err := inv.WithContext(ctx).Run()
105106
require.NoError(t, err, "")
106107
}

cli/root_internal_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package cli
22

33
import (
4+
"os"
5+
"runtime"
46
"testing"
57

68
"github.com/stretchr/testify/require"
@@ -67,6 +69,11 @@ func Test_formatExamples(t *testing.T) {
6769
}
6870

6971
func TestMain(m *testing.M) {
72+
if runtime.GOOS == "windows" {
73+
// Don't run goleak on windows tests, they're super flaky right now.
74+
// See: https://github.com/coder/coder/issues/8954
75+
os.Exit(m.Run())
76+
}
7077
goleak.VerifyTestMain(m,
7178
// The lumberjack library is used by by agent and seems to leave
7279
// goroutines after Close(), fails TestGitSSH tests.

cli/server.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import (
6363
"github.com/coder/coder/cli/config"
6464
"github.com/coder/coder/coderd"
6565
"github.com/coder/coder/coderd/autobuild"
66+
"github.com/coder/coder/coderd/batchstats"
6667
"github.com/coder/coder/coderd/database"
6768
"github.com/coder/coder/coderd/database/dbfake"
6869
"github.com/coder/coder/coderd/database/dbmetrics"
@@ -813,6 +814,16 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
813814
options.SwaggerEndpoint = cfg.Swagger.Enable.Value()
814815
}
815816

817+
batcher, closeBatcher, err := batchstats.New(ctx,
818+
batchstats.WithLogger(options.Logger.Named("batchstats")),
819+
batchstats.WithStore(options.Database),
820+
)
821+
if err != nil {
822+
return xerrors.Errorf("failed to create agent stats batcher: %w", err)
823+
}
824+
options.StatsBatcher = batcher
825+
defer closeBatcher()
826+
816827
closeCheckInactiveUsersFunc := dormancy.CheckInactiveUsers(ctx, logger, options.Database)
817828
defer closeCheckInactiveUsersFunc()
818829

cli/stat.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,16 @@ func (*RootCmd) statDisk(s *clistat.Statter) *clibase.Cmd {
233233
},
234234
Handler: func(inv *clibase.Invocation) error {
235235
pfx := clistat.ParsePrefix(prefixArg)
236+
// Users may also call `coder stat disk <path>`.
237+
if len(inv.Args) > 0 {
238+
pathArg = inv.Args[0]
239+
}
236240
ds, err := s.Disk(pfx, pathArg)
237241
if err != nil {
242+
if os.IsNotExist(err) {
243+
//nolint:gocritic // fmt.Errorf produces a more concise error.
244+
return fmt.Errorf("not found: %q", pathArg)
245+
}
238246
return err
239247
}
240248

cli/stat_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestStatCPUCmd(t *testing.T) {
7474
t.Parallel()
7575
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
7676
t.Cleanup(cancel)
77-
inv, _ := clitest.New(t, "stat", "cpu", "--output=text")
77+
inv, _ := clitest.New(t, "stat", "cpu", "--output=text", "--host")
7878
buf := new(bytes.Buffer)
7979
inv.Stdout = buf
8080
err := inv.WithContext(ctx).Run()
@@ -87,7 +87,7 @@ func TestStatCPUCmd(t *testing.T) {
8787
t.Parallel()
8888
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
8989
t.Cleanup(cancel)
90-
inv, _ := clitest.New(t, "stat", "cpu", "--output=json")
90+
inv, _ := clitest.New(t, "stat", "cpu", "--output=json", "--host")
9191
buf := new(bytes.Buffer)
9292
inv.Stdout = buf
9393
err := inv.WithContext(ctx).Run()
@@ -170,4 +170,16 @@ func TestStatDiskCmd(t *testing.T) {
170170
require.NotZero(t, *tmp.Total)
171171
require.Equal(t, "B", tmp.Unit)
172172
})
173+
174+
t.Run("PosArg", func(t *testing.T) {
175+
t.Parallel()
176+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
177+
t.Cleanup(cancel)
178+
inv, _ := clitest.New(t, "stat", "disk", "/this/path/does/not/exist", "--output=text")
179+
buf := new(bytes.Buffer)
180+
inv.Stdout = buf
181+
err := inv.WithContext(ctx).Run()
182+
require.Error(t, err)
183+
require.Contains(t, err.Error(), `not found: "/this/path/does/not/exist"`)
184+
})
173185
}

coderd/apidoc/docs.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)