Skip to content

Commit f10ee4d

Browse files
committed
Merge main
2 parents dc9ccea + 78bf4c6 commit f10ee4d

File tree

101 files changed

+15420
-3322
lines changed

Some content is hidden

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

101 files changed

+15420
-3322
lines changed

.github/workflows/coder.yaml

+68-18
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ jobs:
7979
- uses: actions/setup-go@v2
8080
with:
8181
go-version: "^1.17"
82-
- run:
83-
curl -sSL
82+
- run: curl -sSL
8483
https://github.com/kyleconroy/sqlc/releases/download/v1.11.0/sqlc_1.11.0_linux_amd64.tar.gz
8584
| sudo tar -C /usr/bin -xz sqlc
8685

@@ -89,14 +88,9 @@ jobs:
8988
- run: "make --output-sync -j gen"
9089
- run: ./scripts/check_unstaged.sh
9190

92-
style:
93-
name: "style/${{ matrix.style }}"
91+
style-fmt:
92+
name: "style/fmt"
9493
runs-on: ubuntu-latest
95-
strategy:
96-
matrix:
97-
style:
98-
- fmt
99-
fail-fast: false
10094
steps:
10195
- name: Checkout
10296
uses: actions/checkout@v2
@@ -117,8 +111,8 @@ jobs:
117111
run: yarn install
118112
working-directory: site
119113

120-
- name: "make ${{ matrix.style }}"
121-
run: "make --output-sync -j ${{ matrix.style }}"
114+
- name: "make fmt"
115+
run: "make --output-sync -j fmt"
122116

123117
test-go:
124118
name: "test/go"
@@ -151,24 +145,37 @@ jobs:
151145
- run: go install gotest.tools/gotestsum@latest
152146

153147
- uses: hashicorp/setup-terraform@v1
154-
if: runner.os == 'Linux'
155148
with:
156149
terraform_version: 1.1.2
157150
terraform_wrapper: false
158151

159152
- name: Test with Mock Database
160-
run:
161-
gotestsum --jsonfile="gotests.json" --packages="./..." --
162-
-covermode=atomic -coverprofile="gotests.coverage" -timeout=3m
163-
-count=3 -race -short -parallel=2
153+
run: gotestsum --junitfile="gotests.xml" --packages="./..." --
154+
-covermode=atomic -coverprofile="gotests.coverage"
155+
-timeout=3m -count=5 -race -short -parallel=2
156+
157+
- name: Upload DataDog Trace
158+
if: (success() || failure()) && github.actor != 'dependabot[bot]'
159+
env:
160+
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
161+
DD_DATABASE: fake
162+
GIT_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
163+
run: go run scripts/datadog-cireport/main.go gotests.xml
164164

165165
- name: Test with PostgreSQL Database
166166
if: runner.os == 'Linux'
167-
run:
168-
DB=true gotestsum --jsonfile="gotests.json" --packages="./..." --
167+
run: DB=true gotestsum --junitfile="gotests.xml" --packages="./..." --
169168
-covermode=atomic -coverprofile="gotests.coverage" -timeout=3m
170169
-count=1 -race -parallel=2
171170

171+
- name: Upload DataDog Trace
172+
if: (success() || failure()) && github.actor != 'dependabot[bot]'
173+
env:
174+
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
175+
DD_DATABASE: postgresql
176+
GIT_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
177+
run: go run scripts/datadog-cireport/main.go gotests.xml
178+
172179
- uses: codecov/codecov-action@v2
173180
if: github.actor != 'dependabot[bot]'
174181
with:
@@ -177,6 +184,46 @@ jobs:
177184
flags: unittest-go-${{ matrix.os }}
178185
fail_ci_if_error: true
179186

187+
deploy:
188+
name: "deploy"
189+
runs-on: ubuntu-latest
190+
if: github.event_name != 'pull_request'
191+
permissions:
192+
contents: read
193+
id-token: write
194+
steps:
195+
- uses: actions/checkout@v2
196+
197+
- name: Authenticate to Google Cloud
198+
uses: google-github-actions/auth@v0
199+
with:
200+
workload_identity_provider: projects/477254869654/locations/global/workloadIdentityPools/github/providers/github
201+
service_account: github-coder@coder-ci.iam.gserviceaccount.com
202+
203+
- name: Set up Google Cloud SDK
204+
uses: google-github-actions/setup-gcloud@v0
205+
206+
- name: Configure Docker for Google Artifact Registry
207+
run: gcloud auth configure-docker us-docker.pkg.dev
208+
209+
- uses: actions/setup-node@v2
210+
with:
211+
node-version: "14"
212+
213+
- run: yarn install
214+
working-directory: site
215+
216+
- uses: actions/setup-go@v2
217+
with:
218+
go-version: "^1.17"
219+
220+
- run: make docker/image/coder
221+
222+
- run: docker push us-docker.pkg.dev/coder-blacktriangle-dev/ci/coder:latest
223+
224+
- name: Update coder service
225+
run: gcloud run services update coder --image us-docker.pkg.dev/coder-blacktriangle-dev/ci/coder:latest --project coder-blacktriangle-dev --tag "git-$(git rev-parse --short HEAD)" --region us-central1
226+
180227
test-js:
181228
name: "test/js"
182229
runs-on: ubuntu-latest
@@ -202,6 +249,9 @@ jobs:
202249
- run: yarn build
203250
working-directory: site
204251

