Skip to content

Commit 8dde9f9

Browse files
committed
Merge branch 'main' into 6724-ssh-metrics
2 parents 1858dc2 + 0c07474 commit 8dde9f9

Some content is hidden

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

62 files changed

+6651
-1551
lines changed

.github/workflows/ci.yaml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
- main
77

88
pull_request:
9-
109
workflow_dispatch:
1110

1211
permissions:
@@ -27,6 +26,9 @@ concurrency:
2726
group: ${{ github.workflow }}-${{ github.ref }}
2827
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
2928

29+
env:
30+
CODER_GO_VERSION: "~1.20"
31+
3032
jobs:
3133
lint:
3234
runs-on: ${{ github.repository_owner == 'coder' && 'ubuntu-latest-8-cores' || 'ubuntu-latest' }}
@@ -37,11 +39,11 @@ jobs:
3739
# Install Go!
3840
- uses: actions/setup-go@v4
3941
with:
40-
go-version: "~1.20"
42+
go-version: ${{ env.CODER_GO_VERSION }}
4143

4244
# Check for any typos!
4345
- name: Check for typos
44-
uses: crate-ci/typos@v1.14.9
46+
uses: crate-ci/typos@v1.14.10
4547
with:
4648
config: .github/workflows/typos.toml
4749
- name: Fix the typos
@@ -153,7 +155,7 @@ jobs:
153155
- uses: actions/setup-go@v4
154156
with:
155157
cache: false
156-
go-version: "~1.20"
158+
go-version: ${{ env.CODER_GO_VERSION }}
157159

158160
- name: Echo Go Cache Paths
159161
id: go-cache-paths
@@ -184,6 +186,8 @@ jobs:
184186
run: go install golang.org/x/tools/cmd/goimports@latest
185187
- name: Install yq
186188
run: go run github.com/mikefarah/yq/v4@v4.30.6
189+
- name: Install mockgen
190+
run: go install github.com/golang/mock/mockgen@v1.6.0
187191

188192
- name: Install Protoc
189193
run: |
@@ -254,7 +258,7 @@ jobs:
254258
- uses: actions/setup-go@v4
255259
with:
256260
cache: false
257-
go-version: "~1.20"
261+
go-version: ${{ env.CODER_GO_VERSION }}
258262

259263
- name: Echo Go Cache Paths
260264
id: go-cache-paths
@@ -343,7 +347,7 @@ jobs:
343347
- uses: actions/setup-go@v4
344348
with:
345349
cache: false
346-
go-version: "~1.20"
350+
go-version: ${{ env.CODER_GO_VERSION }}
347351

348352
- name: Echo Go Cache Paths
349353
id: go-cache-paths
@@ -435,7 +439,7 @@ jobs:
435439
- uses: actions/setup-go@v4
436440
with:
437441
cache: false
438-
go-version: "~1.20"
442+
go-version: ${{ env.CODER_GO_VERSION }}
439443

440444
- name: Echo Go Cache Paths
441445
id: go-cache-paths
@@ -587,7 +591,7 @@ jobs:
587591
- uses: actions/setup-go@v4
588592
with:
589593
cache: false
590-
go-version: "~1.20"
594+
go-version: ${{ env.CODER_GO_VERSION }}
591595

592596
- uses: hashicorp/setup-terraform@v2
593597
with:

.github/workflows/release.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ on:
66
- "v*"
77
workflow_dispatch:
88
inputs:
9+
# For some reason, setup-go won't actually pick up a new patch version if
10+
# it has an old one cached. We need to manually specify the versions so we
11+
# can get the latest release. Never use "~1.xx" here!
12+
go_version:
13+
description: "Go version to use for building."
14+
required: false
15+
default: "1.20.4"
916
dry_run:
1017
description: Perform a dry-run release (devel). Note that ref must be an annotated tag when run without dry-run.
1118
type: boolean
@@ -92,7 +99,7 @@ jobs:
9299

93100
- uses: actions/setup-go@v4
94101
with:
95-
go-version: "~1.20"
102+
go-version: ${{ inputs.go_version }}
96103

97104
- name: Cache Node
98105
id: cache-node

.github/workflows/security.yaml

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ concurrency:
1818
group: ${{ github.workflow }}-${{ github.ref }}-security
1919
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
2020

