Skip to content

Commit 223f649

Browse files
committed
Merge branch 'main' of github.com:coder/coder into bq/previous-version
2 parents c80d66a + 02dcd0e commit 223f649

File tree

105 files changed

+2073
-694
lines changed

Some content is hidden

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

105 files changed

+2073
-694
lines changed

.github/workflows/coder.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
with:
9797
go-version: "~1.19"
9898
- name: golangci-lint
99-
uses: golangci/golangci-lint-action@v3.3.0
99+
uses: golangci/golangci-lint-action@v3.3.1
100100
with:
101101
version: v1.48.0
102102

@@ -336,7 +336,7 @@ jobs:
336336
echo ::set-output name=cover::false
337337
fi
338338
set -x
339-
gotestsum --junitfile="gotests.xml" --packages="./..." -- -parallel=8 -timeout=3m -short -failfast $COVERAGE_FLAGS
339+
gotestsum --junitfile="gotests.xml" --packages="./..." --debug -- -parallel=8 -timeout=3m -short -failfast $COVERAGE_FLAGS
340340
341341
- uses: codecov/codecov-action@v3
342342
# This action has a tendency to error out unexpectedly, it has
@@ -428,7 +428,7 @@ jobs:
428428
fetch-depth: 0
429429

430430
- name: Authenticate to Google Cloud
431-
uses: google-github-actions/auth@v0
431+
uses: google-github-actions/auth@v1
432432
with:
433433
workload_identity_provider: projects/573722524737/locations/global/workloadIdentityPools/github/providers/github
434434
service_account: coder-ci@coder-dogfood.iam.gserviceaccount.com

.github/workflows/dependabot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ jobs:
99
permissions:
1010
pull-requests: write
1111
steps:
12-
- uses: hmarr/auto-approve-action@v2
12+
- uses: hmarr/auto-approve-action@v3
1313
if: github.actor == 'dependabot[bot]'

.github/workflows/dogfood.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
steps:
1818
- name: Get branch name
1919
id: branch-name
20-
uses: tj-actions/branch-names@v6.2
20+
uses: tj-actions/branch-names@v6.3
2121

2222
- name: "Branch name to Docker tag name"
2323
id: docker-tag-name

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ jobs:
170170
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
171171

172172
- name: Authenticate to Google Cloud
173-
uses: google-github-actions/auth@v0
173+
uses: google-github-actions/auth@v1
174174
with:
175175
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_ID_PROVIDER }}
176176
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}

.github/workflows/stale.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ jobs:
1717
with:
1818
stale-issue-label: 'stale'
1919
stale-pr-label: 'stale'
20-
exempt-issue-labels: 'never stale'
21-
exempt-pr-labels: 'never stale'
2220
# Pull Requests become stale more quickly due to merge conflicts.
2321
# Also, we promote minimizing WIP.
2422
days-before-pr-stale: 7

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ vendor
1414
.eslintcache
1515
yarn-error.log
1616
gotests.coverage
17+
gotests.xml
1718
.idea
1819
.gitpod.yml
1920
.DS_Store

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"slogtest",
108108
"sourcemapped",
109109
"Srcs",
110+
"stdbuf",
110111
"stretchr",
111112
"STTY",
112113
"stuntest",

