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

Skip to content

Commit 7f4565c

Browse files
committed
Merge branch 'main' into agent
2 parents d16496c + d04570a commit 7f4565c

File tree

8 files changed

+73
-20
lines changed

8 files changed

+73
-20
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: 8 additions & 2 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
"google.golang.org/api/idtoken"
@@ -23,7 +24,10 @@ type Options struct {
2324
}
2425

2526
// New constructs the Coder API into an HTTP handler.
26-
func New(options *Options) http.Handler {
27+
//
28+
// A wait function is returned to handle awaiting closure
29+
// of hijacked HTTP requests.
30+
func New(options *Options) (http.Handler, func()) {
2731
api := &api{
2832
Options: options,
2933
}
@@ -151,11 +155,13 @@ func New(options *Options) http.Handler {
151155
})
152156
})
153157
r.NotFound(site.Handler(options.Logger).ServeHTTP)
154-
return r
158+
return r, api.websocketWaitGroup.Wait
155159
}
156160

157161
// API contains all route handlers. Only HTTP handlers should
158162
// be added to this struct for code clarity.
159163
type api struct {
160164
*Options
165+
166+
websocketWaitGroup sync.WaitGroup
161167
}

coderd/coderdtest/coderdtest.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func New(t *testing.T, options *Options) *codersdk.Client {
8080
})
8181
}
8282

83-
handler := coderd.New(&coderd.Options{
83+
handler, closeWait := coderd.New(&coderd.Options{
8484
Logger: slogtest.Make(t, nil).Leveled(slog.LevelDebug),
8585
Database: db,
8686
Pubsub: pubsub,
@@ -96,7 +96,10 @@ func New(t *testing.T, options *Options) *codersdk.Client {
9696
srv.Start()
9797
serverURL, err := url.Parse(srv.URL)
9898
require.NoError(t, err)
99-
t.Cleanup(srv.Close)
99+
t.Cleanup(func() {
100+
srv.Close()
101+
closeWait()
102+
})
100103

101104
return codersdk.New(serverURL)
102105
}

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

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[@]}"

0 commit comments

Comments
 (0)