10000 Merge branch 'main' into dean/rpc-version-rework · coder/coder@54dd615 · GitHub
[go: up one dir, main page]

Skip to content

Commit 54dd615

Browse files
committed
Merge branch 'main' into dean/rpc-version-rework
2 parents ccb1ad0 + c8c8e50 commit 54dd615

File tree

102 files changed

+3769
-2693
lines changed

Some content is hidden

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

102 files changed

+3769
-2693
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: "Setup ImDisk"
2+
if: runner.os == 'Windows'
3+
description: |
4+
Sets up the ImDisk toolkit for Windows and creates a RAM disk on drive R:.
5+
runs:
6+
using: "composite"
7+
steps:
8+
- name: Download ImDisk
9+
if: runner.os == 'Windows'
10+
shell: bash
11+
run: |
12+
mkdir imdisk
13+
cd imdisk
14+
curl -L -o files.cab https://github.com/coder/imdisk-artifacts/raw/92a17839ebc0ee3e69be019f66b3e9b5d2de4482/files.cab
15+
curl -L -o install.bat https://github.com/coder/imdisk-artifacts/raw/92a17839ebc0ee3e69be019f66b3e9b5d2de4482/install.bat
16+
cd ..
17+
18+
- name: Install ImDisk
19+
shell: cmd
20+
run: |
21+
cd imdisk
22+
install.bat /silent
23+
24+
- name: Create RAM Disk
25+
shell: cmd
26+
run: |
27+
imdisk -a -s 4096M -m R: -p "/fs:ntfs /q /y"

.github/workflows/ci.yaml

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,15 +370,20 @@ jobs:
370370
api-key: ${{ secrets.DATADOG_API_KEY }}
371371

372372
test-go-pg:
373-
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-latest' }}
374-
needs:
375-
- changes
373+
runs-on: ${{ matrix.os == 'ubuntu-latest' && github.repository_owner == 'coder' && 'depot-ubuntu-22.04-4' || matrix.os == 'macos-latest' && github.repository_owner == 'coder' && 'macos-latest-xlarge' || matrix.os == 'windows-2022' && github.repository_owner == 'coder' && 'windows-latest-16-cores' || matrix.os }}
374+
needs: changes
376375
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
377376
# This timeout must be greater than the timeout set by `go test` in
378377
# `make test-postgres` to ensure we receive a trace of running
379378
# goroutines. Setting this to the timeout +5m should work quite well
380379
# even if some of the preceding steps are slow.
381380
timeout-minutes: 25
381+
strategy:
382+
matrix:
383+
os:
384+
- ubuntu-latest
385+
- macos-latest
386+
- windows-2022
382387
steps:
383388
- name: Harden Runner
384389
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
@@ -396,12 +401,46 @@ jobs:
396401
- name: Setup Terraform
397402
uses: ./.github/actions/setup-tf
398403

404+
# Sets up the ImDisk toolkit for Windows and creates a RAM disk on drive R:.
405+
- name: Setup ImDisk
406+
if: runner.os == 'Windows'
407+
uses: ./.github/actions/setup-imdisk
408+
399409
- name: Test with PostgreSQL Database
400410
env:
401411
POSTGRES_VERSION: "13"
402412
TS_DEBUG_DISCO: "true"
413+
shell: bash
403414
run: |
404-
make test-postgres
415+
# if macOS, install google-chrome for scaletests
416+
# As another concern, should we really have this kind of external dependency
417+
# requirement on standard CI?
418+
if [ "${{ matrix.os }}" == "macos-latest" ]; then
419+
brew install google-chrome
420+
fi
421+
422+
# By default Go will use the number of logical CPUs, which
423+
# is a fine default.
424+
PARALLEL_FLAG=""
425+
426+
# macOS will output "The default interactive shell is now zsh"
427+
# intermittently in CI...
428+
if [ "${{ matrix.os }}" == "macos-latest" ]; then
429+
touch ~/.bash_profile && echo "export BASH_SILENCE_DEPRECATION_WARNING=1" >> ~/.bash_profile
430+
fi
431+
432+
if [ "${{ runner.os }}" == "Linux" ]; then
433+
make test-postgres
434+
elif [ "${{ runner.os }}" == "Windows" ]; then
435+
# Create a temp dir on the R: ramdisk drive for Windows. The default
436+
# C: drive is extremely slow: https://github.com/actions/runner-images/issues/8755
437+
mkdir -p "R:/temp/embedded-pg"
438+
go run scripts/embedded-pg/main.go -path "R:/temp/embedded-pg"
439+
DB=ci gotestsum --format standard-quiet -- -v -short -count=1 ./...
440+
else
441+
go run scripts/embedded-pg/main.go
442+
DB=ci gotestsum --format standard-quiet -- -v -short -count=1 ./...
443+
fi
405444
406445
- name: Upload test stats to Datadog
407446
timeout-minutes: 1
@@ -494,6 +533,47 @@ jobs:
494533
with:
495534
api-key: ${{ secrets.DATADOG_API_KEY }}
496535

