Skip to content

Commit 6d2f65a

Browse files
committed
Merge branch 'main' into bq/offline-docs
2 parents e58adb3 + 4232a2e commit 6d2f65a

File tree

108 files changed

+2277
-1353
lines changed

Some content is hidden

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

108 files changed

+2277
-1353
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ jobs:
126126
127127
# Check for any typos
128128
- name: Check for typos
129-
uses: crate-ci/typos@v1.16.0
129+
uses: crate-ci/typos@v1.16.1
130130
with:
131131
config: .github/workflows/typos.toml
132132

@@ -165,7 +165,7 @@ jobs:
165165
- name: Setup sqlc
166166
uses: sqlc-dev/setup-sqlc@v3
167167
with:
168-
sqlc-version: "1.18.0"
168+
sqlc-version: "1.19.1"
169169

170170
- name: go install tools
171171
run: |

.github/workflows/dogfood.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,30 @@ jobs:
5151
tags: "codercom/oss-dogfood:${{ steps.docker-tag-name.outputs.tag }},codercom/oss-dogfood:latest"
5252
cache-from: type=registry,ref=codercom/oss-dogfood:latest
5353
cache-to: type=inline
54+
5455
deploy_template:
5556
needs: deploy_image
5657
runs-on: ubuntu-latest
5758
steps:
5859
- name: Checkout
5960
uses: actions/checkout@v3
61+
6062
- name: Get short commit SHA
6163
id: vars
6264
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
65+
66+
- name: Get latest commit title
67+
id: message
68+
run: echo "pr_title=$(git log --format=%s -n 1 ${{ github.sha }})" >> $GITHUB_OUTPUT
69+
6370
- name: "Get latest Coder binary from the server"
6471
run: |
6572
curl -fsSL "https://dev.coder.com/bin/coder-linux-amd64" -o "./coder"
6673
chmod +x "./coder"
74+
6775
- name: "Push template"
6876
run: |
69-
./coder templates push $CODER_TEMPLATE_NAME --directory $CODER_TEMPLATE_DIR --yes --name=$CODER_TEMPLATE_VERSION
77+
./coder templates push $CODER_TEMPLATE_NAME --directory $CODER_TEMPLATE_DIR --yes --name=$CODER_TEMPLATE_VERSION --message="$CODER_TEMPLATE_MESSAGE"
7078
env:
7179
# Consumed by Coder CLI
7280
CODER_URL: https://dev.coder.com
@@ -75,3 +83,4 @@ jobs:
7583
CODER_TEMPLATE_NAME: ${{ secrets.CODER_TEMPLATE_NAME }}
7684
CODER_TEMPLATE_VERSION: ${{ steps.vars.outputs.sha_short }}
7785
CODER_TEMPLATE_DIR: ./dogfood
86+
CODER_TEMPLATE_MESSAGE: ${{ steps.message.outputs.pr_title }}

.github/workflows/pr-deploy.yaml

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ permissions:
1717
pull-requests: write
1818

1919
concurrency:
20-
group: ${{ github.workflow }}-${{ github.ref }}
21-
cancel-in-progress: true
20+
group: ${{ github.workflow }}-${{ github.event.issue.number || github.run_id }}
21+
cancel-in-progress: false
2222

2323
jobs:
2424
pr_commented:
@@ -58,23 +58,6 @@ jobs:
5858
CODER_BASE_IMAGE_TAG: ghcr.io/coder/coder-preview-base:pr${{ steps.pr_number.outputs.PR_NUMBER }}
5959
CODER_IMAGE_TAG: ghcr.io/coder/coder-preview:pr${{ steps.pr_number.outputs.PR_NUMBER }}
6060

