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

Skip to content

Commit da729e6

Browse files
committed
Merge branch 'main' into 6724-metrics
2 parents 8d4e67d + 29e9b9e commit da729e6

File tree

213 files changed

+8289
-2090
lines changed

Some content is hidden

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

213 files changed

+8289
-2090
lines changed

.github/workflows/ci.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,14 @@ jobs:
299299
echo "cover=false" >> $GITHUB_OUTPUT
300300
fi
301301
302-
gotestsum --junitfile="gotests.xml" --packages="./..." -- -parallel=8 -timeout=7m -short -failfast $COVERAGE_FLAGS
302+
gotestsum --junitfile="gotests.xml" --jsonfile="gotests.json" --packages="./..." -- -parallel=8 -timeout=7m -short -failfast $COVERAGE_FLAGS
303+
304+
- name: Print test stats
305+
if: success() || failure()
306+
run: |
307+
# Artifacts are not available after rerunning a job,
308+
# so we need to print the test stats to the log.
309+
go run ./scripts/ci-report/main.go gotests.json | tee gotests_stats.json
303310
304311
- uses: actions/upload-artifact@v3
305312
if: success() || failure()
@@ -369,6 +376,13 @@ jobs:
369376
run: |
370377
make test-postgres
371378
379+
- name: Print test stats
380+
if: success() || failure()
381+
run: |
382+
# Artifacts are not available after rerunning a job,
383+
# so we need to print the test stats to the log.
384+
go run ./scripts/ci-report/main.go gotests.json | tee gotests_stats.json
385+
372386
- uses: actions/upload-artifact@v3
373387
if: success() || failure()
374388
with:

