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

Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit b4a7ef8

Browse files
committed
Merge branch 'master' into minor-cleanup-tidy-up
Signed-off-by: Guillaume J. Charmes <[email protected]>
2 parents a89511e + 04a201f commit b4a7ef8

File tree

2 files changed

+75
-9
lines changed

2 files changed

+75
-9
lines changed

ci/steps/build.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ popd() { builtin popd >/dev/null; }
77
set -euo pipefail
88
cd "$(dirname "$0")"
99

10-
export GOARCH=amd64
1110
tag=$(git describe --tags)
1211

1312
build() {
13+
echo "Building coder-cli for $GOOS-$GOARCH..."
14+
1415
tmpdir=$(mktemp -d)
1516
go build -ldflags "-X main.version=${tag}" -o "$tmpdir/coder" ../../cmd/coder
1617

@@ -33,12 +34,11 @@ build() {
3334
# Darwin builds do not work from Linux, so only try to build them from Darwin.
3435
# See: https://github.com/cdr/coder-cli/issues/20
3536
if [[ "$(uname)" == "Darwin" ]]; then
36-
GOOS=linux build
37-
CGO_ENABLED=1 GOOS=darwin build
38-
GOOS=windows GOARCH=386 build
39-
exit 0
37+
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 build
38+
else
39+
echo "Warning: Darwin builds don't work on Linux."
40+
echo "Please use an OSX machine to build Darwin tars."
4041
fi
4142

42-
echo "Warning: Darwin builds don't work on Linux."
43-
echo "Please use an OSX machine to build Darwin tars."
44-
GOOS=linux build
43+
GOOS=linux GOARCH=amd64 build
44+
GOOS=windows GOARCH=386 build

coder-sdk/env.go

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"time"
77

88
"cdr.dev/coder-cli/internal/x/xjson"
9+
"golang.org/x/xerrors"
910
"nhooyr.io/websocket"
11+
"nhooyr.io/websocket/wsjson"
1012
)
1113

1214
// Environment describes a Coder environment
@@ -85,10 +87,20 @@ type CreateEnvironmentRequest struct {
8587
// CreateEnvironment sends a request to create an environment.
8688
func (c Client) CreateEnvironment(ctx context.Context, orgID string, req CreateEnvironmentRequest) (*Environment, error) {
8789
var env Environment
90+
<<<<<<< HEAD
8891
if err := c.requestBody(ctx, http.MethodPost, "/api/orgs/"+orgID+"/environments", req, &env); err != nil {
8992
return nil, err
9093
}
9194
return &env, nil
95+
=======
96+
err := c.requestBody(
97+
ctx,
98+
http.MethodPost, "/api/orgs/"+orgID+"/environments",
99+
req,
100+
&env,
101+
)
102+
return &env, err
103+
>>>>>>> master
92104
}
93105

94106
// EnvironmentsByOrganization gets the list of environments owned by the given user.
@@ -111,7 +123,12 @@ func (c Client) DialWsep(ctx context.Context, env *Environment) (*websocket.Conn
111123
return c.dialWebsocket(ctx, "/proxy/environments/"+env.ID+"/wsep")
112124
}
113125

114-
// DialEnvironmentBuildLog opens a websocket connection for the environment build log messages.
126+
// DialIDEStatus opens a websocket connection for cpu load metrics on the environment
127+
func (c Client) DialIDEStatus(ctx context.Context, envID string) (*websocket.Conn, error) {
128+
return c.dialWs(ctx, "/proxy/environments/"+envID+"/ide/api/status")
129+
}
130+
131+
// DialEnvironmentBuildLog opens a websocket connection for the environment build log messages
115132
func (c Client) DialEnvironmentBuildLog(ctx context.Context, envID string) (*websocket.Conn, error) {
116133
return c.dialWebsocket(ctx, "/api/environments/"+envID+"/watch-update")
117134
}
@@ -120,3 +137,52 @@ func (c Client) DialEnvironmentBuildLog(ctx context.Context, envID string) (*web
120137
func (c Client) DialEnvironmentStats(ctx context.Context, envID string) (*websocket.Conn, error) {
121138
return c.dialWebsocket(ctx, "/api/environments/"+envID+"/watch-stats")
122139
}
140+
141+
// DialResourceLoad opens a websocket connection for cpu load metrics on the environment
142+
func (c Client) DialResourceLoad(ctx context.Context, envID string) (*websocket.Conn, error) {
143+
return c.dialWs(ctx, "/api/environments/"+envID+"/watch-resource-load")
144+
}
145+
146+
// BuildLogType describes the type of an event.
147+
type BuildLogType string
148+
149+
const (
150+
// BuildLogTypeStart signals that a new build log has begun.
151+
BuildLogTypeStart BuildLogType = "start"
152+
// BuildLogTypeStage is a stage-level event for an environment.
153+
// It can be thought of as a major step in the environment's
154+
// lifecycle.
155+
BuildLogTypeStage BuildLogType = "stage"
156+
// BuildLogTypeError describes an error that has occurred.
157+
BuildLogTypeError BuildLogType = "error"
158+
// BuildLogTypeSubstage describes a subevent that occurs as
159+
// part of a stage. This can be the output from a user's
160+
// personalization script, or a long running command.
161+
BuildLogTypeSubstage BuildLogType = "substage"
162+
// BuildLogTypeDone signals that the build has completed.
163+
BuildLogTypeDone BuildLogType = "done"
164+
)
165+
166+
type buildLogMsg struct {
167+
Type BuildLogType `json:"type"`
168+
}
169+
170+
// WaitForEnvironmentReady will watch the build log and return when done
171+
func (c Client) WaitForEnvironmentReady(ctx context.Context, env *Environment) error {
172+
conn, err := c.DialEnvironmentBuildLog(ctx, env.ID)
173+
if err != nil {
174+
return xerrors.Errorf("%s: dial build log: %w", env.Name, err)
175+
}
176+
177+
for {
178+
msg := buildLogMsg{}
179+
err := wsjson.Read(ctx, conn, &msg)
180+
if err != nil {
181+
return xerrors.Errorf("%s: reading build log msg: %w", env.Name, err)
182+
}
183+
184+
if msg.Type == BuildLogTypeDone {
185+
return nil
186+
}
187+
}
188+
}

0 commit comments

Comments
 (0)