61-
- name: Find Deploy Comment
62-
if: github.event_name == 'issue_comment'
63-
uses: peter-evans/find-comment@v2
64-
id: fco
65-
with:
66-
issue-number: ${{ steps.pr_number.outputs.PR_NUMBER }}
67-
comment-author: "github-actions[bot]"
68-
body-includes: /deploy-pr
69-
70-
- name: React with Rocket
71-
if: github.event_name == 'issue_comment'
72-
id: comment_ido
73-
uses: peter-evans/create-or-update-comment@v3
74-
with:
75-
comment-id: ${{ steps.fco.outputs.comment-id }}
76-
reactions: rocket
77-
7861
- name: Find Comment
7962
uses: peter-evans/find-comment@v2
8063
id: fc
@@ -116,7 +99,7 @@ jobs:
11699
- name: Setup sqlc
117100
uses: sqlc-dev/setup-sqlc@v3
118101
with:
119-
sqlc-version: "1.18.0"
102+
sqlc-version: "1.19.1"
120103

121104
- name: GHCR Login
122105
uses: docker/login-action@v2

.github/workflows/security.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
- name: Setup sqlc
8484
uses: sqlc-dev/setup-sqlc@v3
8585
with:
86-
sqlc-version: "1.18.0"
86+
sqlc-version: "1.19.1"
8787

8888
- name: Install yq
8989
run: go run github.com/mikefarah/yq/v4@v4.30.6

cli/cliui/agent.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,26 +137,44 @@ func Agent(ctx context.Context, writer io.Writer, agentID uuid.UUID, opts AgentO
137137
}
138138
defer logsCloser.Close()
139139

140+
var lastLog codersdk.WorkspaceAgentStartupLog
141+
fetchedAgentWhileFollowing := fetchedAgent
142+
if !follow {
143+
fetchedAgentWhileFollowing = nil
144+
}
140145
for {
141146
// This select is essentially and inline `fetch()`.
142147
select {
143148
case <-ctx.Done():
144149
return ctx.Err()
145-
case f := <-fetchedAgent:
150+
case f := <-fetchedAgentWhileFollowing:
146151
if f.err != nil {
147152
return xerrors.Errorf("fetch: %w", f.err)
148153
}
149-
// We could handle changes in the agent status here, like
150-
// if the agent becomes disconnected, we may want to stop.
151-
// But for now, we'll just keep going, hopefully the agent
152-
// will reconnect and update its status.
153154
agent = f.agent
155+
156+
// If the agent is no longer starting, stop following
157+
// logs because FetchLogs will keep streaming forever.
158+
// We do one last non-follow request to ensure we have
159+
// fetched all logs.
160+
if !agent.LifecycleState.Starting() {
161+
_ = logsCloser.Close()
162+
fetchedAgentWhileFollowing = nil
163+
164+
logStream, logsCloser, err = opts.FetchLogs(ctx, agent.ID, lastLog.ID, false)
165+
if err != nil {
166+
return xerrors.Errorf("fetch workspace agent startup logs: %w", err)
167+
}
168+
// Logs are already primed, so we can call close.
169+
_ = logsCloser.Close()
170+
}
154171
case logs, ok := <-logStream:
155172
if !ok {
156173
return nil
157174
}
158175
for _, log := range logs {
159176
sw.Log(log.CreatedAt, log.Level, log.Output)
177+
lastLog = log
160178
}
161179
}
162180
}

