Skip to content

Commit ac74c5e

Browse files
authored
Merge branch 'main' into fixopen
2 parents 1a9fc85 + 693f457 commit ac74c5e

File tree

12 files changed

+93
-44
lines changed

12 files changed

+93
-44
lines changed

.github/workflows/coder.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ jobs:
6060
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
6161

6262
- name: Install node_modules
63-
run: yarn install
64-
working-directory: site
63+
run: ./scripts/yarn_install.sh
6564

6665
- name: "yarn lint"
6766
run: yarn lint
@@ -108,8 +107,7 @@ jobs:
108107
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
109108

110109
- name: Install node_modules
111-
run: yarn install
112-
working-directory: site
110+
run: ./scripts/yarn_install.sh
113111

114112
- name: "make fmt"
115113
run: "make --output-sync -j fmt"
@@ -214,8 +212,8 @@ jobs:
214212
with:
215213
node-version: "14"
216214

217-
- run: yarn install
218-
working-directory: site
215+
- name: Install node_modules
216+
run: ./scripts/yarn_install.sh
219217

220218
- uses: actions/setup-go@v2
221219
with:
@@ -252,13 +250,15 @@ jobs:
252250
with:
253251
node-version: "14"
254252

255-
- run: yarn install
256-
working-directory: site
253+
- name: Install node_modules
254+
run: ./scripts/yarn_install.sh
257255

258-
- run: yarn build
256+
- name: Build frontend
257+
run: yarn build
259258
working-directory: site
260259

261-
- run: yarn storybook:build
260+
- name: Build Storybook
261+
run: yarn storybook:build
262262
working-directory: site
263263

264264
- run: yarn test:coverage

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ provisionersdk/proto: provisionersdk/proto/provisioner.proto
8787
.PHONY: provisionersdk/proto
8888

8989
site/out:
90-
cd site && yarn install
90+
./scripts/yarn_install.sh
9191
cd site && yarn build
9292
cd site && yarn export
93-
.PHONY: site/out
93+
.PHONY: site/out