252+
- run: yarn storybook:build
253+
working-directory: site
254+
205255
- run: yarn test:coverage
206256
working-directory: site
207257

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ yarn-error.log
1919
site/.eslintcache
2020
site/.next/
2121
site/node_modules/
22+
site/storybook-static/
2223
site/yarn-error.log
2324
coverage/
2425

.golangci.yml

+5
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ linters-settings:
100100
# - whyNoLint
101101
# - wrapperFunc
102102
# - yodaStyleExpr
103+
settings:
104+
ruleguard:
105+
failOn: all
106+
rules: rules.go
103107

104108
goimports:
105109
local-prefixes: coder.com,cdr.dev,go.coder.com,github.com/cdr,github.com/coder
@@ -241,6 +245,7 @@ linters:
241245
- staticcheck
242246
- structcheck
243247
- tenv
248+
- testpackage
244249
- tparallel
245250
- typecheck
246251
- unconvert

.vscode/settings.json

+30-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,34 @@
2323
}
2424
]
2525
},
26-
"cSpell.words": ["coderd", "coderdtest", "codersdk", "httpmw", "oneof", "stretchr", "xerrors"]
26+
"cSpell.words": [
27+
"coderd",
28+
"coderdtest",
29+
"codersdk",
30+
"drpc",
31+
"drpcconn",
32+
"drpcmux",
33+
"drpcserver",
34+
"goleak",
35+
"hashicorp",
36+
"httpmw",
37+
"Jobf",
38+
"moby",
39+
"nhooyr",
40+
"nolint",
41+
"nosec",
42+
"oneof",
43+
"parameterscopeid",
44+
"protobuf",
45+
"provisionerd",
46+
"provisionersdk",
47+
"retrier",
48+
"sdkproto",
49+
"stretchr",
50+
"tfexec",
51+
"tfstate",
52+
"unconvert",
53+
"xerrors",
54+
"yamux"
55+
]
2756
}

Makefile

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ bin/coderd:
33
go build -o bin/coderd cmd/coderd/main.go
44
.PHONY: bin/coderd
55

6-
bin/provisionerd:
7-
mkdir -p bin
8-
go build -o bin/provisionerd cmd/provisionerd/main.go
9-
.PHONY: bin/provisionerd
10-
11-
build: site/out bin/coderd bin/provisionerd
6+
build: site/out bin/coderd
127
.PHONY: build
138

149
# Runs migrations to output a dump of the database.
@@ -22,6 +17,11 @@ database/generate: fmt/sql database/dump.sql database/query.sql
2217
cd database && gofmt -w -r 'Queries -> sqlQuerier' *.go
2318
.PHONY: database/generate
2419

20+
docker/image/coder: build
21+
cp ./images/coder/run.sh ./bin
22+
docker build --network=host -t us-docker.pkg.dev/coder-blacktriangle-dev/ci/coder:latest -f images/coder/Dockerfile ./bin
23+
.PHONY: docker/build
24+
2525
fmt/prettier:
2626
@echo "--- prettier"
2727
# Avoid writing files in CI to reduce file write activity

codecov.yml

+1
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ ignore:
3131
- peerbroker/proto
3232
- provisionerd/proto
3333
- provisionersdk/proto
34+
- scripts/datadog-cireport

coderd/cmd/root.go

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"cdr.dev/slog"
1212
"cdr.dev/slog/sloggers/sloghuman"
1313
"github.com/coder/coder/coderd"
14+
"github.com/coder/coder/database"
1415
"github.com/coder/coder/database/databasefake"
1516
)
1617

