Skip to content

Commit 6c896ca

Browse files
committed
Merge branch 'main' into nixdev
2 parents b0f34cb + 9caa4cf commit 6c896ca

File tree

165 files changed

+21325
-1095
lines changed

Some content is hidden

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

165 files changed

+21325
-1095
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ runs:
77
- name: Setup sqlc
88
uses: sqlc-dev/setup-sqlc@v3
99
with:
10-
sqlc-version: "1.19.1"
10+
sqlc-version: "1.20.0"

.github/workflows/ci.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ name: ci
22

33
on:
44
push:
5+
branches:
6+
- main
7+
8+
pull_request:
59
workflow_dispatch:
610

711
permissions:
@@ -43,7 +47,6 @@ jobs:
4347
uses: dorny/paths-filter@v2
4448
id: filter
4549
with:
46-
base: ${{ github.ref }}
4750
filters: |
4851
all:
4952
- "**"
@@ -134,7 +137,7 @@ jobs:
134137
135138
# Check for any typos
136139
- name: Check for typos
137-
uses: crate-ci/typos@v1.16.2
140+
uses: crate-ci/typos@v1.16.4
138141
with:
139142
config: .github/workflows/typos.toml
140143

@@ -637,9 +640,7 @@ jobs:
637640
go install github.com/golang/mock/mockgen@v1.6.0
638641
639642
- name: Setup sqlc
640-
uses: sqlc-dev/setup-sqlc@v3
641-
with:
642-
sqlc-version: "1.19.1"
643+
uses: ./.github/actions/setup-sqlc
643644

644645
- name: Format
645646
run: |

.github/workflows/release.yaml

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ jobs:
141141
build/coder_"$version"_linux_{amd64,armv7,arm64}.{tar.gz,apk,deb,rpm} \
142142
build/coder_"$version"_{darwin,windows}_{amd64,arm64}.zip \
143143
build/coder_"$version"_windows_amd64_installer.exe \
144-
build/coder_helm_"$version".tgz
144+
build/coder_helm_"$version".tgz \
145+
build/provisioner_helm_"$version".tgz
145146
env:
146147
CODER_SIGN_DARWIN: "1"
147148
AC_CERTIFICATE_FILE: /tmp/apple_cert.p12
@@ -295,9 +296,11 @@ jobs:
295296
version="$(./scripts/version.sh)"
296297
mkdir -p build/helm
297298
cp "build/coder_helm_${version}.tgz" build/helm
299+
cp "build/provisioner_helm_${version}.tgz" build/helm
298300
gsutil cp gs://helm.coder.com/v2/index.yaml build/helm/index.yaml
299301
helm repo index build/helm --url https://helm.coder.com/v2 --merge build/helm/index.yaml
300302
gsutil -h "Cache-Control:no-cache,max-age=0" cp build/helm/coder_helm_${version}.tgz gs://helm.coder.com/v2
303+
gsutil -h "Cache-Control:no-cache,max-age=0" cp build/helm/provisioner_helm_${version}.tgz gs://helm.coder.com/v2
301304
gsutil -h "Cache-Control:no-cache,max-age=0" cp build/helm/index.yaml gs://helm.coder.com/v2
302305
gsutil -h "Cache-Control:no-cache,max-age=0" cp helm/artifacthub-repo.yml gs://helm.coder.com/v2
303306
@@ -329,6 +332,7 @@ jobs:
329332
name: Publish to winget-pkgs
330333
runs-on: windows-latest
331334
needs: release
335+
if: ${{ !inputs.dry_run }}
332336
steps:
333337
- name: Checkout
334338
uses: actions/checkout@v3
@@ -364,12 +368,6 @@ jobs:
364368
echo "Installer URL: ${installer_url}"
365369
echo "Package version: ${version}"
366370
367-
# Bail if dry-run.
368-
if ($env:CODER_DRY_RUN -match "t") {
369-
echo "Skipping submission due to dry-run."
370-
exit 0
371-
}
372-
373371
# The URL "|X64" suffix forces the architecture as it cannot be
374372
# sniffed properly from the URL. wingetcreate checks both the URL and
375373
# binary magic bytes for the architecture and they need to both match,
@@ -393,7 +391,6 @@ jobs:
393391
WINGET_GH_TOKEN: ${{ secrets.CDRCI_GITHUB_TOKEN }}
394392

