Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a43eac

Browse files
committed
chore: Merge branch 'main' of github.com:coder/coder into bq/738/suspend-user
2 parents 286fde6 + 34b91fd commit 5a43eac

Some content is hidden

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

81 files changed

+2037
-500
lines changed

.github/workflows/coder.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ jobs:
9999
with:
100100
go-version: "~1.18"
101101
- run: curl -sSL
102-
https://github.com/kyleconroy/sqlc/releases/download/v1.11.0/sqlc_1.11.0_linux_amd64.tar.gz
102+
https://github.com/kyleconroy/sqlc/releases/download/v1.13.0/sqlc_1.13.0_linux_amd64.tar.gz
103103
| sudo tar -C /usr/bin -xz sqlc
104104

105105
- run: go install google.golang.org/protobuf/cmd/[email protected]
@@ -354,8 +354,14 @@ jobs:
354354
restore-keys: |
355355
js-${{ runner.os }}-
356356
357+
- name: Build site
358+
run: make site/out/index.html
359+
357360
- name: Build Release
358-
run: make release
361+
uses: goreleaser/[email protected]
362+
with:
363+
version: latest
364+
args: release --snapshot --rm-dist --skip-sign
359365

360366
- uses: actions/upload-artifact@v3
361367
with:
@@ -482,7 +488,7 @@ jobs:
482488

483489
- name: Build
484490
run: |
485-
make site/out
491+
make site/out/index.html
486492
487493
- run: yarn playwright:install
488494
working-directory: site

.github/workflows/release.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ jobs:
5454
restore-keys: |
5555
js-${{ runner.os }}-
5656
57+
- name: Install make
58+
run: brew install make
59+
5760
- name: Build Site
58-
run: make site/out
61+
run: make site/out/index.html
5962

6063
- name: Run GoReleaser
6164
uses: goreleaser/[email protected]

Makefile

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1+
.DEFAULT_GOAL := build
2+
13
INSTALL_DIR=$(shell go env GOPATH)/bin
24
GOOS=$(shell go env GOOS)
35
GOARCH=$(shell go env GOARCH)
46

5-
bin:
6-
goreleaser build --snapshot --rm-dist
7-
.PHONY: bin
7+
bin: $(shell find . -not -path './vendor/*' -type f -name '*.go') go.mod go.sum
8+
@echo "== This builds binaries for command-line usage."
9+
@echo "== Use \"make build\" to embed the site."
10+
goreleaser build --snapshot --rm-dist --single-target
811

9-
build: site/out bin
12+
build: dist/artifacts.json
1013
.PHONY: build
1114