536+
test-go-race-pg:
537+
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-16' || 'ubuntu-latest' }}
538+
needs: changes
539+
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
540+
timeout-minutes: 25
541+
steps:
542+
- name: Harden Runner
543+
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
544+
with:
545+
egress-policy: audit
546+
547+
- name: Checkout
548+
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
549+
with:
550+
fetch-depth: 1
551+
552+
- name: Setup Go
553+
uses: ./.github/actions/setup-go
554+
555+
- name: Setup Terraform
556+
uses: ./.github/actions/setup-tf
557+
558+
# We run race tests with reduced parallelism because they use more CPU and we were finding
559+
# instances where tests appear to hang for multiple seconds, resulting in flaky tests when
560+
# short timeouts are used.
561+
# c.f. discussion on https://github.com/coder/coder/pull/15106
562+
- name: Run Tests
563+
env:
564+
POSTGRES_VERSION: "16"
565+
run: |
566+
make test-postgres-docker
567+
DB=ci gotestsum --junitfile="gotests.xml" -- -race -parallel 4 -p 4 ./...
568+
569+
- name: Upload test stats to Datadog
570+
timeout-minutes: 1
571+
continue-on-error: true
572+
uses: ./.github/actions/upload-datadog
573+
if: always()
574+
with:
575+
api-key: ${{ secrets.DATADOG_API_KEY }}
576+
497577
# Tailnet integration tests only run when the `tailnet` directory or `go.sum`
498578
# and `go.mod` are changed. These tests are to ensure we don't add regressions
499579
# to tailnet, either due to our code or due to updating dependencies.
@@ -771,6 +851,7 @@ jobs:
771851
- test-go
772852
- test-go-pg
773853
- test-go-race
854+
- test-go-race-pg
774855
- test-js
775856
- test-e2e
776857
- offlinedocs
@@ -793,6 +874,7 @@ jobs:
793874
echo "- test-go: ${{ needs.test-go.result }}"
794875
echo "- test-go-pg: ${{ needs.test-go-pg.result }}"
795876
echo "- test-go-race: ${{ needs.test-go-race.result }}"
877+
echo "- test-go-race-pg: ${{ needs.test-go-race-pg.result }}"
796878
echo "- test-js: ${{ needs.test-js.result }}"
797879
echo "- test-e2e: ${{ needs.test-e2e.result }}"
798880
echo "- offlinedocs: ${{ needs.offlinedocs.result }}"

cli/cliutil/provisionerwarn.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package cliutil
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"io"
7+
"strings"
8+
9+
"github.com/coder/coder/v2/cli/cliui"
10+
"github.com/coder/coder/v2/codersdk"
11+
)
12+
13+
var (
14+
warnNoMatchedProvisioners = `Your build has been enqueued, but there are no provisioners that accept the required tags. Once a compatible provisioner becomes available, your build will continue. Please contact your administrator.
15+
Details:
16+
Provisioner job ID : %s
17+
Requested tags : %s
18+
`
19+
warnNoAvailableProvisioners = `Provisioners that accept the required tags have not responded for longer than expected. This may delay your build. Please contact your administrator if your build does not complete.
20+
Details:
21+
Provisioner job ID : %s
22+
Requested tags : %s
23+
Most recently seen : %s
24+
`
25+
)
26+
27+
// WarnMatchedProvisioners warns the user if there are no provisioners that
28+
// match the requested tags for a given provisioner job.
29+
// If the job is not pending, it is ignored.
30+
func WarnMatchedProvisioners(w io.Writer, mp *codersdk.MatchedProvisioners, job codersdk.ProvisionerJob) {
31+
if mp == nil {
32+
// Nothing in the response, nothing to do here!
33+
return
34+
}
35+
if job.Status != codersdk.ProvisionerJobPending {
36+
// Only warn if the job is pending.
37+
return
38+
}
39+
var tagsJSON strings.Builder
40+
if err := json.NewEncoder(&tagsJSON).Encode(job.Tags); err != nil {
41+
// Fall back to the less-pretty string representation.
42+
tagsJSON.Reset()
43+
_, _ = tagsJSON.WriteString(fmt.Sprintf("%v", job.Tags))
44+
}
45+
if mp.Count == 0 {
46+
cliui.Warnf(w, warnNoMatchedProvisioners, job.ID, tagsJSON.String())
47+
return
48+
}
49+
if mp.Available == 0 {
50+
cliui.Warnf(w, warnNoAvailableProvisioners, job.ID, strings.TrimSpace(tagsJSON.String()), mp.MostRecentlySeen.Time)
51+
return
52+
}
53+
}

