Skip to content

Commit ba5e822

Browse files
author
Katie Horne
committed
Merge branch 'main' into docker-compose
2 parents ed4a1ce + c47b6f0 commit ba5e822

File tree

10 files changed

+49
-21
lines changed

10 files changed

+49
-21
lines changed

coderd/workspaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (api *api) workspaces(rw http.ResponseWriter, r *http.Request) {
151151

152152
// Empty strings mean no filter
153153
orgFilter := r.URL.Query().Get("organization_id")
154-
ownerFilter := r.URL.Query().Get("owner_id")
154+
ownerFilter := r.URL.Query().Get("owner")
155155

156156
filter := database.GetWorkspacesWithFilterParams{Deleted: false}
157157
if orgFilter != "" {

codersdk/workspaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (f WorkspaceFilter) asRequestOption() requestOption {
194194
q.Set("organization_id", f.OrganizationID.String())
195195
}
196196
if f.Owner != "" {
197-
q.Set("owner_id", f.Owner)
197+
q.Set("owner", f.Owner)
198198
}
199199
r.URL.RawQuery = q.Encode()
200200
}

docker-compose.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
version: "3.9"
22
services:
33
coder:
4-
image: ghcr.io/coder/coder:v${CODER_VERSION:-0.5.6}-${ARCH:-amd64}
4+
image: ghcr.io/coder/coder:v${CODER_VERSION:-0.5.10}-${ARCH:-amd64}
55
ports:
66
- "7080:7080"
77
environment:
88
CODER_PG_CONNECTION_URL: "postgresql://${POSTGRES_USER:-username}:${POSTGRES_PASSWORD:-password}@database/${POSTGRES_DB:-coder}?sslmode=disable"
99
CODER_ADDRESS: "0.0.0.0:7080"
10+
# You'll need to set CODER_ACCESS_URL to an
11+
# externally-reachable IP to use non-Docker examples!
12+
CODER_ACCESS_URL: "${CODER_ACCESS_URL:-http://host.docker.internal:7080}"
1013
volumes:
1114
- /var/run/docker.sock:/var/run/docker.sock
1215
depends_on:

examples/docker-image-builds/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Edit the validation to include the new image:
5454

5555
```diff
5656
variable "docker_image" {
57-
description = "What Docker imagewould you like to use for your workspace?"
57+
description = "What Docker image would you like to use for your workspace?"
5858
default = "base"
5959

6060
# List of images available for the user to choose from.

examples/docker-image-builds/main.tf

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ provider "docker" {
4242
}
4343

4444
provider "coder" {
45-
# The below assumes your Coder deployment is running in docker-compose.
46-
# If this is not the case, either comment or edit the below.
47-
url = "http://host.docker.internal:7080"
4845
}
4946

5047
data "coder_workspace" "me" {
@@ -56,7 +53,7 @@ resource "coder_agent" "dev" {
5653
}
5754

5855
variable "docker_image" {
59-
description = "What Docker imagewould you like to use for your workspace?"
56+
description = "What Docker image would you like to use for your workspace?"
6057
default = "base"
6158

6259
# List of images available for the user to choose from.

examples/docker/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Edit the template:
2020
vim main.tf
2121
```
2222
variable "docker_image" {
23-
description = "What Docker imagewould you like to use for your workspace?"
23+
description = "What Docker image would you like to use for your workspace?"
2424
default = "codercom/enterprise-base:ubuntu"
2525
validation {
2626
- condition = contains(["codercom/enterprise-base:ubuntu", "codercom/enterprise-node:ubuntu", "codercom/enterprise-intellij:ubuntu"], var.docker_image)
@@ -46,7 +46,7 @@ To reduce drift, we recommend versioning images in your registry by creating tag
4646

4747
```sh
4848
variable "docker_image" {
49-
description = "What Docker imagewould you like to use for your workspace?"
49+
description = "What Docker image would you like to use for your workspace?"
5050
default = "codercom/enterprise-base:ubuntu"
5151
validation {
5252
- condition = contains(["my-org/base-development:v1.1", "myorg-java-development:v1.1"], var.docker_image)

examples/docker/main.tf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ provider "docker" {
4949
}
5050

5151
provider "coder" {
52-
# The below assumes your Coder deployment is running in docker-compose.
53-
# If this is not the case, either comment or edit the below.
54-
url = "http://host.docker.internal:7080"
5552
}
5653

5754
data "coder_workspace" "me" {

site/src/api/api.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import axios from "axios"
2-
import { getApiKey, login, logout } from "./api"
2+
import { getApiKey, getWorkspacesURL, login, logout } from "./api"
33
import * as TypesGen from "./typesGenerated"
44

55
describe("api.ts", () => {
@@ -113,4 +113,17 @@ describe("api.ts", () => {
113113
}
114114
})
115115
})
116+
117+
describe("getWorkspacesURL", () => {
118+
it.each<[TypesGen.WorkspaceFilter | undefined, string]>([
119+
[undefined, "/api/v2/workspaces"],
120+
121+
[{ OrganizationID: "1", Owner: "" }, "/api/v2/workspaces?organization_id=1"],
122+
[{ OrganizationID: "", Owner: "1" }, "/api/v2/workspaces?owner=1"],
123+
124+
[{ OrganizationID: "1", Owner: "me" }, "/api/v2/workspaces?organization_id=1&owner=me"],
125+
])(`getWorkspacesURL(%p) returns %p`, (filter, expected) => {
126+
expect(getWorkspacesURL(filter)).toBe(expected)
127+
})
128+
})
116129
})

site/src/api/api.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,25 @@ export const getWorkspace = async (workspaceId: string): Promise<TypesGen.Worksp
120120
return response.data
121121
}
122122

123-
// TODO: @emyrk add query params as arguments. Supports 'organization_id' and 'owner'
124-
// 'owner' can be a username, user_id, or 'me'
125-
export const getWorkspaces = async (): Promise<TypesGen.Workspace[]> => {
126-
const response = await axios.get<TypesGen.Workspace[]>(`/api/v2/workspaces`)
123+
export const getWorkspacesURL = (filter?: TypesGen.WorkspaceFilter): string => {
124+
const basePath = "/api/v2/workspaces"
125+
const searchParams = new URLSearchParams()
126+
127+
if (filter?.OrganizationID) {
128+
searchParams.append("organization_id", filter.OrganizationID)
129+
}
130+
if (filter?.Owner) {
131+
searchParams.append("owner", filter.Owner)
132+
}
133+
134+
const searchString = searchParams.toString()
135+
136+
return searchString ? `${basePath}?${searchString}` : basePath
137+
}
138+
139+
export const getWorkspaces = async (filter?: TypesGen.WorkspaceFilter): Promise<TypesGen.Workspace[]> => {
140+
const url = getWorkspacesURL(filter)
141+
const response = await axios.get<TypesGen.Workspace[]>(url)
127142
return response.data
128143
}
129144

site/src/testHelpers/handlers.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ export const handlers = [
3636
rest.post("/api/v2/users/me/workspaces", async (req, res, ctx) => {
3737
return res(ctx.status(200), ctx.json(M.MockWorkspace))
3838
}),
39-
rest.get("/api/v2/workspaces", async (req, res, ctx) => {
40-
return res(ctx.status(200), ctx.json([M.MockWorkspace]))
41-
}),
4239
rest.get("/api/v2/users/me/organizations", (req, res, ctx) => {
4340
return res(ctx.status(200), ctx.json([M.MockOrganization]))
4441
}),
@@ -79,6 +76,12 @@ export const handlers = [
7976
}),
8077

8178
// workspaces
79+
80+
// REMARK: This endpoint works with query parameters, but they won't be
81+
// reflected in the return.
82+
rest.get("/api/v2/workspaces", async (req, res, ctx) => {
83+
return res(ctx.status(200), ctx.json([M.MockWorkspace]))
84+
}),
8285
rest.get("/api/v2/organizations/:organizationId/workspaces/:userName/:workspaceName", (req, res, ctx) => {
8386
if (req.params.workspaceName !== M.MockWorkspace.name) {
8487
return res(

0 commit comments

Comments
 (0)