Skip to content

Commit 9279214

Browse files
committed
wip: coder: agent: register version on agent
1 parent b9b9c2f commit 9279214

File tree

17 files changed

+150
-7
lines changed

17 files changed

+150
-7
lines changed

cli/agent.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"cdr.dev/slog/sloggers/sloghuman"
2121
"github.com/coder/coder/agent"
2222
"github.com/coder/coder/agent/reaper"
23+
"github.com/coder/coder/buildinfo"
2324
"github.com/coder/coder/cli/cliflag"
2425
"github.com/coder/coder/codersdk"
2526
"github.com/coder/retry"
@@ -53,6 +54,7 @@ func workspaceAgent() *cobra.Command {
5354
}
5455
defer logWriter.Close()
5556
logger := slog.Make(sloghuman.Sink(cmd.ErrOrStderr()), sloghuman.Sink(logWriter)).Leveled(slog.LevelDebug)
57+
logger.Info(cmd.Context(), "coder agent version: "+buildinfo.Version())
5658

5759
isLinux := runtime.GOOS == "linux"
5860

coderd/coderd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ func New(options *Options) *API {
333333
r.Route("/me", func(r chi.Router) {
334334
r.Use(httpmw.ExtractWorkspaceAgent(options.Database))
335335
r.Get("/metadata", api.workspaceAgentMetadata)
336+
r.Post("/version", api.postWorkspaceAgentVersion)
336337
r.Get("/listen", api.workspaceAgentListen)
337338
r.Get("/gitsshkey", api.agentGitSSHKey)
338339
r.Get("/turn", api.workspaceAgentTurn)

coderd/coderdtest/authtest.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ func AGPLRoutes(a *AuthTester) (map[string]string, map[string]RouteCheck) {
201201
"GET:/api/v2/workspaceagents/me/metadata": {NoAuthorize: true},
202202
"GET:/api/v2/workspaceagents/me/turn": {NoAuthorize: true},
203203
"GET:/api/v2/workspaceagents/me/derp": {NoAuthorize: true},
204+
"POST:/api/v2/workspaceagents/me/version": {NoAuthorize: true},
204205
"GET:/api/v2/workspaceagents/me/wireguardlisten": {NoAuthorize: true},
205206
"POST:/api/v2/workspaceagents/me/keys": {NoAuthorize: true},
206207
"GET:/api/v2/workspaceagents/{workspaceagent}/iceservers": {NoAuthorize: true},

coderd/database/databasefake/databasefake.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,22 @@ func (q *fakeQuerier) UpdateWorkspaceAgentKeysByID(_ context.Context, arg databa
20402040
return sql.ErrNoRows
20412041
}
20422042

2043+
func (q *fakeQuerier) UpdateWorkspaceAgentVersionByID(_ context.Context, arg database.UpdateWorkspaceAgentVersionByIDParams) error {
2044+
q.mutex.Lock()
2045+
defer q.mutex.Unlock()
2046+
2047+
for index, agent := range q.provisionerJobAgents {
2048+
if agent.ID != arg.ID {
2049+
continue
2050+
}
2051+
2052+
agent.Version = arg.Version
2053+
q.provisionerJobAgents[index] = agent
2054+
return nil
2055+
}
2056+
return sql.ErrNoRows
2057+
}
2058+
20432059
func (q *fakeQuerier) UpdateProvisionerJobByID(_ context.Context, arg database.UpdateProvisionerJobByIDParams) error {
20442060
q.mutex.Lock()
20452061
defer q.mutex.Unlock()

coderd/database/dump.sql

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE ONLY workspace_agents DROP COLUMN version;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE ONLY workspace_agents ADD COLUMN version text DEFAULT ''::text NOT NULL;
2+
COMMENT ON COLUMN workspace_agents.version IS 'version tracks the version of the currently running workspace agent. Workspace agents register their version upon start.';

coderd/database/models.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/querier.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 31 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)