.github/workflows/typos.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ extend-exclude = [
2424
# These files contain base64 strings that confuse the detector
2525
"**XService**.ts",
2626
"**identity.go",
27+
"scripts/ci-report/testdata/**",
2728
]

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
**/*.swp
77
gotests.coverage
88
gotests.xml
9-
gotestsum.json
9+
gotests_stats.json
10+
gotests.json
1011
node_modules/
1112
vendor/
1213
yarn-error.log
@@ -29,9 +30,8 @@ site/e2e/states/*.json
2930
site/playwright-report/*
3031
site/.swc
3132

32-
# Make target for updating golden files.
33-
cli/testdata/.gen-golden
34-
helm/tests/testdata/.gen-golden
33+
# Make target for updating golden files (any dir).
34+
.gen-golden
3535

3636
# Build
3737
/build/

.prettierignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
**/*.swp
1010
gotests.coverage
1111
gotests.xml
12-
gotestsum.json
12+
gotests_stats.json
13+
gotests.json
1314
node_modules/
1415
vendor/
1516
yarn-error.log
@@ -32,9 +33,8 @@ site/e2e/states/*.json
3233
site/playwright-report/*
3334
site/.swc
3435

35-
# Make target for updating golden files.
36-
cli/testdata/.gen-golden
37-
helm/tests/testdata/.gen-golden
36+
# Make target for updating golden files (any dir).
37+
.gen-golden
3838

3939
# Build
4040
/build/

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ coderd/apidoc/swagger.json: $(shell find ./scripts/apidocgen $(FIND_EXCLUSIONS)
514514
./scripts/apidocgen/generate.sh
515515
yarn run --cwd=site format:write:only ../docs/api ../docs/manifest.json ../coderd/apidoc/swagger.json
516516

517-
update-golden-files: cli/testdata/.gen-golden helm/tests/testdata/.gen-golden
517+
update-golden-files: cli/testdata/.gen-golden helm/tests/testdata/.gen-golden scripts/ci-report/testdata/.gen-golden
518518
.PHONY: update-golden-files
519519

520520
cli/testdata/.gen-golden: $(wildcard cli/testdata/*.golden) $(wildcard cli/*.tpl) $(GO_SRC_FILES)
@@ -525,6 +525,10 @@ helm/tests/testdata/.gen-golden: $(wildcard helm/tests/testdata/*.golden) $(GO_S
525525
go test ./helm/tests -run=TestUpdateGoldenFiles -update
526526
touch "$@"
527527

528+
scripts/ci-report/testdata/.gen-golden: $(wildcard scripts/ci-report/testdata/*) $(wildcard scripts/ci-report/*.go)
529+
go test ./scripts/ci-report -run=TestOutputMatchesGoldenFile -update
530+
touch "$@"
531+
528532
# Generate a prettierrc for the site package that uses relative paths for
529533
# overrides. This allows us to share the same prettier config between the
530534
# site and the root of the repo.
@@ -596,6 +600,7 @@ test-postgres: test-clean test-postgres-docker
596600
# more consistent execution.
597601
DB=ci DB_FROM=$(shell go run scripts/migrate-ci/main.go) gotestsum \
598602
--junitfile="gotests.xml" \
603+
--jsonfile="gotests.json" \
599604
--packages="./..." -- \
600605
-covermode=atomic -coverprofile="gotests.coverage" -timeout=20m \
601606
-parallel=4 \

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ coder server --postgres-url <url> --access-url <url>
8484

8585
> <sup>1</sup> For production deployments, set up an external PostgreSQL instance for reliability.
8686
87-
Use `coder --help` to get a list of flags and environment variables. Use our [quickstart guide](https://coder.com/docs/v2/latest/quickstart) for a full walkthrough.
87+
Use `coder --help` to get a list of flags and environment variables. Use our [install guides](https://coder.com/docs/v2/latest/guides) for a full walkthrough.
8888

8989
## Documentation
9090

agent/agent.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type Options struct {
8282
Logger slog.Logger
8383
AgentPorts map[int]string
8484
SSHMaxTimeout time.Duration
85+
TailnetListenPort uint16
8586
}
8687

8788
type Client interface {
@@ -118,6 +119,7 @@ func New(options Options) io.Closer {
118119
}
119120
ctx, cancelFunc := context.WithCancel(context.Background())
120121
a := &agent{
122+
tailnetListenPort: options.TailnetListenPort,
121123
reconnectingPTYTimeout: options.ReconnectingPTYTimeout,
122124
logger: options.Logger,
123125
closeCancel: cancelFunc,
@@ -139,12 +141,13 @@ func New(options Options) io.Closer {
139141
}
140142

141143
type agent struct {
142-
logger slog.Logger
143-
client Client
144-
exchangeToken func(ctx context.Context) (string, error)
145-
filesystem afero.Fs
146-
logDir string
147-
tempDir string
144+
logger slog.Logger
145+
client Client
146+
exchangeToken func(ctx context.Context) (string, error)
147+
tailnetListenPort uint16
148+
filesystem afero.Fs
149+
logDir string
150+
tempDir string
148151
// ignorePorts tells the api handler which ports to ignore when
149152
// listing all listening ports. This is helpful to hide ports that
150153
// are used by the agent, that the user does not care about.
@@ -606,9 +609,10 @@ func (a *agent) trackConnGoroutine(fn func()) error {
606609

607610
func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (_ *tailnet.Conn, err error) {
608611
network, err := tailnet.NewConn(&tailnet.Options{
609-
Addresses: []netip.Prefix{netip.PrefixFrom(codersdk.WorkspaceAgentIP, 128)},
610-
DERPMap: derpMap,
611-
Logger: a.logger.Named("tailnet"),
612+
Addresses: []netip.Prefix{netip.PrefixFrom(codersdk.WorkspaceAgentIP, 128)},
613+
DERPMap: derpMap,
614+
Logger: a.logger.Named("tailnet"),
615+
ListenPort: a.tailnetListenPort,
612616
})
613617
if err != nil {
614618
return nil, xerrors.Errorf("create tailnet: %w", err)

cli/agent.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ import (
3030

3131
func (r *RootCmd) workspaceAgent() *clibase.Cmd {
3232
var (
33-
auth string
34-
logDir string
35-
pprofAddress string
36-
noReap bool
37-
sshMaxTimeout time.Duration
33+
auth string
34+
logDir string
35+
pprofAddress string
36+
noReap bool
37+
sshMaxTimeout time.Duration
38+
tailnetListenPort int64
3839
)
3940
cmd := &clibase.Cmd{
4041
Use: "agent",
@@ -187,9 +188,10 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
187188
}
188189

189190
closer := agent.New(agent.Options{
190-
Client: client,
191-
Logger: logger,
192-
LogDir: logDir,
191+
Client: client,
192+
Logger: logger,
193+
LogDir: logDir,
194+
TailnetListenPort: uint16(tailnetListenPort),
193195
ExchangeToken: func(ctx context.Context) (string, error) {
194196
if exchangeToken == nil {
195197
return client.SDK.SessionToken(), nil
@@ -248,6 +250,13 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
248250
Description: "Specify the max timeout for a SSH connection.",
249251
Value: clibase.DurationOf(&sshMaxTimeout),
250252
},
253+
{
254+
Flag: "tailnet-listen-port",
255+
Default: "0",
256+
Env: "CODER_AGENT_TAILNET_LISTEN_PORT",
257+
Description: "Specify a static port for Tailscale to use for listening.",
258+
Value: clibase.Int64Of(&tailnetListenPort),
259+
},
251260
}
252261

253262
return cmd

cli/cliui/parameter.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ func ParameterSchema(inv *clibase.Invocation, parameterSchema codersdk.Parameter
6262
}
6363

6464
func RichParameter(inv *clibase.Invocation, templateVersionParameter codersdk.TemplateVersionParameter) (string, error) {
65-
_, _ = fmt.Fprintln(inv.Stdout, Styles.Bold.Render(templateVersionParameter.Name))
65+
label := templateVersionParameter.Name
66+
if templateVersionParameter.DisplayName != "" {
67+
label = templateVersionParameter.DisplayName
68+
}
69+
70+
_, _ = fmt.Fprintln(inv.Stdout, Styles.Bold.Render(label))
6671
if templateVersionParameter.DescriptionPlaintext != "" {
6772
_, _ = fmt.Fprintln(inv.Stdout, " "+strings.TrimSpace(strings.Join(strings.Split(templateVersionParameter.DescriptionPlaintext, "\n"), "\n "))+"\n")
6873
}

cli/create.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io"
77
"time"
88

9+
"github.com/google/uuid"
910
"golang.org/x/exp/slices"
1011
"golang.org/x/xerrors"
1112

@@ -213,6 +214,7 @@ type prepWorkspaceBuildArgs struct {
213214
NewWorkspaceName string
214215

215216
UpdateWorkspace bool
217+
WorkspaceID uuid.UUID
216218
}
217219

218220
type buildParameters struct {
@@ -340,8 +342,17 @@ PromptRichParamLoop:
340342
}
341343

342344
if args.UpdateWorkspace && !templateVersionParameter.Mutable {
343-
_, _ = fmt.Fprintln(inv.Stdout, cliui.Styles.Warn.Render(fmt.Sprintf(`Parameter %q is not mutable, so can't be customized after workspace creation.`, templateVersionParameter.Name)))
344-
continue
345+
// Check if the immutable parameter was used in the previous build. If so, then it isn't a fresh one
346+
// and the user should be warned.
347+
exists, err := workspaceBuildParameterExists(ctx, client, args.WorkspaceID, templateVersionParameter)
348+
if err != nil {
349+
return nil, err
350+
}
351+
352+
if exists {
353+
_, _ = fmt.Fprintln(inv.Stdout, cliui.Styles.Warn.Render(fmt.Sprintf(`Parameter %q is not mutable, so can't be customized after workspace creation.`, templateVersionParameter.Name)))
354+
continue
355+
}
345356
}
346357

347358
parameterValue, err := getWorkspaceBuildParameterValueFromMapOrInput(inv, parameterMapFromFile, templateVersionParameter)
@@ -414,3 +425,17 @@ PromptRichParamLoop:
414425
richParameters: richParameters,
415426
}, nil
416427
}
428+
429+
func workspaceBuildParameterExists(ctx context.Context, client *codersdk.Client, workspaceID uuid.UUID, templateVersionParameter codersdk.TemplateVersionParameter) (bool, error) {
430+
lastBuildParameters, err := client.WorkspaceBuildParameters(ctx, workspaceID)
431+
if err != nil {
432+
return false, xerrors.Errorf("can't fetch last workspace build parameters: %w", err)
433+
}
434+
435+
for _, p := range lastBuildParameters {
436+
if p.Name == templateVersionParameter.Name {
437+
return true, nil
438+
}
439+
}
440+
return false, nil
441+
}

cli/create_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ func TestCreateWithRichParameters(t *testing.T) {
366366
firstParameterValue = "1"
367367

368368
secondParameterName = "second_parameter"
369+
secondParameterDisplayName = "Second Parameter"
369370
secondParameterDescription = "This is second parameter"
370371
secondParameterValue = "2"
371372

@@ -382,7 +383,7 @@ func TestCreateWithRichParameters(t *testing.T) {
382383
Complete: &proto.Provision_Complete{
383384
Parameters: []*proto.RichParameter{
384385
{Name: firstParameterName, Description: firstParameterDescription, Mutable: true},
385-
{Name: secondParameterName, Description: secondParameterDescription, Mutable: true},
386+
{Name: secondParameterName, DisplayName: secondParameterDisplayName, Description: secondParameterDescription, Mutable: true},
386387
{Name: immutableParameterName, Description: immutableParameterDescription, Mutable: false},
387388
},
388389
},
@@ -418,6 +419,7 @@ func TestCreateWithRichParameters(t *testing.T) {
418419

419420
matches := []string{
420421
firstParameterDescription, firstParameterValue,
422+
secondParameterDisplayName, "",
421423
secondParameterDescription, secondParameterValue,
422424
immutableParameterDescription, immutableParameterValue,
423425
"Confirm create?", "yes",
@@ -426,7 +428,10 @@ func TestCreateWithRichParameters(t *testing.T) {
426428
match := matches[i]
427429
value := matches[i+1]
428430
pty.ExpectMatch(match)
429-
pty.WriteLine(value)
431+
432+
if value != "" {
433+
pty.WriteLine(value)
434+
}
430435
}
431436
<-doneChan
432437
})

cli/delete.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ func (r *RootCmd) deleteWorkspace() *clibase.Cmd {
3737
}
3838

3939
var state []byte
40-
41-
if orphan {
42-
cliui.Warn(
43-
inv.Stderr,
44-
"Orphaning workspace requires template edit permission",
45-
)
46-
}
47-
4840
build, err := client.CreateWorkspaceBuild(inv.Context(), workspace.ID, codersdk.CreateWorkspaceBuildRequest{
4941
Transition: codersdk.WorkspaceTransitionDelete,
5042
ProvisionerState: state,

cli/server.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"strconv"
3131
"strings"
3232
"sync"
33+
"sync/atomic"
3334
"time"
3435

3536
"github.com/coreos/go-oidc/v3/oidc"
@@ -72,6 +73,7 @@ import (
7273
"github.com/coder/coder/coderd/httpapi"
7374
"github.com/coder/coder/coderd/httpmw"
7475
"github.com/coder/coder/coderd/prometheusmetrics"
76+
"github.com/coder/coder/coderd/schedule"
7577
"github.com/coder/coder/coderd/telemetry"
7678
"github.com/coder/coder/coderd/tracing"
7779
"github.com/coder/coder/coderd/updatecheck"
@@ -632,6 +634,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
632634
LoginRateLimit: loginRateLimit,
633635
FilesRateLimit: filesRateLimit,
634636
HTTPClient: httpClient,
637+
TemplateScheduleStore: &atomic.Pointer[schedule.TemplateScheduleStore]{},
635638
SSHConfig: codersdk.SSHConfigResponse{
636639
HostnamePrefix: cfg.SSHConfig.DeploymentName.String(),
637640
SSHConfigOptions: configSSHOptions,
@@ -1025,7 +1028,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
10251028

10261029
autobuildPoller := time.NewTicker(cfg.AutobuildPollInterval.Value())
10271030
defer autobuildPoller.Stop()
1028-
autobuildExecutor := executor.New(ctx, options.Database, logger, autobuildPoller.C)
1031+
autobuildExecutor := executor.New(ctx, options.Database, coderAPI.TemplateScheduleStore, logger, autobuildPoller.C)
10291032
autobuildExecutor.Run()
10301033

10311034
// Currently there is no way to ask the server to shut

0 commit comments

Comments
 (0)