coderd/cmd/root.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func Root() *cobra.Command {
3333
Use: "coderd",
3434
RunE: func(cmd *cobra.Command, args []string) error {
3535
logger := slog.Make(sloghuman.Sink(os.Stderr))
36-
handler := coderd.New(&coderd.Options{
36+
handler, closeCoderd := coderd.New(&coderd.Options{
3737
Logger: logger,
3838
Database: databasefake.New(),
3939
Pubsub: database.NewPubsubInMemory(),
@@ -49,18 +49,19 @@ func Root() *cobra.Command {
4949
Scheme: "http",
5050
Host: address,
5151
})
52-
closer, err := newProvisionerDaemon(cmd.Context(), client, logger)
52+
daemonClose, err := newProvisionerDaemon(cmd.Context(), client, logger)
5353
if err != nil {
5454
return xerrors.Errorf("create provisioner daemon: %w", err)
5555
}
56-
defer closer.Close()
56+
defer daemonClose.Close()
5757

5858
errCh := make(chan error)
5959
go func() {
6060
defer close(errCh)
6161
errCh <- http.Serve(listener, handler)
6262
}()
6363

64+
closeCoderd()
6465
select {
6566
case <-cmd.Context().Done():
6667
return cmd.Context().Err()

coderd/coderd.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package coderd
22

33
import (
44
"net/http"
5+
"sync"
56

67
"github.com/go-chi/chi/v5"
78

@@ -20,11 +21,12 @@ type Options struct {
2021
}
2122

2223
// New constructs the Coder API into an HTTP handler.
23-
func New(options *Options) http.Handler {
24+
//
25+
// A wait function is returned to handle awaiting closure
26+
// of hijacked HTTP requests.
27+
func New(options *Options) (http.Handler, func()) {
2428
api := &api{
25-
Database: options.Database,
26-
Logger: options.Logger,
27-
Pubsub: options.Pubsub,
29+
Options: options,
2830
}
2931

3032
r := chi.NewRouter()
@@ -144,13 +146,13 @@ func New(options *Options) http.Handler {
144146
})
145147
})
146148
r.NotFound(site.Handler(options.Logger).ServeHTTP)
147-
return r
149+
return r, api.websocketWaitGroup.Wait
148150
}
149151

150152
// API contains all route handlers. Only HTTP handlers should
151153
// be added to this struct for code clarity.
152154
type api struct {
153-
Database database.Store
154-
Logger slog.Logger
155-
Pubsub database.Pubsub
155+
*Options
156+
157+
websocketWaitGroup sync.WaitGroup
156158
}

coderd/coderdtest/coderdtest.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func New(t *testing.T) *codersdk.Client {
5555
})
5656
}
5757

58-
handler := coderd.New(&coderd.Options{
58+
handler, closeWait := coderd.New(&coderd.Options{
5959
Logger: slogtest.Make(t, nil).Leveled(slog.LevelDebug),
6060
Database: db,
6161
Pubsub: pubsub,
@@ -69,7 +69,10 @@ func New(t *testing.T) *codersdk.Client {
6969
srv.Start()
7070
serverURL, err := url.Parse(srv.URL)
7171
require.NoError(t, err)
72-
t.Cleanup(srv.Close)
72+
t.Cleanup(func() {
73+
srv.Close()
74+
closeWait()
75+
})
7376

7477
return codersdk.New(serverURL)
7578
}

coderd/provisionerdaemons.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ func (api *api) provisionerDaemonsServe(rw http.ResponseWriter, r *http.Request)
6262
})
6363
return
6464
}
65+
api.websocketWaitGroup.Add(1)
66+
defer api.websocketWaitGroup.Done()
6567

6668
daemon, err := api.Database.InsertProvisionerDaemon(r.Context(), database.InsertProvisionerDaemonParams{
6769
ID: uuid.New(),
@@ -100,7 +102,9 @@ func (api *api) provisionerDaemonsServe(rw http.ResponseWriter, r *http.Request)
100102
err = server.Serve(r.Context(), session)
101103
if err != nil {
102104
_ = conn.Close(websocket.StatusInternalError, fmt.Sprintf("serve: %s", err))
105+
return
103106
}
107+
_ = conn.Close(websocket.StatusGoingAway, "")
104108
}
105109

106110
// The input for a "workspace_provision" job.

develop.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function create_initial_user() {
2222
}
2323

2424
# Run yarn install, to make sure node_modules are ready to go
25-
yarn --cwd=./site install
25+
"$PROJECT_ROOT/scripts/yarn_install.sh"
2626

2727
# Do initial build - a dev build for coderd.
2828
# It's OK that we don't build the front-end before - because the front-end

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ replace github.com/hashicorp/terraform-config-inspect => github.com/kylecarbs/te
1414
// Required until https://github.com/chzyer/readline/pull/198 is merged.
1515
replace github.com/chzyer/readline => github.com/kylecarbs/readline v0.0.0-20220211054233-0d62993714c8
1616

17+
// Required until https://github.com/pion/ice/pull/425 is merged.
18+
replace github.com/pion/ice/v2 => github.com/kylecarbs/ice/v2 v2.1.8-0.20220221162453-b262a62902c3
19+
1720
require (
1821
cdr.dev/slog v1.4.1
1922
github.com/briandowns/spinner v1.18.1
@@ -114,7 +117,7 @@ require (
114117
github.com/pion/sdp/v3 v3.0.4 // indirect
115118
github.com/pion/srtp/v2 v2.0.5 // indirect
116119
github.com/pion/stun v0.3.5 // indirect
117-
github.com/pion/turn/v2 v2.0.6 // indirect
120+
github.com/pion/turn/v2 v2.0.8 // indirect
118121
github.com/pion/udp v0.1.1 // indirect
119122
github.com/pkg/errors v0.9.1 // indirect
120123
github.com/pmezard/go-difflib v1.0.0 // indirect

go.sum

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
842842
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
843843
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
844844
github.com/ktrysmt/go-bitbucket v0.6.4/go.mod h1:9u0v3hsd2rqCHRIpbir1oP7F58uo5dq19sBYvuMoyQ4=
845+
github.com/kylecarbs/ice/v2 v2.1.8-0.20220221162453-b262a62902c3 h1:/SkVJxNTLozVOnU5OAQhnwt5Nb7h15c1BHad6t4h5MM=
846+
github.com/kylecarbs/ice/v2 v2.1.8-0.20220221162453-b262a62902c3/go.mod h1:Op8jlPtjeiycsXh93Cs4jK82C9j/kh7vef6ztIOvtIQ=
845847
github.com/kylecarbs/promptui v0.8.1-0.20201231190244-d8f2159af2b2 h1:MUREBTh4kybLY1KyuBfSx+QPfTB8XiUHs6ZxUhOPTnU=
846848
github.com/kylecarbs/promptui v0.8.1-0.20201231190244-d8f2159af2b2/go.mod h1:n4zTdgP0vr0S3w7/O/g98U+e0gwLScEXGwov2nIKuGQ=
847849
github.com/kylecarbs/readline v0.0.0-20220211054233-0d62993714c8 h1:Y7O3Z3YeNRtw14QrtHpevU4dSjCkov0J40MtQ7Nc0n8=
@@ -1024,11 +1026,8 @@ github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi
10241026
github.com/pierrec/lz4/v4 v4.1.8/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
10251027
github.com/pion/datachannel v1.5.2 h1:piB93s8LGmbECrpO84DnkIVWasRMk3IimbcXkTQLE6E=
10261028
github.com/pion/datachannel v1.5.2/go.mod h1:FTGQWaHrdCwIJ1rw6xBIfZVkslikjShim5yr05XFuCQ=
1027-
github.com/pion/dtls/v2 v2.1.1/go.mod h1:qG3gA7ZPZemBqpEFqRKyURYdKEwFZQCGb7gv9T3ON3Y=
10281029
github.com/pion/dtls/v2 v2.1.2 h1:22Q1Jk9L++Yo7BIf9130MonNPfPVb+YgdYLeyQotuAA=
10291030
github.com/pion/dtls/v2 v2.1.2/go.mod h1:o6+WvyLDAlXF7YiPB/RlskRoeK+/JtuaZa5emwQcWus=
1030-
github.com/pion/ice/v2 v2.1.20 h1:xpxXyX5b4WjCh/D905gzBeW/hbJxMEPx2ptVfrhVE6M=
1031-
github.com/pion/ice/v2 v2.1.20/go.mod h1:hEAldRzBhTtAfvlU1V/2/nLCMvveQWFKPNCop+63/Iw=
10321031
github.com/pion/interceptor v0.1.7 h1:HThW0tIIKT9RRoDWGURe8rlZVOx0fJHxBHpA0ej0+bo=
10331032
github.com/pion/interceptor v0.1.7/go.mod h1:Lh3JSl/cbJ2wP8I3ccrjh1K/deRGRn3UlSPuOTiHb6U=
10341033
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
@@ -1056,8 +1055,8 @@ github.com/pion/transport v0.12.2/go.mod h1:N3+vZQD9HlDP5GWkZ85LohxNsDcNgofQmyL6
10561055
github.com/pion/transport v0.12.3/go.mod h1:OViWW9SP2peE/HbwBvARicmAVnesphkNkCVZIWJ6q9A=
10571056
github.com/pion/transport v0.13.0 h1:KWTA5ZrQogizzYwPEciGtHPLwpAjE91FgXnyu+Hv2uY=
10581057
github.com/pion/transport v0.13.0/go.mod h1:yxm9uXpK9bpBBWkITk13cLo1y5/ur5VQpG22ny6EP7g=
1059-
github.com/pion/turn/v2 v2.0.6 h1:AsXjSPR6Im15DMTB39NlfdTY9BQfieANPBjdg/aVNwY=
1060-
github.com/pion/turn/v2 v2.0.6/go.mod h1:+y7xl719J8bAEVpSXBXvTxStjJv3hbz9YFflvkpcGPw=
1058+
github.com/pion/turn/v2 v2.0.8 h1:KEstL92OUN3k5k8qxsXHpr7WWfrdp7iJZHx99ud8muw=
1059+
github.com/pion/turn/v2 v2.0.8/go.mod h1:+y7xl719J8bAEVpSXBXvTxStjJv3hbz9YFflvkpcGPw=
10611060
github.com/pion/udp v0.1.1 h1:8UAPvyqmsxK8oOjloDk4wUt63TzFe9WEJkg5lChlj7o=
10621061
github.com/pion/udp v0.1.1/go.mod h1:6AFo+CMdKQm7UiA0eUPA8/eVCTx8jBIITLZHc9DWX5M=
10631062
github.com/pion/webrtc/v3 v3.1.23 h1:suyNiF9o2/6SBsyWA1UweraUWYkaHCNJdt/16b61I5w=
@@ -1327,7 +1326,6 @@ golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5y
13271326
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
13281327
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
13291328
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
1330-
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
13311329
golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838 h1:71vQrMauZZhcTVK6KdYM+rklehEEwb3E+ZhaE5jrPrE=
13321330
golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
13331331
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@@ -1443,7 +1441,6 @@ golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qx
14431441
golang.org/x/net v0.0.0-20211013171255-e13a2654a71e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
14441442
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
14451443
golang.org/x/net v0.0.0-20211201190559-0a0e4e1bb54c/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
1446-
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
14471444
golang.org/x/net v0.0.0-20220111093109-d55c255bac03/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
14481445
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
14491446
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=

scripts/yarn_install.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
#
3+
# Run "yarn install" with flags appropriate to the environment
4+
# (local development vs build system)
5+
#
6+
# Usage: yarn_install.sh [optional extra flags]
7+
8+
set -euo pipefail
9+
10+
PROJECT_ROOT=$(git rev-parse --show-toplevel)
11+
cd "$PROJECT_ROOT/site"
12+
13+
yarn_flags=(
14+
# Do not execute install scripts
15+
# TODO: check if build works properly with this enabled
16+
# --ignore-scripts
17+
18+
# Check if existing node_modules are valid
19+
# TODO: determine if this is necessary
20+
# --check-files
21+
)
22+
23+
if [ -n "${CI:-}" ]; then
24+
yarn_flags+=(
25+
# Install dependencies from lockfile, ensuring builds are fully
26+
# reproducible
27+
--frozen-lockfile
28+
# Suppress progress information
29+
--silent
30+
# Disable interactive prompts for build
31+
--non-interactive
32+
)
33+
fi
34+
35+
# Append whatever is specified on the command line
36+
yarn_flags+=("$@")
37+
38+
echo "+ yarn install ${yarn_flags[*]}"
39+
yarn install "${yarn_flags[@]}"

site/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"@typescript-eslint/eslint-plugin": "4.33.0",
3737
"@typescript-eslint/parser": "4.33.0",
3838
"eslint": "7.32.0",
39-
"eslint-config-prettier": "8.3.0",
39+
"eslint-config-prettier": "8.4.0",
4040
"eslint-import-resolver-alias": "1.1.2",
4141
"eslint-import-resolver-typescript": "2.5.0",
4242
"eslint-plugin-compat": "4.0.2",
@@ -58,7 +58,7 @@
5858
"react": "17.0.2",
5959
"react-dom": "17.0.2",
6060
"sql-formatter": "^4.0.2",
61-
"swr": "1.2.1",
61+
"swr": "1.2.2",
6262
"ts-jest": "27.1.3",
6363
"ts-loader": "9.2.6",
6464
"ts-node": "10.5.0",

site/yarn.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5700,10 +5700,10 @@ escodegen@^2.0.0:
57005700
optionalDependencies:
57015701
source-map "~0.6.1"
57025702

5703-
eslint-config-prettier@8.3.0:
5704-
version "8.3.0"
5705-
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.3.0.tgz#f7471b20b6fe8a9a9254cc684454202886a2dd7a"
5706-
integrity sha512-BgZuLUSeKzvlL/VUjx/Yb787VQ26RU3gGjA3iiFvdsp/2bMfVIWUVP7tjxtjS0e+HP409cPlPvNkQloz8C91ew==
5703+
eslint-config-prettier@8.4.0:
5704+
version "8.4.0"
5705+
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.4.0.tgz#8e6d17c7436649e98c4c2189868562921ef563de"
5706+
integrity sha512-CFotdUcMY18nGRo5KGsnNxpznzhkopOcOo0InID+sgQssPrzjvsyKZPvOgymTFeHrFuC3Tzdf2YndhXtULK9Iw==
57075707

57085708
eslint-import-resolver-alias@1.1.2:
57095709
version "1.1.2"
@@ -11386,10 +11386,10 @@ supports-preserve-symlinks-flag@^1.0.0:
1138611386
resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"
1138711387
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==
1138811388

11389-
swr@1.2.1:
11390-
version "1.2.1"
11391-
resolved "https://registry.yarnpkg.com/swr/-/swr-1.2.1.tgz#c21a4fe2139cb1c4630450589b5b5add947a9d41"
11392-
integrity sha512-1cuWXqJqXcFwbgONGCY4PHZ8v05009JdHsC3CIC6u7d00kgbMswNr1sHnnhseOBxtzVqcCNpOHEgVDciRer45w==
11389+
swr@1.2.2:
11390+
version "1.2.2"
11391+
resolved "https://registry.yarnpkg.com/swr/-/swr-1.2.2.tgz#6cae09928d30593a7980d80f85823e57468fac5d"
11392+
integrity sha512-ky0BskS/V47GpW8d6RU7CPsr6J8cr7mQD6+do5eky3bM0IyJaoi3vO8UhvrzJaObuTlGhPl2szodeB2dUd76Xw==
1139311393

1139411394
symbol-tree@^3.2.4:
1139511395
version "3.2.4"

0 commit comments

Comments
 (0)