ADOPTERS.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Adopters
1+
# Adopters
2+
23
[!["Join us on
34
Discord"](https://img.shields.io/badge/join-us%20on%20Discord-gray.svg?longCache=true&logo=discord&colorB=green)](https://coder.com/chat?utm_source=github.com/coder/coder&utm_medium=github&utm_campaign=adopters.md) [![Twitter
45
Follow](https://img.shields.io/twitter/follow/coderhq?label=%40coderhq&style=social)](https://twitter.com/coderhq)
@@ -7,6 +8,6 @@ Follow](https://img.shields.io/twitter/follow/coderhq?label=%40coderhq&style=soc
78

89
> 👋 _If you are considering using Coder in your organization please introduce yourself via https://coder.com/demo_ 🙇🏻‍♂️
910
10-
| Organization | Contact | Description of Use |
11-
| --------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
12-
| [Coder](https://www.coder.com) | [@coderhq](https://twitter.com/coderhq) | Coder builds coder with Coder. |
11+
| Organization | Contact | Description of Use |
12+
| ------------------------------ | --------------------------------------- | ------------------------------ |
13+
| [Coder](https://www.coder.com) | [@coderhq](https://twitter.com/coderhq) | Coder builds coder with Coder. |

Makefile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ fmt/prettier:
359359
cd site
360360
# Avoid writing files in CI to reduce file write activity
361361
ifdef CI
362-
yarn run format:check
362+
yarn run format:check . ../*.md ../docs
363363
else
364-
yarn run format:write
364+
yarn run format:write . ../*.md ../docs
365365
endif
366366
.PHONY: fmt/prettier
367367

@@ -452,11 +452,7 @@ site/src/api/typesGenerated.ts: scripts/apitypings/main.go $(shell find codersdk
452452
docs/admin/prometheus.md: scripts/metricsdocgen/main.go scripts/metricsdocgen/metrics
453453
go run scripts/metricsdocgen/main.go
454454
cd site
455-
ifdef CI
456-
yarn run format:check
457-
else
458-
yarn run format:write
459-
endif
455+
yarn run format:write ../docs/admin/prometheus.md
460456

461457
update-golden-files: cli/testdata/.gen-golden
462458
.PHONY: update-golden-files
@@ -467,7 +463,7 @@ cli/testdata/.gen-golden: $(wildcard cli/testdata/*.golden) $(GO_SRC_FILES)
467463
touch "$@"
468464

469465
test: test-clean
470-
gotestsum -- -v -short ./...
466+
gotestsum --debug -- -v -short ./...
471467
.PHONY: test
472468

473469
# When updating -timeout for this test, keep in sync with

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Software development on your infrastructure. Offload your team's development fro
1111

1212
> "By leveraging Terraform, Coder lets developers run any IDE on any compute platform including on-prem, AWS, Azure, GCP, DigitalOcean, Kubernetes, Docker, and more, with workspaces running on Linux, Windows, or Mac." - **Kevin Fishner Chief of Staff at [HashiCorp](https://hashicorp.com/)**
1313
14-
1514
<p align="center">
1615
<img src="./docs/images/hero-image.png">
1716
</p>
@@ -83,6 +82,10 @@ Use `coder --help` to get a complete list of flags and environment variables. Us
8382

8483
Visit our docs [here](https://coder.com/docs/coder-oss).
8584

85+
## Templates
86+
87+
Find our templates [here](./examples/templates).
88+
8689
## Comparison
8790

8891
Please file [an issue](https://github.com/coder/coder/issues/new) if any information is out of date. Also refer to: [What Coder is not](https://coder.com/docs/coder-oss/latest/index#what-coder-is-not).
@@ -92,7 +95,7 @@ Please file [an issue](https://github.com/coder/coder/issues/new) if any informa
9295
| [Coder](https://github.com/coder/coder) | Platform | OSS + Self-Managed | Pay your cloud | All [Terraform](https://www.terraform.io/registry/providers) resources, all clouds, multi-architecture: Linux, Mac, Windows, containers, VMs, amd64, arm64 |
9396
| [code-server](https://github.com/cdr/code-server) | Web IDE | OSS + Self-Managed | Pay your cloud | Linux, Mac, Windows, containers, VMs, amd64, arm64 |
9497
| [Coder (Classic)](https://coder.com/docs) | Platform | Self-Managed | Pay your cloud + license fees | Kubernetes Linux Containers |
95-
| [GitHub Codespaces](https://github.com/features/codespaces) | Platform | SaaS | 2x Azure Compute | Linux Virtual Machines |
98+
| [GitHub Codespaces](https://github.com/features/codespaces) | Platform | SaaS | 2x Azure Compute | Linux Virtual Machines |
9699

97100
---
98101

agent/agent.go

Lines changed: 77 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,27 @@ func (a *agent) run(ctx context.Context) error {
231231
return nil
232232
}
233233

234-
func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*tailnet.Conn, error) {
234+
func (a *agent) trackConnGoroutine(fn func()) error {
235+
a.closeMutex.Lock()
236+
defer a.closeMutex.Unlock()
237+
if a.isClosed() {
238+
return xerrors.New("track conn goroutine: agent is closed")
239+
}
240+
a.connCloseWait.Add(1)
241+
go func() {
242+
defer a.connCloseWait.Done()
243+
fn()
244+
}()
245+
return nil
246+
}
247+
248+
func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (network *tailnet.Conn, err error) {
235249
a.closeMutex.Lock()
236250
if a.isClosed() {
237251
a.closeMutex.Unlock()
238252
return nil, xerrors.New("closed")
239253
}
240-
network, err := tailnet.NewConn(&tailnet.Options{
254+
network, err = tailnet.NewConn(&tailnet.Options{
241255
Addresses: []netip.Prefix{netip.PrefixFrom(codersdk.TailnetIP, 128)},
242256
DERPMap: derpMap,
243257
Logger: a.logger.Named("tailnet"),
@@ -247,31 +261,45 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
247261
a.closeMutex.Unlock()
248262
return nil, xerrors.Errorf("create tailnet: %w", err)
249263
}
264+
defer func() {
265+
if err != nil {
266+
network.Close()
267+
}
268+
}()
250269
a.network = network
251-
a.connCloseWait.Add(4)
252270
a.closeMutex.Unlock()
253271

254272
sshListener, err := network.Listen("tcp", ":"+strconv.Itoa(codersdk.TailnetSSHPort))
255273
if err != nil {
256274
return nil, xerrors.Errorf("listen on the ssh port: %w", err)
257275
}
258-
go func() {
259-
defer a.connCloseWait.Done()
276+
defer func() {
277+
if err != nil {
278+
_ = sshListener.Close()
279+
}
280+
}()
281+
if err = a.trackConnGoroutine(func() {
260282
for {
261283
conn, err := sshListener.Accept()
262284
if err != nil {
263285
return
264286
}
265287
go a.sshServer.HandleConn(conn)
266288
}
267-
}()
289+
}); err != nil {
290+
return nil, err
291+
}
268292

269293
reconnectingPTYListener, err := network.Listen("tcp", ":"+strconv.Itoa(codersdk.TailnetReconnectingPTYPort))
270294
if err != nil {
271295
return nil, xerrors.Errorf("listen for reconnecting pty: %w", err)
272296
}
273-
go func() {
274-
defer a.connCloseWait.Done()
297+
defer func() {
298+
if err != nil {
299+
_ = reconnectingPTYListener.Close()
300+
}
301+
}()
302+
if err = a.trackConnGoroutine(func() {
275303
for {
276304
conn, err := reconnectingPTYListener.Accept()
277305
if err != nil {
@@ -298,36 +326,48 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
298326
}
299327
go a.handleReconnectingPTY(ctx, msg, conn)
300328
}
301-
}()
329+
}); err != nil {
330+
return nil, err
331+
}
302332

303333
speedtestListener, err := network.Listen("tcp", ":"+strconv.Itoa(codersdk.TailnetSpeedtestPort))
304334
if err != nil {
305335
return nil, xerrors.Errorf("listen for speedtest: %w", err)
306336
}
307-
go func() {
308-
defer a.connCloseWait.Done()
337+
defer func() {
338+
if err != nil {
339+
_ = speedtestListener.Close()
340+
}
341+
}()
342+
if err = a.trackConnGoroutine(func() {
309343
for {
310344
conn, err := speedtestListener.Accept()
311345
if err != nil {
312346
a.logger.Debug(ctx, "speedtest listener failed", slog.Error(err))
313347
return
314348
}
315-
a.closeMutex.Lock()
316-
a.connCloseWait.Add(1)
317-
a.closeMutex.Unlock()
318-
go func() {
319-
defer a.connCloseWait.Done()
349+
if err = a.trackConnGoroutine(func() {
320350
_ = speedtest.ServeConn(conn)
321-
}()
351+
}); err != nil {
352+
a.logger.Debug(ctx, "speedtest listener failed", slog.Error(err))
353+
_ = conn.Close()
354+
return
355+
}
322356
}
323-
}()
357+
}); err != nil {
358+
return nil, err
359+
}
324360

325361
statisticsListener, err := network.Listen("tcp", ":"+strconv.Itoa(codersdk.TailnetStatisticsPort))
326362
if err != nil {
327363
return nil, xerrors.Errorf("listen for statistics: %w", err)
328364
}
329-
go func() {
330-
defer a.connCloseWait.Done()
365+
defer func() {
366+
if err != nil {
367+
_ = statisticsListener.Close()
368+
}
369+
}()
370+
if err = a.trackConnGoroutine(func() {
331371
defer statisticsListener.Close()
332372
server := &http.Server{
333373
Handler: a.statisticsHandler(),
@@ -341,11 +381,13 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (*t
341381
_ = server.Close()
342382
}()
343383

344-
err = server.Serve(statisticsListener)
384+
err := server.Serve(statisticsListener)
345385
if err != nil && !xerrors.Is(err, http.ErrServerClosed) && !strings.Contains(err.Error(), "use of closed network connection") {
346386
a.logger.Critical(ctx, "serve statistics HTTP server", slog.Error(err))
347387
}
348-
}()
388+
}); err != nil {
389+
return nil, err
390+
}
349391

350392
return network, nil
351393
}
@@ -527,12 +569,15 @@ func (a *agent) init(ctx context.Context) {
527569
a.logger.Error(ctx, "report stats", slog.Error(err))
528570
return
529571
}
530-
a.connCloseWait.Add(1)
531-
go func() {
532-
defer a.connCloseWait.Done()
572+
573+
if err = a.trackConnGoroutine(func() {
533574
<-a.closed
534-
cl.Close()
535-
}()
575+
_ = cl.Close()
576+
}); err != nil {
577+
a.logger.Error(ctx, "report stats goroutine", slog.Error(err))
578+
_ = cl.Close()
579+
return
580+
}
536581
}
537582

538583
func convertAgentStats(counts map[netlogtype.Connection]netlogtype.Counts) *codersdk.AgentStats {
@@ -787,9 +832,6 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, msg codersdk.Reconnec
787832
return
788833
}
789834

790-
a.closeMutex.Lock()
791-
a.connCloseWait.Add(1)
792-
a.closeMutex.Unlock()
793835
ctx, cancelFunc := context.WithCancel(ctx)
794836
rpty = &reconnectingPTY{
795837
activeConns: map[string]net.Conn{
@@ -818,7 +860,7 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, msg codersdk.Reconnec
818860
_ = process.Wait()
819861
rpty.Close()
820862
}()
821-
go func() {
863+
if err = a.trackConnGoroutine(func() {
822864
buffer := make([]byte, 1024)
823865
for {
824866
read, err := rpty.ptty.Output().Read(buffer)
@@ -846,8 +888,10 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, msg codersdk.Reconnec
846888
_ = process.Kill()
847889
rpty.Close()
848890
a.reconnectingPTYs.Delete(msg.ID)
849-
a.connCloseWait.Done()
850-
}()
891+
}); err != nil {
892+
a.logger.Error(ctx, "start reconnecting pty routine", slog.F("id", msg.ID), slog.Error(err))
893+
return
894+
}
851895
}
852896
// Resize the PTY to initial height + width.
853897
err := rpty.ptty.Resize(msg.Height, msg.Width)

buildinfo/buildinfo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ func VersionsMatch(v1, v2 string) bool {
6868
return semver.MajorMinor(v1) == semver.MajorMinor(v2)
6969
}
7070

71+
// IsDev returns true if this is a development build.
72+
func IsDev() bool {
73+
return strings.HasPrefix(Version(), develPrefix)
74+
}
75+
7176
// ExternalURL returns a URL referencing the current Coder version.
7277
// For production builds, this will link directly to a release.
7378
// For development builds, this will link to a commit.

0 commit comments

Comments
 (0)