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

Skip to content

Commit d20626a

Browse files
committed
Merge branch 'main' into 5574-cli-add-template-version-parameters
2 parents 1af7b9a + 8819f79 commit d20626a

File tree

245 files changed

+4313
-2507
lines changed

Some content is hidden

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

245 files changed

+4313
-2507
lines changed

.github/workflows/coder.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ jobs:
556556
- name: Install node_modules
557557
run: ./scripts/yarn_install.sh
558558

559-
- run: yarn test:coverage
559+
- run: yarn test:ci
560560
working-directory: site
561561

562562
- uses: codecov/codecov-action@v3
@@ -575,7 +575,7 @@ jobs:
575575
name: "test/e2e/${{ matrix.os }}"
576576
needs:
577577
- changes
578-
if: false #needs.changes.outputs.docs-only == 'false'
578+
if: needs.changes.outputs.docs-only == 'false'
579579
runs-on: ${{ matrix.os }}
580580
timeout-minutes: 20
581581
strategy:

.github/workflows/release.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ jobs:
214214
./build/*.rpm
215215
env:
216216
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
217+
CODER_GPG_RELEASE_KEY_BASE64: ${{ secrets.CODER_GPG_RELEASE_KEY_BASE64 }}
217218

218219
- name: Authenticate to Google Cloud
219220
uses: google-github-actions/auth@v1

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ cli/testdata/.gen-golden
3636
/dist/
3737
site/out/
3838

39+
# Bundle analysis
40+
site/stats/
41+
3942
*.tfstate
4043
*.tfstate.backup
4144
*.tfplan

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ cli/testdata/.gen-golden
3939
/dist/
4040
site/out/
4141

42+
# Bundle analysis
43+
site/stats/
44+
4245
*.tfstate
4346
*.tfstate.backup
4447
*.tfplan

Makefile

+2-3
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,9 @@ docs/admin/prometheus.md: scripts/metricsdocgen/main.go scripts/metricsdocgen/me
490490
cd site
491491
yarn run format:write:only ../docs/admin/prometheus.md
492492

493-
coderd/apidoc/swagger.json: $(shell find ./scripts/apidocgen -not \( -path './scripts/apidocgen/node_modules' -prune \) -type f) $(wildcard coderd/*.go) $(wildcard enterprise/coderd/*.go) $(wildcard codersdk/*.go) .swaggo
493+
coderd/apidoc/swagger.json: $(shell find ./scripts/apidocgen $(FIND_EXCLUSIONS) -type f) $(wildcard coderd/*.go) $(wildcard enterprise/coderd/*.go) $(wildcard codersdk/*.go) .swaggo docs/manifest.json
494494
./scripts/apidocgen/generate.sh
495-
cd site
496-
yarn run format:write:only ../docs/api ../docs/manifest.json ../coderd/apidoc/swagger.json
495+
yarn run --cwd=site format:write:only ../docs/api ../docs/manifest.json ../coderd/apidoc/swagger.json
497496

498497
update-golden-files: cli/testdata/.gen-golden
499498
.PHONY: update-golden-files

buildinfo/buildinfo.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ var (
2121
version string
2222
readVersion sync.Once
2323

24-
// Injected with ldflags at build!
25-
tag string
24+
// Updated by buildinfo_slim.go on start.
25+
slim bool
26+
27+
// Injected with ldflags at build, see scripts/build_go.sh
28+
tag string
29+
agpl string // either "true" or "false", ldflags does not support bools
2630
)
2731

2832
const (
@@ -73,6 +77,16 @@ func IsDev() bool {
7377
return strings.HasPrefix(Version(), develPrefix)
7478
}
7579

80+
// IsSlim returns true if this is a slim build.
81+
func IsSlim() bool {
82+
return slim
83+
}
84+
85+
// IsAGPL returns true if this is an AGPL build.
86+
func IsAGPL() bool {
87+
return strings.Contains(agpl, "t")
88+
}
89+
7690
// ExternalURL returns a URL referencing the current Coder version.
7791
// For production builds, this will link directly to a release.
7892
// For development builds, this will link to a commit.

buildinfo/buildinfo_slim.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build slim
2+
3+
package buildinfo
4+
5+
func init() {
6+
slim = true
7+
}

cli/agent.go

+23
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,26 @@ func workspaceAgent() *cobra.Command {
181181
cliflag.StringVarP(cmd.Flags(), &pprofAddress, "pprof-address", "", "CODER_AGENT_PPROF_ADDRESS", "127.0.0.1:6060", "The address to serve pprof.")
182182
return cmd
183183
}
184+
185+
func serveHandler(ctx context.Context, logger slog.Logger, handler http.Handler, addr, name string) (closeFunc func()) {
186+
logger.Debug(ctx, "http server listening", slog.F("addr", addr), slog.F("name", name))
187+
188+
// ReadHeaderTimeout is purposefully not enabled. It caused some issues with
189+
// websockets over the dev tunnel.
190+
// See: https://github.com/coder/coder/pull/3730
191+
//nolint:gosec
192+
srv := &http.Server{
193+
Addr: addr,
194+
Handler: handler,
195+
}
196+
go func() {
197+
err := srv.ListenAndServe()
198+
if err != nil && !xerrors.Is(err, http.ErrServerClosed) {
199+
logger.Error(ctx, "http server listen", slog.F("name", name), slog.Error(err))
200+
}
201+
}()
202+
203+
return func() {
204+
_ = srv.Close()
205+
}
206+
}

cli/deployment/config.go

+35-6
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,19 @@ func newConfig() *codersdk.DeploymentConfig {
446446
Default: 512,
447447
},
448448
},
449+
// DEPRECATED: use Experiments instead.
449450
Experimental: &codersdk.DeploymentConfigField[bool]{
450-
Name: "Experimental",
451-
Usage: "Enable experimental features. Experimental features are not ready for production.",
452-
Flag: "experimental",
451+
Name: "Experimental",
452+
Usage: "Enable experimental features. Experimental features are not ready for production.",
453+
Flag: "experimental",
454+
Default: false,
455+
Hidden: true,
456+
},
457+
Experiments: &codersdk.DeploymentConfigField[[]string]{
458+
Name: "Experiments",
459+
Usage: "Enable one or more experiments. These are not ready for production. Separate multiple experiments with commas, or enter '*' to opt-in to all available experiments.",
460+
Flag: "experiments",
461+
Default: []string{},
453462
},
454463
UpdateCheck: &codersdk.DeploymentConfigField[bool]{
455464
Name: "Update Check",
@@ -491,6 +500,26 @@ func newConfig() *codersdk.DeploymentConfig {
491500
Default: "",
492501
},
493502
},
503+
Dangerous: &codersdk.DangerousConfig{
504+
AllowPathAppSharing: &codersdk.DeploymentConfigField[bool]{
505+
Name: "DANGEROUS: Allow Path App Sharing",
506+
Usage: "Allow workspace apps that are not served from subdomains to be shared. Path-based app sharing is DISABLED by default for security purposes. Path-based apps can make requests to the Coder API and pose a security risk when the workspace serves malicious JavaScript. Path-based apps can be disabled entirely with --disable-path-apps for further security.",
507+
Flag: "dangerous-allow-path-app-sharing",
508+
Default: false,
509+
},
510+
AllowPathAppSiteOwnerAccess: &codersdk.DeploymentConfigField[bool]{
511+
Name: "DANGEROUS: Allow Site Owners to Access Path Apps",
512+
Usage: "Allow site-owners to access workspace apps from workspaces they do not own. Owners cannot access path-based apps they do not own by default. Path-based apps can make requests to the Coder API and pose a security risk when the workspace serves malicious JavaScript. Path-based apps can be disabled entirely with --disable-path-apps for further security.",
513+
Flag: "dangerous-allow-path-app-site-owner-access",
514+
Default: false,
515+
},
516+
},
517+
DisablePathApps: &codersdk.DeploymentConfigField[bool]{
518+
Name: "Disable Path Apps",
519+
Usage: "Disable workspace apps that are not served from subdomains. Path-based apps can make requests to the Coder API and pose a security risk when the workspace serves malicious JavaScript. This is recommended for security purposes if a --wildcard-access-url is configured.",
520+
Flag: "disable-path-apps",
521+
Default: false,
522+
},
494523
}
495524
}
496525

@@ -557,12 +586,12 @@ func setConfig(prefix string, vip *viper.Viper, target interface{}) {
557586
// with a comma, but Viper only supports with a space. This
558587
// is a small hack around it!
559588
rawSlice := reflect.ValueOf(vip.GetStringSlice(prefix)).Interface()
560-
slice, ok := rawSlice.([]string)
589+
stringSlice, ok := rawSlice.([]string)
561590
if !ok {
562591
panic(fmt.Sprintf("string slice is of type %T", rawSlice))
563592
}
564-
value := make([]string, 0, len(slice))
565-
for _, entry := range slice {
593+
value := make([]string, 0, len(stringSlice))
594+
for _, entry := range stringSlice {
566595
value = append(value, strings.Split(entry, ",")...)
567596
}
568597
val.FieldByName("Value").Set(reflect.ValueOf(value))

cli/deployment/config_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,23 @@ func TestConfig(t *testing.T) {
232232
require.Equal(t, config.Prometheus.Enable.Value, true)
233233
require.Equal(t, config.Prometheus.Address.Value, config.Prometheus.Address.Default)
234234
},
235+
}, {
236+
Name: "Experiments - no features",
237+
Env: map[string]string{
238+
"CODER_EXPERIMENTS": "",
239+
},
240+
Valid: func(config *codersdk.DeploymentConfig) {
241+
require.Empty(t, config.Experiments.Value)
242+
},
243+
}, {
244+
Name: "Experiments - multiple features",
245+
Env: map[string]string{
246+
"CODER_EXPERIMENTS": "foo,bar",
247+
},
248+
Valid: func(config *codersdk.DeploymentConfig) {
249+
expected := []string{"foo", "bar"}
250+
require.ElementsMatch(t, expected, config.Experiments.Value)
251+
},
235252
}} {
236253
tc := tc
237254
t.Run(tc.Name, func(t *testing.T) {

cli/restart.go

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
"time"
6+
7+
"github.com/spf13/cobra"
8+
9+
"github.com/coder/coder/cli/cliui"
10+
"github.com/coder/coder/codersdk"
11+
)
12+
13+
func restart() *cobra.Command {
14+
cmd := &cobra.Command{
15+
Annotations: workspaceCommand,
16+
Use: "restart <workspace>",
17+
Short: "Restart a workspace",
18+
Args: cobra.ExactArgs(1),
19+
RunE: func(cmd *cobra.Command, args []string) error {
20+
ctx := cmd.Context()
21+
out := cmd.OutOrStdout()
22+
23+
_, err := cliui.Prompt(cmd, cliui.PromptOptions{
24+
Text: "Confirm restart workspace?",
25+
IsConfirm: true,
26+
})
27+
if err != nil {
28+
return err
29+
}
30+
31+
client, err := CreateClient(cmd)
32+
if err != nil {
33+
return err
34+
}
35+
workspace, err := namedWorkspace(cmd, client, args[0])
36+
if err != nil {
37+
return err
38+
}
39+
40+
build, err := client.CreateWorkspaceBuild(ctx, workspace.ID, codersdk.CreateWorkspaceBuildRequest{
41+
Transition: codersdk.WorkspaceTransitionStop,
42+
})
43+
if err != nil {
44+
return err
45+
}
46+
err = cliui.WorkspaceBuild(ctx, out, client, build.ID)
47+
if err != nil {
48+
return err
49+
}
50+
51+
build, err = client.CreateWorkspaceBuild(ctx, workspace.ID, codersdk.CreateWorkspaceBuildRequest{
52+
Transition: codersdk.WorkspaceTransitionStart,
53+
})
54+
if err != nil {
55+
return err
56+
}
57+
err = cliui.WorkspaceBuild(ctx, out, client, build.ID)
58+
if err != nil {
59+
return err
60+
}
61+
62+
_, _ = fmt.Fprintf(out, "\nThe %s workspace has been restarted at %s!\n", cliui.Styles.Keyword.Render(workspace.Name), cliui.Styles.DateTimeStamp.Render(time.Now().Format(time.Stamp)))
63+
return nil
64+
},
65+
}
66+
cliui.AllowSkipPrompt(cmd)
67+
return cmd
68+
}

cli/restart_test.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package cli_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
8+
"github.com/coder/coder/cli/clitest"
9+
"github.com/coder/coder/coderd/coderdtest"
10+
"github.com/coder/coder/pty/ptytest"
11+
"github.com/coder/coder/testutil"
12+
)
13+
14+
func TestRestart(t *testing.T) {
15+
t.Parallel()
16+
17+
t.Run("OK", func(t *testing.T) {
18+
t.Parallel()
19+
20+
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
21+
user := coderdtest.CreateFirstUser(t, client)
22+
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
23+
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
24+
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
25+
workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
26+
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
27+
28+
ctx, _ := testutil.Context(t)
29+
30+
cmd, root := clitest.New(t, "restart", workspace.Name, "--yes")
31+
clitest.SetupConfig(t, client, root)
32+
33+
pty := ptytest.New(t)
34+
cmd.SetIn(pty.Input())
35+
cmd.SetOut(pty.Output())
36+
37+
done := make(chan error, 1)
38+
go func() {
39+
done <- cmd.ExecuteContext(ctx)
40+
}()
41+
pty.ExpectMatch("Stopping workspace")
42+
pty.ExpectMatch("Starting workspace")
43+
pty.ExpectMatch("workspace has been restarted")
44+
45+
err := <-done
46+
require.NoError(t, err, "execute failed")
47+
})
48+
}

cli/root.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func Core() []*cobra.Command {
9595
start(),
9696
state(),
9797
stop(),
98+
restart(),
9899
templates(),
99100
tokens(),
100101
update(),
@@ -213,12 +214,22 @@ func versionCmd() *cobra.Command {
213214
Short: "Show coder version",
214215
RunE: func(cmd *cobra.Command, args []string) error {
215216
var str strings.Builder
216-
_, _ = str.WriteString(fmt.Sprintf("Coder %s", buildinfo.Version()))
217+
_, _ = str.WriteString("Coder ")
218+
if buildinfo.IsAGPL() {
219+
_, _ = str.WriteString("(AGPL) ")
220+
}
221+
_, _ = str.WriteString(buildinfo.Version())
217222
buildTime, valid := buildinfo.Time()
218223
if valid {
219224
_, _ = str.WriteString(" " + buildTime.Format(time.UnixDate))
220225
}
221-
_, _ = str.WriteString("\r\n" + buildinfo.ExternalURL() + "\r\n")
226+
_, _ = str.WriteString("\r\n" + buildinfo.ExternalURL() + "\r\n\r\n")
227+
228+
if buildinfo.IsSlim() {
229+
_, _ = str.WriteString(fmt.Sprintf("Slim build of Coder, does not support the %s subcommand.\n", cliui.Styles.Code.Render("server")))
230+
} else {
231+
_, _ = str.WriteString(fmt.Sprintf("Full build of Coder, supports the %s subcommand.\n", cliui.Styles.Code.Render("server")))
232+
}
222233

223234
_, _ = fmt.Fprint(cmd.OutOrStdout(), str.String())
224235
return nil

0 commit comments

Comments
 (0)