cli/cliui/agent_test.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ func TestAgent(t *testing.T) {
4646
func(_ context.Context, agent *codersdk.WorkspaceAgent, logs chan []codersdk.WorkspaceAgentStartupLog) error {
4747
agent.Status = codersdk.WorkspaceAgentConnected
4848
agent.FirstConnectedAt = ptr.Ref(time.Now())
49-
close(logs)
5049
return nil
5150
},
5251
},
@@ -79,7 +78,6 @@ func TestAgent(t *testing.T) {
7978
agent.FirstConnectedAt = ptr.Ref(time.Now())
8079
agent.LifecycleState = codersdk.WorkspaceAgentLifecycleReady
8180
agent.ReadyAt = ptr.Ref(time.Now())
82-
close(logs)
8381
return nil
8482
},
8583
},
@@ -113,10 +111,6 @@ func TestAgent(t *testing.T) {
113111
agent.LastConnectedAt = ptr.Ref(time.Now())
114112
return nil
115113
},
116-
func(_ context.Context, _ *codersdk.WorkspaceAgent, logs chan []codersdk.WorkspaceAgentStartupLog) error {
117-
close(logs)
118-
return nil
119-
},
120114
},
121115
want: []string{
122116
"⧗ The workspace agent lost connection",
@@ -154,7 +148,6 @@ func TestAgent(t *testing.T) {
154148
Output: "Bye now",
155149
},
156150
}
157-
close(logs)
158151
return nil
159152
},
160153
},
@@ -184,7 +177,6 @@ func TestAgent(t *testing.T) {
184177
Output: "Hello world",
185178
},
186179
}
187-
close(logs)
188180
return nil
189181
},
190182
},
@@ -205,7 +197,6 @@ func TestAgent(t *testing.T) {
205197
func(_ context.Context, agent *codersdk.WorkspaceAgent, logs chan []codersdk.WorkspaceAgentStartupLog) error {
206198
agent.Status = codersdk.WorkspaceAgentDisconnected
207199
agent.LifecycleState = codersdk.WorkspaceAgentLifecycleOff
208-
close(logs)
209200
return nil
210201
},
211202
},
@@ -234,7 +225,6 @@ func TestAgent(t *testing.T) {
234225
func(_ context.Context, agent *codersdk.WorkspaceAgent, logs chan []codersdk.WorkspaceAgentStartupLog) error {
235226
agent.ReadyAt = ptr.Ref(time.Now())
236227
agent.LifecycleState = codersdk.WorkspaceAgentLifecycleShuttingDown
237-
close(logs)
238228
return nil
239229
},
240230
},
@@ -316,8 +306,21 @@ func TestAgent(t *testing.T) {
316306
}
317307
return agent, err
318308
}
319-
tc.opts.FetchLogs = func(_ context.Context, _ uuid.UUID, _ int64, _ bool) (<-chan []codersdk.WorkspaceAgentStartupLog, io.Closer, error) {
320-
return logs, closeFunc(func() error { return nil }), nil
309+
tc.opts.FetchLogs = func(ctx context.Context, _ uuid.UUID, _ int64, follow bool) (<-chan []codersdk.WorkspaceAgentStartupLog, io.Closer, error) {
310+
if follow {
311+
return logs, closeFunc(func() error { return nil }), nil
312+
}
313+
314+
fetchLogs := make(chan []codersdk.WorkspaceAgentStartupLog, 1)
315+
select {
316+
case <-ctx.Done():
317+
return nil, nil, ctx.Err()
318+
case l := <-logs:
319+
fetchLogs <- l
320+
default:
321+
}
322+
close(fetchLogs)
323+
return fetchLogs, closeFunc(func() error { return nil }), nil
321324
}
322325
err := cliui.Agent(inv.Context(), &buf, uuid.Nil, tc.opts)
323326
return err

cli/cliui/resources.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource
5050
row := table.Row{"Resource"}
5151
if !options.HideAgentState {
5252
row = append(row, "Status")
53+
row = append(row, "Health")
5354
row = append(row, "Version")
5455
}
5556
if !options.HideAccess {
@@ -81,6 +82,7 @@ func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource
8182
DefaultStyles.Bold.Render(resourceAddress),
8283
"",
8384
"",
85+
"",
8486
})
8587
// Display all agents associated with the resource.
8688
for index, agent := range resource.Agents {
@@ -93,13 +95,13 @@ func WorkspaceResources(writer io.Writer, resources []codersdk.WorkspaceResource
9395
fmt.Sprintf("%s─ %s (%s, %s)", pipe, agent.Name, agent.OperatingSystem, agent.Architecture),
9496
}
9597
if !options.HideAgentState {
96-
var agentStatus string
97-
var agentVersion string
98+
var agentStatus, agentHealth, agentVersion string
9899
if !options.HideAgentState {
99100
agentStatus = renderAgentStatus(agent)
101+
agentHealth = renderAgentHealth(agent)
100102
agentVersion = renderAgentVersion(agent.Version, options.ServerVersion)
101103
}
102-
row = append(row, agentStatus, agentVersion)
104+
row = append(row, agentStatus, agentHealth, agentVersion)
103105
}
104106
if !options.HideAccess {
105107
sshCommand := "coder ssh " + options.WorkspaceName
@@ -141,6 +143,13 @@ func renderAgentStatus(agent codersdk.WorkspaceAgent) string {
141143
}
142144
}
143145

146+
func renderAgentHealth(agent codersdk.WorkspaceAgent) string {
147+
if agent.Health.Healthy {
148+
return DefaultStyles.Keyword.Render("✔ healthy")
149+
}
150+
return DefaultStyles.Error.Render("✘ " + agent.Health.Reason)
151+
}
152+
144153
func renderAgentVersion(agentVersion, serverVersion string) string {
145154
if agentVersion == "" {
146155
agentVersion = "(unknown)"

cli/cliui/resources_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func TestWorkspaceResources(t *testing.T) {
2929
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
3030
Architecture: "amd64",
3131
OperatingSystem: "linux",
32+
Health: codersdk.WorkspaceAgentHealth{Healthy: true},
3233
}},
3334
}}, cliui.WorkspaceResourcesOptions{
3435
WorkspaceName: "example",
@@ -65,6 +66,7 @@ func TestWorkspaceResources(t *testing.T) {
6566
Name: "dev",
6667
OperatingSystem: "linux",
6768
Architecture: "amd64",
69+
Health: codersdk.WorkspaceAgentHealth{Healthy: true},
6870
}},
6971
}, {
7072
Transition: codersdk.WorkspaceTransitionStart,
@@ -76,13 +78,18 @@ func TestWorkspaceResources(t *testing.T) {
7678
Name: "go",
7779
Architecture: "amd64",
7880
OperatingSystem: "linux",
81+
Health: codersdk.WorkspaceAgentHealth{Healthy: true},
7982
}, {
8083
DisconnectedAt: &disconnected,
8184
Status: codersdk.WorkspaceAgentDisconnected,
8285
LifecycleState: codersdk.WorkspaceAgentLifecycleReady,
8386
Name: "postgres",
8487
Architecture: "amd64",
8588
OperatingSystem: "linux",
89+
Health: codersdk.WorkspaceAgentHealth{
90+
Healthy: false,
91+
Reason: "agent has lost connection",
92+
},
8693
}},
8794
}}, cliui.WorkspaceResourcesOptions{
8895
WorkspaceName: "dev",
@@ -94,6 +101,12 @@ func TestWorkspaceResources(t *testing.T) {
94101
}()
95102
ptty.ExpectMatch("google_compute_disk.root")
96103
ptty.ExpectMatch("google_compute_instance.dev")
104+
ptty.ExpectMatch("healthy")
105+
ptty.ExpectMatch("coder ssh dev.dev")
106+
ptty.ExpectMatch("kubernetes_pod.dev")
107+
ptty.ExpectMatch("healthy")
108+
ptty.ExpectMatch("coder ssh dev.go")
109+
ptty.ExpectMatch("agent has lost connection")
97110
ptty.ExpectMatch("coder ssh dev.postgres")
98111
<-done
99112
})

cli/create.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ func (r *RootCmd) create() *clibase.Cmd {
2323
startAt string
2424
stopAfter time.Duration
2525
workspaceName string
26-
27-
parameterFlags workspaceParameterFlags
2826
)
2927
client := new(codersdk.Client)
3028
cmd := &clibase.Cmd{
@@ -135,7 +133,6 @@ func (r *RootCmd) create() *clibase.Cmd {
135133
Template: template,
136134
RichParameterFile: richParameterFile,
137135
NewWorkspaceName: workspaceName,
138-
BuildOptions: parameterFlags.buildOptions,
139136
})
140137
if err != nil {
141138
return xerrors.Errorf("prepare build: %w", err)
@@ -204,8 +201,6 @@ func (r *RootCmd) create() *clibase.Cmd {
204201
},
205202
cliui.SkipPromptOption(),
206203
)
207-
cmd.Options = append(cmd.Options, parameterFlags.options()...)
208-
209204
return cmd
210205
}
211206

0 commit comments

Comments
 (0)