1215
# Runs migrations to output a dump of the database.
1316
coderd/database/dump.sql: $(wildcard coderd/database/migrations/*.sql)
1417
go run coderd/database/dump/main.go
15-
.PHONY: coderd/database/dump.sql
1618

1719
# Generates Go code for querying the database.
18-
coderd/database/generate: coderd/database/dump.sql $(wildcard coderd/database/queries/*.sql)
20+
coderd/database/querier.go: coderd/database/dump.sql $(wildcard coderd/database/queries/*.sql)
1921
coderd/database/generate.sh
20-
.PHONY: coderd/database/generate
2122

22-
apitypings/generate: site/src/api/types.ts
23-
go run scripts/apitypings/main.go > site/src/api/typesGenerated.ts
24-
cd site && yarn run format:types
25-
.PHONY: apitypings/generate
23+
dist/artifacts.json: site/out/index.html $(shell find . -not -path './vendor/*' -type f -name '*.go') go.mod go.sum
24+
goreleaser release --snapshot --rm-dist --skip-sign
2625

2726
fmt/prettier:
2827
@echo "--- prettier"
@@ -36,12 +35,12 @@ endif
3635

3736
fmt/terraform: $(wildcard *.tf)
3837
terraform fmt -recursive
38+
.PHONY: fmt/terraform
3939

4040
fmt: fmt/prettier fmt/terraform
4141
.PHONY: fmt
4242

43-
gen: coderd/database/generate peerbroker/proto provisionersdk/proto provisionerd/proto apitypings/generate
44-
.PHONY: gen
43+
gen: coderd/database/querier.go peerbroker/proto/peerbroker.pb.go provisionersdk/proto/provisioner.pb.go provisionerd/proto/provisionerd.pb.go site/src/api/typesGenerated.ts
4544

4645
install: build
4746
@echo "--- Copying from bin to $(INSTALL_DIR)"
@@ -53,44 +52,40 @@ lint:
5352
golangci-lint run
5453
.PHONY: lint
5554

56-
peerbroker/proto: peerbroker/proto/peerbroker.proto
55+
peerbroker/proto/peerbroker.pb.go: peerbroker/proto/peerbroker.proto
5756
protoc \
5857
--go_out=. \
5958
--go_opt=paths=source_relative \
6059
--go-drpc_out=. \
6160
--go-drpc_opt=paths=source_relative \
6261
./peerbroker/proto/peerbroker.proto
63-
.PHONY: peerbroker/proto
6462

65-
provisionerd/proto: provisionerd/proto/provisionerd.proto
63+
provisionerd/proto/provisionerd.pb.go: provisionerd/proto/provisionerd.proto
6664
protoc \
6765
--go_out=. \
6866
--go_opt=paths=source_relative \
6967
--go-drpc_out=. \
7068
--go-drpc_opt=paths=source_relative \
7169
./provisionerd/proto/provisionerd.proto
72-
.PHONY: provisionerd/proto
7370

74-
provisionersdk/proto: provisionersdk/proto/provisioner.proto
71+
provisionersdk/proto/provisioner.pb.go: provisionersdk/proto/provisioner.proto
7572
protoc \
7673
--go_out=. \
7774
--go_opt=paths=source_relative \
7875
--go-drpc_out=. \
7976
--go-drpc_opt=paths=source_relative \
8077
./provisionersdk/proto/provisioner.proto
81-
.PHONY: provisionersdk/proto
8278

83-
release: site/out
84-
goreleaser release --snapshot --rm-dist --skip-sign
85-
.PHONY: release
86-
87-
site/out:
79+
site/out/index.html: $(shell find ./site -not -path './site/node_modules/*' -type f -name '*.tsx') $(shell find ./site -not -path './site/node_modules/*' -type f -name '*.ts') site/package.json
8880
./scripts/yarn_install.sh
8981
cd site && yarn typegen
9082
cd site && yarn build
9183
# Restores GITKEEP files!
9284
git checkout HEAD site/out
93-
.PHONY: site/out
85+
86+
site/src/api/typesGenerated.ts: $(shell find codersdk -type f -name '*.go')
87+
go run scripts/apitypings/main.go > site/src/api/typesGenerated.ts
88+
cd site && yarn run format:types
9489

9590
test:
9691
gotestsum -- -v -short ./...

agent/agent.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"os"
1313
"os/exec"
1414
"os/user"
15+
"path/filepath"
1516
"runtime"
1617
"strconv"
1718
"strings"
@@ -21,7 +22,6 @@ import (
2122
"github.com/armon/circbuf"
2223
"github.com/google/uuid"
2324

24-
gsyslog "github.com/hashicorp/go-syslog"
2525
"go.uber.org/atomic"
2626

2727
"cdr.dev/slog"
@@ -166,15 +166,9 @@ func (*agent) runStartupScript(ctx context.Context, script string) error {
166166
return xerrors.Errorf("get user shell: %w", err)
167167
}
168168

169-
var writer io.WriteCloser
170-
// Attempt to use the syslog to write startup information.
171-
writer, err = gsyslog.NewLogger(gsyslog.LOG_INFO, "USER", "coder-startup-script")
169+
writer, err := os.OpenFile(filepath.Join(os.TempDir(), "coder-startup-script.log"), os.O_CREATE|os.O_RDWR, 0600)
172170
if err != nil {
173-
// If the syslog isn't supported or cannot be created, use a text file in temp.
174-
writer, err = os.CreateTemp("", "coder-startup-script-*.txt")
175-
if err != nil {
176-
return xerrors.Errorf("open startup script log file: %w", err)
177-
}
171+
return xerrors.Errorf("open startup script log file: %w", err)
178172
}
179173
defer func() {
180174
_ = writer.Close()
@@ -524,7 +518,9 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, rawID string, conn ne
524518
break
525519
}
526520
part := buffer[:read]
521+
rpty.circularBufferMutex.Lock()
527522
_, err = rpty.circularBuffer.Write(part)
523+
rpty.circularBufferMutex.Unlock()
528524
if err != nil {
529525
a.logger.Error(ctx, "reconnecting pty write buffer", slog.Error(err), slog.F("id", id))
530526
break
@@ -551,7 +547,9 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, rawID string, conn ne
551547
a.logger.Error(ctx, "resize reconnecting pty", slog.F("id", id), slog.Error(err))
552548
}
553549
// Write any previously stored data for the TTY.
550+
rpty.circularBufferMutex.RLock()
554551
_, err = conn.Write(rpty.circularBuffer.Bytes())
552+
rpty.circularBufferMutex.RUnlock()
555553
if err != nil {
556554
a.logger.Warn(ctx, "write reconnecting pty buffer", slog.F("id", id), slog.Error(err))
557555
return
@@ -646,9 +644,10 @@ type reconnectingPTY struct {
646644
activeConnsMutex sync.Mutex
647645
activeConns map[string]net.Conn
648646

649-
circularBuffer *circbuf.Buffer
650-
timeout *time.Timer
651-
ptty pty.PTY
647+
circularBuffer *circbuf.Buffer
648+
circularBufferMutex sync.RWMutex
649+
timeout *time.Timer
650+
ptty pty.PTY
652651
}
653652

654653
// Close ends all connections to the reconnecting

buildinfo/buildinfo.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,17 @@ func Version() string {
3333
revision = "+" + revision[:7]
3434
}
3535
if tag == "" {
36+
// This occurs when the tag hasn't been injected,
37+
// like when using "go run".
3638
version = "v0.0.0-devel" + revision
3739
return
3840
}
39-
if semver.Build(tag) == "" {
40-
tag += revision
41-
}
4241
version = "v" + tag
42+
// The tag must be prefixed with "v" otherwise the
43+
// semver library will return an empty string.
44+
if semver.Build(version) == "" {
45+
version += revision
46+
}
4347
})
4448
return version
4549
}

cli/agent.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"net/http"
66
"net/url"
7+
"os"
8+
"path/filepath"
79
"time"
810

911
"cloud.google.com/go/compute/metadata"
@@ -17,6 +19,8 @@ import (
1719
"github.com/coder/coder/cli/cliflag"
1820
"github.com/coder/coder/codersdk"
1921
"github.com/coder/retry"
22+
23+
"gopkg.in/natefinch/lumberjack.v2"
2024
)
2125

2226
func workspaceAgent() *cobra.Command {
@@ -36,7 +40,13 @@ func workspaceAgent() *cobra.Command {
3640
if err != nil {
3741
return xerrors.Errorf("parse %q: %w", rawURL, err)
3842
}
39-
logger := slog.Make(sloghuman.Sink(cmd.OutOrStdout())).Leveled(slog.LevelDebug)
43+
44+
logWriter := &lumberjack.Logger{
45+
Filename: filepath.Join(os.TempDir(), "coder-agent.log"),
46+
MaxSize: 5, // MB
47+
}
48+
defer logWriter.Close()
49+
logger := slog.Make(sloghuman.Sink(cmd.ErrOrStderr()), sloghuman.Sink(logWriter)).Leveled(slog.LevelDebug)
4050
client := codersdk.New(coderURL)
4151

4252
// exchangeToken returns a session token.

cli/workspaceautostart.go renamed to cli/autostart.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,30 @@ When enabling autostart, provide the minute, hour, and day(s) of week.
1616
The default schedule is at 09:00 in your local timezone (TZ env, UTC by default).
1717
`
1818

19-
func workspaceAutostart() *cobra.Command {
19+
func autostart() *cobra.Command {
2020
autostartCmd := &cobra.Command{
2121
Use: "autostart enable <workspace>",
2222
Short: "schedule a workspace to automatically start at a regular time",
2323
Long: autostartDescriptionLong,
24-
Example: "coder workspaces autostart enable my-workspace --minute 30 --hour 9 --days 1-5 --tz Europe/Dublin",
24+
Example: "coder autostart enable my-workspace --minute 30 --hour 9 --days 1-5 --tz Europe/Dublin",
2525
Hidden: true,
2626
}
2727

28-
autostartCmd.AddCommand(workspaceAutostartEnable())
29-
autostartCmd.AddCommand(workspaceAutostartDisable())
28+
autostartCmd.AddCommand(autostartEnable())
29+
autostartCmd.AddCommand(autostartDisable())
3030

3131
return autostartCmd
3232
}
3333

34-
func workspaceAutostartEnable() *cobra.Command {
34+
func autostartEnable() *cobra.Command {
3535
// yes some of these are technically numbers but the cron library will do that work
3636
var autostartMinute string
3737
var autostartHour string
3838
var autostartDayOfWeek string
3939
var autostartTimezone string
4040
cmd := &cobra.Command{
41-
Use: "enable <workspace_name> <schedule>",
42-
ValidArgsFunction: validArgsWorkspaceName,
43-
Args: cobra.ExactArgs(1),
41+
Use: "enable <workspace_name> <schedule>",
42+
Args: cobra.ExactArgs(1),
4443
RunE: func(cmd *cobra.Command, args []string) error {
4544
client, err := createClient(cmd)
4645
if err != nil {
@@ -86,11 +85,10 @@ func workspaceAutostartEnable() *cobra.Command {
8685
return cmd
8786
}
8887

89-
func workspaceAutostartDisable() *cobra.Command {
88+
func autostartDisable() *cobra.Command {
9089
return &cobra.Command{
91-
Use: "disable <workspace_name>",
92-
ValidArgsFunction: validArgsWorkspaceName,
93-
Args: cobra.ExactArgs(1),
90+
Use: "disable <workspace_name>",
91+
Args: cobra.ExactArgs(1),
9492
RunE: func(cmd *cobra.Command, args []string) error {
9593
client, err := createClient(cmd)
9694
if err != nil {

cli/workspaceautostart_test.go renamed to cli/autostart_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/coder/coder/coderd/coderdtest"
1414
)
1515

16-
func TestWorkspaceAutostart(t *testing.T) {
16+
func TestAutostart(t *testing.T) {
1717
t.Parallel()
1818

1919
t.Run("EnableDisableOK", func(t *testing.T) {
@@ -29,7 +29,7 @@ func TestWorkspaceAutostart(t *testing.T) {
2929
project = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
3030
workspace = coderdtest.CreateWorkspace(t, client, user.OrganizationID, project.ID)
3131
tz = "Europe/Dublin"
32-
cmdArgs = []string{"workspaces", "autostart", "enable", workspace.Name, "--minute", "30", "--hour", "9", "--days", "1-5", "--tz", tz}
32+
cmdArgs = []string{"autostart", "enable", workspace.Name, "--minute", "30", "--hour", "9", "--days", "1-5", "--tz", tz}
3333
sched = "CRON_TZ=Europe/Dublin 30 9 * * 1-5"
3434
stdoutBuf = &bytes.Buffer{}
3535
)
@@ -48,7 +48,7 @@ func TestWorkspaceAutostart(t *testing.T) {
4848
require.Equal(t, sched, updated.AutostartSchedule, "expected autostart schedule to be set")
4949

5050
// Disable schedule
51-
cmd, root = clitest.New(t, "workspaces", "autostart", "disable", workspace.Name)
51+
cmd, root = clitest.New(t, "autostart", "disable", workspace.Name)
5252
clitest.SetupConfig(t, client, root)
5353
cmd.SetOut(stdoutBuf)
5454

@@ -73,7 +73,7 @@ func TestWorkspaceAutostart(t *testing.T) {
7373
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
7474
)
7575

76-
cmd, root := clitest.New(t, "workspaces", "autostart", "enable", "doesnotexist")
76+
cmd, root := clitest.New(t, "autostart", "enable", "doesnotexist")
7777
clitest.SetupConfig(t, client, root)
7878

7979
err := cmd.Execute()
@@ -91,7 +91,7 @@ func TestWorkspaceAutostart(t *testing.T) {
9191
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
9292
)
9393

94-
cmd, root := clitest.New(t, "workspaces", "autostart", "disable", "doesnotexist")
94+
cmd, root := clitest.New(t, "autostart", "disable", "doesnotexist")
9595
clitest.SetupConfig(t, client, root)
9696

9797
err := cmd.Execute()
@@ -118,7 +118,7 @@ func TestWorkspaceAutostart(t *testing.T) {
118118
currTz = "UTC"
119119
}
120120
expectedSchedule := fmt.Sprintf("CRON_TZ=%s 0 9 * * 1-5", currTz)
121-
cmd, root := clitest.New(t, "workspaces", "autostart", "enable", workspace.Name)
121+
cmd, root := clitest.New(t, "autostart", "enable", workspace.Name)
122122
clitest.SetupConfig(t, client, root)
123123

124124
err := cmd.Execute()

0 commit comments

Comments
 (0)