cli/cliutil/provisionerwarn_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package cliutil_test
2+
3+
import (
4+
"strings"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
9+
"github.com/coder/coder/v2/cli/cliutil"
10+
"github.com/coder/coder/v2/codersdk"
11+
)
12+
13+
func TestWarnMatchedProvisioners(t *testing.T) {
14+
t.Parallel()
15+
16+
for _, tt := range []struct {
17+
name string
18+
mp *codersdk.MatchedProvisioners
19+
job codersdk.ProvisionerJob
20+
expect string
21+
}{
22+
{
23+
name: "no_match",
24+
mp: &codersdk.MatchedProvisioners{
25+
Count: 0,
26+
Available: 0,
27+
},
28+
job: codersdk.ProvisionerJob{
29+
Status: codersdk.ProvisionerJobPending,
30+
},
31+
expect: `there are no provisioners that accept the required tags`,
32+
},
33+
{
34+
name: "no_available",
35+
mp: &codersdk.MatchedProvisioners{
36+
Count: 1,
37+
Available: 0,
38+
},
39+
job: codersdk.ProvisionerJob{
40+
Status: codersdk.ProvisionerJobPending,
41+
},
42+
expect: `Provisioners that accept the required tags have not responded for longer than expected`,
43+
},
44+
{
45+
name: "match",
46+
mp: &codersdk.MatchedProvisioners{
47+
Count: 1,
48+
Available: 1,
49+
},
50+
job: codersdk.ProvisionerJob{
51+
Status: codersdk.ProvisionerJobPending,
52+
},
53+
},
54< 97AE /td>+
{
55+
name: "not_pending",
56+
mp: &codersdk.MatchedProvisioners{},
57+
job: codersdk.ProvisionerJob{
58+
Status: codersdk.ProvisionerJobRunning,
59+
},
60+
},
61+
} {
62+
tt := tt
63+
t.Run(tt.name, func(t *testing.T) {
64+
t.Parallel()
65+
var w strings.Builder
66+
cliutil.WarnMatchedProvisioners(&w, tt.mp, tt.job)
67+
if tt.expect != "" {
68+
require.Contains(t, w.String(), tt.expect)
69+
} else {
70+
require.Empty(t, w.String())
71+
}
72+
})
73+
}
74+
}

cli/create.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/coder/pretty"
1515

1616
"github.com/coder/coder/v2/cli/cliui"
17+
"github.com/coder/coder/v2/cli/cliutil"
1718
"github.com/coder/coder/v2/coderd/util/ptr"
1819
"github.com/coder/coder/v2/coderd/util/slice"
1920
"github.com/coder/coder/v2/codersdk"
@@ -289,7 +290,7 @@ func (r *RootCmd) create() *serpent.Command {
289290
ttlMillis = ptr.Ref(stopAfter.Milliseconds())
290291
}
291292

292-
workspace, err := client.CreateWorkspace(inv.Context(), template.OrganizationID, workspaceOwner, codersdk.CreateWorkspaceRequest{
293+
workspace, err := client.CreateUserWorkspace(inv.Context(), workspaceOwner, codersdk.CreateWorkspaceRequest{
293294
TemplateVersionID: templateVersionID,
294295
Name: workspaceName,
295296
AutostartSchedule: schedSpec,
@@ -301,6 +302,8 @@ func (r *RootCmd) create() *serpent.Command {
301302
return xerrors.Errorf("create workspace: %w", err)
302303
}
303304

305+
cliutil.WarnMatchedProvisioners(inv.Stderr, workspace.LatestBuild.MatchedProvisioners, workspace.LatestBuild.Job)
306+
304307
err = cliui.WorkspaceBuild(inv.Context(), inv.Stdout, client, workspace.LatestBuild.ID)
305308
if err != nil {
306309
return xerrors.Errorf("watch build: %w", err)
@@ -433,6 +436,12 @@ func prepWorkspaceBuild(inv *serpent.Invocation, client *codersdk.Client, args p
433436
if err != nil {
434437
return nil, xerrors.Errorf("begin workspace dry-run: %w", err)
435438
}
439+
440+
matchedProvisioners, err := client.TemplateVersionDryRunMatchedProvisioners(inv.Context(), templateVersion.ID, dryRun.ID)
441+
if err != nil {
442+
return nil, xerrors.Errorf("get matched provisioners: %w", err)
443+
}
444+
cliutil.WarnMatchedProvisioners(inv.Stdout, &matchedProvisioners, dryRun)
436445
_, _ = fmt.Fprintln(inv.Stdout, "Planning workspace...")
437446
err = cliui.ProvisionerJob(inv.Context(), inv.Stdout, cliui.ProvisionerJobOptions{
438447
Fetch: func() (codersdk.ProvisionerJob, error) {

cli/delete.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"time"
66

77
"github.com/coder/coder/v2/cli/cliui"
8+
"github.com/coder/coder/v2/cli/cliutil"
89
"github.com/coder/coder/v2/codersdk"
910
"github.com/coder/serpent"
1011
)
@@ -55,6 +56,7 @@ func (r *RootCmd) deleteWorkspace() *serpent.Command {
5556
if err != nil {
5657
return err
5758
}
59+
cliutil.WarnMatchedProvisioners(inv.Stdout, build.MatchedProvisioners, build.Job)
5860

5961
err = cliui.WorkspaceBuild(inv.Context(), inv.Stdout, client, build.ID)
6062
if err != nil {

0 commit comments

Comments
 (0)
0