Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit036d18f

Browse files
committed
Merge branch 'main' of github.com:coder/coder into bq/refactor-full-page-loader-design
2 parents8524f1f +9410237 commit036d18f

File tree

48 files changed

+1292
-128
lines changed

Some content is hidden

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

48 files changed

+1292
-128
lines changed

‎.github/workflows/release.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,32 @@ on:
33
push:
44
tags:
55
-"v*"
6+
workflow_dispatch:
7+
68
jobs:
79
goreleaser:
810
runs-on:macos-latest
11+
env:
12+
# Necessary for Docker manifest
13+
DOCKER_CLI_EXPERIMENTAL:"enabled"
914
steps:
15+
# Docker is not included on macos-latest
16+
-uses:docker-practice/actions-setup-docker@v1.0.8
17+
1018
-uses:actions/checkout@v3
1119
with:
1220
fetch-depth:0
21+
22+
-name:Set up QEMU
23+
uses:docker/setup-qemu-action@v1
24+
25+
-name:Docker Login
26+
uses:docker/login-action@v1
27+
with:
28+
registry:ghcr.io
29+
username:${{ github.repository_owner }}
30+
password:${{ secrets.GITHUB_TOKEN }}
31+
1332
-uses:actions/setup-go@v3
1433
with:
1534
go-version:"~1.18"

‎.goreleaser.yaml

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,17 @@ before:
2828
builds:
2929
-id:coder-slim
3030
dir:cmd/coder
31-
ldflags:
32-
["-s -w -X github.com/coder/coder/buildinfo.tag={{ .Version }}"]
31+
ldflags:["-s -w -X github.com/coder/coder/buildinfo.tag={{ .Version }}"]
3332
env:[CGO_ENABLED=0]
3433
goos:[darwin, linux, windows]
3534
goarch:[amd64, arm, arm64]
3635
goarm:["7"]
3736
# Only build arm 7 for Linux
3837
ignore:
3938
-goos:windows
40-
goarm:'7'
39+
goarm:"7"
4140
-goos:darwin
42-
goarm:'7'
41+
goarm:"7"
4342
hooks:
4443
# The "trimprefix" appends ".exe" on Windows.
4544
post:|
@@ -48,8 +47,7 @@ builds:
4847
-id:coder-linux
4948
dir:cmd/coder
5049
flags:[-tags=embed]
51-
ldflags:
52-
["-s -w -X github.com/coder/coder/buildinfo.tag={{ .Version }}"]
50+
ldflags:["-s -w -X github.com/coder/coder/buildinfo.tag={{ .Version }}"]
5351
env:[CGO_ENABLED=0]
5452
goos:[linux]
5553
goarch:[amd64, arm, arm64]
@@ -58,24 +56,22 @@ builds:
5856
-id:coder-windows
5957
dir:cmd/coder
6058
flags:[-tags=embed]
61-
ldflags:
62-
["-s -w -X github.com/coder/coder/buildinfo.tag={{ .Version }}"]
59+
ldflags:["-s -w -X github.com/coder/coder/buildinfo.tag={{ .Version }}"]
6360
env:[CGO_ENABLED=0]
6461
goos:[windows]
6562
goarch:[amd64, arm64]
6663

6764
-id:coder-darwin
6865
dir:cmd/coder
6966
flags:[-tags=embed]
70-
ldflags:
71-
["-s -w -X github.com/coder/coder/buildinfo.tag={{ .Version }}"]
67+
ldflags:["-s -w -X github.com/coder/coder/buildinfo.tag={{ .Version }}"]
7268
env:[CGO_ENABLED=0]
7369
goos:[darwin]
7470
goarch:[amd64, arm64]
7571
hooks:
7672
# This signs the binary that will be located inside the zip.
7773
# MacOS requires the binary to be signed for notarization.
78-
#
74+
#
7975
# If it doesn't successfully sign, the zip sign step will error.
8076
post:|
8177
sh -c 'codesign -s {{.Env.AC_APPLICATION_IDENTITY}} -f -v --timestamp --options runtime {{.Path}} || true'
@@ -107,6 +103,54 @@ nfpms:
107103
-src:coder.service
108104
dst:/usr/lib/systemd/system/coder.service
109105