@@ -24,6 +25,7 @@ func Root() *cobra.Command {
2425
handler := coderd.New(&coderd.Options{
2526
Logger: slog.Make(sloghuman.Sink(os.Stderr)),
2627
Database: databasefake.New(),
28+
Pubsub: database.NewPubsubInMemory(),
2729
})
2830

2931
listener, err := net.Listen("tcp", address)

coderd/coderd.go

+44-7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Options struct {
2323
func New(options *Options) http.Handler {
2424
api := &api{
2525
Database: options.Database,
26+
Logger: options.Logger,
2627
Pubsub: options.Pubsub,
2728
}
2829

@@ -61,9 +62,18 @@ func New(options *Options) http.Handler {
6162
r.Use(httpmw.ExtractProjectParam(options.Database))
6263
r.Get("/", api.projectByOrganization)
6364
r.Get("/workspaces", api.workspacesByProject)
64-
r.Route("/history", func(r chi.Router) {
65-
r.Get("/", api.projectHistoryByOrganization)
66-
r.Post("/", api.postProjectHistoryByOrganization)
65+
r.Route("/parameters", func(r chi.Router) {
66+
r.Get("/", api.parametersByProject)
67+
r.Post("/", api.postParametersByProject)
68+
})
69+
r.Route("/versions", func(r chi.Router) {
70+
r.Get("/", api.projectVersionsByOrganization)
71+
r.Post("/", api.postProjectVersionByOrganization)
72+
r.Route("/{projectversion}", func(r chi.Router) {
73+
r.Use(httpmw.ExtractProjectVersionParam(api.Database))
74+
r.Get("/", api.projectVersionByOrganizationAndName)
75+
r.Get("/parameters", api.projectVersionParametersByOrganizationAndName)
76+
})
6777
})
6878
})
6979
})
@@ -76,27 +86,54 @@ func New(options *Options) http.Handler {
7686
r.Get("/", api.workspaces)
7787
r.Route("/{user}", func(r chi.Router) {
7888
r.Use(httpmw.ExtractUserParam(options.Database))
79-
r.Get("/", api.workspaces)
8089
r.Post("/", api.postWorkspaceByUser)
8190
r.Route("/{workspace}", func(r chi.Router) {
8291
r.Use(httpmw.ExtractWorkspaceParam(options.Database))
8392
r.Get("/", api.workspaceByUser)
84-
r.Route("/history", func(r chi.Router) {
93+
r.Route("/version", func(r chi.Router) {
8594
r.Post("/", api.postWorkspaceHistoryByUser)
8695
r.Get("/", api.workspaceHistoryByUser)
87-
r.Get("/latest", api.latestWorkspaceHistoryByUser)
96+
r.Route("/{workspacehistory}", func(r chi.Router) {
97+
r.Use(httpmw.ExtractWorkspaceHistoryParam(options.Database))
98+
r.Get("/", api.workspaceHistoryByName)
99+
})
88100
})
89101
})
90102
})
91103
})
104+
105+
r.Route("/files", func(r chi.Router) {
106+
r.Use(httpmw.ExtractAPIKey(options.Database, nil))
107+
r.Post("/", api.postFiles)
108+
})
109+
110+
r.Route("/provisioners", func(r chi.Router) {
111+
r.Route("/daemons", func(r chi.Router) {
112+
r.Get("/", api.provisionerDaemons)
113+
r.Get("/serve", api.provisionerDaemonsServe)
114+
})
115+
r.Route("/jobs/{organization}", func(r chi.Router) {
116+
r.Use(
117+
httpmw.ExtractAPIKey(options.Database, nil),
118+
httpmw.ExtractOrganizationParam(options.Database),
119+
)
120+
r.Post("/import", api.postProvisionerImportJobByOrganization)
121+
r.Route("/{provisionerjob}", func(r chi.Router) {
122+
r.Use(httpmw.ExtractProvisionerJobParam(options.Database))
123+
r.Get("/", api.provisionerJobByOrganization)
124+
r.Get("/logs", api.provisionerJobLogsByID)
125+
})
126+
})
127+
})
92128
})
93-
r.NotFound(site.Handler().ServeHTTP)
129+
r.NotFound(site.Handler(options.Logger).ServeHTTP)
94130
return r
95131
}
96132

97133
// API contains all route handlers. Only HTTP handlers should
98134
// be added to this struct for code clarity.
99135
type api struct {
100136
Database database.Store
137+
Logger slog.Logger
101138
Pubsub database.Pubsub
102139
}

coderd/coderd_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package coderd_test
2+
3+
import (
4+
"testing"
5+
6+
"go.uber.org/goleak"
7+
)
8+
9+
func TestMain(m *testing.M) {
10+
goleak.VerifyTestMain(m)
11+
}

0 commit comments

Comments
 (0)