Skip to content

Commit d170d27

Browse files
authored
feat: add external property to coder_app (coder#5425)
* Add schema * feat: add `external` property to `coder_app` This allows exposing applications that open an external URL.
1 parent 8bc247d commit d170d27

File tree

20 files changed

+213
-158
lines changed

20 files changed

+213
-158
lines changed

agent/apphealth.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.Workspace
3434
hasHealthchecksEnabled := false
3535
health := make(map[uuid.UUID]codersdk.WorkspaceAppHealth, 0)
3636
for _, app := range apps {
37-
health[app.ID] = app.Health
38-
if !hasHealthchecksEnabled && app.Health != codersdk.WorkspaceAppHealthDisabled {
39-
hasHealthchecksEnabled = true
37+
if app.Health == codersdk.WorkspaceAppHealthDisabled {
38+
continue
4039
}
40+
health[app.ID] = app.Health
41+
hasHealthchecksEnabled = true
4142
}
4243

4344
// no need to run this loop if no health checks are configured.
@@ -77,7 +78,7 @@ func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.Workspace
7778
return err
7879
}
7980
// successful healthcheck is a non-5XX status code
80-
res.Body.Close()
81+
_ = res.Body.Close()
8182
if res.StatusCode >= http.StatusInternalServerError {
8283
return xerrors.Errorf("error status code: %d", res.StatusCode)
8384
}

coderd/database/databasefake/databasefake.go

+1
Original file line numberDiff line numberDiff line change
@@ -2742,6 +2742,7 @@ func (q *fakeQuerier) InsertWorkspaceApp(_ context.Context, arg database.InsertW
27422742
Icon: arg.Icon,
27432743
Command: arg.Command,
27442744
Url: arg.Url,
2745+
External: arg.External,
27452746
Subdomain: arg.Subdomain,
27462747
SharingLevel: arg.SharingLevel,
27472748
HealthcheckUrl: arg.HealthcheckUrl,

coderd/database/dump.sql

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE workspace_apps DROP COLUMN external;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE workspace_apps ADD COLUMN external boolean NOT NULL DEFAULT false;

coderd/database/models.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

+13-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaceapps.sql

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ INSERT INTO
2121
icon,
2222
command,
2323
url,
24+
external,
2425
subdomain,
2526
sharing_level,
2627
healthcheck_url,
@@ -29,7 +30,7 @@ INSERT INTO
2930
health
3031
)
3132
VALUES
32-
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) RETURNING *;
33+
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) RETURNING *;
3334

3435
-- name: UpdateWorkspaceAppHealthByID :exec
3536
UPDATE

coderd/provisionerdserver/provisionerdserver.go

+1
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,7 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
952952
String: app.Url,
953953
Valid: app.Url != "",
954954
},
955+
External: app.External,
955956
Subdomain: app.Subdomain,
956957
SharingLevel: sharingLevel,
957958
HealthcheckUrl: app.Healthcheck.Url,

coderd/workspaceagents.go

+2
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,8 @@ func convertApps(dbApps []database.WorkspaceApp) []codersdk.WorkspaceApp {
644644
for _, dbApp := range dbApps {
645645
apps = append(apps, codersdk.WorkspaceApp{
646646
ID: dbApp.ID,
647+
URL: dbApp.Url.String,
648+
External: dbApp.External,
647649
Slug: dbApp.Slug,
648650
DisplayName: dbApp.DisplayName,
649651
Command: dbApp.Command.String,

codersdk/workspaceapps.go

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ const (
2323

2424
type WorkspaceApp struct {
2525
ID uuid.UUID `json:"id"`
26+
// URL is the address being proxied to inside the workspace.
27+
// If external is specified, this will be opened on the client.
28+
URL string `json:"url"`
29+
// External specifies whether the URL should be opened externally on
30+
// the client or not.
31+
External bool `json:"external"`
2632
// Slug is a unique identifier within the agent.
2733
Slug string `json:"slug"`
2834
// DisplayName is a friendly name for the app.

provisioner/terraform/resources.go

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type agentAppAttributes struct {
3838
Name string `mapstructure:"name"`
3939
Icon string `mapstructure:"icon"`
4040
URL string `mapstructure:"url"`
41+
External bool `mapstructure:"external"`
4142
Command string `mapstructure:"command"`
4243
Share string `mapstructure:"share"`
4344
Subdomain bool `mapstructure:"subdomain"`
@@ -297,6 +298,7 @@ func ConvertResources(module *tfjson.StateModule, rawGraph string) ([]*proto.Res
297298
Slug: attrs.Slug,
298299
DisplayName: attrs.DisplayName,
299300
Command: attrs.Command,
301+
External: attrs.External,
300302
Url: attrs.URL,
301303
Icon: attrs.Icon,
302304
Subdomain: attrs.Subdomain,

0 commit comments

Comments
 (0)