106+
dockers:
107+
-image_templates:["ghcr.io/coder/coder:{{ .Tag }}-amd64"]
108+
id:coder-linux
109+
dockerfile:Dockerfile
110+
use:buildx
111+
build_flag_templates:
112+
---platform=linux/amd64
113+
---label=org.opencontainers.image.title=Coder
114+
---label=org.opencontainers.image.description=A tool for provisioning self-hosted development environments with Terraform.
115+
---label=org.opencontainers.image.url=https://github.com/coder/coder
116+
---label=org.opencontainers.image.source=https://github.com/coder/coder
117+
---label=org.opencontainers.image.version={{ .Version }}
118+
---label=org.opencontainers.image.revision={{ .FullCommit }}
119+
---label=org.opencontainers.image.licenses=AGPL-3.0
120+
-image_templates:["ghcr.io/coder/coder:{{ .Tag }}-arm64"]
121+
goarch:arm64
122+
dockerfile:Dockerfile
123+
use:buildx
124+
build_flag_templates:
125+
---platform=linux/arm64/v8
126+
---label=org.opencontainers.image.title=coder
127+
---label=org.opencontainers.image.description=A tool for provisioning self-hosted development environments with Terraform.
128+
---label=org.opencontainers.image.url=https://github.com/coder/coder
129+
---label=org.opencontainers.image.source=https://github.com/coder/coder
130+
---label=org.opencontainers.image.version={{ .Tag }}
131+
---label=org.opencontainers.image.revision={{ .FullCommit }}
132+
---label=org.opencontainers.image.licenses=AGPL-3.0
133+
-image_templates:["ghcr.io/coder/coder:{{ .Tag }}-armv7"]
134+
goarch:arm
135+
goarm:"7"
136+
dockerfile:Dockerfile
137+
use:buildx
138+
build_flag_templates:
139+
---platform=linux/arm/v7
140+
---label=org.opencontainers.image.title=Coder
141+
---label=org.opencontainers.image.description=A tool for provisioning self-hosted development environments with Terraform.
142+
---label=org.opencontainers.image.url=https://github.com/coder/coder
143+
---label=org.opencontainers.image.source=https://github.com/coder/coder
144+
---label=org.opencontainers.image.version={{ .Tag }}
145+
---label=org.opencontainers.image.revision={{ .FullCommit }}
146+
---label=org.opencontainers.image.licenses=AGPL-3.0
147+
docker_manifests:
148+
-name_template:ghcr.io/coder/coder:{{ .Tag }}
149+
image_templates:
150+
-ghcr.io/coder/coder:{{ .Tag }}-amd64
151+
-ghcr.io/coder/coder:{{ .Tag }}-arm64
152+
-ghcr.io/coder/coder:{{ .Tag }}-armv7
153+
110154
release:
111155
ids:[coder-linux, coder-darwin, coder-windows, packages]
112156

‎Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM alpine
2+
3+
# Generated by goreleaser on `goreleaser release`
4+
ADD coder /opt/coder
5+
6+
ENTRYPOINT ["/opt/coder","server" ]

‎cli/autostart.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ func autostart() *cobra.Command {
2323
Short:"schedule a workspace to automatically start at a regular time",
2424
Long:autostartDescriptionLong,
2525
Example:"coder autostart enable my-workspace --minute 30 --hour 9 --days 1-5 --tz Europe/Dublin",
26-
Hidden:true,
2726
}
2827

2928
autostartCmd.AddCommand(autostartEnable())

‎cli/autostop.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ func autostop() *cobra.Command {
2222
Short:"schedule a workspace to automatically stop at a regular time",
2323
Long:autostopDescriptionLong,
2424
Example:"coder autostop enable my-workspace --minute 0 --hour 18 --days 1-5 -tz Europe/Dublin",
25-
Hidden:true,
2625
}
2726

2827
autostopCmd.AddCommand(autostopEnable())

‎cli/resetpassword.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package cli
2+
3+
import (
4+
"database/sql"
5+
6+
"github.com/spf13/cobra"
7+
"golang.org/x/xerrors"
8+
9+
"github.com/coder/coder/cli/cliflag"
10+
"github.com/coder/coder/cli/cliui"
11+
"github.com/coder/coder/coderd/database"
12+
"github.com/coder/coder/coderd/userpassword"
13+
)
14+
15+
funcresetPassword()*cobra.Command {
16+
var (
17+
postgresURLstring
18+
)
19+
20+
root:=&cobra.Command{
21+
Use:"reset-password <username>",
22+
Short:"Reset a user's password by directly updating the database",
23+
Args:cobra.ExactArgs(1),
24+
RunE:func(cmd*cobra.Command,args []string)error {
25+
username:=args[0]
26+
27+
sqlDB,err:=sql.Open("postgres",postgresURL)
28+
iferr!=nil {
29+
returnxerrors.Errorf("dial postgres: %w",err)
30+
}
31+
defersqlDB.Close()
32+
err=sqlDB.Ping()
33+
iferr!=nil {
34+
returnxerrors.Errorf("ping postgres: %w",err)
35+
}
36+
37+
err=database.EnsureClean(sqlDB)
38+
iferr!=nil {
39+
returnxerrors.Errorf("database needs migration: %w",err)
40+
}
41+
db:=database.New(sqlDB)
42+
43+
user,err:=db.GetUserByEmailOrUsername(cmd.Context(), database.GetUserByEmailOrUsernameParams{
44+
Username:username,
45+
})
46+
iferr!=nil {
47+
returnxerrors.Errorf("retrieving user: %w",err)
48+
}
49+
50+
password,err:=cliui.Prompt(cmd, cliui.PromptOptions{
51+
Text:"Enter new "+cliui.Styles.Field.Render("password")+":",
52+
Secret:true,
53+
Validate:cliui.ValidateNotEmpty,
54+
})
55+
iferr!=nil {
56+
returnxerrors.Errorf("password prompt: %w",err)
57+
}
58+
confirmedPassword,err:=cliui.Prompt(cmd, cliui.PromptOptions{
59+
Text:"Confirm "+cliui.Styles.Field.Render("password")+":",
60+
Secret:true,
61+
Validate:cliui.ValidateNotEmpty,
62+
})
63+
iferr!=nil {
64+
returnxerrors.Errorf("confirm password prompt: %w",err)
65+
}
66+
ifpassword!=confirmedPassword {
67+
returnxerrors.New("Passwords do not match")
68+
}
69+
70+
hashedPassword,err:=userpassword.Hash(password)
71+
iferr!=nil {
72+
returnxerrors.Errorf("hash password: %w",err)
73+
}
74+
75+
err=db.UpdateUserHashedPassword(cmd.Context(), database.UpdateUserHashedPasswordParams{
76+
ID:user.ID,
77+
HashedPassword: []byte(hashedPassword),
78+
})
79+
iferr!=nil {
80+
returnxerrors.Errorf("updating password: %w",err)
81+
}
82+
83+
returnnil
84+
},
85+
}
86+
87+
cliflag.StringVarP(root.Flags(),&postgresURL,"postgres-url","","CODER_PG_CONNECTION_URL","","URL of a PostgreSQL database to connect to")
88+
89+
returnroot
90+
}