21+
env:
22+
CODER_GO_VERSION: "1.20.4"
23+
2124
jobs:
2225
codeql:
2326
runs-on: ${{ github.repository_owner == 'coder' && 'ubuntu-latest-8-cores' || 'ubuntu-latest' }}
@@ -32,18 +35,7 @@ jobs:
3235
- name: Setup Go
3336
uses: actions/setup-go@v4
3437
with:
35-
go-version: "~1.20"
36-
37-
- name: Go Cache Paths
38-
id: go-cache-paths
39-
run: |
40-
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
41-
42-
- name: Go Mod Cache
43-
uses: actions/cache@v3
44-
with:
45-
path: ${{ steps.go-cache-paths.outputs.GOMODCACHE }}
46-
key: ${{ runner.os }}-release-go-mod-${{ hashFiles('**/go.sum') }}
38+
go-version: ${{ env.CODER_GO_VERSION }}
4739

4840
# Workaround to prevent CodeQL from building the dashboard.
4941
- name: Remove Makefile
@@ -73,18 +65,7 @@ jobs:
7365

7466
- uses: actions/setup-go@v4
7567
with:
76-
go-version: "~1.20"
77-
78-
- name: Go Cache Paths
79-
id: go-cache-paths
80-
run: |
81-
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
82-
83-
- name: Go Mod Cache
84-
uses: actions/cache@v3
85-
with:
86-
path: ${{ steps.go-cache-paths.outputs.GOMODCACHE }}
87-
key: ${{ runner.os }}-release-go-mod-${{ hashFiles('**/go.sum') }}
68+
go-version: ${{ env.CODER_GO_VERSION }}
8869

8970
- name: Cache Node
9071
id: cache-node
@@ -102,6 +83,8 @@ jobs:
10283
curl -sSL https://github.com/kyleconroy/sqlc/releases/download/v1.17.2/sqlc_1.17.2_linux_amd64.tar.gz | sudo tar -C /usr/bin -xz sqlc
10384
- name: Install yq
10485
run: go run github.com/mikefarah/yq/v4@v4.30.6
86+
- name: Install mockgen
87+
run: go install github.com/golang/mock/mockgen@v1.6.0
10588
- name: Install protoc-gen-go
10689
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26
10790
- name: Install protoc-gen-go-drpc

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ lint/shellcheck: $(SHELL_SRC_FILES)
420420
gen: \
421421
coderd/database/dump.sql \
422422
coderd/database/querier.go \
423+
coderd/database/dbmock/store.go \
423424
provisionersdk/proto/provisioner.pb.go \
424425
provisionerd/proto/provisionerd.pb.go \
425426
site/src/api/typesGenerated.ts \
@@ -441,6 +442,7 @@ gen/mark-fresh:
441442
files="\
442443
coderd/database/dump.sql \
443444
coderd/database/querier.go \
445+
coderd/database/dbmock/store.go \
444446
provisionersdk/proto/provisioner.pb.go \
445447
provisionerd/proto/provisionerd.pb.go \
446448
site/src/api/typesGenerated.ts \
@@ -476,6 +478,10 @@ coderd/database/dump.sql: coderd/database/gen/dump/main.go $(wildcard coderd/dat
476478
coderd/database/querier.go: coderd/database/sqlc.yaml coderd/database/dump.sql $(wildcard coderd/database/queries/*.sql) coderd/database/gen/enum/main.go
477479
./coderd/database/generate.sh
478480

481+
482+
coderd/database/dbmock/store.go: coderd/database/db.go coderd/database/querier.go
483+
go generate ./coderd/database/dbmock/
484+
479485
provisionersdk/proto/provisioner.pb.go: provisionersdk/proto/provisioner.proto
480486
protoc \
481487
--go_out=. \

cli/agent.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,18 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
128128
_ = pprof.Handler
129129
pprofSrvClose := ServeHandler(ctx, logger, nil, pprofAddress, "pprof")
130130
defer pprofSrvClose()
131-
// Do a best effort here. If this fails, it's not a big deal.
132-
if port, err := urlPort(pprofAddress); err == nil {
131+
if port, err := extractPort(pprofAddress); err == nil {
133132
ignorePorts[port] = "pprof"
134133
}
135134

136-
// Do a best effort here. If this fails, it's not a big deal.
137-
if port, err := urlPort(prometheusAddress); err == nil {
135+
if port, err := extractPort(prometheusAddress); err == nil {
138136
ignorePorts[port] = "prometheus"
139137
}
140138

139+
if port, err := extractPort(debugAddress); err == nil {
140+
ignorePorts[port] = "debug"
141+
}
142+
141143
// exchangeToken returns a session token.
142144
// This is abstracted to allow for the same looping condition
143145
// regardless of instance identity auth type.
@@ -232,10 +234,6 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
232234

233235
debugSrvClose := ServeHandler(ctx, logger, agnt.HTTPDebug(), debugAddress, "debug")
234236
defer debugSrvClose()
235-
// Do a best effort here. If this fails, it's not a big deal.
236-
if port, err := urlPort(debugAddress); err == nil {
237-
ignorePorts[port] = "debug"
238-
}
239237

240238
<-ctx.Done()
241239
return agnt.Close()

cli/agent_internal_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ func Test_extractPort(t *testing.T) {
4646
urlString: "6060",
4747
wantErr: true,
4848
},
49+
{
50+
name: "127.0.0.1",
51+
urlString: "127.0.0.1:2113",
52+
want: 2113,
53+
wantErr: false,
54+
},
4955
}
5056
for _, tt := range tests {
5157
tt := tt

cli/server.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,12 @@ func newProvisionerDaemon(
11831183
return nil, xerrors.Errorf("mkdir %q: %w", cacheDir, err)
11841184
}
11851185

1186+
tfDir := filepath.Join(cacheDir, "terraform")
1187+
err = os.MkdirAll(tfDir, 0o700)
1188+
if err != nil {
1189+
return nil, xerrors.Errorf("mkdir terraform dir: %w", err)
1190+
}
1191+
11861192
tracer := coderAPI.TracerProvider.Tracer(tracing.TracerName)
11871193
terraformClient, terraformServer := provisionersdk.MemTransportPipe()
11881194
wg.Add(1)
@@ -1201,7 +1207,7 @@ func newProvisionerDaemon(
12011207
ServeOptions: &provisionersdk.ServeOptions{
12021208
Listener: terraformServer,
12031209
},
1204-
CachePath: cacheDir,
1210+
CachePath: tfDir,
12051211
Logger: logger,
12061212
Tracer: tracer,
12071213
})
@@ -1213,9 +1219,10 @@ func newProvisionerDaemon(
12131219
}
12141220
}()
12151221

1216-
tempDir, err := os.MkdirTemp("", "provisionerd")
1222+
workDir := filepath.Join(cacheDir, "work")
1223+
err = os.MkdirAll(workDir, 0o700)
12171224
if err != nil {
1218-
return nil, err
1225+
return nil, xerrors.Errorf("mkdir work dir: %w", err)
12191226
}
12201227

12211228
provisioners := provisionerd.Provisioners{
@@ -1259,7 +1266,7 @@ func newProvisionerDaemon(
12591266
UpdateInterval: time.Second,
12601267
ForceCancelInterval: cfg.Provisioner.ForceCancelInterval.Value(),
12611268
Provisioners: provisioners,
1262-
WorkDirectory: tempDir,
1269+
WorkDirectory: workDir,
12631270
TracerProvider: coderAPI.TracerProvider,
12641271
Metrics: &metrics,
12651272
}), nil

cli/templatedelete_test.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,13 @@ func TestTemplateDelete(t *testing.T) {
5151

5252
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
5353
user := coderdtest.CreateFirstUser(t, client)
54-
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
55-
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
56-
templates := []codersdk.Template{
57-
coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID),
58-
coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID),
59-
coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID),
60-
}
54+
templates := []codersdk.Template{}
6155
templateNames := []string{}
62-
for _, template := range templates {
56+
for i := 0; i < 3; i++ {
57+
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
58+
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
59+
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
60+
templates = append(templates, template)
6361
templateNames = append(templateNames, template.Name)
6462
}
6563

@@ -78,15 +76,13 @@ func TestTemplateDelete(t *testing.T) {
7876

7977
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
8078
user := coderdtest.CreateFirstUser(t, client)
81-
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
82-
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
83-
templates := []codersdk.Template{
84-
coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID),
85-
coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID),
86-
coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID),
87-
}
79+
templates := []codersdk.Template{}
8880
templateNames := []string{}
89-
for _, template := range templates {
81+
for i := 0; i < 3; i++ {
82+
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
83+
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
84+
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
85+
templates = append(templates, template)
9086
templateNames = append(templateNames, template.Name)
9187
}
9288

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)