395393
- name: Comment on PR
396-
if: ${{ !inputs.dry_run }}
397394
run: |
398395
# wait 30 seconds
399396
Start-Sleep -Seconds 30.0
@@ -409,3 +406,63 @@ jobs:
409406
# For gh CLI. We need a real token since we're commenting on a PR in a
410407
# different repo.
411408
GH_TOKEN: ${{ secrets.CDRCI_GITHUB_TOKEN }}
409+
410+
publish-chocolatey:
411+
name: Publish to Chocolatey
412+
runs-on: windows-latest
413+
needs: release
414+
if: ${{ !inputs.dry_run }}
415+
steps:
416+
- name: Checkout
417+
uses: actions/checkout@v3
418+
with:
419+
fetch-depth: 0
420+
421+
# Same reason as for release.
422+
- name: Fetch git tags
423+
run: git fetch --tags --force
424+
425+
# From https://chocolatey.org
426+
- name: Install Chocolatey
427+
run: |
428+
Set-ExecutionPolicy Bypass -Scope Process -Force
429+
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
430+
431+
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
432+
433+
- name: Build chocolatey package
434+
run: |
435+
cd scripts/chocolatey
436+
437+
# The package version is the same as the tag minus the leading "v".
438+
# The version in this output already has the leading "v" removed but
439+
# we do it again to be safe.
440+
$version = "${{ needs.release.outputs.version }}".Trim('v')
441+
442+
$release_assets = gh release view --repo coder/coder "v${version}" --json assets | `
443+
ConvertFrom-Json
444+
445+
# Get the URL for the Windows ZIP from the release assets.
446+
$zip_url = $release_assets.assets | `
447+
Where-Object name -Match ".*_windows_amd64.zip$" | `
448+
Select -ExpandProperty url
449+
450+
echo "ZIP URL: ${zip_url}"
451+
echo "Package version: ${version}"
452+
453+
echo "Downloading ZIP..."
454+
Invoke-WebRequest $zip_url -OutFile assets.zip
455+
456+
echo "Extracting ZIP..."
457+
Expand-Archive assets.zip -DestinationPath assets/
458+
459+
# No need to specify nuspec if there's only one in the directory.
460+
choco pack --version=$version binary_path=assets/coder.exe
461+
462+
choco apikey --api-key $env:CHOCO_API_KEY --source https://push.chocolatey.org/
463+
464+
# No need to specify nupkg if there's only one in the directory.
465+
choco push --source https://push.chocolatey.org/
466+
467+
env:
468+
CHOCO_API_KEY: ${{ secrets.CHOCO_API_KEY }}

.golangci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ issues:
211211
run:
212212
skip-dirs:
213213
- node_modules
214+
- .git
214215
skip-files:
215216
- scripts/rules.go
216217
timeout: 10m

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,15 +344,19 @@ push/$(CODER_MAIN_IMAGE): $(CODER_MAIN_IMAGE)
344344
docker manifest push "$$image_tag"
345345
.PHONY: push/$(CODER_MAIN_IMAGE)
346346

347+
# Helm charts that are available
348+
charts = coder provisioner
349+
347350
# Shortcut for Helm chart package.
348-
build/coder_helm.tgz: build/coder_helm_$(VERSION).tgz
351+
$(foreach chart,$(charts),build/$(chart)_helm.tgz): build/%_helm.tgz: build/%_helm_$(VERSION).tgz
349352
rm -f "$@"
350353
ln "$<" "$@"
351354

352355
# Helm chart package.
353-
build/coder_helm_$(VERSION).tgz:
356+
$(foreach chart,$(charts),build/$(chart)_helm_$(VERSION).tgz): build/%_helm_$(VERSION).tgz:
354357
./scripts/helm.sh \
355358
--version "$(VERSION)" \
359+
--chart $* \
356360
--output "$@"
357361

358362
site/out/index.html: site/package.json $(shell find ./site $(FIND_EXCLUSIONS) -type f \( -name '*.ts' -o -name '*.tsx' \))

agent/agent.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ func (a *agent) trackConnGoroutine(fn func()) error {
758758

759759
func (a *agent) createTailnet(ctx context.Context, agentID uuid.UUID, derpMap *tailcfg.DERPMap, disableDirectConnections bool) (_ *tailnet.Conn, err error) {
760760
network, err := tailnet.NewConn(&tailnet.Options{
761+
ID: agentID,
761762
Addresses: a.wireguardAddresses(agentID),
762763
DERPMap: derpMap,
763764
Logger: a.logger.Named("net.tailnet"),
@@ -1134,7 +1135,7 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, logger slog.Logger, m
11341135
rpty.Wait()
11351136
a.reconnectingPTYs.Delete(msg.ID)
11361137
}); err != nil {
1137-
rpty.Close(err.Error())
1138+
rpty.Close(err)
11381139
return xerrors.Errorf("start routine: %w", err)
11391140
}
11401141

agent/agent_test.go

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

33
import (
4-
"bufio"
54
"bytes"
65
"context"
76
"encoding/json"
@@ -1588,10 +1587,6 @@ func TestAgent_Startup(t *testing.T) {
15881587
})
15891588
}
15901589

1591-
const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
1592-
1593-
var re = regexp.MustCompile(ansi)
1594-
15951590
//nolint:paralleltest // This test sets an environment variable.
15961591
func TestAgent_ReconnectingPTY(t *testing.T) {
15971592
if runtime.GOOS == "windows" {
@@ -1635,17 +1630,14 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
16351630
//nolint:dogsled
16361631
conn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
16371632
id := uuid.New()
1638-
netConn1, err := conn.ReconnectingPTY(ctx, id, 100, 100, "bash")
1633+
netConn1, err := conn.ReconnectingPTY(ctx, id, 80, 80, "bash")
16391634
require.NoError(t, err)
16401635
defer netConn1.Close()
16411636

1642-
scanner1 := bufio.NewScanner(netConn1)
1643-
16441637
// A second simultaneous connection.
1645-
netConn2, err := conn.ReconnectingPTY(ctx, id, 100, 100, "bash")
1638+
netConn2, err := conn.ReconnectingPTY(ctx, id, 80, 80, "bash")
16461639
require.NoError(t, err)
16471640
defer netConn2.Close()
1648-
scanner2 := bufio.NewScanner(netConn2)
16491641

16501642
// Brief pause to reduce the likelihood that we send keystrokes while
16511643
// the shell is simultaneously sending a prompt.
@@ -1658,17 +1650,6 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
16581650
_, err = netConn1.Write(data)
16591651
require.NoError(t, err)
16601652

1661-
hasLine := func(scanner *bufio.Scanner, matcher func(string) bool) bool {
1662-
for scanner.Scan() {
1663-
line := scanner.Text()
1664-
t.Logf("bash tty stdout = %s", re.ReplaceAllString(line, ""))
1665-
if matcher(line) {
1666-
return true
1667-
}
1668-
}
1669-
return false
1670-
}
1671-
16721653
matchEchoCommand := func(line string) bool {
16731654
return strings.Contains(line, "echo test")
16741655
}
@@ -1683,25 +1664,23 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
16831664
}
16841665

16851666
// Once for typing the command...
1686-
require.True(t, hasLine(scanner1, matchEchoCommand), "find echo command")
1667+
require.NoError(t, testutil.ReadUntil(ctx, t, netConn1, matchEchoCommand), "find echo command")
16871668
// And another time for the actual output.
1688-
require.True(t, hasLine(scanner1, matchEchoOutput), "find echo output")
1669+
require.NoError(t, testutil.ReadUntil(ctx, t, netConn1, matchEchoOutput), "find echo output")
16891670

16901671
// Same for the other connection.
1691-
require.True(t, hasLine(scanner2, matchEchoCommand), "find echo command")
1692-
require.True(t, hasLine(scanner2, matchEchoOutput), "find echo output")
1672+
require.NoError(t, testutil.ReadUntil(ctx, t, netConn2, matchEchoCommand), "find echo command")
1673+
require.NoError(t, testutil.ReadUntil(ctx, t, netConn2, matchEchoOutput), "find echo output")
16931674

16941675
_ = netConn1.Close()
16951676
_ = netConn2.Close()
1696-
netConn3, err := conn.ReconnectingPTY(ctx, id, 100, 100, "bash")
1677+
netConn3, err := conn.ReconnectingPTY(ctx, id, 80, 80, "bash")
16971678
require.NoError(t, err)
16981679
defer netConn3.Close()
16991680

1700-
scanner3 := bufio.NewScanner(netConn3)
1701-
17021681
// Same output again!
1703-
require.True(t, hasLine(scanner3, matchEchoCommand), "find echo command")
1704-
require.True(t, hasLine(scanner3, matchEchoOutput), "find echo output")
1682+
require.NoError(t, testutil.ReadUntil(ctx, t, netConn3, matchEchoCommand), "find echo command")
1683+
require.NoError(t, testutil.ReadUntil(ctx, t, netConn3, matchEchoOutput), "find echo output")
17051684

17061685
// Exit should cause the connection to close.
17071686
data, err = json.Marshal(codersdk.ReconnectingPTYRequest{
@@ -1712,26 +1691,19 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
17121691
require.NoError(t, err)
17131692

17141693
// Once for the input and again for the output.
1715-
require.True(t, hasLine(scanner3, matchExitCommand), "find exit command")
1716-
require.True(t, hasLine(scanner3, matchExitOutput), "find exit output")
1694+
require.NoError(t, testutil.ReadUntil(ctx, t, netConn3, matchExitCommand), "find exit command")
1695+
require.NoError(t, testutil.ReadUntil(ctx, t, netConn3, matchExitOutput), "find exit output")
17171696

17181697
// Wait for the connection to close.
1719-
for scanner3.Scan() {
1720-
line := scanner3.Text()
1721-
t.Logf("bash tty stdout = %s", re.ReplaceAllString(line, ""))
1722-
}
1698+
require.ErrorIs(t, testutil.ReadUntil(ctx, t, netConn3, nil), io.EOF)
17231699

17241700
// Try a non-shell command. It should output then immediately exit.
1725-
netConn4, err := conn.ReconnectingPTY(ctx, uuid.New(), 100, 100, "echo test")
1701+
netConn4, err := conn.ReconnectingPTY(ctx, uuid.New(), 80, 80, "echo test")
17261702
require.NoError(t, err)
17271703
defer netConn4.Close()
17281704

1729-
scanner4 := bufio.NewScanner(netConn4)
1730-
require.True(t, hasLine(scanner4, matchEchoOutput), "find echo output")
1731-
for scanner4.Scan() {
1732-
line := scanner4.Text()
1733-
t.Logf("bash tty stdout = %s", re.ReplaceAllString(line, ""))
1734-
}
1705+
require.NoError(t, testutil.ReadUntil(ctx, t, netConn4, matchEchoOutput), "find echo output")
1706+
require.ErrorIs(t, testutil.ReadUntil(ctx, t, netConn3, nil), io.EOF)
17351707
})
17361708
}
17371709
}

agent/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"sync"
66
"time"
77

8-
"github.com/go-chi/chi"
8+
"github.com/go-chi/chi/v5"
99

1010
"github.com/coder/coder/coderd/httpapi"
1111
"github.com/coder/coder/codersdk"

0 commit comments

Comments
 (0)