‎cli/resetpassword_test.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package cli_test
2+
3+
import (
4+
"context"
5+
"net/url"
6+
"runtime"
7+
"testing"
8+
"time"
9+
10+
"github.com/stretchr/testify/require"
11+
12+
"github.com/coder/coder/cli/clitest"
13+
"github.com/coder/coder/coderd/database/postgres"
14+
"github.com/coder/coder/codersdk"
15+
"github.com/coder/coder/pty/ptytest"
16+
)
17+
18+
funcTestResetPassword(t*testing.T) {
19+
t.Parallel()
20+
21+
ifruntime.GOOS!="linux"||testing.Short() {
22+
// Skip on non-Linux because it spawns a PostgreSQL instance.
23+
t.SkipNow()
24+
}
25+
26+
constemail="some@one.com"
27+
constusername="example"
28+
constoldPassword="password"
29+
constnewPassword="password2"
30+
31+
// start postgres and coder server processes
32+
33+
connectionURL,closeFunc,err:=postgres.Open()
34+
require.NoError(t,err)
35+
defercloseFunc()
36+
ctx,cancelFunc:=context.WithCancel(context.Background())
37+
serverDone:=make(chanstruct{})
38+
serverCmd,cfg:=clitest.New(t,"server","--address",":0","--postgres-url",connectionURL)
39+
gofunc() {
40+
deferclose(serverDone)
41+
err=serverCmd.ExecuteContext(ctx)
42+
require.ErrorIs(t,err,context.Canceled)
43+
}()
44+
varclient*codersdk.Client
45+
require.Eventually(t,func()bool {
46+
rawURL,err:=cfg.URL().Read()
47+
iferr!=nil {
48+
returnfalse
49+
}
50+
accessURL,err:=url.Parse(rawURL)
51+
require.NoError(t,err)
52+
client=codersdk.New(accessURL)
53+
returntrue
54+
},15*time.Second,25*time.Millisecond)
55+
_,err=client.CreateFirstUser(ctx, codersdk.CreateFirstUserRequest{
56+
Email:email,
57+
Username:username,
58+
Password:oldPassword,
59+
OrganizationName:"example",
60+
})
61+
require.NoError(t,err)
62+
63+
// reset the password
64+
65+
resetCmd,cmdCfg:=clitest.New(t,"reset-password","--postgres-url",connectionURL,username)
66+
clitest.SetupConfig(t,client,cmdCfg)
67+
cmdDone:=make(chanstruct{})
68+
pty:=ptytest.New(t)
69+
resetCmd.SetIn(pty.Input())
70+
resetCmd.SetOut(pty.Output())
71+
gofunc() {
72+
deferclose(cmdDone)
73+
err=resetCmd.Execute()
74+
require.NoError(t,err)
75+
}()
76+
77+
matches:= []struct {
78+
outputstring
79+
inputstring
80+
}{
81+
{"Enter new",newPassword},
82+
{"Confirm",newPassword},
83+
}
84+
for_,match:=rangematches {
85+
pty.ExpectMatch(match.output)
86+
pty.WriteLine(match.input)
87+
}
88+
<-cmdDone
89+
90+
// now try logging in
91+
92+
_,err=client.LoginWithPassword(ctx, codersdk.LoginWithPasswordRequest{
93+
Email:email,
94+
Password:oldPassword,
95+
})
96+
require.Error(t,err)
97+
98+
_,err=client.LoginWithPassword(ctx, codersdk.LoginWithPasswordRequest{
99+
Email:email,
100+
Password:newPassword,
101+
})
102+
require.NoError(t,err)
103+
104+
cancelFunc()
105+
<-serverDone
106+
}

‎cli/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func Root() *cobra.Command {
6161
list(),
6262
login(),
6363
publickey(),
64+
resetPassword(),
6465
server(),
6566
show(),
6667
start(),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp