Skip to content

Commit 08b2814

Browse files
committed
Merge remote-tracking branch 'origin/main' into pb-improvements
2 parents 6f914a4 + 60cec02 commit 08b2814

File tree

80 files changed

+1458
-476
lines changed

Some content is hidden

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

80 files changed

+1458
-476
lines changed

.github/workflows/typos.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ MacOS = "macOS"
99
doas = "doas"
1010
darcula = "darcula"
1111
Hashi = "Hashi"
12+
trialer = "trialer"
1213

1314
[files]
1415
extend-exclude = [

.golangci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ linters-settings:
123123

124124
misspell:
125125
locale: US
126+
ignore-words:
127+
- trialer
126128

127129
nestif:
128130
min-complexity: 4 # Min complexity of if statements (def 5, goal 4)

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"codersdk",
1818
"cronstrue",
1919
"databasefake",
20+
"dbtype",
2021
"DERP",
2122
"derphttp",
2223
"derpmap",
@@ -127,6 +128,7 @@
127128
"tfstate",
128129
"tios",
129130
"tparallel",
131+
"trialer",
130132
"trimprefix",
131133
"tsdial",
132134
"tslogger",

cli/deployment/config.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func newConfig() *codersdk.DeploymentConfig {
143143
Name: "Cache Directory",
144144
Usage: "The directory to cache temporary files. If unspecified and $CACHE_DIRECTORY is set, it will be used for compatibility with systemd.",
145145
Flag: "cache-dir",
146-
Default: defaultCacheDir(),
146+
Default: DefaultCacheDir(),
147147
},
148148
InMemoryDatabase: &codersdk.DeploymentConfigField[bool]{
149149
Name: "In Memory Database",
@@ -529,9 +529,11 @@ func readSliceFromViper[T any](vip *viper.Viper, key string, value any) []T {
529529
newType := reflect.Indirect(reflect.New(elementType))
530530
instance = &newType
531531
}
532-
switch instance.Field(i).Type().String() {
532+
switch v := instance.Field(i).Type().String(); v {
533533
case "[]string":
534534
value = vip.GetStringSlice(configKey)
535+
case "bool":
536+
value = vip.GetBool(configKey)
535537
default:
536538
}
537539
instance.Field(i).Set(reflect.ValueOf(value))
@@ -672,7 +674,7 @@ func formatEnv(key string) string {
672674
return "CODER_" + strings.ToUpper(strings.NewReplacer("-", "_", ".", "_").Replace(key))
673675
}
674676

675-
func defaultCacheDir() string {
677+
func DefaultCacheDir() string {
676678
defaultCacheDir, err := os.UserCacheDir()
677679
if err != nil {
678680
defaultCacheDir = os.TempDir()

cli/deployment/config_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ func TestConfig(t *testing.T) {
167167
"CODER_GITAUTH_0_TOKEN_URL": "https://token.com",
168168
"CODER_GITAUTH_0_REGEX": "github.com",
169169
"CODER_GITAUTH_0_SCOPES": "read write",
170+
"CODER_GITAUTH_0_NO_REFRESH": "true",
170171

171172
"CODER_GITAUTH_1_ID": "another",
172173
"CODER_GITAUTH_1_TYPE": "gitlab",
@@ -187,6 +188,7 @@ func TestConfig(t *testing.T) {
187188
TokenURL: "https://token.com",
188189
Regex: "github.com",
189190
Scopes: []string{"read", "write"},
191+
NoRefresh: true,
190192
}, {
191193
ID: "another",
192194
Type: "gitlab",

cli/gitaskpass.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func gitAskpass() *cobra.Command {
2626
RunE: func(cmd *cobra.Command, args []string) error {
2727
ctx := cmd.Context()
2828

29-
ctx, stop := signal.NotifyContext(ctx, interruptSignals...)
29+
ctx, stop := signal.NotifyContext(ctx, InterruptSignals...)
3030
defer stop()
3131

3232
user, host, err := gitauth.ParseAskpass(args[0])

cli/gitssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func gitssh() *cobra.Command {
2929

3030
// Catch interrupt signals to ensure the temporary private
3131
// key file is cleaned up on most cases.
32-
ctx, stop := signal.NotifyContext(ctx, interruptSignals...)
32+
ctx, stop := signal.NotifyContext(ctx, InterruptSignals...)
3333
defer stop()
3434

3535
// Early check so errors are reported immediately.

cli/login.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ func init() {
3838
}
3939

4040
func login() *cobra.Command {
41+
const firstUserTrialEnv = "CODER_FIRST_USER_TRIAL"
42+
4143
var (
4244
email string
4345
username string
4446
password string
47+
trial bool
4548
)
4649
cmd := &cobra.Command{
4750
Use: "login <url>",
@@ -162,11 +165,20 @@ func login() *cobra.Command {
162165
}
163166
}
164167

168+
if !cmd.Flags().Changed("first-user-trial") && os.Getenv(firstUserTrialEnv) == "" {
169+
v, _ := cliui.Prompt(cmd, cliui.PromptOptions{
170+
Text: "Start a 30-day trial of Enterprise?",
171+
IsConfirm: true,
172+
Default: "yes",
173+
})
174+
trial = v == "yes" || v == "y"
175+
}
176+
165177
_, err = client.CreateFirstUser(cmd.Context(), codersdk.CreateFirstUserRequest{
166-
Email: email,
167-
Username: username,
168-
OrganizationName: username,
169-
Password: password,
178+
Email: email,
179+
Username: username,
180+
Password: password,
181+
Trial: trial,
170182
})
171183
if err != nil {
172184
return xerrors.Errorf("create initial user: %w", err)
@@ -251,6 +263,7 @@ func login() *cobra.Command {
251263
cliflag.StringVarP(cmd.Flags(), &email, "first-user-email", "", "CODER_FIRST_USER_EMAIL", "", "Specifies an email address to use if creating the first user for the deployment.")
252264
cliflag.StringVarP(cmd.Flags(), &username, "first-user-username", "", "CODER_FIRST_USER_USERNAME", "", "Specifies a username to use if creating the first user for the deployment.")
253265
cliflag.StringVarP(cmd.Flags(), &password, "first-user-password", "", "CODER_FIRST_USER_PASSWORD", "", "Specifies a password to use if creating the first user for the deployment.")
266+
cliflag.BoolVarP(cmd.Flags(), &trial, "first-user-trial", "", firstUserTrialEnv, false, "Specifies whether a trial license should be provisioned for the Coder deployment or not.")
254267
return cmd
255268
}
256269

cli/login_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func TestLogin(t *testing.T) {
5656
"email", "user@coder.com",
5757
"password", "password",
5858
"password", "password", // Confirm.
59+
"trial", "yes",
5960
}
6061
for i := 0; i < len(matches); i += 2 {
6162
match := matches[i]
@@ -74,7 +75,7 @@ func TestLogin(t *testing.T) {
7475
// accurately detect Windows ptys when they are not attached to a process:
7576
// https://github.com/mattn/go-isatty/issues/59
7677
doneChan := make(chan struct{})
77-
root, _ := clitest.New(t, "login", client.URL.String(), "--first-user-username", "testuser", "--first-user-email", "user@coder.com", "--first-user-password", "password")
78+
root, _ := clitest.New(t, "login", client.URL.String(), "--first-user-username", "testuser", "--first-user-email", "user@coder.com", "--first-user-password", "password", "--first-user-trial")
7879
pty := ptytest.New(t)
7980
root.SetIn(pty.Input())
8081
root.SetOut(pty.Output())
@@ -127,6 +128,8 @@ func TestLogin(t *testing.T) {
127128
pty.WriteLine("pass")
128129
pty.ExpectMatch("Confirm")
129130
pty.WriteLine("pass")
131+
pty.ExpectMatch("trial")
132+
pty.WriteLine("yes")
130133
pty.ExpectMatch("Welcome to Coder")
131134
<-doneChan
132135
})

cli/resetpassword_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ func TestResetPassword(t *testing.T) {
6060
client := codersdk.New(accessURL)
6161

6262
_, err = client.CreateFirstUser(ctx, codersdk.CreateFirstUserRequest{
63-
Email: email,
64-
Username: username,
65-
Password: oldPassword,
66-
OrganizationName: "example",
63+
Email: email,
64+
Username: username,
65+
Password: oldPassword,
6766
})
6867
require.NoError(t, err)
6968

cli/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
108108
//
109109
// To get out of a graceful shutdown, the user can send
110110
// SIGQUIT with ctrl+\ or SIGKILL with `kill -9`.
111-
notifyCtx, notifyStop := signal.NotifyContext(ctx, interruptSignals...)
111+
notifyCtx, notifyStop := signal.NotifyContext(ctx, InterruptSignals...)
112112
defer notifyStop()
113113

114114
// Clean up idle connections at the end, e.g.
@@ -946,7 +946,7 @@ func newProvisionerDaemon(
946946
return provisionerd.New(func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error) {
947947
// This debounces calls to listen every second. Read the comment
948948
// in provisionerdserver.go to learn more!
949-
return coderAPI.ListenProvisionerDaemon(ctx, time.Second)
949+
return coderAPI.CreateInMemoryProvisionerDaemon(ctx, time.Second)
950950
}, &provisionerd.Options{
951951
Logger: logger,
952952
PollInterval: 500 * time.Millisecond,

cli/server_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,9 @@ func TestServer(t *testing.T) {
7171
client := codersdk.New(accessURL)
7272

7373
_, err = client.CreateFirstUser(ctx, codersdk.CreateFirstUserRequest{
74-
Email: "some@one.com",
75-
Username: "example",
76-
Password: "password",
77-
OrganizationName: "example",
74+
Email: "some@one.com",
75+
Username: "example",
76+
Password: "password",
7877
})
7978
require.NoError(t, err)
8079
cancelFunc()

cli/signal_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"syscall"
88
)
99

10-
var interruptSignals = []os.Signal{
10+
var InterruptSignals = []os.Signal{
1111
os.Interrupt,
1212
syscall.SIGTERM,
1313
syscall.SIGHUP,

cli/signal_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ import (
66
"os"
77
)
88

9-
var interruptSignals = []os.Signal{os.Interrupt}
9+
var InterruptSignals = []os.Signal{os.Interrupt}

cli/templatecreate.go

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ import (
2424

2525
func templateCreate() *cobra.Command {
2626
var (
27-
directory string
28-
provisioner string
29-
parameterFile string
30-
defaultTTL time.Duration
27+
directory string
28+
provisioner string
29+
provisionerTags []string
30+
parameterFile string
31+
defaultTTL time.Duration
3132
)
3233
cmd := &cobra.Command{
3334
Use: "create [name]",
@@ -87,12 +88,18 @@ func templateCreate() *cobra.Command {
8788
}
8889
spin.Stop()
8990

91+
tags, err := ParseProvisionerTags(provisionerTags)
92+
if err != nil {
93+
return err
94+
}
95+
9096
job, _, err := createValidTemplateVersion(cmd, createValidTemplateVersionArgs{
91-
Client: client,
92-
Organization: organization,
93-
Provisioner: database.ProvisionerType(provisioner),
94-
FileID: resp.ID,
95-
ParameterFile: parameterFile,
97+
Client: client,
98+
Organization: organization,
99+
Provisioner: database.ProvisionerType(provisioner),
100+
FileID: resp.ID,
101+
ParameterFile: parameterFile,
102+
ProvisionerTags: tags,
96103
})
97104
if err != nil {
98105
return err
@@ -131,6 +138,7 @@ func templateCreate() *cobra.Command {
131138
cmd.Flags().StringVarP(&directory, "directory", "d", currentDirectory, "Specify the directory to create from")
132139
cmd.Flags().StringVarP(&provisioner, "test.provisioner", "", "terraform", "Customize the provisioner backend")
133140
cmd.Flags().StringVarP(&parameterFile, "parameter-file", "", "", "Specify a file path with parameter values.")
141+
cmd.Flags().StringArrayVarP(&provisionerTags, "provisioner-tag", "", []string{}, "Specify a set of tags to target provisioner daemons.")
134142
cmd.Flags().DurationVarP(&defaultTTL, "default-ttl", "", 24*time.Hour, "Specify a default TTL for workspaces created from this template.")
135143
// This is for testing!
136144
err := cmd.Flags().MarkHidden("test.provisioner")
@@ -154,6 +162,7 @@ type createValidTemplateVersionArgs struct {
154162
// before prompting the user. Set to false to always prompt for param
155163
// values.
156164
ReuseParameters bool
165+
ProvisionerTags map[string]string
157166
}
158167

159168
func createValidTemplateVersion(cmd *cobra.Command, args createValidTemplateVersionArgs, parameters ...codersdk.CreateParameterRequest) (*codersdk.TemplateVersion, []codersdk.CreateParameterRequest, error) {
@@ -165,6 +174,7 @@ func createValidTemplateVersion(cmd *cobra.Command, args createValidTemplateVers
165174
FileID: args.FileID,
166175
Provisioner: codersdk.ProvisionerType(args.Provisioner),
167176
ParameterValues: parameters,
177+
ProvisionerTags: args.ProvisionerTags,
168178
}
169179
if args.Template != nil {
170180
req.TemplateID = args.Template.ID
@@ -334,3 +344,15 @@ func prettyDirectoryPath(dir string) string {
334344
}
335345
return pretty
336346
}
347+
348+
func ParseProvisionerTags(rawTags []string) (map[string]string, error) {
349+
tags := map[string]string{}
350+
for _, rawTag := range rawTags {
351+
parts := strings.SplitN(rawTag, "=", 2)
352+
if len(parts) < 2 {
353+
return nil, xerrors.Errorf("invalid tag format for %q. must be key=value", rawTag)
354+
}
355+
tags[parts[0]] = parts[1]
356+
}
357+
return tags, nil
358+
}

cli/templatepush.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ import (
1818

1919
func templatePush() *cobra.Command {
2020
var (
21-
directory string
22-
versionName string
23-
provisioner string
24-
parameterFile string
25-
alwaysPrompt bool
21+
directory string
22+
versionName string
23+
provisioner string
24+
parameterFile string
25+
alwaysPrompt bool
26+
provisionerTags []string
2627
)
2728

2829
cmd := &cobra.Command{
@@ -75,6 +76,11 @@ func templatePush() *cobra.Command {
7576
}
7677
spin.Stop()
7778

79+
tags, err := ParseProvisionerTags(provisionerTags)
80+
if err != nil {
81+
return err
82+
}
83+
7884
job, _, err := createValidTemplateVersion(cmd, createValidTemplateVersionArgs{
7985
Name: versionName,
8086
Client: client,
@@ -84,6 +90,7 @@ func templatePush() *cobra.Command {
8490
ParameterFile: parameterFile,
8591
Template: &template,
8692
ReuseParameters: !alwaysPrompt,
93+
ProvisionerTags: tags,
8794
})
8895
if err != nil {
8996
return err

coderd/autobuild/executor/lifecycle_executor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ func build(ctx context.Context, store database.Store, workspace database.Workspa
278278
Type: database.ProvisionerJobTypeWorkspaceBuild,
279279
StorageMethod: priorJob.StorageMethod,
280280
FileID: priorJob.FileID,
281+
Tags: priorJob.Tags,
281282
Input: input,
282283
})
283284
if err != nil {

0 commit comments

Comments
 (0)