Compare commits

...

1838 Commits

Author SHA1 Message Date
Ben Potter d843735c02 docs: explain Template inheritance with Terraform modules (#8328)
* docs: explain Template inheritance with Terraform modules

* make fmt & title renaming

---------

Co-authored-by: Eric <ericpaulsen@coder.com>
2023-07-05 15:06:16 -04:00
Colin Adler c0835c443d chore: pin terraform to 1.5.2 (#8322)
The Alpine ARM builders are no longer behind on releases.
2023-07-05 12:59:58 -05:00
Steven Masley 418c9b8743 docs: update template acl example params (#8320)
Param examples were unhelpful
2023-07-05 17:24:21 +00:00
Steven Masley 4a008a8f34 chore: prevent nil dereferences on cmd handlers (#8319)
* chore: detect nil cmd handlers

Prevent nil panic dereferences on cmd handlers. Add a unit test
to prevent future mistakes
2023-07-05 17:20:12 +00:00
Steven Masley d70e2d97de chore: use correct prettier version in ci (#8321)
Install prettier in package.json + yarn.lock. Global install was using incorrect version
2023-07-05 13:11:08 -04:00
Steven Masley 0f5a1ad480 feat: add spinner to latencies when refetching (#8278)
* feat: add spinner to latencies when refetching
2023-07-05 13:06:09 -04:00
Steven Masley 9a7705c656 feat: generate a new session with coder login --token (#8275)
* feat: coder login --token generates a new session

Makes sure /logout does not delete the inputted token
* flag to enable previous behavior if needed
2023-07-05 08:59:38 -04:00
Mathias Fredriksson 88c35d3f04 fix(pty): close output writer before reader on Windows to unblock close (#8299) 2023-07-05 15:25:07 +03:00
Colin Adler 59246e054f chore(dogfood): add libssl-dev to image (#8312) 2023-07-05 00:24:32 -05:00
sharkymark 65112ecc04 docs: update examples of IDEs: remove JetBrains Projector and add VS Code Server (#8310)
* docs: remove mention of jetbrains projector; add vs code server web IDE example

* fmt

---------

Co-authored-by: Ben <me@bpmct.net>
2023-07-04 13:27:49 +00:00
dependabot[bot] 647fd7699b chore: bump github.com/prometheus/client_golang from 1.15.1 to 1.16.0 (#8300)
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.15.1 to 1.16.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.15.1...v1.16.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-03 13:00:37 -05:00
dependabot[bot] 865f49af35 chore: bump github.com/gohugoio/hugo from 0.114.1 to 0.115.0 (#8301)
Bumps [github.com/gohugoio/hugo](https://github.com/gohugoio/hugo) from 0.114.1 to 0.115.0.
- [Release notes](https://github.com/gohugoio/hugo/releases)
- [Changelog](https://github.com/gohugoio/hugo/blob/master/hugoreleaser.toml)
- [Commits](https://github.com/gohugoio/hugo/compare/v0.114.1...v0.115.0)

---
updated-dependencies:
- dependency-name: github.com/gohugoio/hugo
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-03 13:00:31 -05:00
dependabot[bot] 2fc8a275fe chore: bump google.golang.org/api from 0.128.0 to 0.129.0 (#8303)
Bumps [google.golang.org/api](https://github.com/googleapis/google-api-go-client) from 0.128.0 to 0.129.0.
- [Release notes](https://github.com/googleapis/google-api-go-client/releases)
- [Changelog](https://github.com/googleapis/google-api-go-client/blob/main/CHANGES.md)
- [Commits](https://github.com/googleapis/google-api-go-client/compare/v0.128.0...v0.129.0)

---
updated-dependencies:
- dependency-name: google.golang.org/api
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-03 13:00:15 -05:00
dependabot[bot] 82a6405bfa chore: bump golang.org/x/tools from 0.9.3 to 0.10.0 (#8304)
Bumps [golang.org/x/tools](https://github.com/golang/tools) from 0.9.3 to 0.10.0.
- [Release notes](https://github.com/golang/tools/releases)
- [Commits](https://github.com/golang/tools/compare/v0.9.3...v0.10.0)

---
updated-dependencies:
- dependency-name: golang.org/x/tools
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-03 13:00:05 -05:00
Jon Ayers 4a9c8f407a feat: add auto-locking/deleting workspace based on template config (#8240) 2023-07-02 21:29:52 -05:00
dependabot[bot] 818c4a7f23 chore: bump yup from 0.32.11 to 1.2.0 in /site (#8287)
Bumps [yup](https://github.com/jquense/yup) from 0.32.11 to 1.2.0.
- [Release notes](https://github.com/jquense/yup/releases)
- [Changelog](https://github.com/jquense/yup/blob/master/CHANGELOG.md)
- [Commits](https://github.com/jquense/yup/compare/v0.32.11...v1.2.0)

---
updated-dependencies:
- dependency-name: yup
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-02 10:32:43 -05:00
dependabot[bot] 2af41a439b chore: bump @vitejs/plugin-react from 2.1.0 to 4.0.1 in /site (#8288)
Bumps [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/tree/HEAD/packages/plugin-react) from 2.1.0 to 4.0.1.
- [Release notes](https://github.com/vitejs/vite-plugin-react/releases)
- [Changelog](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite-plugin-react/commits/plugin-react@4.0.1/packages/plugin-react)

---
updated-dependencies:
- dependency-name: "@vitejs/plugin-react"
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-02 10:32:36 -05:00
dependabot[bot] 2899b9431d chore: bump monaco-editor from 0.38.0 to 0.39.0 in /site (#8289)
Bumps [monaco-editor](https://github.com/microsoft/monaco-editor) from 0.38.0 to 0.39.0.
- [Changelog](https://github.com/microsoft/monaco-editor/blob/main/CHANGELOG.md)
- [Commits](https://github.com/microsoft/monaco-editor/compare/v0.38.0...v0.39.0)

---
updated-dependencies:
- dependency-name: monaco-editor
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-02 10:32:30 -05:00
dependabot[bot] c19541e28f chore: bump eslint-plugin-unicorn from 44.0.0 to 47.0.0 in /site (#8291)
Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 44.0.0 to 47.0.0.
- [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases)
- [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v44.0.0...v47.0.0)

---
updated-dependencies:
- dependency-name: eslint-plugin-unicorn
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-02 10:32:19 -05:00
Jon Ayers 681e2db9ec Revert "fix: add front-end fixes for minor workspace action bugs (#8252)" (#8286)
This reverts commit c569528fb7.
2023-06-30 20:26:38 -05:00
Muhammad Atif Ali 83bee35c36 chore: prevent running ci when other workflows are updated (#8285) 2023-06-30 22:38:50 +00:00
Muhammad Atif Ali dad4876e90 chore: react to deploy-pr comment (#8284) 2023-06-30 22:25:23 +00:00
Asher 6015319e9d feat: show service banner in SSH/TTY sessions (#8186)
* Allow workspace agents to get appearance
* Poll for service banner every two minutes
* Show service banner before MOTD if not quiet
2023-06-30 10:41:29 -08:00
Steven Masley eb0497ff82 feat: fetch proxy latencies at most once per 30s (#8277)
* feat: fetch proxy latencies at most once per 30s
2023-06-30 12:45:02 -04:00
Steven Masley f0bd258ff1 feat: move proxy settings page to deployment options (#8246)
* feat: Move workspace proxy page to deployment options

Workspace proxy settings page is now an admin feature

* WorkspaceProxy response extends region
2023-06-30 11:32:35 -04:00
Cian Johnston 1e8cc2ca8d feat: scaletest: scale down nodegroups by default (#8276)
* feat: allow scaling down scaletest environments

* fix bugged namespace deletion

* misc fixes to scaletest.sh

* destroy namespaces is a no-op as the cluster will be gone anyway
2023-06-30 16:07:47 +01:00
Cian Johnston a6bd85df38 feat: scaletest: add Grafana dashboard for scale testing (#8274)
* feat: scaletest: add Grafana dashboard for scale testing

Fixes #7600.

* make fmt
2023-06-30 14:04:46 +00:00
Kira Pilot c569528fb7 fix: add front-end fixes for minor workspace action bugs (#8252)
* fix: incorrect copy on inactivity_ttl field

* disabling locked fields unless inactivity TTL is set

* scoping inactivity dialog message to template

* fixed pluralization for inactivity dialog

* amending logic gate to show inactivity dialog

* fixed pagination bug
2023-06-30 09:45:44 -04:00
Steven Masley 9f76dab348 chore: Bump migration to remove conflict (#8273) 2023-06-30 13:12:40 +00:00
Cian Johnston 8b2d4b87fc fix: examples/lima: use new parameter name when creating template (#8272) 2023-06-30 12:45:47 +00:00
Steven Masley b5f26d9bdf feat: add ability for users to convert their password login type to oauth/github login (#8105)
* Currently toggled by experiment flag

---------

Co-authored-by: Bruno Quaresma <bruno@coder.com>
2023-06-30 08:38:48 -04:00
Cian Johnston 357f3b38f7 fix: scaletest: mount CODER_CACHE volume under /tmp (#8271)
Mounting the CODER_CACHE volume under /tmp/coder causes
template creation to fail due to read-only tmp dir.
2023-06-30 12:48:34 +01:00
Marcin Tojek 6639c69fad feat: add "display_order" column to coder_parameter to keep parameters sorted in UI (#8227) 2023-06-30 12:41:55 +02:00
Colin Adler 72a48bee52 fix: pin datadog-ci version (#8270) 2023-06-30 03:42:13 +00:00
Kyle Carberry 34467a3289 feat: add github device flow for authentication (#8232)
* feat: add github device flow for authentication

This will allow us to add a GitHub OAuth provider out-of-the-box
to reduce setup requirements.

* Improve askpass view

* Add routes to improve clarity of git auth

* Redesign the git auth page

* Refactor to add a page view

* Fix sideways layout

* Remove legacy notify

* Fix git auth redirects

* Add E2E tests

* Fix route documentation

* Fix imports

* Remove unused imports

* Fix E2E web test

* Fix friendly message appearance

* Fix layout shifting for full-screen sign-in

* Fix height going to 100%

* Fix comments
2023-06-29 18:58:01 +00:00
Eric Paulsen 7f82eca64a docs: note SSH key location in workspaces (#8264) 2023-06-29 12:01:07 -04:00
Cian Johnston 7072b8eff5 chore: update scaletest terraform with latest findings (#8249)
Updates scaletest terraform with learnings from #8213:

- Increase max pods per node to 256
- Decrease CPU requests for test workspace to allow maxing out workspaces per node
- Explicitly set CODER_ACCESS_URL for ssh to work
- Explicitly disable rate limits in coderd
- Increase DB size for medium and large scenarios
- Mount cache volume directly under /tmp/coder instead of /tmp.
- Plumb through requests and limits for workspaces
- Plumb through requests for coderd
2023-06-29 14:03:11 +00:00
Marcin Tojek 83fee4b192 feat: enable Terraform debug mode via deployment configuration (#8260) 2023-06-29 15:22:21 +02:00
Kira Pilot 7ca624eceb fix: removing prettier path in vscode config (#8255) 2023-06-29 09:00:51 -04:00
Jon Ayers 749307ef08 feat: provide endpoint to lock/unlock workspace (#8239) 2023-06-28 16:12:49 -05:00
Steven Masley 72e83df578 hotfix: fix broken link in the group sync docs (#8251) 2023-06-28 13:55:50 -04:00
Marcin Tojek 3dbc96d597 feat: show queue position of pending workspace build (#8244) 2023-06-28 14:48:58 +02:00
Mathias Fredriksson d3c39b60c9 feat: add agent log streaming and follow provisioner format (#8170) 2023-06-28 10:54:13 +02:00
Spike Curtis c0a01ec81c fix: fix TestPGCoordinatorDual_Mainline flake (#8228)
* fix TestPGCoordinatorDual_Mainline flake

Signed-off-by: Spike Curtis <spike@coder.com>

* use slices.Contains instead of local function

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
2023-06-28 11:37:45 +04:00
Eric Paulsen df95cf7ab2 feat: helm rbac perms for deployments (#8233) 2023-06-27 15:14:39 -04:00
Colin Adler b8a143566b fix: use *string instead of error in healthcheck response (#8234) 2023-06-27 19:13:54 +00:00
Asher e2e07b01e9 fix: revert to canvas renderer for xterm (#8138)
The default changed from canvas to DOM in the last update.  The canvas
renderer resolves line spacing issues and has better performance, as
well as bringing us back to the previous status quo.

In the new version the canvas is enabled via an addon.
2023-06-27 09:57:16 -08:00
Mathias Fredriksson b4751c72d8 fix(cli/agent): wrap lumberjack logger to prevent re-open (#8229) 2023-06-27 12:49:44 +00:00
Mathias Fredriksson 6d176aee5d test(agent): fix lifecycle test flakeyness (#8230) 2023-06-27 12:44:16 +00:00
Muhammad Atif Ali 25decc152a chore: fix broken docs links (#8198)
* chore: add examples templates to docs filter

* chore: fix broken docs links

* Discard changes to .github/workflows/ci.yaml
2023-06-27 08:20:57 -04:00
Ben Potter 70cd87140d docs: mark agent metadata as GA (#8111)
* docs: agent metadata is now GA

* fmt
2023-06-27 07:35:01 -04:00
Muhammad Atif Ali 9cefd46bcf chore: delete skipped workflow runs of pr-deploy.yaml (#8225) 2023-06-27 14:26:21 +03:00
Marcin Tojek b83cdfe428 chore: update nix flake to include sqlc v1.18.0 (#8226) 2023-06-27 12:50:04 +02:00
Spike Curtis 7943a5b85e fix PG coordinator context and RBAC subject (#8223)
Signed-off-by: Spike Curtis <spike@coder.com>
2023-06-27 10:14:31 +00:00
Spike Curtis 5d26637686 feat(scaletest): add license and experiment to scaletest (#8222)
* add license and experiment to scaletest

Signed-off-by: Spike Curtis <spike@coder.com>

* appease lint & fmt

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
2023-06-27 10:13:36 +00:00
Muhammad Atif Ali 96435ee2ce chore: fix condition in pr-deploy.yaml (#8224) 2023-06-27 09:59:15 +00:00
dependabot[bot] c969da469d chore: bump semver from 7.3.7 to 7.5.2 in /site (#8162)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-27 12:54:19 +03:00
Muhammad Atif Ali b4ca285582 chore: ignore sub directories in examples for go files check (#8197)
There are no go files in any of the subdirectories in examples directory.
2023-06-27 00:35:09 +03:00
Steven Masley 140683813d chore: reword wsproxy help (#8168) 2023-06-26 12:32:47 -05:00
Mathias Fredriksson 31076ad665 fix(enterprise/coderd): prevent deadlock during entitlements update (#8215) 2023-06-26 20:22:28 +03:00
Steven Masley 56395410bd chore: disable auto proxy selection based on latency (#8137)
* chore: disable auto pick proxy based on latency

* Remove latency pulled from storage
2023-06-26 13:08:32 -04:00
Steven Masley 82415a6541 chore: add documentation to address common group sync errors (#8212)
* chore: Add documentation to address common group sync errors
2023-06-26 13:08:20 -04:00
Cian Johnston 80ef147060 fix(cli): stat: explicitly specify resource SI prefix (#8206)
* fix(cli): move to explicitly specifying units

* make gen
2023-06-26 18:06:38 +01:00
dependabot[bot] 1558ef52f1 chore: bump github.com/gohugoio/hugo from 0.113.0 to 0.114.1 (#8201)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-26 10:48:39 -05:00
dependabot[bot] 98457e993b chore: bump github.com/valyala/fasthttp from 1.47.0 to 1.48.0 (#8204)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-26 15:40:21 +00:00
Kyle Carberry f40865bc2f chore: use mutex around blockEndpoints (#8209)
https://github.com/coder/coder/actions/runs/5378950122/jobs/9759972142
2023-06-26 10:01:50 -05:00
dependabot[bot] 4539ce7db6 chore: bump golang.org/x/oauth2 from 0.8.0 to 0.9.0 (#8203)
Bumps [golang.org/x/oauth2](https://github.com/golang/oauth2) from 0.8.0 to 0.9.0.
- [Commits](https://github.com/golang/oauth2/compare/v0.8.0...v0.9.0)

---
updated-dependencies:
- dependency-name: golang.org/x/oauth2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-26 10:01:10 -05:00
Cian Johnston b8437ce453 fix(scaletest): adjust sessionAffinity and scenario resources (#8205)
* scaletest: adjust scenario resources
* scaletest: set sessionAffinity=None for coder service
2023-06-26 15:54:05 +01:00
Muhammad Atif Ali cfbe96a379 chore: return success if pr-cleanup.yaml faisl to find a PR image tag (#8208) 2023-06-26 14:47:10 +00:00
Marcin Tojek b4f14cc6a9 feat: include coder_parameters from external modules (#8195) 2023-06-26 13:46:30 +00:00
Muhammad Atif Ali 0a6e6442b8 chore: add examples templates to docs filter (#8196) 2023-06-26 09:48:23 +00:00
野漫横江 bdecf53413 Update additional-clusters.md (#8190)
Domain name should not be localhost
2023-06-25 15:41:17 +00:00
野漫横江 e27cfe6e6a docs: fix incorrect command in project documentation (#8191) 2023-06-25 15:12:10 +00:00
Dean Sheather 98a5ae7f48 feat: add provisioner job hang detector (#7927) 2023-06-25 13:17:00 +00:00
Eric Paulsen 3671846b1b docs: add default dir for VS Code Desktop (#8184) 2023-06-23 17:52:01 -05:00
Eric Paulsen 46df6c58bc docs: add max lifetime docs and refactor UI helper text (#8185) 2023-06-23 17:51:42 -05:00
Spike Curtis 5d48122f12 fix: fix PG Coordinator to update when heartbeats (re)start (#8178)
* fix: fix PG Coordinator to update when heartbeats (re)start

Signed-off-by: Spike Curtis <spike@coder.com>

* rename resetExpiryTimer(WithLock)

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
2023-06-23 10:38:58 +00:00
Spike Curtis ba9d038d42 feat: add periodic cleanup of PG Coordinator state (#8142)
* PG Coordinator cleans orphaned state

Signed-off-by: Spike Curtis <spike@coder.com>

* Don't need pubsub

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
2023-06-23 13:23:28 +04:00
Rodrigo Maia c594f02948 fix(site): display correct user_limit on license ui (#8118) 2023-06-23 08:38:36 +02:00
Steven Masley 797e91d4c6 feat: add flag for Windows to create unix compatible filepaths (#8164)
* feat: add flag for Windows to create unix compatible filepaths
2023-06-22 17:08:12 -05:00
Marcin Tojek 5d45218a5d docs: application logs (#8166) 2023-06-22 23:25:17 +02:00
Mathias Fredriksson 3b9b06fe5a feat(codersdk/agentsdk): add StartupLogsSender and StartupLogsWriter (#8129)
This commit adds two new `agentsdk` functions, `StartupLogsSender` and
`StartupLogsWriter` that can be used by any client looking to send
startup logs to coderd.

We also refactor the `agent` to use these new functions.

As a bonus, agent startup logs are separated into "info" and "error"
levels to separate stdout and stderr.

---------

Co-authored-by: Marcin Tojek <mtojek@users.noreply.github.com>
2023-06-22 23:28:59 +03:00
Steven Masley f56db1b41b feat: add user search query param on last_seen (#8139)
* feat: add sql filter for before/after on last_seen column
2023-06-22 15:24:48 -05:00
Colin Adler 97945ae272 fix(scripts): properly shift for --build-base option (#8167) 2023-06-22 15:24:03 -05:00
Colin Adler 41e7216df7 chore: upgrade terraform to 1.5.1 (#8160) 2023-06-22 19:08:40 +00:00
Marcin Tojek 8e2422d42c feat: use named loggers in coderd (#8148) 2023-06-22 20:09:33 +02:00
Muhammad Atif Ali 1417c12229 ci: get PR number correctly from pull_request event (#8158) 2023-06-22 17:19:14 +00:00
Muhammad Atif Ali 2c046ef475 ci: use single quotes when we have backticks in title (#8159) 2023-06-22 16:57:44 +00:00
Muhammad Atif Ali f4a712b271 ci: delete old workflow runs for pr-cleanup.yaml(#8146) 2023-06-22 19:16:06 +03:00
Muhammad Atif Ali ea4b9a4354 ci: fix syntax issue in pr-deploy.yaml (#8154) 2023-06-22 16:06:15 +00:00
Muhammad Atif Ali eee4f835ec ci: fix wrong trigger pr-deploy.yaml (#8151) 2023-06-22 18:29:27 +03:00
Muhammad Atif Ali 1ffc8058c2 ci: deploy automatic PR deployments on request (#8121) 2023-06-22 14:35:58 +00:00
Spike Curtis e856491476 feat: enable PG Coordinator as experiment (#8144)
Signed-off-by: Spike Curtis <spike@coder.com>
2023-06-22 13:12:29 +04:00
Spike Curtis e738123a9c chore: log ssh connection disconnects with errors (#8143)
Signed-off-by: Spike Curtis <spike@coder.com>
2023-06-22 11:37:50 +04:00
Jon Ayers 1b0124ecdb feat: automatically stop workspaces based on failure_ttl (#7989) 2023-06-22 00:33:22 -04:00
Kyle Carberry d434181941 feat: add cohesive e2e tests for the web terminal, apps, and workspaces (#8140)
* feat: add cohesive e2e tests for the web terminal, apps, and workspaces

* Fix web terminal flake
2023-06-22 00:21:40 +00:00
Kyle Carberry 2a492b7008 chore: improve the setup experience with various fixes (#8130)
* Move updatecheck logs to debug mode

This was causing logs to be emitted immediately after
initial setup, which seemed odd for the user.

* Fix setup page text to say "Create" instead of "Setup" account

* Improve copy on the empty workspaces page

- This view can be seen after the user creates their first workspace, so saying first is bad.
- It should describe what a workspace is, so I modified the description.
- The create from template button wasn't helpful!

* Improve the copy for the empty templates view

- This didn't describe what a template actually is.
- The title had the same problem as workspaces, where first makes no sense.

* Improve text consistency on the Create Template page

* Fix "View activity" displaying for non-Enterprise users

This was causing an exception to be thrown.

* Improve messaging of empty groups view

* Appropriately capitalize Workspace and Template

* Improve Docker template taglines

* Fix types
2023-06-21 18:23:59 -05:00
Dean Sheather a28d422c35 feat: add flag to disable all direct connections (#7936) 2023-06-21 22:02:05 +00:00
Asher 96f9e61ca1 Strip CORS headers from applications (#8057)
The problem is that the headers get doubled up (not overwritten) and
browsers do not like multiple values for the allowed origin even though
it appears the spec allows for it.

We could prefer the application's headers instead of ours but since we
control OPTIONS I think preferring ours will by the more consistent
experience and also aligns with the original RFC.
2023-06-21 13:41:27 -08:00
Dean Sheather 24b95e16c4 feat: add --disable-direct flag to CLI (#8131) 2023-06-21 20:22:43 +00:00
Colin Adler bc739bdfce feat(cli): add hidden netcheck command (#8136) 2023-06-21 14:33:19 -05:00
Colin Adler 7703bb77a7 ci: update sqlc version in security scan (#8135) 2023-06-21 13:53:41 -05:00
Eric Paulsen a0d0e0e72d docs: add coder ping example for troubleshooting (#8133) 2023-06-21 18:07:24 +00:00
Bruno Quaresma 1faed639c4 fix(site): show error when parameter is invalid (#8125) 2023-06-21 11:39:28 -03:00
Bruno Quaresma bce8a983fe chore(site): remove new filter from experimental (#8112) 2023-06-21 10:20:37 -03:00
Spike Curtis cc17d2feea refactor: add postgres tailnet coordinator (#8044)
* postgres tailnet coordinator

Signed-off-by: Spike Curtis <spike@coder.com>

* Fix db migration; tests

Signed-off-by: Spike Curtis <spike@coder.com>

* Add fixture, regenerate

Signed-off-by: Spike Curtis <spike@coder.com>

* Fix fixtures

Signed-off-by: Spike Curtis <spike@coder.com>

* review comments, run clean gen

Signed-off-by: Spike Curtis <spike@coder.com>

* Rename waitForConn -> cleanupConn

Signed-off-by: Spike Curtis <spike@coder.com>

* code review updates

Signed-off-by: Spike Curtis <spike@coder.com>

* db migration order

Signed-off-by: Spike Curtis <spike@coder.com>

* fix log field name last_heartbeat

Signed-off-by: Spike Curtis <spike@coder.com>

* fix heartbeat_from log field

Signed-off-by: Spike Curtis <spike@coder.com>

* fix slog fields for linting

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
2023-06-21 16:20:58 +04:00
Marcin Tojek 4fb4c9b270 chore: add more rules to ensure logs consistency (#8104) 2023-06-21 12:00:38 +02:00
Spike Curtis 1c8f564fdb feat: add logging of ssh connections to agent (#8096)
* feat: adds logging of ssh connections to agent

Signed-off-by: Spike Curtis <spike@coder.com>

* code review improvements

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
2023-06-21 13:49:58 +04:00
Colin Adler 4a431b6eb8 feat(helm): add coder.command to control pod command (#8116) 2023-06-20 22:59:01 +00:00
Colin Adler 15cba05dfc ci: scan images with sysdig (#8037) 2023-06-20 22:58:17 +00:00
Eric Paulsen b398814ab0 docs: add prometheus scrape_config example (#8113)
* docs: add prometheus scrape_config example

* make: fmt

* add: label

* fix: spelling

* scheme: http
2023-06-20 21:09:35 +00:00
Colin Adler 7d43f4ceee chore: update dogfood image (#8114) 2023-06-20 15:08:15 -05:00
Kyle Carberry 69f911dfd5 feat: add queue_position and queue_size to provisioner jobs (#8074) 2023-06-20 15:07:18 -05:00
Kyle Carberry bbb0fab1de chore: merge database gen scripts (#8073)
* chore: merge database gen scripts

* Fix type params gen

* Merge enum into dbgen
2023-06-20 16:24:33 +00:00
Kyle Carberry f3b2009499 chore: reorder helm chart to improve ux (#8108)
It makes no sense that the primary option `env` was so far
below infrequently used options.
2023-06-20 16:23:56 +00:00
Kyle Carberry 467b0a1004 chore: restyle provisioner job output format (#8106)
Reduce colors and formatting to reduce bugs and increase UNIX-feel.
2023-06-20 16:16:27 +00:00
Colin Adler 823127e761 feat: add healthcheck database section (#8060) 2023-06-20 15:13:22 +00:00
Bruno Quaresma 2db4488337 fix(site): fix filters errors display (#8103) 2023-06-20 12:08:05 -03:00
Mathias Fredriksson ea4b7d60d7 fix(agent): refactor trackScriptLogs to avoid deadlock (#8084)
During agent close it was possible for the startup script logs consumer
to enter a deadlock state where by agent close was waiting via
`a.trackConnGoroutine` and the log reader for a flush event.

This refactor removes the mutex in favor of channel communication and
relies on two goroutines without shared state.
2023-06-20 18:05:11 +03:00
Colin Adler adf14f1917 chore(cli): warn on template push or create when no lockfile present (#8059) 2023-06-20 15:02:44 +00:00
Bruno Quaresma a47a9b1cfe fix(site): prevent filter input update when focused (#8102) 2023-06-20 13:46:04 +00:00
Mathias Fredriksson b8ba287128 fix: disable websocket compression for startup logs in Safari (#8087) 2023-06-20 16:29:32 +03:00
Bruno Quaresma c3781d95b4 fix(site): fix build logs route (#8100) 2023-06-20 13:24:48 +00:00
Cian Johnston eb0783ff24 chore(cli): do not assert non-zero host cpu usage (#8097) 2023-06-20 13:03:56 +00:00
Cian Johnston 0f754f0bb9 fix(clistat): do not include buffers/cache for host memory used (#8095) 2023-06-20 13:29:27 +01:00
Marcin Tojek 06a5e24f5b skip: TestStatCPUCmd/JSON (#8093) 2023-06-20 12:08:11 +00:00
Mathias Fredriksson 8dac0356ed refactor: replace startup script logs EOF with starting/ready time (#8082)
This commit reverts some of the changes in #8029 and implements an
alternative method of keeping track of when the startup script has ended
and there will be no more logs.

This is achieved by adding new agent fields for tracking when the agent
enters the "starting" and "ready"/"start_error" lifecycle states. The
timestamps simplify logic since we don't need understand if the current
state is before or after the state we're interested in. They can also be
used to show data like how long the startup script took to execute. This
also allowed us to remove the EOF field from the logs as the
implementation was problematic when we returned the EOF log entry in the
response since requesting _after_ that ID would give no logs and the API
would thus lose track of EOF.
2023-06-20 14:41:55 +03:00
Marcin Tojek b1d1b63113 chore: ensure logs consistency across Coder (#8083) 2023-06-20 12:30:45 +02:00
Cian Johnston d6f8bd7847 feat(cli): add coder stat command (#8005) 2023-06-20 11:16:57 +02:00
Jon Ayers c3aef9363b feat: add locked TTL field to template meta (#8020) 2023-06-19 22:37:55 -04:00
dependabot[bot] 1ecc371ade chore: bump google.golang.org/grpc from 1.55.0 to 1.56.0 (#8079)
Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.55.0 to 1.56.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](https://github.com/grpc/grpc-go/compare/v1.55.0...v1.56.0)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-19 20:48:05 -05:00
Mathias Fredriksson af45e64b1d chore(coderd/database/gen): improve generated fake stub (#8088)
* chore(coderd/database/gen): generate arg validation where applicable
* fix(coderd/database/gen): support pointers and slices as return types
2023-06-20 00:05:26 +03:00
Kyle Carberry f444100aa6 feat: add region querying to pre-fetched html (#8077) 2023-06-19 11:23:26 -05:00
dependabot[bot] e083cbca6a chore: bump golang.org/x/mod from 0.10.0 to 0.11.0 (#8078)
Bumps [golang.org/x/mod](https://github.com/golang/mod) from 0.10.0 to 0.11.0.
- [Commits](https://github.com/golang/mod/compare/v0.10.0...v0.11.0)

---
updated-dependencies:
- dependency-name: golang.org/x/mod
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-19 10:00:37 -05:00
dependabot[bot] 020c6fb71e chore: bump google.golang.org/api from 0.127.0 to 0.128.0 (#8080)
Bumps [google.golang.org/api](https://github.com/googleapis/google-api-go-client) from 0.127.0 to 0.128.0.
- [Release notes](https://github.com/googleapis/google-api-go-client/releases)
- [Changelog](https://github.com/googleapis/google-api-go-client/blob/main/CHANGES.md)
- [Commits](https://github.com/googleapis/google-api-go-client/compare/v0.127.0...v0.128.0)

---
updated-dependencies:
- dependency-name: google.golang.org/api
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-19 10:00:21 -05:00
dependabot[bot] 456ad85ce3 chore: bump golang.org/x/crypto from 0.9.0 to 0.10.0 (#8081)
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.9.0 to 0.10.0.
- [Commits](https://github.com/golang/crypto/compare/v0.9.0...v0.10.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-19 10:00:13 -05:00
Kyle Carberry 5b9c3784bc docs: add steps for registering a github app with coder (#7976)
Co-authored-by: Muhammad Atif Ali <atif@coder.com>
2023-06-18 14:01:37 -05:00
Kyle Carberry 9df9ad4503 feat: embed common client requests into the template html (#8076)
This should reduce the number of API requests a client makes
when loading the dashboard dramatically!
2023-06-18 13:57:27 -05:00
Kyle Carberry 2a10c9127f fix: show git provider id instead of type (#8075)
Fixes #6343.
2023-06-18 17:01:44 +00:00
Ammar Bandukwala ca6b9e9368 chore: use robust RNG in cryptorand (#8040) 2023-06-17 17:33:40 -05:00
Montasser abd majid ZEHRI c8e67833f5 docs: add oidc keycloak docs (#8042)
* adding docs for keycloak to solve the problem with the refraish token

* fmt
2023-06-16 10:18:26 -05:00
Mathias Fredriksson 0c5077464b fix: avoid missed logs when streaming startup logs (#8029)
* feat(coderd,agent): send startup log eof at the end

* fix(coderd): fix edge case in startup log pubsub

* fix(coderd): ensure startup logs are closed on lifecycle state change (fallback)

* fix(codersdk): fix startup log channel shared memory bug

* fix(site): remove the EOF log line
2023-06-16 17:14:22 +03:00
Marcin Tojek 247f8a973f feat: replace ssh maxTimeout with keep-alive mechanism (#8062)
* Bump up coder/ssh

* feat: Set default agent timeout to ~72h

* Address PR comments

* Fix
2023-06-16 15:22:18 +02:00
Cian Johnston 751c0505bf chore: add benchmark for prometheusmetrics.MetricsAggregator (#8066)
* add benchmark for prom metrics aggregator

* fixup! add benchmark for prom metrics aggregator

* make fmt
2023-06-16 14:04:28 +01:00
Colin Adler 3ec2e96ff4 chore: tidy up grafana example dashboard (#8056) 2023-06-15 14:22:31 -05:00
dependabot[bot] 137b51e2c7 chore: bump cronstrue from 2.21.0 to 2.27.0 in /site (#7851)
Bumps [cronstrue](https://github.com/bradymholt/cronstrue) from 2.21.0 to 2.27.0.
- [Release notes](https://github.com/bradymholt/cronstrue/releases)
- [Changelog](https://github.com/bradymholt/cRonstrue/blob/main/CHANGELOG.md)
- [Commits](https://github.com/bradymholt/cronstrue/compare/v2.21.0...v2.27.0)

---
updated-dependencies:
- dependency-name: cronstrue
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Muhammad Atif Ali <atif@coder.com>
2023-06-15 14:34:00 -03:00
Bruno Quaresma e4d23ff5fe fix(site): add test and fix username params in terminal (#8052) 2023-06-15 13:18:19 -03:00
Bruno Quaresma f61001d049 chore(docs): optimize images (#8047) 2023-06-15 10:49:47 -03:00
dependabot[bot] 33c0674d76 chore: bump react-router-dom from 6.4.1 to 6.12.1 in /site (#7950)
* chore: bump react-router-dom from 6.4.1 to 6.12.1 in /site

Bumps [react-router-dom](https://github.com/remix-run/react-router/tree/HEAD/packages/react-router-dom) from 6.4.1 to 6.12.1.
- [Release notes](https://github.com/remix-run/react-router/releases)
- [Changelog](https://github.com/remix-run/react-router/blob/main/packages/react-router-dom/CHANGELOG.md)
- [Commits](https://github.com/remix-run/react-router/commits/react-router-dom@6.12.1/packages/react-router-dom)

---
updated-dependencies:
- dependency-name: react-router-dom
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix what needs to be fixed

* fix storybook

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: BrunoQuaresma <bruno_nonato_quaresma@hotmail.com>
2023-06-15 10:34:49 -03:00
Cian Johnston 6e598234b6 fix: only collect prometheus database metrics when explicitly enabled (#8045)
* fix: only collect prometheus database metrics when explicitly enabled

* add missing test

* de-duplicate wrapping
2023-06-15 12:34:16 +01:00
Mathias Fredriksson 3f81f38fcc ci: fix commit type prefix regexp in release script (#8046)
Previously we were incorrectly categorizing `fix(a/b): ...` as other
because the regexp only expected letters, not `/`. Now we accept any
input within the parenthesis.

---------

Co-authored-by: Cian Johnston <cian@coder.com>
2023-06-15 10:57:18 +00:00
Cian Johnston b1588fa596 fix(helm): use /healthz for liveness and readiness probes instead of /api/v2/buildinfo (#8035) 2023-06-15 10:08:48 +01:00
Eric Paulsen 977e9ef505 docs: add steps for configuring trusted headers & origins in Helm chart (#8031) 2023-06-14 16:20:40 -04:00
Kyle Carberry 8ac68c95a4 chore: lazily initialize find commands in makefile (#8030)
Improves make performance for small targets!
2023-06-14 13:17:16 -05:00
Bruno Quaresma af06e80949 fix(site): fix footer year (#8036) 2023-06-14 14:59:33 -03:00
Steven Masley 6c4c3d6ce5 feat: add login type 'none' to prevent password login (#8009)
* feat: add login type 'none' to prevent login

Users with this login type must use tokens to authenticate.
Tokens must come from some other source, not a /login with password
authentication
2023-06-14 12:48:43 -05:00
Bruno Quaresma cbd49abfcd fix(site): resize terminal when dismissing warning (#8028) 2023-06-14 14:40:55 -03:00
Steven Masley 3619a3a6dd feat: add disabling of default 'everyone' group access to template (#7982)
* feat: add disabling of default 'everyone' group access to template
* add FE to disable everyone group
* require entitlement to uncheck box
2023-06-14 11:08:58 -05:00
Kyle Carberry e4b6f5695b chore: separate pubsub into a new package (#8017)
* chore: rename store to dbmock for consistency

* chore: remove redundant dbtype package

This wasn't necessary and forked how we do DB types.

* chore: separate pubsub into a new package

This didn't need to be in database and was bloating it.
2023-06-14 15:34:54 +00:00
Dean Sheather 2c843f4011 fix: fix --header flag in CLI (#8023) 2023-06-14 21:52:01 +10:00
Cian Johnston df842b31e8 chore: fix miscellaneous issues in scaletest scripts (#8006)
* chore: scaletest: plumb through more options

* bump terraform version

* scaletest.sh: pprof during traffic gen

* cli/scaletest: actually wait for prometheus metrics to be scraped

* increase prometheus wait
2023-06-14 09:38:04 +01:00
Rodrigo Maia 1da2570e14 feat(site): add documentation links to webterminal notifications (#8019)
* feat(site): add documentation links to webterminal notifications

* change button variant
2023-06-14 00:27:40 +00:00
dependabot[bot] 7a7ee63225 chore: bump github.com/hashicorp/terraform-json from 0.16.0 to 0.17.0 (#7972)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-13 22:19:01 +00:00
dependabot[bot] af50ef76f9 chore: bump google.golang.org/api from 0.125.0 to 0.127.0 (#8018)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-14 01:15:08 +03:00
dependabot[bot] 299260361a chore: bump github.com/gohugoio/hugo from 0.111.3 to 0.113.0 (#7969)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-13 16:50:45 -05:00
Kyle Carberry 8c4b7c01e2 chore: remove redundant dbtype package (#8014)
* chore: rename store to dbmock for consistency

* chore: remove redundant dbtype package

This wasn't necessary and forked how we do DB types.
2023-06-13 19:14:55 +00:00
Mathias Fredriksson 4f512fb230 chore: use gcr.io for postgres image in OpenContainerized (#8015)
Refs #7935
2023-06-13 22:03:33 +03:00
Kyle Carberry 7d54fd5e0d chore: rename store to dbmock for consistency (#8013) 2023-06-13 13:57:43 -05:00
Kyle Carberry a658c94a67 chore: automatically generate dbauthz when new queries are added (#8007)
* chore: automatically generate dbauthz when new queries are added

* Merge system functions
2023-06-13 13:40:46 -05:00
Mathias Fredriksson c12c9f1f4e chore(go.mod): update cdr.dev/slog (#7994)
* chore(mod): update cdr.dev/slog

* fix: change uses of []slog.Field to []any to match new API
2023-06-13 18:17:04 +00:00
Mathias Fredriksson 74fdcb1ace fix(agent/agentssh): wait for sessions to exit (#8008) 2023-06-13 17:52:31 +00:00
Kyle Carberry 794a551176 chore: generate dbmetrics automatically when adding new queries (#7999)
* chore: rename dbgen package files and remove small file

* chore: automatically generate dbmetrics when new queries are added
2023-06-13 12:35:12 -05:00
Colin Adler f2758fcb33 feat: add example grafana dashboard (#7987)
* feat: add example grafana dashboard

* fixup! feat: add example grafana dashboard

* fixup! feat: add example grafana dashboard

* fixup! feat: add example grafana dashboard
2023-06-13 12:26:42 -05:00
Mathias Fredriksson 51226c55ab test(coderd): close metricscache and avoid background context (#7996) 2023-06-13 20:18:31 +03:00
Kyle Carberry 2e7e99b135 fix: scope errors to subtests for flake (#8004)
See: https://github.com/coder/coder/actions/runs/5257676837/jobs/9500882394
2023-06-13 11:52:17 -05:00
Kyle Carberry 24953869a6 chore: remove key comparison check to fix gitsshkey flake (#8002)
In tests we use weak randomness and the same key was generated which
caused a test flake here.
2023-06-13 15:51:45 +00:00
Kyle Carberry 75078fafa2 chore: try removing cache from fmt and lint (#8001) 2023-06-13 10:48:53 -05:00
Steven Masley 9cf3c582cb test: add unit test that deletes abandoned workspace (#7990)
* test: add unit test that deletes abandoned workspace

This is to ensure we do not break this functionality in future.
This is important incase this edge case happens, an admin can
clean up the abandoned resources.
2023-06-13 10:42:18 -05:00
Mathias Fredriksson c916a9e67f fix(agent): guard against multiple rpty race for same id (#7998)
* fix(agent): guard against multiple rpty race for same id
* fix(agent): ensure pty is closed on error
2023-06-13 15:14:07 +00:00
Kyle Carberry 9440b3da66 chore: rename dbgen package files and remove small file (#7997) 2023-06-13 09:21:12 -05:00
Mathias Fredriksson 1d0fae83a2 fix(coderd): prevent lost messages in watchWorkspaceAgentMetadata (#7934)
* fix(codersdk): wait for subscription in WatchWorkspaceAgentMetadata
* fix(coderd): subscribe before sending initial metadata event
* test(coderd): add retries to TestWorkspaceAgent_Metadata to avoid flake
2023-06-13 12:21:06 +00:00
Mathias Fredriksson 518300a26c fix(coderd/database): improve pubsub closure and context cancellation (#7993) 2023-06-13 15:19:56 +03:00
Ben Potter aba5cb8377 fix(docs): capture and export audit logs (#7991)
* hotfix(docs): Capturing/exporting audit logs

We frequntly get questions about this!

* fmt
2023-06-12 23:06:58 -05:00
Jon Ayers 31bd2b0bdc chore: update legacy parameters in envbox template (#7898) 2023-06-12 20:53:12 -05:00
Colin Adler ac605bad3d ci: scan images with prisma (#7988) 2023-06-12 23:11:45 +00:00
Kyle Carberry 28f35393e7 chore: generate and order dbfake funcs automatically (#7986)
* chore: rename `databasefake` to `dbfake`

* Remove unused method

* chore: add generation to dbfake

* Auto gen on make gen

* Fix preserving imports

* gen dbfake

* Add goimports

* Fix the makefile

* Make it panic instead of a comment
2023-06-12 17:40:58 -05:00
Kyle Carberry 685abfc6d7 chore: rename databasefake to dbfake (#7979)
* chore: rename `databasefake` to `dbfake`

* Remove unused method
2023-06-12 16:05:37 -05:00
Asher 4a0ac13bb7 docs: document CORS behavior between forwarded apps (#7944)
* docs: document CORS behavior

* docs: move CORS documentation under dashboard section

None of this applies to ports forwarded in other ways.
2023-06-12 20:59:47 +00:00
Kyle Carberry 6ac7d86c93 chore: prevent gen from rerunning every time (#7985) 2023-06-12 14:45:17 -05:00
Steven Masley b70d2b1767 fix: correct the correct cli output for 'template version list --output=json' (#7984)
* fix: correct 'template version list --output=json' cli cmd
2023-06-12 14:35:51 -05:00
Kira Pilot f13632cea8 feat: add impending deletion filter to workspaces page (#7860)
* add workspace deletion dialog

* add deleting_by query param

* added test

* filtering on workspaces to be deleted

* cleaned up form

* added story

* added banner filter

* PR feedback

* fix lint and stories

* PR feedback

* added enterprise test

* added unit tests in search_test.go

* remove unused fn

* unstaged changes
2023-06-12 11:55:51 -07:00
Mathias Fredriksson 4068f70d2b fix(coderd): avoid deadlock in (*logFollower).follow (#7983) 2023-06-12 18:38:46 +00:00
Ammar Bandukwala aa9dbf2eb3 ci: reduce Windows parallelism (#7981)
We have seen an uptick in Windows failures.
2023-06-12 18:24:54 +00:00
dependabot[bot] 0d71314ae1 chore: Bump aquasecurity/trivy-action from 0.10.0 to 0.11.2 (#7967)
Bumps [aquasecurity/trivy-action](https://github.com/aquasecurity/trivy-action) from 0.10.0 to 0.11.2.
- [Release notes](https://github.com/aquasecurity/trivy-action/releases)
- [Commits](https://github.com/aquasecurity/trivy-action/compare/e5f43133f6e8736992c9f3c1b3296e24b37e17f2...41f05d9ecffa2ed3f1580af306000f734b733e54)

---
updated-dependencies:
- dependency-name: aquasecurity/trivy-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-12 21:22:10 +03:00
Ammar Bandukwala a540e629e5 ci: improve caching (#7954) 2023-06-12 12:09:54 -05:00
Mathias Fredriksson 4bc4e63637 fix(cli/ssh): fix lint error (#7974) 2023-06-12 16:17:41 +00:00
Muhammad Atif Ali 68ebf93fdb ci: add fmt and lint to required tests (#7975) 2023-06-12 10:43:45 -05:00
Ammar Bandukwala 5de1084639 feat(cli/ssh): simplify log file flags (#7863)
And, fix a race condition.
2023-06-12 09:18:33 +04:00
Dean Sheather ec7b117878 chore: add gen and test-go-race to required check (#7952) 2023-06-10 04:07:17 +00:00
dependabot[bot] 1ec463d74d chore: bump i18next from 21.9.1 to 22.5.0 in /site (#7812)
* chore: Bump i18next from 21.9.1 to 22.5.0 in /site

Bumps [i18next](https://github.com/i18next/i18next) from 21.9.1 to 22.5.0.
- [Release notes](https://github.com/i18next/i18next/releases)
- [Changelog](https://github.com/i18next/i18next/blob/master/CHANGELOG.md)
- [Commits](https://github.com/i18next/i18next/compare/v21.9.1...v22.5.0)

---
updated-dependencies:
- dependency-name: i18next
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix i18n types

* prettier

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Rodrigo Maia <rodrigo.maia.pereira@gmail.com>
2023-06-09 18:54:17 -05:00
Dean Sheather 634e146032 ci: skip ts or go tests based on changed files (#7134)
* chore: skip ts or go tests based on files changed

* comments

* chore: add 'required' job

* fixup! chore: add 'required' job

* fake go modification

* merge main into dean/skip-tests-fe-be

* fix typo

* remove x_test.go

* remove duplicate setup-node action

* condition test-go-race too

* skip ete on docs changes

* allows tests to run if changes are made .github directory

---------

Co-authored-by: Atif Ali <atif@coder.com>
2023-06-10 02:53:16 +03:00
Ammar Bandukwala 71c908974c ci: improve caching (#7943) 2023-06-09 16:46:44 -05:00
Cian Johnston 2bbe650eb0 chore: scaletest: collect database metrics using prometheus-postgres-exporter (#7945)
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
2023-06-09 21:21:08 +00:00
Muhammad Atif Ali 175561bf36 docs: update CONTRIBUTING.md (#7937) 2023-06-09 19:38:16 +03:00
Steven Masley 065206345e test: add golden files to enterprise cli (#7924)
* test: Add golden files to enterprise cli
2023-06-09 11:35:20 -05:00
Dean Sheather 4f9d3155c9 ci: use macos-latest-xl runners (#7938) 2023-06-09 11:22:29 -05:00
Muhammad Atif Ali 16ebe10ff2 docs(admin/workspace-proxies): add instructions to run using the Docker image (#7915)
* docs(admin/workspace-proxies): add instructions to run using the Docker image.

* make fmt
2023-06-09 10:53:04 -05:00
Eric Paulsen 53969415ec docs: add multi git providers to enterprise chart (#7941)
* docs: add multi git providers to enterprise chart

* make: fmt
2023-06-09 14:52:51 +00:00
Dean Sheather c60ea38691 chore: use gcr.io for postgres image in CI (#7935) 2023-06-09 13:39:55 +00:00
Mathias Fredriksson e4744686ec fix(codersdk): handle API older than client for startup script behavior (#7933) 2023-06-09 13:01:56 +00:00
Colin Adler 30a635aa5f fix(enterprise): ensure scim usernames are validated (#7925) 2023-06-08 17:59:49 -05:00
Steven Masley a4cc883be1 chore: add proxy health interval flag/env config (#7919)
* chore: plumbing for proxy health interval from flag/env
2023-06-08 12:58:24 -05:00
Steven Masley fa8153a0fd chore: make default workspace proxy editable (#7903)
* chore: add editing the default workspace proxy
2023-06-08 10:30:15 -05:00
Steven Masley 5e647ba07a chore: improve workspace proxy create cli flow (#7907)
* chore: improve workspace proxy create cli flow
2023-06-08 10:02:35 -05:00
Muhammad Atif Ali 26f575e284 ci: prevent running nightly-gauntlet.yaml on PRs (#7920) 2023-06-08 14:57:39 +00:00
Mathias Fredriksson 976d23e3dc docs(templates): fix docs for updated --wait flag (#7918) 2023-06-08 14:31:22 +00:00
Mathias Fredriksson 03034dc508 chore(cli/configssh): add comment about wait and skip proxy (#7917) 2023-06-08 14:23:03 +00:00
Mathias Fredriksson fa91e11105 fix(cli/help): show deprecation notice properly for flags (#7904) 2023-06-08 14:14:42 +00:00
Mathias Fredriksson a1c32954d9 feat(cli/configssh): add support for wait yes/no/auto (#7893)
Refs #7768
2023-06-08 14:06:50 +00:00
Mathias Fredriksson 94aa9be33a feat(cli/ssh): implement wait options and deprecate no-wait (#7894)
Fixes #7768
Refs #7893
2023-06-08 16:52:44 +03:00
Steven Masley b2324325fa chore: add warning log if misconfigured groups oidc (#7874)
* chore: add warning log if misconfigured groups oidc

This is not perfect, but if we find a 'groups' claim and it is not
configured, put out a warning log to give some information
2023-06-08 08:51:59 -05:00
Montasser abd majid ZEHRI 479467473e docs: add RStudio community template without requiring a subdomain (#7909)
* adding a comunity template

* make fmt

* fixing typo in url

---------

Co-authored-by: Atif Ali <atif@coder.com>
2023-06-08 13:07:20 +00:00
Cian Johnston efbb55803b chore: add scaletest convenience script (#7819)
- Adds a convenience script `scaletest.sh` to automate process of running scale tests
- Enables pprof endpoint by default, and captures pprof traces before tearing down infra.
- Improves idempotency of coder_init.sh
- Removes the promtest.Float64 invocations in workspacetraffic runner, these metrics will be in prometheus.
- Increases default workspace traffic output to 40KB/s/workspace.
2023-06-08 09:30:02 +01:00
Ammar Bandukwala 9ec1fcf1a7 ci: move timing tests to nightly gauntlet (#7910)
Test_Runner_Timing was one of our flakiest tests before.
2023-06-08 04:03:03 +00:00
Ammar Bandukwala fcca639d38 test(agent/agentssh): close SSH servers in all tests (#7911)
Potentially solves the flake seen here:

https://github.com/coder/coder/actions/runs/5167029213/jobs/9307647816.
2023-06-07 23:43:38 +00:00
Ammar Bandukwala f6db95e71c test(coderd/database/migrations): increase fixture test timeout 2023-06-07 23:17:29 +00:00
Technofab 52ead3d933 feat(provisioner): add support for .tf.json templates (#7835)
Co-authored-by: Colin Adler <colin1adler@gmail.com>
2023-06-08 08:06:50 +10:00
Asher f0c5201617 feat: allow cross-origin requests between users' own apps (#7688) 2023-06-07 11:08:14 -08:00
Asher 125e9ef00e fix: validate that parameter names are unique (#7882) 2023-06-07 09:44:50 -08:00
Bruno Quaresma fbdbc8a6c5 fix(site): return correct useer when using me on filter menu (#7906) 2023-06-07 14:32:52 -03:00
Bruno Quaresma 5be2b77830 fix(site): format numbers in pagination text (#7900) 2023-06-07 15:25:03 +00:00
Bruno Quaresma df82f29945 fix(site): improve filter on smaller screens (#7899) 2023-06-07 15:01:49 +00:00
Bruno Quaresma 2a5025c84c feat(site): add view activity on user context menu (#7897) 2023-06-07 11:58:40 -03:00
Mathias Fredriksson eb11b50bd1 docs(templates): improve workspace incomplete and session docs (#7896) 2023-06-07 17:34:49 +03:00
Bruno Quaresma d793564937 feat(site): add new filter to audit logs (#7878) 2023-06-07 14:10:58 +00:00
Mathias Fredriksson ab3a649520 docs(templates): improve startup_script_behavior docs (#7892)
Refs #7857
2023-06-07 13:39:44 +00:00
Steven Masley 1376ba3724 chore: use a cache to select best latency (#7879)
* chore: Testing using a cache to choose the best latency
* Allow storing more latencies if needed

This PR enables a feature to record and save latencies to local storage for later analysis
2023-06-07 08:29:18 -05:00
Kira Pilot 74ffd2756a fix: respect uppercase letters in username filter for audit (#7880)
* fix: respect uppercase letters in username filter for audit

* updated documentation
2023-06-07 05:48:08 -07:00
Bruno Quaresma 91dd3fbfab feat(site): add presets back to the filters (#7876) 2023-06-07 09:46:16 -03:00
Mathias Fredriksson a77b48a5e3 docs(templates): document startup_script_behavior in-depth (#7857)
Fixes #7759

---------

Co-authored-by: Cian Johnston <cian@coder.com>
2023-06-07 12:29:19 +03:00
Cian Johnston 4f29f9abe3 fixup! fix(cli): speed up CLI over SSH (#7885) (#7888) 2023-06-07 09:13:22 +00:00
Muhammad Atif Ali 8c4b6b02e7 ci: rename cron-weekly.yaml to weekly-docs.yaml (#7886)
Renames `cron-weekly.yaml` to `weekly-docs.yaml`
2023-06-07 07:56:19 +00:00
Ammar Bandukwala 5eaf809851 fix(cli): speed up CLI over SSH (#7885)
By caching the terminal's color profile, we avoid myriad round trips during command execution.
2023-06-07 05:22:58 +00:00
Colin Adler 1288a83e42 chore: upgrade openssl (#7883) 2023-06-06 16:59:56 -05:00
goodspark 0665a6c2f2 feat: add metric for provisioner daemons (#7858) 2023-06-06 16:50:11 -05:00
Muhammad Atif Ali 4954052ff6 ci: use builder runners to build dogfood image (#7881) 2023-06-06 16:11:25 -05:00
Colin Adler 003120882f chore: update Go to 1.20.5 (#7877) 2023-06-06 14:05:09 -05:00
Steven Masley 72f59950f2 chore: add prometheus timing to latency endpoint (#7742)
* chore: Prometheus timing to latency endpoint
2023-06-06 10:26:13 -05:00
Bruno Quaresma 944c42dcb6 docs: add docs for the available query filter for workspaces and users (#7875)
* Add docs for user filtering

* Add filter for workspace

* Apply suggestions from code review

Co-authored-by: Muhammad Atif Ali <atif@coder.com>

---------

Co-authored-by: Muhammad Atif Ali <atif@coder.com>
2023-06-06 15:12:10 +00:00
Bruno Quaresma 3121ccc7ff fix(site): Update the template form when a value is changed (#7873) 2023-06-06 11:25:25 -03:00
Bruno Quaresma 6d3dc30207 refactor(site): Remove terminal padding and add border to bottom bar (#7871) 2023-06-06 11:08:07 -03:00
Bruno Quaresma baa9922a82 feat(site): add new filter to the users page (#7818) 2023-06-06 09:59:15 -03:00
Marcin Tojek ee45b3df77 fix: ignore case while sorting usernames (#7870) 2023-06-06 12:37:41 +02:00
Mathias Fredriksson 660bbb8d38 refactor: deprecate login_before_ready in favor of startup_script_behavior (#7837)
Fixes #7758
2023-06-06 11:58:07 +03:00
Marcin Tojek 93378daeb3 feat: sort users by username (#7838) 2023-06-06 08:47:59 +02:00
Muhammad Atif Ali 2ad1308450 ci: run dogfood.yaml action when the action is updated (#7866) 2023-06-06 06:34:20 +00:00
Muhammad Atif Ali 2be7ef88e8 ci: use coder binary from the server (#7865) 2023-06-06 09:13:25 +03:00
dependabot[bot] 7332acc935 chore: bump vite from 4.3.0 to 4.3.9 in /site (#7864)
Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 4.3.0 to 4.3.9.
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v4.3.9/packages/vite)

---
updated-dependencies:
- dependency-name: vite
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-05 21:57:53 -05:00
sharkymark 8e655b42b1 chore(docs): Added macOS self-signed cert add step and moved plugin docs to top (#7859) 2023-06-05 19:59:01 -04:00
Steven Masley fa8f50a169 fix: fix workspace status filter returning more statuses that requested (#7732) 2023-06-05 18:12:10 -05:00
Bruno Quaresma b9e3226612 refactor(site): give default error message when description is missing (#7846) 2023-06-05 17:43:24 -03:00
Bruno Quaresma 7ec16cf779 feat(site): add latency to the terminal (#7801) 2023-06-05 18:32:49 +00:00
dependabot[bot] 0413ed0178 chore: update xterm, xterm-addon-fit, and xterm-addon-web-links in /site (#7765)
* chore: bump xterm, xterm-addon-fit and xterm-addon-web-links in /site

Bumps [xterm](https://github.com/xtermjs/xterm.js), [xterm-addon-fit](https://github.com/xtermjs/xterm.js) and [xterm-addon-web-links](https://github.com/xtermjs/xterm.js). These dependencies needed to be updated together.

Updates `xterm` from 4.19.0 to 5.1.0
- [Release notes](https://github.com/xtermjs/xterm.js/releases)
- [Commits](https://github.com/xtermjs/xterm.js/compare/4.19.0...5.1.0)

Updates `xterm-addon-fit` from 0.5.0 to 0.7.0
- [Release notes](https://github.com/xtermjs/xterm.js/releases)
- [Commits](https://github.com/xtermjs/xterm.js/compare/0.5...0.7)

Updates `xterm-addon-web-links` from 0.6.0 to 0.8.0
- [Release notes](https://github.com/xtermjs/xterm.js/releases)
- [Commits](https://github.com/xtermjs/xterm.js/compare/0.6...0.8)

---
updated-dependencies:
- dependency-name: xterm
  dependency-type: direct:production
  update-type: version-update:semver-major
- dependency-name: xterm-addon-fit
  dependency-type: direct:production
  update-type: version-update:semver-minor
- dependency-name: xterm-addon-web-links
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Remove rendererType

This option no longer exists.  Renderers other than the DOM renderer
have been split into addons.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Asher <ash@coder.com>
2023-06-05 13:53:27 -03:00
dependabot[bot] a2e129083e chore: bump github.com/hashicorp/hcl/v2 from 2.14.0 to 2.17.0 (#7853)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-05 11:30:20 -05:00
dependabot[bot] 3a7c92a56f chore: bump go.uber.org/atomic from 1.10.0 to 1.11.0 (#7854)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-05 11:27:57 -05:00
dependabot[bot] b79bfb2874 chore: bump alpine from 3.16 to 3.18 in /dogfood (#7847)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-05 11:26:58 -05:00
Colin Adler 1ab2450250 fix(provisioner/terraform): ensure ordering rich parameters produces no nil values (#7824) 2023-06-05 11:26:04 -05:00
dependabot[bot] 5a3d6b589a chore: bump eslint-plugin-jsx-a11y from 6.6.1 to 6.7.1 in /site (#7850)
Bumps [eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y) from 6.6.1 to 6.7.1.
- [Release notes](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/releases)
- [Changelog](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/CHANGELOG.md)
- [Commits](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/compare/v6.6.1...v6.7.1)

---
updated-dependencies:
- dependency-name: eslint-plugin-jsx-a11y
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-05 08:33:38 -07:00
Muhammad Atif Ali 466c530525 ci: add dogfood to dependabot (#7844) 2023-06-05 18:12:15 +03:00
dependabot[bot] 3fa7ee969d chore: bump github.com/elastic/go-sysinfo from 1.9.0 to 1.11.0 (#7841)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-05 09:56:41 -05:00
dependabot[bot] 82c709b1ba chore: bump google.golang.org/api from 0.122.0 to 0.125.0 (#7843)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-05 09:54:44 -05:00
dependabot[bot] cb42396596 chore: bump github.com/ory/dockertest/v3 from 3.9.1 to 3.10.0 (#7840)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-05 09:52:26 -05:00
sharkymark 88dc66ae47 chore(docs): Add clarifying language that resetting a user password must run on the coderd host (#7845) 2023-06-05 13:37:12 +00:00
Bruno Quaresma 6fde86d1ac fix(site): remove tar file type limitation (#7817) 2023-06-05 10:34:36 -03:00
dependabot[bot] cdba0744a2 chore: Bump jest-runner-eslint from 2.0.0 to 2.1.0 in /site (#7810)
Bumps [jest-runner-eslint](https://github.com/jest-community/jest-runner-eslint) from 2.0.0 to 2.1.0.
- [Release notes](https://github.com/jest-community/jest-runner-eslint/releases)
- [Changelog](https://github.com/jest-community/jest-runner-eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/jest-community/jest-runner-eslint/compare/v2.0.0...v2.1.0)

---
updated-dependencies:
- dependency-name: jest-runner-eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-05 06:08:25 -07:00
Steven Masley bbecff28ae feat: return better error if file size is too big to upload (#7775)
* feat: return better error if file size is too big to upload
* Use a limit writer to capture actual tar size
2023-06-05 11:19:25 +00:00
Spike Curtis e016c307ae Fix postgres ephemeral ports; don't use for TestPubsub_Disconnect (#7798)
Signed-off-by: Spike Curtis <spike@coder.com>
2023-06-05 09:24:44 +04:00
dependabot[bot] f14f011abf chore: Bump github.com/hashicorp/yamux (#7808) 2023-06-04 07:30:36 +03:00
dependabot[bot] 53e5625292 chore: Bump @typescript-eslint/parser from 5.45.1 to 5.59.8 in /site (#7807) 2023-06-04 07:29:30 +03:00
dependabot[bot] 4d5f723740 chore: Bump golangci/golangci-lint-action from 3.3.1 to 3.5.0 (#7805)
Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 3.3.1 to 3.5.0.
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](https://github.com/golangci/golangci-lint-action/compare/v3.3.1...v3.5.0)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-04 03:37:18 +00:00
dependabot[bot] 2bf3cae3cb chore: Bump crate-ci/typos from 1.14.11 to 1.14.12 (#7804)
Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.14.11 to 1.14.12.
- [Release notes](https://github.com/crate-ci/typos/releases)
- [Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md)
- [Commits](https://github.com/crate-ci/typos/compare/v1.14.11...v1.14.12)

---
updated-dependencies:
- dependency-name: crate-ci/typos
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-04 03:31:41 +00:00
dependabot[bot] e10644f86a chore: Bump monaco-editor from 0.37.1 to 0.38.0 in /site (#7814)
Bumps [monaco-editor](https://github.com/microsoft/monaco-editor) from 0.37.1 to 0.38.0.
- [Changelog](https://github.com/microsoft/monaco-editor/blob/main/CHANGELOG.md)
- [Commits](https://github.com/microsoft/monaco-editor/compare/v0.37.1...v0.38.0)

---
updated-dependencies:
- dependency-name: monaco-editor
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-03 22:40:59 +00:00
goodspark e2613c91a7 feat(cli): support non-active template version pushes (#7488)
So that we can push template updates for testing without impacting
normal users of the template.

---------

Co-authored-by: Ammar Bandukwala <ammar@ammar.io>
Co-authored-by: Muhammad Atif Ali <matifali@live.com>
Co-authored-by: Atif Ali <atif@coder.com>
2023-06-03 22:39:00 +00:00
Muhammad Atif Ali 1f8e817da7 ci: delete CODEOWNERS (#7830) 2023-06-03 17:08:55 -05:00
Ammar Bandukwala 38d0f6fb74 perf(provisioner/terraform): upgrade hc-install (#7832)
By upgrading hc-install, we benefit from increased performance
in checksum verification introduced here:

- https://github.com/hashicorp/hc-install/commit/858962c71d47df1ea505b9031bccd5fdf7c8e07f

Also:

- Made minor improvements to tests
- Excluded TestInstall from the race detector
2023-06-03 22:03:41 +00:00
Ammar Bandukwala b62e22766f ci: skip DataDog upload for dependabot (#7831) 2023-06-03 20:47:09 +00:00
Marcin Tojek b26dd4b802 docs: remove unsupported legacy parameters (#7799)
* docs: unsupported legacy parameters

* Update docs/templates/parameters.md

Co-authored-by: Muhammad Atif Ali <atif@coder.com>

---------

Co-authored-by: Muhammad Atif Ali <atif@coder.com>
2023-06-03 06:05:06 +02:00
Colin Adler 14a63d7b4a revert(provisionersdk): remove support for .tf.json files (#7829) 2023-06-02 23:13:41 +00:00
Colin Adler c6cd042e80 fix(clitest): use slogtest for logging stdin and stdout (#7828) 2023-06-02 22:38:31 +00:00
Ammar Bandukwala a4424205c7 ci: truly fix repo name detection 2023-06-02 22:03:21 +00:00
Muhammad Atif Ali 887bbea72a hotfix(docs): fix broken link reported by ci (#7825)
Resolves
https://github.com/coder/coder/actions/runs/5159895963/jobs/9295371489#step:4:188
2023-06-03 00:53:06 +03:00
Ammar Bandukwala f37e007b8e ci: fix repo name detection 2023-06-02 21:40:18 +00:00
dependabot[bot] ea03c7276b chore: Bump github.com/golang-migrate/migrate/v4 from 4.15.2 to 4.16.0 (#7811)
Bumps [github.com/golang-migrate/migrate/v4](https://github.com/golang-migrate/migrate) from 4.15.2 to 4.16.0.
- [Release notes](https://github.com/golang-migrate/migrate/releases)
- [Changelog](https://github.com/golang-migrate/migrate/blob/master/.goreleaser.yml)
- [Commits](https://github.com/golang-migrate/migrate/compare/v4.15.2...v4.16.0)

---
updated-dependencies:
- dependency-name: github.com/golang-migrate/migrate/v4
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-03 00:12:20 +03:00
Eric Paulsen 6715cb6a95 docs: resolve README 404s (#7822) 2023-06-02 20:56:06 +00:00
Colin Adler edccd2de73 fix(agent): configure logger for both reaper and agent (#7823) 2023-06-02 15:51:10 -05:00
Ammar Bandukwala 97fb5020cf hotfix(ci): correctly detect repo name (#7820) 2023-06-02 20:18:09 +00:00
Eric Paulsen d082ab59b4 docs: add note on log truncation (#7821) 2023-06-02 19:36:43 +00:00
Ammar Bandukwala 2631a8436c hotfix: disable nightly-flake on all pushes 2023-06-02 18:11:04 +00:00
Ammar Bandukwala 6d8caf6f14 ci: add nightly flake workflow (#7803) 2023-06-02 12:48:51 -05:00
Ammar Bandukwala 902265bdd7 hotfix(ci): skip DataDog upload on forks (#7802)
* hotfix(ci): skip DataDog upload on forks

* fixup! hotfix(ci): skip DataDog upload on forks
2023-06-02 17:47:14 +00:00
Colin Adler 6fdebd8a07 hotfix(agent): only retain 1 logfile at a time (#7815) 2023-06-02 12:28:38 -05:00
Colin Adler 8f736fe5f5 fix(prometheusmetrics): ensure periodic metrics tick on startup (#7585) 2023-06-02 11:56:37 -05:00
Muhammad Atif Ali 9f810b1964 chore(dependabot): assign frontend team to review dependabot PRs automatically (#7800)
* chore(dependabot): assign frontend tam to review dependabot PRs automatically

* fix team name
2023-06-02 16:34:40 +00:00
Spike Curtis 078926f612 fix: select on context to avoid leak in logFollower (#7792)
Signed-off-by: Spike Curtis <spike@coder.com>
2023-06-02 11:25:46 -05:00
dependabot[bot] 004ad1755f chore: bump formik from 2.2.9 to 2.4.1 in /site (#7763)
* chore: bump formik from 2.2.9 to 2.4.1 in /site

Bumps [formik](https://github.com/formium/formik) from 2.2.9 to 2.4.1.
- [Release notes](https://github.com/formium/formik/releases)
- [Commits](https://github.com/formium/formik/compare/formik@2.2.9...formik@2.4.1)

---
updated-dependencies:
- dependency-name: formik
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Fix ESLINT

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: BrunoQuaresma <bruno_nonato_quaresma@hotmail.com>
2023-06-02 09:58:59 -03:00
Marcin Tojek 10036ab5fb fix: use minDisabled, maxDisabled for parameter validation (#7755) 2023-06-02 11:43:48 +02:00
Marcin Tojek a7366a8b76 feat!: drop support for legacy parameters (#7663) 2023-06-02 11:16:46 +02:00
Colin Adler 2b63492649 feat(healthcheck): add failing sections to report (#7789) 2023-06-01 19:21:24 -05:00
Colin Adler 9b8e5c2d8a feat(provisionersdk): add support for .tf.json templates (#7744) 2023-06-02 00:03:59 +00:00
Bruno Quaresma 9dbbe82cf8 fix(site): proxy menu not showing latency (#7785) 2023-06-01 20:03:27 -03:00
Asher 9704945428 fix: standardize on CODER_PG_CONNECTION_URL (#7781)
Fixes #7513.
2023-06-01 15:02:29 -08:00
Ammar Bandukwala 613f90cf2b ci: send test statistics to DataDog (#7786) 2023-06-01 16:25:52 -05:00
dependabot[bot] 083449c438 chore: bump github.com/gin-gonic/gin from 1.9.0 to 1.9.1 (#7787)
Bumps [github.com/gin-gonic/gin](https://github.com/gin-gonic/gin) from 1.9.0 to 1.9.1.
- [Release notes](https://github.com/gin-gonic/gin/releases)
- [Changelog](https://github.com/gin-gonic/gin/blob/master/CHANGELOG.md)
- [Commits](https://github.com/gin-gonic/gin/compare/v1.9.0...v1.9.1)

---
updated-dependencies:
- dependency-name: github.com/gin-gonic/gin
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-01 16:25:09 -05:00
sharkymark 49ae49095c docs: make template git auth example in sync with git auth setup example (#7784) 2023-06-01 19:34:52 +00:00
Eric Paulsen 4acf36b84a docs: describe gateway and internal certs (#7747)
* docs: gateway & self-signed certs

* docs: update trust store locations

* toolbox paths

* fix: windows cacerts location

---------

Co-authored-by: Ammar Bandukwala <ammar@ammar.io>
2023-06-01 14:49:30 -04:00
Bruno Quaresma 62b2560bd0 chore(site): add type check on lint (#7778) 2023-06-01 15:45:15 -03:00
Bruno Quaresma 1a615778e6 chore(site): add workspace filter experiments into all (#7779) 2023-06-01 15:45:04 -03:00
dependabot[bot] 0bed8b57bc chore: bump eslint from 8.35.0 to 8.41.0 in /site (#7761)
Bumps [eslint](https://github.com/eslint/eslint) from 8.35.0 to 8.41.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.35.0...v8.41.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-01 15:44:33 -03:00
dependabot[bot] 33f1e468cb chore: bump @fontsource/inter from 4.5.11 to 5.0.2 in /site (#7762)
Bumps [@fontsource/inter](https://github.com/fontsource/font-files/tree/HEAD/fonts/google/inter) from 4.5.11 to 5.0.2.
- [Changelog](https://github.com/fontsource/font-files/blob/main/fonts/google/inter/CHANGELOG.md)
- [Commits](https://github.com/fontsource/font-files/commits/HEAD/fonts/google/inter)

---
updated-dependencies:
- dependency-name: "@fontsource/inter"
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-01 15:44:22 -03:00
dependabot[bot] 93f4a5008e chore: bump @types/jest from 29.4.0 to 29.5.2 in /site (#7764)
Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 29.4.0 to 29.5.2.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest)

---
updated-dependencies:
- dependency-name: "@types/jest"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-01 15:43:26 -03:00
Bruno Quaresma 0f439d5374 hotfix: initial options as empty array (#7782) 2023-06-01 18:25:54 +00:00
Ammar Bandukwala ba3e6cea51 hotfix: remove cryptorand.Bool (#7780)
It caused a CI flake and we we weren't using it anywhere.

`cryptorand.Float64() < 0.5` can be used in the future too.
2023-06-01 17:59:08 +00:00
Bruno Quaresma 332362cf4b chore(site): simplify the logic to load workspace initial data (#7772) 2023-06-01 14:20:17 -03:00
Bruno Quaresma 4de4e8ee21 feat(site): Show total of items in the workspaces table (#7774) 2023-06-01 13:21:16 -03:00
Bruno Quaresma 80b60e158d refactor(site): make vscode dropdown button thiner (#7773) 2023-06-01 16:17:56 +00:00
Bruno Quaresma e80e88e019 refactor(site): add default owner:me filter to workspaces (#7738) 2023-06-01 12:04:10 -03:00
Bruno Quaresma 1952c042e1 fix(site): Fix navbar alignment on small screens (#7739)
Co-authored-by: Ammar Bandukwala <ammar@ammar.io>
2023-06-01 13:49:20 +00:00
Steven Masley b32ed2d97e chore: add function to refetch latencies to ProxyContext (#7769)
* Allow refetching of proxy latencies
* Pass refetch funtion up the context stack
* Add to menu bar
2023-06-01 13:37:20 +00:00
Steven Masley cf8d2bc096 feat: use tz_offset when doing deployment dau query (#7736)
* Have FE query correct tz_offset data
2023-06-01 09:23:50 -04:00
Ammar Bandukwala 555ea64669 ci: deduplicate language setup (#7753)
* Deduplicate actions

* Split up go-race and go-pg
2023-06-01 08:20:49 +00:00
Muhammad Atif Ali 80269ba1b9 hotfix(.github): fix dependency in contrib.yaml (#7754)
`title` job was removed in #7743, so this job was falling.
2023-06-01 10:29:07 +03:00
Spike Curtis a46e8f2e49 fix: concurrent writes to executor stats (#7731)
Signed-off-by: Spike Curtis <spike@coder.com>
2023-06-01 05:23:51 +00:00
Ammar Bandukwala 9810339fd6 ci: use Buildjet and faster Windows runners (#7751) 2023-06-01 00:06:37 -05:00
Ben Potter 36f4e0dc35 hotfix(docs): minor updates to workspace proxies (#7735) 2023-05-31 21:32:26 +00:00
Colin Adler f1d27ba42d hotfix(healthcheck): properly calculate healthy status (#7746) 2023-05-31 20:17:33 +00:00
Ammar Bandukwala 828f33ac7b hotfix(.github): remove legacy title validator (#7743)
* hotfix(.github): remove legacy title validator

`cdr-bot` centralizes the behavior and can enforce stricter
standards.

* Increase jest timeout
2023-05-31 19:39:41 +00:00
Muhammad Atif Ali b80756e4f5 feat(site): Add support for insiders channel to "VS Code Desktop" button (#7730) 2023-05-31 16:28:27 +00:00
Cian Johnston 784696dfa5 feat: add prometheus metrics to database.Store (#7713)
* Adds dbmetrics package and wraps database.Store with a Prometheus HistogramVec of timings.
* Adds Wrappers method to database.Store to avoid double-wrapping interfaces
* Fixes test flake in TestLicensesListFake
2023-05-31 14:55:57 +01:00
Bruno Quaresma 00a30775bc refactor(site): Improve and fix loading buttons (#7719) 2023-05-31 10:00:30 -03:00
Bruno Quaresma b34894977d fix(site): Confirm delete on press Enter in delete dialog (#7720) 2023-05-31 09:59:36 -03:00
Bruno Quaresma be2067bb0d fix(site): Make current user first in the list and fix search (#7722) 2023-05-31 09:59:25 -03:00
Muhammad Atif Ali ce6b698048 hotfix(ci): fix a syntax issue in contrib.yaml (#7727) 2023-05-31 07:21:25 +00:00
Spike Curtis 7c3dbbbe93 fix: stream provisioner logs (#7712)
* stream provisioner logs

Signed-off-by: Spike Curtis <spike@coder.com>

* Fix imports

Signed-off-by: Spike Curtis <spike@coder.com>

* Better logging, naming, arg order

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
2023-05-31 06:15:58 +00:00
Spike Curtis 583b777251 fix: wildcard dns docs (#7709)
* Fix wildcard dns docs

Signed-off-by: Spike Curtis <spike@coder.com>

* Clarify

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
2023-05-31 10:10:30 +04:00
dependabot[bot] ec3ef167d2 chore: bump eslint-config-prettier from 8.5.0 to 8.8.0 in /site (#7556)
Bumps [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) from 8.5.0 to 8.8.0.
- [Changelog](https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/eslint-config-prettier/compare/v8.5.0...v8.8.0)

---
updated-dependencies:
- dependency-name: eslint-config-prettier
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-30 23:30:13 -05:00
dependabot[bot] ae82a5985d chore: bump xstate from 4.33.5 to 4.37.2 in /site (#7560)
Bumps [xstate](https://github.com/statelyai/xstate) from 4.33.5 to 4.37.2.
- [Release notes](https://github.com/statelyai/xstate/releases)
- [Commits](https://github.com/statelyai/xstate/compare/xstate@4.33.5...xstate@4.37.2)

---
updated-dependencies:
- dependency-name: xstate
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-30 23:29:23 -05:00
Ammar Bandukwala 43eee35ae8 chore(cli): correctly report telemetry even when transport replaced (#7670)
By introducing the "ExtraHeaders" map, we can apply headers even when
handlers replace the transport, as in the case of our scaletests.

Also, only send telemetry header when it's small.
2023-05-31 00:11:56 +00:00
Ammar Bandukwala 867996aa18 chore(.github): specify PR types 2023-05-30 23:57:45 +00:00
Colin Adler 43e0968dac feat: format healthcheck responses (#7723) 2023-05-30 16:59:39 -05:00
Steven Masley 73d795f426 chore: Revert to only using 1 timezone support for template DAUs (#7721)
* chore: Revert to only using 1 timezone support for template DAUs

Keeping the logic to support more in case we optimize later
2023-05-30 15:37:07 -04:00
Colin Adler 022372dd73 feat(healthcheck): add websocket report (#7689) 2023-05-30 14:22:32 -05:00
Bruno Quaresma 77b0ca0b53 refactor(site): Improve workspaces filtering (#7681) 2023-05-30 14:52:13 -03:00
Steven Masley c795a0e500 feat: Fix Deployment DAUs to work with local timezones (#7647)
* chore: Add timezone param to DAU SQL query
* Merge DAUs response
* Pass time offsets to metricscache
2023-05-30 13:18:27 -04:00
dependabot[bot] 68658b5197 chore: bump github.com/valyala/fasthttp from 1.44.0 to 1.47.0 (#7703)
Co-authored-by: Colin Adler <colin1adler@gmail.com>
2023-05-30 11:48:56 -05:00
dependabot[bot] 2aa48d4143 chore: bump crate-ci/typos from 1.14.10 to 1.14.11 (#7701)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-30 11:38:33 -05:00
dependabot[bot] 115f80737a chore: bump github.com/coder/retry (#7705)
Bumps [github.com/coder/retry](https://github.com/coder/retry) from 1.3.1-0.20230210155434-e90a2e1e091d to 1.4.0.
- [Commits](https://github.com/coder/retry/commits/v1.4.0)

---
updated-dependencies:
- dependency-name: github.com/coder/retry
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-30 11:09:12 -05:00
Bruno Quaresma c2d2751897 feat(site): Add proxy menu into navbar (#7715) 2023-05-30 11:41:23 -03:00
Ammar Bandukwala e8eb28adb4 chore(.github): remove stalebot messages 2023-05-30 14:10:39 +00:00
Marcin Tojek 702c9081e0 fix: do not skip parameter validation if min or max = 0 (#7707) 2023-05-30 14:57:06 +02:00
Marcin Tojek 4eb0baa849 chore: update protoc-gen-go (#7708) 2023-05-30 10:24:34 +02:00
Rodrigo Maia 61dc875454 feat(cli): show license_expires as rfc3339 date instead of unix time (#7687)
* feat(licenses): show license_expires time as rfc3339 date

* fix review comments
2023-05-26 14:36:26 +00:00
Mathias Fredriksson 66f5d39ff5 test(agent): Improve use of inv.Context() (#7696)
This will ensure tests timeout instead of hang indefinitely since
`inv.Context()` is assigned a timeout by default.
2023-05-26 13:48:39 +00:00
Mathias Fredriksson 05efd64320 test: Skip tests that send os.Interrupt to test pid (#7695)
This can cause test flakes due to clitest commands running in memory and
listening to interrupt signals.
2023-05-26 16:17:09 +03:00
Cian Johnston 795050bba3 chore: add prometheus monitoring of workspace traffic generation (#7583)
- Exposes reads/writes from scaletest traffic generation (default: 0.0.0.0:21112)
- Adds self-hosted prometheus with remote_write to loadtest terraform
- Adds convenience script to run a traffic generation test
2023-05-26 13:53:35 +01:00
Mathias Fredriksson 0fd2ea4044 test(coderd/rbac): Increase TestFilter timeout (#7694) 2023-05-26 15:44:05 +03:00
Muhammad Atif Ali e5add7292f chore: Only run deploy_template after deploy_image has been completed (#7693) 2023-05-26 12:20:14 +00:00
Bruno Quaresma 79ab72fbb1 fix(site): Fix retry on debug mode alert (#7686) 2023-05-25 17:22:57 -03:00
Kira Pilot 4d4ffa2d99 feat: add expiration indicators to license card (#7684)
* sorting licenses; add expiration badge

* updated story
2023-05-25 11:37:51 -07:00
Kira Pilot 0c665235ff feat: add impending deletion banner to workspace page (#7634)
* add banner to workspace page

* fix prettier and lint

* color-code banner

* using warning instead

* improve prop name for clarity
2023-05-25 10:55:41 -07:00
Marcin Tojek 5d2b2c577b fix: add mockgen to nix env (#7682) 2023-05-25 12:44:32 -04:00
Rodrigo Maia d9299caa12 feat: order workspaces by running first (#7656)
* wip

* use updated sql

* wip

* Implement sorting in databasefake.go

* More fixes

* sql fmt

---------

Co-authored-by: Marcin Tojek <marcin@coder.com>
2023-05-25 13:35:47 -03:00
Spike Curtis 96a2e63809 chore: upgrade to golangci-lint 1.52.2 (#7674)
* Disable ioutilDeprecated lint

Signed-off-by: Spike Curtis <spike@coder.com>

* Upgrade to golangci-lint 1.52.2

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
2023-05-25 14:56:31 +04:00
Marcin Tojek 14efdadd3c feat: Collect agent SSH metrics (#7584) 2023-05-25 12:52:36 +02:00
Spike Curtis 05da1e94a2 Fix pubsub goroutines in tests (#7677)
Signed-off-by: Spike Curtis <spike@coder.com>
2023-05-25 14:46:32 +04:00
Spike Curtis 67cc196c92 feat: pubsub reports dropped messages (#7660)
* Implementation; need linux tests

Signed-off-by: Spike Curtis <spike@coder.com>

* Pubsub with errors tests and fixes

Signed-off-by: Spike Curtis <spike@coder.com>

* Deal with test goroutines

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
2023-05-25 06:22:30 +00:00
Spike Curtis 6a1e7ee1d0 feat: add file logger to coder ssh (#7646)
* coder ssh can log to file

Signed-off-by: Spike Curtis <spike@coder.com>

* Update golden file

Signed-off-by: Spike Curtis <spike@coder.com>

* generate CLI docs

Signed-off-by: Spike Curtis <spike@coder.com>

* Fix imports, typo

Signed-off-by: Spike Curtis <spike@coder.com>

* log more things!

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
2023-05-25 05:07:39 +00:00
Colin Adler a903d7c249 fix(ci): use env for Go version in release workflow (#7673) 2023-05-24 22:52:18 +00:00
Colin Adler dd69cc9148 fix: use different terraform cache dir (#7672) 2023-05-24 22:35:00 +00:00
Colin Adler 5eb41e8794 feat(cli): allow specifying the listen address in coder port-forward (#7635) 2023-05-24 15:38:40 -04:00
Ammar Bandukwala d413b261d8 chore: deduplicate CLI telemetry reports (#7669) 2023-05-24 12:45:41 -05:00
Ammar Bandukwala ec117e841a chore: add CLI invokation telemetry (#7589) 2023-05-24 11:08:03 -05:00
sharkymark b6604e8845 chore(docs): AWS EKS load balancer setup steps (#7665) 2023-05-24 10:19:45 -05:00
goodspark 71c52ea93c feat: Add logging options for coder agent (#7474)
Similar to logging options in the coderd server, but for the agent
running in workspaces. Meant to make hollistic log collection and
querying simpler.
2023-05-24 14:32:40 +00:00
Mathias Fredriksson b6c8e5be48 fix(cli/ssh): Fetch up-to-date build info to avoid ws has no agents (#7650)
Fixes #5836
2023-05-24 12:37:22 +03:00
Cian Johnston f47ecc29f0 chore(dogfood): Update sqlc version in dogfood image to match CI (#7661) 2023-05-24 09:30:56 +00:00
Colin Adler 0c074742a5 fix(ci): manually select Go version (#7654) 2023-05-24 07:47:44 +00:00
Colin Adler f72d8e95a4 fix(ci): add mockgen to trivy scan (#7655) 2023-05-23 17:09:16 -04:00
Colin Adler 02cc325047 chore(mod): symbolically bump tailscale (#7653) 2023-05-23 15:20:22 -04:00
dependabot[bot] 8f13c145c4 chore: bump github.com/moby/moby from 20.10.23+incompatible to 24.0.1+incompatible (#7622)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-23 19:04:00 +00:00
Colin Adler c8ea76c7fa fix(cli): correctly use cache dir for provisionerd work dir (#7651) 2023-05-23 13:37:27 -04:00
Bruno Quaresma ba02dc8f3a chore(site): Force exact deps (#7649) 2023-05-23 07:43:46 -08:00
Steven Masley d203f5259d fix: Port forward should ignore coder ports (#7645)
Ports opened by coder agent should be ignored in the listening ports
map.
2023-05-23 17:14:05 +02:00
Spike Curtis cd416c86dd refactor: workspace builds (#7541)
* refactor workspace builds

Signed-off-by: Spike Curtis <spike@coder.com>

* make gen

Signed-off-by: Spike Curtis <spike@coder.com>

* Remove ParameterResolver from typescript

Signed-off-by: Spike Curtis <spike@coder.com>

* rename conversion -> database/db2sdk

Signed-off-by: Spike Curtis <spike@coder.com>

* tests for db2sdk

Signed-off-by: Spike Curtis <spike@coder.com>

* Tests for ParameterResolver

Signed-off-by: Spike Curtis <spike@coder.com>

* wsbuilder tests

Signed-off-by: Spike Curtis <spike@coder.com>

* Move parameter validation tests to richparameters_test.go

Signed-off-by: Spike Curtis <spike@coder.com>

* Fix CI generation; rename mock->dbmock

Signed-off-by: Spike Curtis <spike@coder.com>

* Fix test imports

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
2023-05-23 12:06:33 +04:00
Spike Curtis 622456faf8 docs: Add autoscale recommendations docs (#7617)
* Add autoscale recommendations

Signed-off-by: Spike Curtis <spike@coder.com>

* review updates

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
2023-05-23 09:22:29 +04:00
Rodrigo Maia 4a320617b4 feat(workspaces): change sorting order of the workspace list (#7594)
* feat(workspaces): implement sorting order on workspace list

* split slice into its own function and test it

* use require instead of assert

* Update coderd/workspaces_internal_test.go

Co-authored-by: Cian Johnston <cian@coder.com>

* refactor tests into table tests

* fix test

---------

Co-authored-by: Cian Johnston <cian@coder.com>
2023-05-22 20:51:29 +00:00
Steven Masley 5d711fc95a chore: CORs option for yarn dev server (#7630)
* chore: Yarn dev servers require CORs headers for external proxies

Adds a flag to set CORs headers to `*` for yarn dev servers
2023-05-22 20:02:39 +02:00
dependabot[bot] 1f4f0efed6 chore: bump github.com/prometheus/client_golang from 1.14.0 to 1.15.1 (#7620)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-22 13:18:44 -04:00
dependabot[bot] 808e83f87d chore: bump golang.org/x/tools from 0.6.0 to 0.9.1 (#7619)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-22 13:16:27 -04:00
dependabot[bot] 7d1ca7c12f chore: bump crate-ci/typos from 1.14.9 to 1.14.10 (#7618)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-22 13:13:03 -04:00
dependabot[bot] 9c923d71ca chore: bump github.com/hashicorp/terraform-json from 0.14.0 to 0.16.0 (#7621)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-22 13:10:11 -04:00
Steven Masley b8c07ff014 feat: Auto select workspace proxy based on lowest latency (#7515)
* feat: Proxy auto select and user selection state
* chore: Auto select based on latency
* Add extra test for unknown latencies
* Mock latencies for unit tests
2023-05-22 16:56:41 +02:00
Marcin Tojek f9a97c25dc fix: disable TCP SACK (#7624) 2023-05-22 13:37:05 +00:00
dependabot[bot] b38fb90e06 chore: bump @emotion/styled from 11.10.8 to 11.11.0 in /site (#7561)
Bumps [@emotion/styled](https://github.com/emotion-js/emotion) from 11.10.8 to 11.11.0.
- [Release notes](https://github.com/emotion-js/emotion/releases)
- [Changelog](https://github.com/emotion-js/emotion/blob/main/CHANGELOG.md)
- [Commits](https://github.com/emotion-js/emotion/compare/@emotion/styled@11.10.8...@emotion/styled@11.11.0)

---
updated-dependencies:
- dependency-name: "@emotion/styled"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-22 09:23:33 -03:00
dependabot[bot] 1bd3ed9ecd chore: bump chromatic from 6.15.0 to 6.17.4 in /site (#7554)
Bumps [chromatic](https://github.com/chromaui/chromatic-cli) from 6.15.0 to 6.17.4.
- [Changelog](https://github.com/chromaui/chromatic-cli/blob/main/CHANGELOG.md)
- [Commits](https://github.com/chromaui/chromatic-cli/compare/v6.15.0...v6.17.4)

---
updated-dependencies:
- dependency-name: chromatic
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-21 13:12:03 -05:00
Muhammad Atif Ali 51130540af docs: Add steps to migrate from the built-in database to an external database (#7614) 2023-05-21 10:31:06 -05:00
Colin Adler ef2411ef17 fix(provisionersdk): allow .terraform.lock.hcl files to be archived (#7604) 2023-05-19 13:22:59 -04:00
Cian Johnston a29c4c543d chore(dogfood): fix dogfood image (#7603)
* chore(dogfood): update keys, add script to do so

* chore(dogfood): fix urls in Dockerfile

* fmt
2023-05-19 15:09:34 +01:00
Muhammad Atif Ali e375169ac0 chore: remove CPU usage calculation for hosts on cgroup v1 (#7602) 2023-05-19 14:08:20 +00:00
Muhammad Atif Ali ef635f12ea chore(dogfood): update the dogfood template to add workspace CPU and RAM usage from cgroup (#7529)
Co-authored-by: Cian Johnston <cian@coder.com>
2023-05-19 15:15:48 +03:00
Colin Adler dd5b0b2721 fix(scim): ensure scim users aren't created with their own org (#7595) 2023-05-18 20:54:45 -04:00
Kira Pilot 0b15b1bcd1 feat: add impending deletion indicators to the workspace page (#7588)
* created WorkspaceDeletion directory

* remove commented code

* attempting to fix workspace stories

* fix lint

* fix the rest of the stories

* fix right stories

* PR comments

* fix lint
2023-05-18 11:08:55 -07:00
Bruno Quaresma 8e31ed4072 refactor(site): Refactor alerts (#7587) 2023-05-18 13:17:16 -03:00
Muhammad Atif Ali 63a9e34381 fix: correct free disk space reported by agent metadata in fly.io example (#7592) 2023-05-18 11:42:04 +03:00
Jon Ayers ec5ef51b49 feat: add session token injection to provisioner (#7461) 2023-05-17 23:29:22 -05:00
Jon Ayers 00a2413c03 feat: add telemetry support for workspace agent subsystem (#7579) 2023-05-17 22:49:25 -05:00
dependabot[bot] 52bb84a26f chore: bump google.golang.org/api from 0.108.0 to 0.122.0 (#7558)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-17 14:06:17 -04:00
Bruno Quaresma 12f87cb98d refactor(site): Show update notification as snackbar (#7546) 2023-05-17 13:56:26 -03:00
Bruno Quaresma a7f14f89e3 fix(site): Fix loading buttons (#7549) 2023-05-17 13:56:15 -03:00
dependabot[bot] 119098a1eb chore: bump github.com/coreos/go-oidc/v3 from 3.4.0 to 3.6.0 (#7553)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-17 16:29:42 +00:00
Kyle Carberry 6e7175b589 chore: fix lengthy tests in psql (#7545)
* chore: fix lengthy tests in psql

This was adding at a minimum 3mins to our psql tests!

* fix: automatically cancel tests on cleanup
2023-05-17 11:26:53 -05:00
dependabot[bot] d1b1122690 chore: bump github.com/gohugoio/hugo from 0.110.0 to 0.111.3 (#7562)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-17 12:14:38 -04:00
dependabot[bot] bfa136276c chore: bump crate-ci/typos from 1.14.8 to 1.14.9 (#7552)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-17 12:11:56 -04:00
dependabot[bot] ce91009d6b chore: bump beatlabs/delete-old-branches-action from 0.0.9 to 0.0.10 (#7551)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-17 12:11:43 -04:00
Ben Potter e951778147 fix: indentation in rootless podman docs (#7577)
* fix: indentation in rootless podman docs

* fmt
2023-05-17 01:26:13 +00:00
Colin Adler 75b0643623 chore: enable dependabot for coder base image (#7550) 2023-05-16 19:09:45 +00:00
Colin Adler e3b324a1a1 chore(dogfood): update dependency versions (#7548) 2023-05-16 18:26:06 +00:00
Steve Coder 04f68e8f15 doc:fixed enterprise feature 404s. (#7547) 2023-05-16 12:32:54 -05:00
Pfau, Sascha ad9a29dfa6 feat(site): added URL param name to allow setting workspace name (#7528)
* feat: added URL param name to allow setting workspace name

* fix: format

---------

Co-authored-by: SaschaPfau <Sascha.Pfau@ilabnordlb.onmicrosoft.com>
2023-05-16 13:26:13 -03:00
Kira Pilot dca77ba487 feat: add workspaces banner for impending deletion (#7538)
* feat: add workspaces banner for impending deletion

* added storybook

* remove storybook - cannot add because of hook used in badge component
2023-05-16 07:01:22 -07:00
Marcin Tojek 97b4743a47 Revert "fix: set default sshMaxTimeout to 60s (#7532)" (#7544)
This reverts commit 049e557675.
2023-05-16 15:28:15 +02:00
Kyle Carberry c6055c64be chore: improve input hover color (#7534) 2023-05-16 09:00:20 -03:00
dependabot[bot] a1853f2fa2 chore: bump date-fns from 2.29.3 to 2.30.0 in /site (#7335)
Bumps [date-fns](https://github.com/date-fns/date-fns) from 2.29.3 to 2.30.0.
- [Release notes](https://github.com/date-fns/date-fns/releases)
- [Changelog](https://github.com/date-fns/date-fns/blob/v2.30.0/CHANGELOG.md)
- [Commits](https://github.com/date-fns/date-fns/compare/v2.29.3...v2.30.0)

---
updated-dependencies:
- dependency-name: date-fns
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-15 16:05:52 -03:00
dependabot[bot] 4997b86548 chore: bump eslint-plugin-compat from 4.0.2 to 4.1.4 in /site (#7339)
Bumps [eslint-plugin-compat](https://github.com/amilajack/eslint-plugin-compat) from 4.0.2 to 4.1.4.
- [Release notes](https://github.com/amilajack/eslint-plugin-compat/releases)
- [Changelog](https://github.com/amilajack/eslint-plugin-compat/blob/main/CHANGELOG.md)
- [Commits](https://github.com/amilajack/eslint-plugin-compat/compare/v4.0.2...v4.1.4)

---
updated-dependencies:
- dependency-name: eslint-plugin-compat
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-15 15:45:54 -03:00
Ben Potter 78f862eedc chore: rename "external workspace proxies" and "external provisioners" (#7454) 2023-05-15 21:38:49 +03:00
Bruno Quaresma 11b7732720 feat(site): Show confirmation dialog on restart (#7531) 2023-05-15 14:43:51 -03:00
Bruno Quaresma d9fc94f9a9 fix(site): Fix focus state on buttons (#7526) 2023-05-15 14:43:16 -03:00
Spike Curtis 0b156420de Make coder dotfiles symlinking idempotent (#7525)
Signed-off-by: Spike Curtis <spike@coder.com>
2023-05-15 21:00:50 +04:00
Kyle Carberry 424f954b91 fix: use password style for session token auth (#7533) 2023-05-15 11:27:39 -05:00
Ben Potter 2aea5b76aa docs: parameters are not alpha (#7487) 2023-05-15 16:14:59 +00:00
Bruno Quaresma 6f62204d38 feat(site): Add template embed page (#7501) 2023-05-15 13:07:39 -03:00
Marcin Tojek 049e557675 fix: set default sshMaxTimeout to 60s (#7532)
* fix: set default sshMaxTimeout to 60s

* fix
2023-05-15 10:40:19 -05:00
Kira Pilot 224d25d4e1 feat: add 'impending deletion' badges to workspaces page (#7530)
* update deleting logic

* added status badge on workspaces page

* licensing and feature flagging

* preset filter for failed workspaces

* remove comment

* PR feedback

* Revert "PR feedback"

This reverts commit 2dfbb50acd.

* PR feedback 2
2023-05-15 07:59:17 -07:00
Cian Johnston 854e974bb4 chore: add terraform for spinning up load test cluster (#7504)
Adds terraform configs for spinning up loadtest environments
2023-05-15 15:56:47 +01:00
Bruno Quaresma dab1d1fe20 fix(site): Fix terminal elements size (#7527) 2023-05-15 10:48:41 -03:00
Marcin Tojek 87784493e8 fix: use mtojek/gvisor to tweak RTO (#7500)
* fix: use mtojek/gvisor to tweak RTO

* fix
2023-05-15 09:12:45 +02:00
Kyle Carberry a08e8a16ab chore: switch make test to use the standard go format (#7519)
I find it easier to read.
2023-05-14 21:20:19 -05:00
Kyle Carberry 70d2203b9e chore: reduce the log output of skipped tests (#7520)
With the introduction of the workspace proxy tests there was a lot
of output if a test was eventually skipped.
2023-05-14 19:37:00 -05:00
Ammar Bandukwala 9bb0253290 chore: update various dependencies (#7503)
This will help us pass the security scanners.
2023-05-14 20:37:50 +00:00
Kyle Carberry 26490aecca chore: improve postgres test time by removing cleanup (#7522)
We don't need to delete databases on cleanup... and we don't need to
always run without a cache either!
2023-05-14 15:32:44 -05:00
Kyle Carberry 778cb7494a chore: adjust the style and wording of the license page (#7396)
- Reduce the size of the card to improve the use of space
- Adjust the language of the add page to remove word redundancy
- Change from using background colors to text colors
2023-05-14 15:31:54 -05:00
Kyle Carberry 8e1da5e628 chore: run yarn-deduplicate to speed up yarn install (#7523) 2023-05-14 15:28:07 -05:00
Ammar Bandukwala f05f12231d feat: update slog to use logfmt (#7477) 2023-05-14 20:23:13 +00:00
Ammar Bandukwala 0f4717e471 hotfix(.github): only push dogfood template when /dogfood changes 2023-05-14 20:13:37 +00:00
Kyle Carberry 50f2d0c7e9 fix: add a mutex around reading logs from scaletests (#7521) 2023-05-14 12:16:00 -05:00
Ammar Bandukwala fcde77b35f chore(.github): only deploy dogfood on main (#7518) 2023-05-14 11:32:22 -05:00
Ben Potter 6bb4a4c3c5 chore: add latest dogfood template (#7321)
Co-authored-by: Muhammad Atif Ali <matifali@live.com>
2023-05-13 15:42:10 +03:00
Muhammad Atif Ali 8d4a8fde66 docs: add instructions for connecting via RDP (#7510) 2023-05-12 11:41:10 -05:00
Marcin Tojek cd38cb8290 feat: Add template version warnings (#7483) 2023-05-12 09:21:49 +00:00
Steven Masley 8f768f8276 feat: Workspace Proxy picker show latency to each proxy (#7486)
* chore: Add cors to workspace proxies to allow for latency checks
* Add latency check to wsproxy

Use performance API timings.
- Fix cors and timing headers
- Accept custom headers
2023-05-11 15:42:30 -05:00
Ammar Bandukwala 640fcf450c chore: improve terraform install performance (#7478) 2023-05-11 19:30:51 +00:00
Eric Paulsen 0e6361383c fix(helm): change proxy to wsproxy (#7499) 2023-05-11 17:55:04 +00:00
Kira Pilot ae3473dc1b feat: add deleted_at field to workspace model (#7475)
* added impending_deletion workspace field

* gen docs

* update golden files

* added test

* PR comments
2023-05-11 08:47:53 -07:00
Eric Paulsen fe0e94ece9 docs: add docs for disabling email/pass auth (#7494) 2023-05-11 10:09:14 -05:00
Ben Potter 892bddfb7b fix: scroll to reveal template create errors (#7464)
Co-authored-by: Kira Pilot <kira@coder.com>
2023-05-11 14:47:51 +03:00
Steven Masley b7f4f3a771 chore: Implement workspace proxy going away (graceful shutdown) (#7459)
* chore: Implement workspace proxy going away

When a workspace proxy shuts down, the health status of that
proxy should immediately be updated. This is purely a courtesy
and technically not required
2023-05-10 19:23:16 -05:00
Kira Pilot a42a36a474 feat: add workspace actions cleanup configuration flags to CLI template create and edit (#7453)
* added cleanup flags on template create

* added cleanup flags on template edit

* fixed tests

* added to tests
2023-05-10 12:57:11 -07:00
Bruno Quaresma 816c37dd0d chore(site): Upgrade to MUI v5 (#7437) 2023-05-10 19:42:40 +00:00
Steven Masley fb86ac2608 chore: If selecting an unhealthy proxy, default to primary (#7472)
* chore: If selecting an unhealthy proxy, default to primary
2023-05-10 13:10:06 -05:00
Steven Masley 3f9af6f5e7 chore: Allow cors requests to workspace proxies for latency checks (#7484)
* CSP addition for web requests
* chore: Add cors to workspace proxies to allow for latency checks
2023-05-10 17:19:55 +00:00
Muhammad Atif Ali d17ea84b4a docs: change --ttl to --default-ttl (#7479) 2023-05-10 07:03:50 -05:00
Spike Curtis d35a458767 feat: Windows on Azure example template (#7469)
* WIP Azure template for windows machine

Signed-off-by: Spike Curtis <spike@coder.com>

* WIP windows uses data disk

Signed-off-by: Spike Curtis <spike@coder.com>

* Data drive working

Signed-off-by: Spike Curtis <spike@coder.com>

* Add az cli commands to start & stop

Signed-off-by: Spike Curtis <spike@coder.com>

* Remove commented line

Signed-off-by: Spike Curtis <spike@coder.com>

* Prettierify

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
2023-05-10 05:56:19 +00:00
Steven Masley b5ad628460 chore: Allow editing proxy fields via api. (#7435)
* chore: Add ability to update workspace proxy fields
2023-05-09 13:46:50 -05:00
Steven Masley fc1bc374cb chore: Drop application host call, default to regions for info (#7457)
* chore: Drop application host call, default to regions for info
2023-05-09 09:28:25 -05:00
Ben Potter 2d62cbc83a chore: minor change to workspace actions copy (#7458) 2023-05-09 08:31:07 -05:00
Eric Paulsen 503e94a5c2 docs: fix proxy cmd ref (#7460) 2023-05-08 19:22:35 -04:00
Kira Pilot 0755ff32ef label change (#7455) 2023-05-08 16:13:14 -03:00
Steven Masley 1aac8200fa chore: Fix column name in proxy ls command (#7450) 2023-05-08 12:23:12 -05:00
Ben Potter 3931a6c7bc fix: accurate list of experiments in docs (#7449) 2023-05-08 14:58:07 +00:00
Steven Masley c3e60dcdfb chore: Fix proxy description wording on workspace proxy page (#7448) 2023-05-08 14:41:14 +00:00
Ben Potter 8f9a3ea1a7 docs: add docs for selecting a proxy (#7444) 2023-05-08 14:37:56 +00:00
Ammar Bandukwala 8899dd89ca chore: add global caching to rbac (#7439)
Co-authored-by: Steven Masley <stevenmasley@coder.com>
2023-05-08 08:59:01 -05:00
Bruno Quaresma 643a9efea9 chore(site): Add type checking (#7441) 2023-05-05 18:46:51 -03:00
Steven Masley 52d2bc930b chore: Make better error message if missing license (#7440)
* chore: Make better error message if missing license

* Change word to proxies
2023-05-05 14:22:56 -05:00
Steven Masley 07608fc3fb chore: fix proxy 404 page (#7421)
* chore: fix proxy 404 page

---------

Co-authored-by: Kyle Carberry <kyle@coder.com>
2023-05-05 13:53:19 -05:00
Steven Masley 2624ee8f12 chore: Remove extra opt and fix 'proxy' alias (#7413)
* chore: Remove extra opt and fix 'proxy' alias
* proxy -> wsproxy
2023-05-05 13:09:04 -05:00
Bruno Quaresma ec11405208 chore(site): Remove dead code (#7436) 2023-05-05 16:30:08 +00:00
Spike Curtis dc3d39baf8 fix: agent disconnects from coordinator (#7430)
* work around websocket deadline bug

Signed-off-by: Spike Curtis <spike@coder.com>

* Use test context to hold websocket open

Signed-off-by: Spike Curtis <spike@coder.com>

* Fix race creating test websocket

Signed-off-by: Spike Curtis <spike@coder.com>

* set write deadline to time.Time zero

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
2023-05-05 20:29:03 +04:00
Kira Pilot 5ffa6dae50 feat: add inactivity cleanup and failure cleanup configuration fields to Template Schedule Form (#7402)
* added workspace actions entitlement

* added workspace actions experiment

* added new route for template enterprise meta

* removing new route; repurposing old

* add new fields to get endpoints

* removed workspace actions experiment

* added logic to enterprise template store

* added new form fields

* feature flagged new fields

* fix validation

* fixed submit btn

* fix tests

* changed ttl defaults

* added FE tests

* added BE tests

* fixed lint

* adjusted comment language

* fixing unstaged changes check

* fix test

* Update coderd/database/migrations/000122_add_template_cleanup_ttls.down.sql

Co-authored-by: Dean Sheather <dean@deansheather.com>

* Update coderd/database/migrations/000122_add_template_cleanup_ttls.up.sql

Co-authored-by: Dean Sheather <dean@deansheather.com>

---------

Co-authored-by: Dean Sheather <dean@deansheather.com>
2023-05-05 08:19:26 -07:00
Bruno Quaresma 3632ac8c01 refactor(site): Update workspace header (#7433) 2023-05-05 15:02:21 +00:00
Cian Johnston 7f02fa696a chore(docs): update openshift documentation re psp (#7432) 2023-05-05 13:00:07 +01:00
Cian Johnston 08fb9a6f1b feat(cli): add trafficgen command for load testing (#7307)
This PR adds a scaletest workspace-traffic command for load testing. This opens a
ReconnectingPTY connection to each scaletest workspace (via coderd) and 
concurrently writes and reads random data to/from the PTY. Payloads are of the
form #${RANDOM_ALPHANUMERIC_STRING}, which essentially drops garbage
comments in the remote shell, and should not result in any commands being executed.
2023-05-05 10:34:58 +01:00
Cian Johnston a172e073e3 chore(ci): update golden files (#7431) 2023-05-05 09:05:45 +00:00
Spike Curtis a6a44896bf fix: pubsub ordering (#7404)
* fix: pubsub sends messages in order

Signed-off-by: Spike Curtis <spike@coder.com>

* Drop messages rather than block

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
2023-05-05 09:39:07 +04:00
Dean Sheather 667d9a7557 chore: add workspaceProxy to helm chart (#7398) 2023-05-05 07:07:49 +10:00
Bruno Quaresma 164146c462 feat(site): Show update confirmation dialog (#7420) 2023-05-04 15:40:41 -03:00
Steven Masley 6d24f7c894 feat: Add documentation for workspace proxy creation (#7377)
* feat: Add documentation for workspace proxy creation
2023-05-04 13:30:06 -05:00
Bruno Quaresma 8909110f58 fix(site): Fix template icon field validation (#7394) 2023-05-04 14:30:48 -03:00
Jon Ayers 614bdfbf3c fix: update envbox template to use hostname (#7417) 2023-05-04 12:21:20 -05:00
Kyle Carberry 11ac3be4d8 fix: redirect to login on gitauth invalid session (#7416) 2023-05-04 17:19:44 +00:00
Steven Masley 9908c84b2a test: Return early and avoid using nil handler (#7411)
* test: Return early and avoid using nil handler
2023-05-04 11:14:53 -05:00
Cian Johnston b4d913e24f fix(helm): explode verbs instead of wildcarding (#7405)
Updates the Helm chart role specification for Coder to explicitly list required verbs instead of requesting wildcard.
2023-05-04 10:45:51 +00:00
Spike Curtis b3689c8f64 Only send tailnet nodes updates with preferred DERP (#7387)
Signed-off-by: Spike Curtis <spike@coder.com>
2023-05-04 14:30:57 +04:00
Colin Adler 4e52112112 fix: template versions test flake (#7400) 2023-05-03 20:19:49 -05:00
Colin Adler 8bd9f9c351 feat: unified tracing between coderd<->provisionerd (#7370) 2023-05-03 23:02:35 +00:00
Steven Masley 3368b8b65f chore: Minor rbac memory optimization (#7391)
* test: Add benchmark for static rbac roles
* static roles should only be allocated once
* A unit test that modifies the ast value should not mess with the globals
* Cache subject AST values to avoid reallocating slices
2023-05-03 14:42:24 -05:00
Kira Pilot 2e9310b203 chore: add workspace actions entitlement and experiment (#7361)
* added workspace actions entitlement

* added workspace actions experiment
2023-05-03 11:34:43 -07:00
Dean Sheather 5961cf900d chore: bump terraform from 1.3.4-r3 to r4 in image (#7393)
Looks like 1.3.4-r3 isn't available anymore, and 1.3.4-r4 is available
instead.
2023-05-03 18:21:11 +00:00
Bruno Quaresma 2ea438cf4f refactor(site): Show immutable parameters in the settings (#7383) 2023-05-03 14:40:47 -03:00
Steven Masley 434c4be9f1 chore: Add listing proxies to cli 'coder proxy ls' (#7376)
* feat: Add listing proxies to cli 'coder proxy ls'

* Add unit test

* Ignore errors

* Make gen and update golden files

* Update golden files
2023-05-03 10:12:56 -05:00
Kyle Carberry 90c57a538c fix: make telemetry source a string not an enum (#7390) 2023-05-03 14:33:51 +00:00
Spike Curtis 9c030a8888 fix: pty.Start respects context on Windows too (#7373)
* fix: pty.Start respects context on Windows too

Signed-off-by: Spike Curtis <spike@coder.com>

* Fix windows imports; rename ToExec -> AsExec

Signed-off-by: Spike Curtis <spike@coder.com>

* Fix import in windows test

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
2023-05-03 11:43:05 +04:00
Bruno Quaresma e6931d6920 refactor(site): Remove optimistic workspace action (#7385) 2023-05-02 18:38:53 -03:00
Steven Masley dd67283323 chore: Adjust wording to mention only browser connections (#7384) 2023-05-02 13:39:23 -05:00
Bruno Quaresma 730039f35f feat(site): Show warning if startup script is running (#7326) 2023-05-02 14:49:16 -03:00
Colin Adler 75ad72de56 fix(server): prevent otel tracer provider from immediately being closed (#7369) 2023-05-02 12:06:58 -05:00
Spike Curtis bd630113b2 fix: coordinator node update race (#7345)
* fix: coordinator node update race

Signed-off-by: Spike Curtis <spike@coder.com>

* Lint fixes, make core private

Signed-off-by: Spike Curtis <spike@coder.com>

* Don't log broken connections as errors

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
2023-05-02 20:58:21 +04:00
Bruno Quaresma 0e78d0a502 fix(site): Remove extra spacing between ssh button (#7380) 2023-05-02 13:54:52 -03:00
dependabot[bot] 6dfce5a2c9 chore: bump jest-runner-eslint from 1.1.0 to 2.0.0 in /site (#7343)
Bumps [jest-runner-eslint](https://github.com/jest-community/jest-runner-eslint) from 1.1.0 to 2.0.0.
- [Release notes](https://github.com/jest-community/jest-runner-eslint/releases)
- [Changelog](https://github.com/jest-community/jest-runner-eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/jest-community/jest-runner-eslint/compare/v1.1.0...v2.0.0)

---
updated-dependencies:
- dependency-name: jest-runner-eslint
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-02 09:56:58 -05:00
Muhammad Atif Ali f5ce911b8d docs: make use of display_name and name in Open with Coder (#7372)
This PR removed the spaces from `name` and makes it equal to the resource name as we now have a sperate field `display_name` https://github.com/coder/coder/pull/6919

The docs references https://github.com/bpmct/coder-templates/tree/main/kubernetes-open-in-coder example which does not yet makes use of  `display name` and needs updating.
2023-05-02 09:51:50 -05:00
Steven Masley a1db82582f chore: Dynamic CSP connect-src to support terminals connecting to workspace proxies (#7352)
* chore: Expose proxy hostnames to csp header
2023-05-02 08:30:44 -05:00
Ammar Bandukwala 465fe8658d chore: skip timing-sensistive AgentMetadata test in the standard suite (#7237)
* chore: skip timing-sensistive AgentMetadata test in the standard suite

* Add test-timing target

* fix windows?

* Works on my Windows desktop?

* Use tag system

* fixup! Use tag system
2023-05-02 10:41:41 +00:00
Dean Sheather 398d08a0cf chore: fix ci.yaml deploy step for other regions 2 (#7368) 2023-05-02 01:34:21 +00:00
Dean Sheather 41726a785e chore: fix ci.yaml deploy step for other regions (#7367) 2023-05-02 01:00:55 +00:00
Dean Sheather 140637448c chore: fix nfpm.yaml (#7366) 2023-05-01 22:44:11 +00:00
Dean Sheather 3b15234660 chore: add continuous deployment for workspace proxies (#7364) 2023-05-02 08:02:51 +10:00
Ammar Bandukwala 4b9621f9ae fix(coderd): don't hang on first gitauth clone (#7331)
Previously, the `coder git ssh` command would hang on the API, which was endlessly polling the database for oauth tokens that expire in the future.

Some oAuth implementations (including GitHub by default) will not give back a token expiry date, and the absence of such a date was represented as a zero data in the database as opposed to a null value.

Follow-up calls to `git clone` would succeed because this hot path doesn't check expiry, perhaps originally by mistake.

In addition to fixing the zero date issue, this PR removes all gitauth PubSub, which added too much complexity when the polling interval is 1 second.
2023-05-01 19:19:41 +00:00
Steven Masley 55824986bc chore: 404 Requests to workspace proxy direct back to the primary (#7353)
* chore: 404 Requests to workspace proxy direct back to the primary

* Remove unnecessary sprintf
2023-05-01 13:58:36 -05:00
dependabot[bot] 04f9ca824f chore: bump golang.org/x/mod from 0.8.0 to 0.10.0 (#7338)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-01 16:51:28 +00:00
dependabot[bot] 6030847c94 chore: bump golang.org/x/crypto from 0.7.0 to 0.8.0 (#7336)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-01 11:39:40 -05:00
dependabot[bot] 4dec828c88 chore: bump tj-actions/branch-names from 6.4 to 6.5 (#7334)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-01 16:26:52 +00:00
dependabot[bot] 38fd4c0820 chore: bump gopkg.in/natefinch/lumberjack.v2 from 2.0.0 to 2.2.1 (#7337)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-01 11:15:38 -05:00
dependabot[bot] 0bf00d6122 chore: bump aquasecurity/trivy-action from 0.9.2 to 0.10.0 (#7333)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-01 11:15:09 -05:00
dependabot[bot] a3f3d7e682 chore: bump github.com/hashicorp/hc-install from 0.4.1-0.20220912074615-4487b02cbcbb to 0.5.1 (#7342)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-01 16:14:43 +00:00
dependabot[bot] 97c8bb5c1d chore: bump crate-ci/typos from 1.14.3 to 1.14.8 (#7332)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-01 11:14:15 -05:00
Steven Masley 079d2821f5 chore: Set proxy health checks to 1 minute intervals (#7351) 2023-05-01 16:06:29 +00:00
Rodrigo Maia d3a9d7c497 chore: minor tweaks to license ui (#7314)
* chore: minor tweaks to license ui

* minor license ui tweaks

* rename stories
2023-04-28 21:49:54 +00:00
Steven Masley 4a9d1c16c7 chore: UI/UX for regions (#7283)
* chore: Allow regular users to query for all workspaces
* FE to add workspace proxy options to account settings
* WorkspaceProxy context syncs with coderd on region responses

---------

Co-authored-by: Dean Sheather <dean@deansheather.com>
2023-04-28 16:04:52 -05:00
Colin Adler c00f5e499a fix(server): retry initial connection to postgres (#7325) 2023-04-28 13:51:31 -05:00
Kira Pilot a2ff674158 fix(UI): workspace restart button stops build before starting a new one (#7301)
* feat(UI): add workspace restart button (#7137)

* Refactor primary buttons

* refactor(site): Always show the main actions

* Remove tests that are testes on Storybook

* Fix tests

* Fix keys

* added restart btn

---------

Co-authored-by: BrunoQuaresma <bruno_nonato_quaresma@hotmail.com>

* added restart hook

* added error handling

* going back to chaining in success callback

* add restarting btn

* added test

* PR feedback

---------

Co-authored-by: BrunoQuaresma <bruno_nonato_quaresma@hotmail.com>
2023-04-28 11:16:04 -07:00
Eric Paulsen 3078cd3d98 fix: envbox template 404 (#7324) 2023-04-28 12:49:26 -05:00
Ben Potter 8d1f163cae chore: remove login_before_ready from example templates (#7322) 2023-04-28 14:59:50 +00:00
Bruno Quaresma 88c362dfdc refactor(site): Refactor error state (#7313) 2023-04-28 13:03:01 +00:00
Marley e747aad2b6 docs: added additional documentation for azure devops git provider (#6923)
Co-authored-by: Ben Potter <me@bpmct.net>
Co-authored-by: Atif Ali <matifali@live.com>
2023-04-28 11:41:47 +00:00
Colin Adler 59efa4a528 fix(audit): ensure template creation errors are audited (#7315) 2023-04-27 18:55:34 -05:00
Marcin Tojek 77d9937dc4 fix: vite fatals on receiving HTTP4xx (#7306)
* fix: vite fatals on receiving HTTP4xx

* tune Vite

* fmt

* rewrite

* fmt
2023-04-27 19:04:24 +02:00
Eric Paulsen ed1b33acd6 docs: clarify quota allocation (#7310) 2023-04-27 16:51:05 +00:00
Ben Potter fe323a159e fix: keep "workspace create" form when rendering errors (#7289)
* fix: keep "workspace create" form when rendering errors

* fmt

* scroll to top if errors are present
2023-04-27 16:31:42 +00:00
Marcin Tojek bb0a38b161 feat: Implement aggregator for agent metrics (#7259) 2023-04-27 12:34:00 +02:00
Spike Curtis b6666cf1cf chore: tailnet debug logging (#7260)
* Enable discovery (disco) debug

Signed-off-by: Spike Curtis <spike@coder.com>

* Better debug on reconnectingPTY

Signed-off-by: Spike Curtis <spike@coder.com>

* Agent logging in appstest

Signed-off-by: Spike Curtis <spike@coder.com>

* More reconnectingPTY logging

Signed-off-by: Spike Curtis <spike@coder.com>

* Add logging to coordinator

Signed-off-by: Spike Curtis <spike@coder.com>

* Update agent/agent.go

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* Update agent/agent.go

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* Update agent/agent.go

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* Update agent/agent.go

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* Clarify logs; remove unrelated changes

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
2023-04-27 13:59:01 +04:00
winter0mute 7aa07cfc8d docs: Fix relay link in HA doc (#7159)
Co-authored-by: Muhammad Atif Ali <atif@coder.com>
2023-04-27 08:25:15 +00:00
Jon Ayers f1763f2aa5 chore: add envbox documentation (#7198) 2023-04-26 16:42:33 -05:00
Rodrigo Maia 87b7537878 feat: add license settings UI (#7210)
* wip: license page

* WIP

* WIP

* wip

* wip

* wip

* wip

* wip

* wip

* Apply suggestions from code review

Co-authored-by: Ben Potter <ben@coder.com>

* wip: ui improvements

* wip: extract components

* wip: stories

* wip: stories

* fixes from PR reviews

* fix stories

* fix empty license page

* fix copy

* fix

* wip

* add golang test

---------

Co-authored-by: Ben Potter <ben@coder.com>
2023-04-26 17:47:46 -03:00
Rodrigo Maia c3fe2515a7 feat: add license expiration warning (#7264)
* wip: add expiration warning

* Use GraceAt

* show expiration warning for trial accounts

* fix test

* only show license banner for users with deployment permission

---------

Co-authored-by: Marcin Tojek <marcin@coder.com>
2023-04-26 16:39:39 -03:00
Colin Adler 3eb7f06bf1 feat(agent): add http debug routes for magicsock (#7287) 2023-04-26 13:01:49 -05:00
Ben Potter 272573e9f0 chore: change some wording in the dashboard (#7293) 2023-04-26 11:34:17 -05:00
Bruno Quaresma 0e469031b8 fix(site): Fix secondary buttons with popovers (#7296) 2023-04-26 15:33:23 +00:00
Bruno Quaresma 218d6a92d4 docs(site): Mention template editor in template edit docs (#7261) 2023-04-26 12:11:12 +00:00
Spike Curtis 29cbc5404a Reconnecting PTY waits for command output or EOF (#7279)
Signed-off-by: Spike Curtis <spike@coder.com>
2023-04-26 09:02:06 +04:00
Dean Sheather f1dfeb03db chore: fix flake in apptest reconnecting-pty test (#7281) 2023-04-26 00:31:41 +00:00
Bruno Quaresma 35b3ed255c fix(site): Fix default value for options (#7265) 2023-04-25 17:26:42 -03:00
Bruno Quaresma 1134e78b7b fix(site): Do not show template params if there is no param to be displayed (#7263) 2023-04-25 19:54:33 +00:00
Cian Johnston 9afad8241b chore: add security advisories to docs (#7282)
* chore: add security advisories to docs

* Update docs/security/0001_user_apikeys_invalidation.md

Co-authored-by: Ammar Bandukwala <ammar@ammar.io>

---------

Co-authored-by: Ammar Bandukwala <ammar@ammar.io>
2023-04-25 16:56:09 +01:00
Colin Adler b62b6af0eb fix(healthcheck): don't allow panics to exit coderd (#7276) 2023-04-25 15:11:45 +00:00
Dean Sheather a98341612c feat: add regions endpoint for proxies feature (#7277)
* feat: add regions endpoint for proxies feature
2023-04-25 09:37:52 -05:00
Spike Curtis 6e8ff2d95c Fix macOS pty race with dropped output (#7278)
Signed-off-by: Spike Curtis <spike@coder.com>
2023-04-25 12:32:28 +04:00
Colin Adler e2d8bda246 chore(dogfood): remove unnecessary docker host replace (#7269) 2023-04-25 04:58:09 +00:00
Cian Johnston 8fc8559076 fix(coderd): ensure that user API keys are deleted when a user is (#7270)
Fixes an issue where API tokens belonging to a deleted user were
not invalidated:
- Adds a trigger to delete rows from the api_key stable when the
  column deleted is set to true in the users table.
- Adds a trigger to the api_keys table to ensure that new rows
  may not be added where user_id corresponds to a deleted user.
- Adds a migration to delete all API keys from deleted users.
- Adds tests + dbfake implementation for the above.
2023-04-24 21:48:26 +01:00
Bruno Quaresma ad82a60806 refactor(site): Group app and agent actions together (#7267) 2023-04-24 16:59:52 -03:00
Kira Pilot 96a12d17ef Revert "feat(UI): add workspace restart button (#7137)" (#7268)
This reverts commit 9ec16d4454.
2023-04-24 12:44:22 -07:00
Steven Masley 3129741e08 chore: Proxy health status checks + endpoint (#7233)
* chore: Implement workspace proxy health check cron

At a given interval will check the reachability of workspace proxies.

* Proxyhealth is an enterprise feature
* Start proxyhealth go routine on enterprise coder
2023-04-24 10:25:35 -05:00
Nathanial Spearing 63e68c11d1 feat(community-templates): Added vscode-server-template (#7219)
Co-authored-by: Kyle Carberry <kyle@carberry.com>
2023-04-24 15:22:18 +03:00
Spike Curtis daee91c6dc refactor: PTY & SSH (#7100)
* Add ssh tests for longoutput, orphan

Signed-off-by: Spike Curtis <spike@coder.com>

* PTY/SSH tests & improvements

Signed-off-by: Spike Curtis <spike@coder.com>

* Fix some tests

Signed-off-by: Spike Curtis <spike@coder.com>

* Fix linting

Signed-off-by: Spike Curtis <spike@coder.com>

* fmt

Signed-off-by: Spike Curtis <spike@coder.com>

* Fix windows test

Signed-off-by: Spike Curtis <spike@coder.com>

* Windows copy test

Signed-off-by: Spike Curtis <spike@coder.com>

* WIP Windows pty handling

Signed-off-by: Spike Curtis <spike@coder.com>

* Fix truncation tests

Signed-off-by: Spike Curtis <spike@coder.com>

* Appease linter/fmt

Signed-off-by: Spike Curtis <spike@coder.com>

* Fix typo

Signed-off-by: Spike Curtis <spike@coder.com>

* Rework truncation test to not assume OS buffers

Signed-off-by: Spike Curtis <spike@coder.com>

* Disable orphan test on Windows --- uses sh

Signed-off-by: Spike Curtis <spike@coder.com>

* agent_test running SSH in pty use ptytest.Start

Signed-off-by: Spike Curtis <spike@coder.com>

* More detail about closing pseudoconsole on windows

Signed-off-by: Spike Curtis <spike@coder.com>

* Code review fixes

Signed-off-by: Spike Curtis <spike@coder.com>

* Rearrange ptytest method order

Signed-off-by: Spike Curtis <spike@coder.com>

* Protect pty.Resize on windows from races

Signed-off-by: Spike Curtis <spike@coder.com>

* Fix windows bugs

Signed-off-by: Spike Curtis <spike@coder.com>

* PTY doesn't extend PTYCmd

Signed-off-by: Spike Curtis <spike@coder.com>

* Fix windows types

Signed-off-by: Spike Curtis <spike@coder.com>

---------

Signed-off-by: Spike Curtis <spike@coder.com>
2023-04-24 14:53:57 +04:00
Marcin Tojek c000f2ec28 fix: coder_parameter fallbacks to default (#7240) 2023-04-24 09:51:34 +02:00
sharkymark ab077d1f15 docs: fixed broken podman template link and added already-installed ide gateway doc (#6352)
Co-authored-by: Eric Paulsen <ericpaulsen@coder.com>
2023-04-21 20:43:19 +00:00
Mathias Fredriksson 712098fa2b test(agent): Increase the time to wait for agent reachable (#7245) 2023-04-21 19:40:17 +00:00
Colin Adler 501dfeedf7 fix: invalid version for github.com/coder/ssh (#7250) 2023-04-21 18:10:35 +00:00
Colin Adler 1fc32b1c3d ci: disable caching in setup/go action (#7251) 2023-04-21 13:01:42 -05:00
Kyle Carberry fd84df769d fix: add DISPLAY env var for X11 connections (#7248)
* fix: add `DISPLAY` env var for X11 connections

* Update agent/agentssh/agentssh.go

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

---------

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
2023-04-21 16:43:49 +00:00
Mathias Fredriksson f9da2631e9 test(cli): Fix portforward test timeouts (#7241) 2023-04-21 11:40:31 -05:00
Kyle Carberry f39e6a79de feat: add support for X11 forwarding (#7205)
* feat: add support for X11 forwarding

* Only run X forwarding on Linux

* Fix piping

* Fix comments
2023-04-21 15:52:40 +00:00
Mathias Fredriksson 6f06f8dadb test: Fix test timeouts due to contexts created too early (#7242) 2023-04-21 17:32:25 +03:00
Mathias Fredriksson ea78ca5dff test(coderd/workspaceapps): Fix incorrect use of testing.T (#7243) 2023-04-21 17:32:10 +03:00
Dean Sheather 3680e158d9 chore: fix lint in main caused by incompatible merge (#7239) 2023-04-21 10:27:56 +00:00
Steven Masley 4353ad7940 chore: Remove url and wildcard url from moon create (#7224)
* chore: Remove url and wildcard url from moon create
2023-04-20 21:09:14 -05:00
Dean Sheather 68667323f3 chore: support signed token query param for web terminal (#7197)
* chore: add endpoint to get token for web terminal

* chore: support signed token query param for web terminal
2023-04-20 23:59:45 +00:00
Colin Adler ac3c530283 fix(cli/clitest): race between Start/StartWithWaiter cleanup order (#7232) 2023-04-20 23:41:56 +00:00
Colin Adler 745868fd8a revert: chore: upgrade tailscale (#7236) 2023-04-20 17:58:22 -05:00
Mathias Fredriksson 300ae4a6bf test(agent): Fix TestAgent_UnixRemoteForwarding timeout (#7235) 2023-04-21 01:35:51 +03:00
Mathias Fredriksson 38a6d546ab fix(enterprise/replicasync): Avoid deadlock during Close^2 (#7230) 2023-04-20 22:48:44 +03:00
Colin Adler 34c6ad671c fix(clitest): use separate channel when waiting for exit (#7231) 2023-04-20 14:37:44 -05:00
Mathias Fredriksson ad0070354f test: Fix generated workspace name length (#7228) 2023-04-20 18:40:36 +00:00
Bruno Quaresma d8eda97dbe refactor(site): Redesign the agent row (#7226) 2023-04-20 18:37:10 +00:00
Colin Adler a86830a283 chore: upgrade tailscale (#7207) 2023-04-20 13:29:56 -05:00
Kira Pilot e2a7448cc8 fix: allow update of empty template description (#7225) 2023-04-20 10:59:57 -07:00
Colin Adler ea27129348 chore: upgrade github.com/open-policy-agent/opa (#7204) 2023-04-20 12:50:21 -05:00
Bruno Quaresma e90a076fad fix(site): Fix websocket connections (#7187) 2023-04-20 17:01:08 +00:00
Steven Masley 7fa1112958 chore: Enforce workspace proxy unique name case insensitive (#7202)
* chore: Enforce workspace proxy unique name case insensitive
2023-04-20 11:30:52 -05:00
Bruno Quaresma 9abfe97dcc Revert "fix(site): Fix update when missing parameters (#7221)" (#7223)
This reverts commit 7d9a7636e9.
2023-04-20 12:40:31 -03:00
Steven Masley a5a5c4d400 chore: Add workspace proxy enterprise cli commands (#7176)
* feat: Add workspace proxy enterprise cli commands
* chore: Handle custom workspace proxy options. Remove excess
* chore: Add endpoint to register workspace proxies
2023-04-20 09:48:47 -05:00
Muhammad Atif Ali 8926c10b7d chore: remove disk metadata from Kubernetes examples (#7215) 2023-04-20 09:42:35 -05:00
Bruno Quaresma 7d9a7636e9 fix(site): Fix update when missing parameters (#7221) 2023-04-20 09:32:20 -05:00
Bruno Quaresma 93d0956465 chore(site): Upgrade Vite to 4.3 (#7222) 2023-04-20 14:28:56 +00:00
Mathias Fredriksson 8d27978760 fix(enterprise/replicasync): Avoid deadlock during Close (#7220) 2023-04-20 15:37:30 +03:00
Dean Sheather 528a0686c0 chore: fix deadlock in dbfake and incorrect lock types (#7218)
I manually went through every single dbfake function and ensured it has
the correct lock type depending on whether it writes or only reads.
There were a surprising amount of methods that had the wrong lock type
(Lock when only reading, or RLock when writing (!!!)).

This also manually fixes every method that acquires a RLock and then
calls a method that also acquires it's own RLock to use noLock methods
instead. You cannot rely on acquiring a RLock twice in the same
goroutine as RWMutex prioritizes any waiting Lock calls.

I tried writing a ruleguard rule for this but because of limitations in
ruleguard it doesn't seem possible.
2023-04-20 21:53:34 +10:00
Colin Adler 5f5edb18b0 chore(healthcheck): fix DERP test flakes (#7211) 2023-04-19 20:03:05 -05:00
Colin Adler f60b5579a7 chore: remove usage of k8s.io/utils/pointer (#7209) 2023-04-19 15:53:47 -05:00
Mathias Fredriksson c2871e12aa fix(cli/ssh): Avoid connection hang when workspace is stopped (#7201)
* fix(cli/ssh): Avoid connection hang when workspace is stopped

Two issues are addressed here:
1. We were not detecting disconnects due to waiting for Stdin to close
   (disconnect would only propagate after entering input and failing to
   write to the connection).
2. In other scenarios, where the connection drop is not detected, we now
   also watch workspace status and drop the connection when a workspace
   reaches the stopped state.

Fixes: https://github.com/coder/jetbrains-coder/issues/199

Refs: #6180, #6175
2023-04-19 21:32:28 +03:00
Marc fff2b1dc90 fix(cli): Fix postgres TDE failing version check (#7203) 2023-04-19 11:59:56 -05:00
Ammar Bandukwala 2b9d12828a cli: add --debug-http flag (#7192)
This makes it easier to help debug client issues.
2023-04-19 11:07:53 -05:00
Marcin Tojek f94ac55f02 feat(agent): Expose magicsock metrics (#7183)
* feat: Expose magicsock metrics

* golden-files
2023-04-19 09:09:23 +02:00
Colin Adler fbf329fbb7 fix(tailnet): set TCP keepalive idle to 72 hours for SSH conns (#7196) 2023-04-18 17:53:11 -05:00
Colin Adler 57c4de4647 feat(healthcheck): add accessurl check (#7193) 2023-04-18 15:52:00 -05:00
Dean Sheather fa5387ce07 chore: fix make gen (#7190) 2023-04-18 17:56:52 +00:00
Kyle Carberry 888eb238ec fix: use CODER_HTTP_ADDRESS in docker-compose.yml (#7185)
Fixes #7184.
2023-04-18 11:44:41 -05:00
Steven Masley 7f041fecd8 test: Enable filter test with cancelled context (#7189)
* test: Enable filter test with cancelled context

* fixup! test: Enable filter test with cancelled context
2023-04-18 11:06:10 -05:00
Cian Johnston b26826ee3f chore(docs): update advice for cache dir (#7182)
* Adds a note in openshift documentation regarding CODER_CACHE_DIRECTORY with readOnlyRootFS=true
2023-04-18 14:13:45 +01:00
Kyle Carberry 693e5d94bc fix: add global headers to vscodessh command (#7181) 2023-04-18 08:07:10 -05:00
Bruno Quaresma 56bf9cfdbe fix(site): Handle carriage on logs output (#7172) 2023-04-17 20:45:48 +00:00
Colin Adler b44e6e6711 fix(healthcheck): remove t.Parallel() from healthcheck tests (#7174) 2023-04-17 15:01:47 -05:00
Steven Masley 658246d5f2 chore: add workspace proxies to the backend (#7032)
Co-authored-by: Dean Sheather <dean@deansheather.com>
2023-04-17 19:57:21 +00:00
Kira Pilot dc5e16ae22 feat: add success modal with token value to create token page (#7170)
* added token success modal

* added a test for new modal
2023-04-17 11:54:43 -07:00
Bruno Quaresma 76b5deea78 chore(site): Remove template editor out of experimental (#7165) 2023-04-17 14:40:21 -03:00
Ammar Bandukwala 80bf042528 chore(coderd): remove timing check (#7144) 2023-04-17 17:40:02 +00:00
Mathias Fredriksson b3b26a62f2 test(agent/reaper): Fix restructure issue (#7168)
In #7164 we accidentally removed the "in CI" check, this fixes it.
2023-04-17 17:39:10 +00:00
Bruno Quaresma bb3b8bab78 fix(site): Reset delete modal data when selected user changes (#7167) 2023-04-17 12:29:08 -05:00
Mathias Fredriksson bf0fed4f3f chore: Update pion/udp and improve parallel/non-parallel tests (#7164)
* test(all): Improve and fix subtests with parallell/nonparallel parents

* chore: Update pion/udp to fix buffer close
2023-04-17 20:23:10 +03:00
Ammar Bandukwala c6b2861493 feat: allow disabling stun addresses via env (#7066)
* feat: allow disabling stun addresses via env

Resolves #6791

* Specify a dummy access URL so the tunnel wouldn't start

* Document

---------

Co-authored-by: Kyle Carberry <kyle@carberry.com>
2023-04-17 17:20:26 +00:00
Cian Johnston 25c1e45930 chore(helm): add unit tests for setting labels / annotations on serviceaccount / deployment / pod (#7156)
* chore(helm): add unit tests for setting sa annotations

* chore(cli): also add test for labels / annotations / podLabels / podAnnotations
2023-04-17 16:49:25 +01:00
Kyle Carberry 26cfc18b74 fix: use proper deployment access setting name (#7162) 2023-04-17 10:01:51 -05:00
Mathias Fredriksson 51841e9e11 test(cli): Fix TestTemplatePush/UseWorkingDir bad use of chdir (#7160) 2023-04-17 17:58:25 +03:00
Bruno Quaresma 53f521aaf9 chore(site): Make requests when offline (#7161) 2023-04-17 14:44:38 +00:00
Muhammad Atif Ali 4061a254a5 docs: fix a broken link in docs/README.md (#7150) 2023-04-17 13:05:12 +00:00
Mathias Fredriksson 8b2aead7f4 test(coderd/rbac): Use static name for tests (#7155) 2023-04-17 12:17:18 +00:00
Bruno Quaresma d639e6b898 feat(site): Ask for missing template variables in the template editor (#7108) 2023-04-17 09:12:28 -03:00
Marcin Tojek c39c0dcc7c fix: select default option value (#7152) 2023-04-17 12:55:28 +02:00
Ammar Bandukwala 285646bf24 docs: disclaim write load for agent metadata (#7048)
* docs: disclaim write load for agent metadata

* Update docs/templates/agent-metadata.md

Co-authored-by: Muhammad Atif Ali <atif@coder.com>

* Update docs/templates/agent-metadata.md

Co-authored-by: Muhammad Atif Ali <atif@coder.com>

---------

Co-authored-by: Muhammad Atif Ali <atif@coder.com>
2023-04-16 05:46:04 +00:00
Kyle Carberry d3356fa48e fix: upgrade terraform in apk (#7146) 2023-04-14 20:10:17 -05:00
Eric Paulsen c37f22ba78 feat(helm): add labels for coder pod (#7139)
* feat(helm): add labels for coder pod

* feedback & syntax fix

* ordering

* fix: notation
2023-04-14 18:55:38 +00:00
am009 706326715d fix(docs): fix a wrong word. (#7113) 2023-04-14 18:32:38 +00:00
Ben Potter 9afbd152fc chore: fix one broken link (#7143)
* fix one broken link

* Fix the hopefully last broken link

---------

Co-authored-by: Muhammad Atif Ali <atif@coder.com>
2023-04-14 18:28:58 +00:00
Steven Masley 2137db0445 test: Handle Filter flake with ctx errors (#7119)
* test: Handle Fitler flake with ctx errors
* Add unit test to check filter for proper error
* Correctly return category of errors
2023-04-14 12:30:35 -05:00
Ammar Bandukwala c87ec484ff docs: restore supportLinks (#7142)
* docs: restore supportLinks

* fixup! docs: restore supportLinks
2023-04-14 17:28:34 +00:00
Kyle Carberry 7f12020229 fix: remove irrelevant help info from coder tokens create (#7135)
The additional text didn't help much, and made it much harder to script around.
2023-04-14 12:18:01 -05:00
Ammar Bandukwala f36a4a0b07 chore: fix race check for AgentMetadata test (#7141) 2023-04-14 20:02:44 +03:00
Muhammad Atif Ali 0e50afe4cf fix(docs): fix broken docs (#7138)
* fixing a lot of broken links

* more fixes

* add 0 as valid status codes

https://tools.ietf.org/html/rfc7231#section-6.3.1 --> 0 as status code
2023-04-14 11:11:51 -05:00
Kira Pilot 9ec16d4454 feat(UI): add workspace restart button (#7137)
* Refactor primary buttons

* refactor(site): Always show the main actions

* Remove tests that are testes on Storybook

* Fix tests

* Fix keys

* added restart btn

---------

Co-authored-by: BrunoQuaresma <bruno_nonato_quaresma@hotmail.com>
2023-04-14 08:48:05 -07:00
Bruno Quaresma 7bbbb91df5 refactor(site): Refactor workspace actions (#7124) 2023-04-14 15:28:52 +00:00
Muhammad Atif Ali 9c0f59e3e5 chore: Also check README.md for dead links (#7130) 2023-04-14 14:46:16 +00:00
Muhammad Atif Ali 69797add49 chore: turn on experiments while developing (#7121) 2023-04-14 17:42:03 +03:00
Kyle Carberry 0bbe1562f3 fix: adjust manifest for networking doc (#7136) 2023-04-14 09:36:23 -05:00
Muhammad Atif Ali bb43713d38 fix: VSCode desktop connection (#7120)
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
2023-04-14 17:32:18 +03:00
Marcin Tojek 942aba3a66 feat: expose agent stats via Prometheus endpoint (#7115)
* WIP

* WIP

* WIP

* Agents

* fix

* 1min

* fix

* WIP

* Test

* docs

* fmt

* Add timer to measure the metrics collection

* Use CachedGaugeVec

* Unit tests

* WIP

* WIP

* db: GetWorkspaceAgentStatsAndLabels

* fmt

* WIP

* gauges

* feat: collect

* fix

* fmt

* minor fixes

* Prometheus flag

* fix

* WIP

* fix tests

* WIP

* fix json

* Rx Tx bytes

* CloseFunc

* fix

* fix

* Fixes

* fix

* fix: IgnoreErrors

* Fix: Windows

* fix

* reflect.DeepEquals
2023-04-14 16:14:52 +02:00
Mathias Fredriksson e0689456cb fix(scripts): Use gh api to fetch ci logs more reliably (#7133) 2023-04-14 16:29:13 +03:00
Bruno Quaresma dafb7663c5 fix(site): Fix button text overflow (#7132) 2023-04-14 15:13:55 +02:00
Bruno Quaresma ad665cef91 fix(site): Load monaco locally (#7092) 2023-04-14 13:11:28 +00:00
Bruno Quaresma 17bb1a1ff1 chore(site): Upgrade storybook to 7.0.4 (#7127) 2023-04-13 21:36:20 +00:00
Colin Adler 085330ad96 fix(provisionerd): only heartbeat when logs aren't being flushed (#7110) 2023-04-13 14:02:10 -05:00
Colin Adler f5a8a27714 fix(healthcheck): prevent infinite loop if DERP message exchange fails (#7112) 2023-04-13 13:46:16 -05:00
Steven Masley 38e5b9679b chore: Rbac errors should be returned, and not hidden behind 404 (#7122)
* chore: Rbac errors should be returned, and not hidden behind 404

SqlErrNoRows was hiding actual errors
* Replace sql.ErrNoRow checks
* Remove sql err no rows check from dbauthz test
* Fix to use dbauthz system user
2023-04-13 13:06:16 -05:00
Steven Masley fa64c58e56 chore: Export all functions used by server cmd (#7118)
* chore: Export all functions used by server cmd

Required to make workspace proxy cmd
* Factor out httpservers and tracer
2023-04-13 09:07:19 -05:00
Cian Johnston 87fe16cde9 feat(cli): add --id parameter to templates init command (#7116)
This PR makes the following changes:

- Adds an --id parameter to coder templates init so that you can non-interactively initialize a specific example template by ID (e.g. folder name)
- Updates develop.sh and lima/coder.yaml to use this parameter to select the docker example template.
2023-04-13 15:02:49 +01:00
Colin Adler 17f692a89a fix(scaletest): correctly validate configs using SessionToken (#7111) 2023-04-12 17:36:05 -05:00
Ben Potter f517724caa chore: reorganize some docs (#7062)
* chore: move docs pages into corresponding folder

* chore: prioritize clouds in platforms list

* chore: fix networking docs links

* chore: rename to "docker in workspaces"

* mention CLI documentation

* fmt
2023-04-12 21:47:25 +00:00
Muhammad Atif Ali 114d4aac23 chore: update example templates to use display_name (#7001)
* add `display_name`

* fix typos and `terraform validate`

* update display_name

* Update examples/templates/aws-windows/main.tf

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/templates/aws-linux/main.tf

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/templates/azure-linux/main.tf

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/templates/azure-linux/main.tf

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/templates/do-linux/main.tf

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/templates/do-linux/main.tf

Co-authored-by: Ben Potter <me@bpmct.net>

* Update main.tf

* Update main.tf

* Update main.tf

* Update main.tf

* Update main.tf

---------

Co-authored-by: Ben Potter <me@bpmct.net>
2023-04-12 16:33:38 -05:00
Kira Pilot f6c89a2615 feat: differentiate new user registration from user login in the audit log (#7096)
* auditing register events

* fix tests

* update docs

* update comments

* Update coderd/audit/request.go

Co-authored-by: Colin Adler <colin1adler@gmail.com>

---------

Co-authored-by: Colin Adler <colin1adler@gmail.com>
2023-04-12 11:46:16 -07:00
Rodrigo Maia d1d459cb79 feat(site): add advanced schedule settings to UI (#7061)
* feat: add advanced schedule settings

* Update site/src/pages/CreateTemplatePage/CreateTemplateForm.tsx

Co-authored-by: Dean Sheather <dean@deansheather.com>

* rename variable

* fix optionText css

---------

Co-authored-by: Dean Sheather <dean@deansheather.com>
2023-04-12 17:47:48 +00:00
Muhammad Atif Ali 264093a874 chore: add agent metadata to example templates (#7044)
* add `display_name`

* fix typos and `terraform validate`

* update display_name

* Add agent metadata

* add % to cpu usage

* update disk usage check script

* remove metadata from containers and pods workspaces

* removes disk metadata from container workspaces

---------

Co-authored-by: Ben <me@bpmct.net>
2023-04-12 12:05:16 -05:00
Ben Potter af24aea04f chore: reduce docker examples (#6849) 2023-04-12 16:26:03 +00:00
Mathias Fredriksson 770712e1f5 ci: Add script for fetching past test stats from CI (#7086)
Refs: #6677, #6675
2023-04-12 10:03:26 +00:00
Muhammad Atif Ali 531fd23fd2 fix(docs): fix broken markdown links (#7081)
* fix(docs): fix markdown docs links

More than half of them were actually valid links but, due to missing file extensions were flagged as invalid. I added a file extension, so it should pass now.

* Updated docgen to include extension
2023-04-11 15:05:51 -05:00
Colin Adler a44070e2ec feat(scaletest): allow scaletests to run using the host credentials (#7075) 2023-04-11 19:49:28 +00:00
Steven Masley 2585249014 chore: Move writeConfig to a cli middleware (#7093)
* chore: Move writeConfig to a cli middleware

Trying to reduce the server LoC, it's very long and unwieldy.
The workspace proxy code needs to replicate, and trying to reuse
as much as possible

* Move deprecation warnings too
2023-04-11 14:47:07 -05:00
Marcin Tojek e1db64a1e8 chore: bump up coder/tailscale (#7089) 2023-04-11 11:44:47 -05:00
Bruno Quaresma b86ed11bc0 refactor(site): Refactor the schedule controls in the workspace page (#7083) 2023-04-11 13:33:24 -03:00
Bruno Quaresma b92e7d4fab refactor(site): Refactor workspace schedule page (#7069) 2023-04-11 16:27:52 +00:00
Kevin Conley 4dd5d79412 fix: Parse CODER_GITAUTH_N_NO_REFRESH env var value instead of key (#7051) 2023-04-11 09:18:17 -05:00
Marcin Tojek 3b10e89047 Revert "fix: change auto-start to automatically update workspaces (#6053)" (#7084)
This reverts commit bdddc3e7ae.
2023-04-11 14:14:35 +00:00
Steven Masley 9d39371ee0 feat: Option to remove WorkspaceExec from owner role (#7050)
* chore: Add AllResources option for listing all RBAC objects
* Owners cannot do workspace exec site wide
* Fix FE authchecks to valid RBAC resources
2023-04-11 08:57:23 -05:00
Marcin Tojek ad2353c3d8 chore: improve syntax in metrics collector (#7085) 2023-04-11 13:50:34 +00:00
Muhammad Atif Ali 63af4c6ed1 chore: Add exceptions for markdown check (#7078)
* rename and run slack step on failure

* add exceptions
2023-04-11 13:15:44 +02:00
Ben Potter 45776e57f6 docs: remove RBAC section (#7040) 2023-04-10 21:57:00 -05:00
Muhammad Atif Ali fb44dc653e fix(ci): fix typo in cron-weekly.yaml (#7059)
Co-authored-by: Dean Sheather <dean@deansheather.com>
2023-04-11 01:58:37 +00:00
Kyle Carberry 81e2b2500a feat: add level support for startup logs (#7067)
This allows external services like our devcontainer support to display
errors and warnings with custom styles to indicate failures to users.
2023-04-10 14:29:59 -05:00
Bruno Quaresma aa2468b16e fix(site): Handle rename a folder to a file (#7063) 2023-04-10 13:30:21 -03:00
Eric Paulsen e5c6ebdc96 docs: bump tf version in offline docs (#7065) 2023-04-10 11:04:31 -04:00
Ammar Bandukwala 4b99e2d07e feat: add YAML support to server (#6934) 2023-04-07 22:58:21 +00:00
Colin Adler a3c6cb1768 fix: don't query workspace in UpdateWorkspaceAgentConnectionByID (#7042) 2023-04-07 15:21:52 -05:00
Muhammad Atif Ali 592b84984f chore: Update code-server in example templates (#6806)
Update code-server from `4.8.3` to `4.11.0`
2023-04-07 12:09:46 -05:00
Muhammad Atif Ali 7e530b0652 chore: check for invalid markdown links in docs weekly (#6795)
* chore(ci): add an automatic check to verify markdown links. 

As per #6793, there are multiple broken links in our docs. This action will check if all markdown links are valid.

cc: @ammario @bpmct

* Revert "chore(ci): add an automatic check to verify markdown links. "

This reverts commit 294767e056.

* Create cron-weekly.yaml

* add workflow dispatch for testing

* fmt

* Update cron-weekly.yaml

* remove slack notification for now

* Add slack notification

* Update cron-weekly.yaml

* Add logs URL

* fmt
2023-04-07 16:50:08 +00:00
Marcin Tojek 3e250c6609 chore: clidocgen: generate consistent docs (#7047)
* chore: clidocgen: ensure same generated docs

* fix
2023-04-07 18:32:06 +02:00
Marcin Tojek 0347231bb8 feat: expose agent metrics via Prometheus endpoint (#7011)
* WIP

* WIP

* WIP

* Agents

* fix

* 1min

* fix

* WIP

* Test

* docs

* fmt

* Add timer to measure the metrics collection

* Use CachedGaugeVec

* Unit tests

* Address PR comments
2023-04-07 17:48:52 +02:00
Ammar Bandukwala dd85ea8977 feat: tolerate disconnects in agent metadata frontend (#6939) 2023-04-06 19:51:52 -05:00
Dean Sheather 5398150c25 chore: move workspace apps tests to new package (#7025)
* chore: move workspace apps tests to new package
* chore: move reconnecting pty to apptest package
2023-04-06 16:35:27 -05:00
Steven Masley b2892c3d17 test: Increase test coverage on auditable resources (#7038)
* test: Increase test coverage on auditable resources

When adding a new audit resource, we also need to add it to the
function switch statements. This is a likely mistake, now a unit
test will check this for you
2023-04-06 16:16:53 -05:00
Ammar Bandukwala 24d8644c0b chore: de-flake TestWorkspaceAgent_Metadata (round 2) (#7039)
This time, we keep the timing / "racey" tests, but avoid running
them in the harsher CI conditions.
2023-04-06 21:10:13 +00:00
Kyle Carberry e1149992d8 feat: support ansi colors in startup script logs (#7037)
This will help with beautiful output for devcontainers!
2023-04-06 12:39:09 -05:00
Ammar Bandukwala 2637f5501b chore: de-flake TestWorkspaceAgent_Metadata (#7036) 2023-04-06 17:20:16 +00:00
Kyle Carberry c68ab7d9a8 fix: support X-Forwarded-Host with CODER_REDIRECT_TO_ACCESS_URL (#7035)
Fixes #7026.
2023-04-06 12:07:24 -05:00
Mathias Fredriksson aa660e0631 feat(agentssh): Gracefully close SSH sessions on Close (#7027)
By tracking and closing sessions manually before closing the underlying
connections, we ensure that the termination is propagated to SSH/SFTP
clients and they're not left waiting for a connection timeout.

Refs: #6177
2023-04-06 19:57:30 +03:00
Colin Adler f4f40d0ed2 fix: increase workspace name randomess in tests (#7018) 2023-04-06 11:53:02 -05:00
Mathias Fredriksson 0224426e5b refactor(agent): Move SSH server into agentssh package (#7004)
Refs: #6177
2023-04-06 19:39:22 +03:00
Kyle Carberry 3ff2ae1b1a fix: output askpass to stderr (#7034)
This fixes askpass not outputting a prompt.
2023-04-06 11:32:43 -05:00
Marcin Tojek 5bd02917ec docs: Update description for mutable parameters (#7003) 2023-04-06 18:23:47 +02:00
Mathias Fredriksson 121c2bcde8 test(agent): Fix tests without cmd.Wait() (#7029) 2023-04-06 16:45:53 +03:00
Eric Paulsen 2da0702009 fix(helm): missing templating for deployment labels (#6869)
Co-authored-by: Dean Sheather <dean@deansheather.com>
2023-04-06 17:03:21 +10:00
Colin Adler a32951c46a fix: reduce idle workspace queries (#7022) 2023-04-06 01:58:54 +00:00
Dean Sheather 63f9ef2480 chore: fix minor int coercion codeql vulnerability (#7024) 2023-04-05 21:43:24 +00:00
Dean Sheather c18ed6197c chore: fix trivy ci workflow (#7023) 2023-04-05 21:36:04 +00:00
Eric Paulsen 0167d76a7c docs: add helm example for OIDC_GROUP_MAPPING var (#7007)
* docs: add helm example for OIDC_GROU_MAPPING var

* fix: fmt
2023-04-05 21:05:48 +00:00
Colin Adler e0f7cf5ec6 chore: fix postGroupByOrganization swagger tag (#7021) 2023-04-05 20:17:36 +00:00
Colin Adler 391738cc25 chore: remove documented groups endpoint that doesn't exist (#7020) 2023-04-05 14:26:21 -05:00
Ben Potter 865c8b7c09 docs: additional kubernetes clusters (#7019)
* docs: additional kubernetes clusters

* fmt and change wording

* fmt
2023-04-05 14:03:36 -05:00
Dean Sheather eb66cc9f35 chore: move app proxying code to workspaceapps pkg (#6998)
* chore: move app proxying code to workspaceapps pkg

Moves path-app, subdomain-app and reconnecting PTY proxying to the new
workspaceapps.WorkspaceAppServer struct. This is in preparation for
external workspace proxies.

Updates app logout flow to avoid redirecting to coder-logout.${app_host}
on logout. Instead, all subdomain app tokens owned by the logging-out
user will be deleted every time you logout for simplicity sake.

Tests will remain in their original package, pending being moved to an
apptest package (or similar).

Co-authored-by: Steven Masley <stevenmasley@coder.com>
2023-04-05 13:41:55 -05:00
ElliotG 0069831e8d fix: use error log when failing provisioner job (#6812)
Co-authored-by: Colin Adler <colin1adler@gmail.com>
2023-04-05 13:30:53 -05:00
dependabot[bot] bf1a0791f7 chore: bump github.com/docker/docker from 20.10.17+incompatible to 20.10.24+incompatible (#7009)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-05 18:29:27 +00:00
Colin Adler 72c84c5b0a fix(loadtest): use cryptorand.String to generate user password (#7006) 2023-04-05 12:52:47 -05:00
Colin Adler 407f80a1ef fix(dbpurge): use dbauthz.AsSystemRestricted (#7017) 2023-04-05 17:48:39 +00:00
Steven Masley a361673ad8 fix: Include 'CODER' env var prefix on group mappings (#7015)
* fix: Include 'CODER' env var prefix on group mappings
* Unit test to force CODER prefix
2023-04-05 17:47:40 +00:00
Cian Johnston 00d468b964 feat(cli): add --output={text,json} to version cmd (#7010)
* feat(cliui): add TextFormat
* feat(cli): add --format={text,json} to version cmd
2023-04-05 13:16:05 +01:00
Cian Johnston 9c4ccd76a0 fix(coderd)!: add CODER_OIDC_IGNORE_USERINFO configuration option (#6922)
* add CODER_OIDC_IGNORE_USERINFO option
* chore: update docs for CODER_OIDC_IGNORE_USERINFO w.r.t ADFS
* fix!: codersdk: fix incorrectly named OIDC_GROUP_MAPPING -> CODER_OIDC_GROUP_MAPPING
2023-04-05 09:07:43 +01:00
sharkymark 929589ddfa docs: fixed incorrect agent metadata docs (#7005)
* docs: fixed incorrect agent metadata docs

* docs: prettier; fixed incorrect agent metadata docs
2023-04-04 15:50:27 -05:00
Steven Masley b4afbe7720 feat: Implement experiment gated CRUD for workspace proxies (#6928)
* feat: Implement basic moon crud
* chore: Implement enterprise endpoints for moons
2023-04-04 15:07:29 -05:00
Kyle Carberry 385a4262e2 fix: remove audit-logging flag from the server (#6991)
Co-authored-by: Colin Adler <colin1adler@gmail.com>
2023-04-04 12:11:10 -05:00
Bruno Quaresma 29e9b9e663 feat(site): Add change version for template admins (#6988) 2023-04-04 10:25:49 -03:00
Kyle Carberry c12bc39821 fix: always show a newly created workspace at the top of the list (#6984)
Fixes #5795.
2023-04-04 08:24:04 -05:00
Bruno Quaresma 46f42ea9ac fix(site): Prompting user for missing variables (#7002) 2023-04-04 13:15:35 +00:00
Dean Sheather e33941b7c2 feat: allow disabling autostart and custom autostop for template (#6933)
API only, frontend in upcoming PR.
2023-04-04 12:48:35 +00:00
Marcin Tojek 083fc89f93 feat: accept immutable parameters when used first time (#7000)
* Backend fixes

* CLI: adjust update flow
2023-04-04 14:22:46 +02:00
Josh Vawdrey e84061e2be feat(provisioner): bump the maximum terraform version (#6995) 2023-04-04 06:19:48 +00:00
Steven Masley a96376e02e chore: Add "required" to allow requring url params (#6994) 2023-04-03 20:59:59 -05:00
Dean Sheather 3cca30c770 chore: make version.sh work in forks (#6993) 2023-04-04 01:13:32 +00:00
Dean Sheather 34593e3944 chore: ticket provider interface (#6915) 2023-04-04 00:59:41 +00:00
Colin Adler e0f7f011d8 fix(healthcheck): ensure STUNOnly nodes aren't marked as unhealthy (#6990) 2023-04-03 16:14:48 -05:00
Rodrigo Maia a1371dbd60 feat(site): move template's readme to its own tab (#6863)
* feat(site): display template's readme first on template page

* chore: prettier

* move readme to a new docs tab

* test

* prettier

* fix tests

* prettier
2023-04-03 18:18:28 +00:00
Colin Adler 95e578ba10 fix: derp healthcheck test flake (#6982) 2023-04-03 11:36:26 -05:00
Kyle Carberry 861d4afdd8 fix: update tailscale to remove websocket logs (#6981) 2023-04-03 16:28:49 +00:00
Kyle Carberry bc18f6c113 fix: add CODER_AGENT_TAILNET_LISTEN_PORT for specifying a static tailnet port (#6980)
Fixes #5175.
2023-04-03 16:20:19 +00:00
Kyle Carberry 4ee01dc95c fix: remove orphan rbac warning message (#6979)
The request will fail if the user doesn't have permissions, so it seems
useless to output this.
2023-04-03 11:15:56 -05:00
Kyle Carberry 55c0b26977 fix: update status text for the workspace progress bar (#6977)
Fixes #4691.
2023-04-03 11:00:56 -05:00
dependabot[bot] 8e69f02695 chore: bump axios from 0.26.1 to 1.3.4 in /site (#6954)
Bumps [axios](https://github.com/axios/axios) from 0.26.1 to 1.3.4.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](https://github.com/axios/axios/compare/v0.26.1...v1.3.4)

---
updated-dependencies:
- dependency-name: axios
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-03 10:30:39 -05:00
Ben Potter ded931f0f6 docs: rename quickstart to platforms + Kubernetes guide (#6972)
* rename quickstart to platforms + Kubernetes guide

* fmt
2023-04-03 09:51:07 -05:00
Kyle Carberry 2d051094e7 fix: ignore deleted workspaces in global stats (#6973)
Fixes #6568.
2023-04-03 14:46:09 +00:00
Bruno Quaresma aa43f998d4 feat(site): Promote template version (#6929) 2023-04-03 14:27:17 +00:00
Steven Masley fab8da633b chore: Merge more rbac files (#6927)
* chore: Merge more rbac files

- Remove cache.go -> authz.go
- Remove query.go -> authz.go
- Remove role.go -> roles.go

* Order imports

* fmt
2023-04-03 09:05:06 -05:00
Ben Potter 333718d1fa docs: remove mention of support links (#6970)
* docs: remove mention of support links

* fmt
2023-04-03 13:18:28 +00:00
Marcin Tojek 633dfbdb2e feat: rich parameters: introduce display_name (#6919)
* model

* DB

* fix: DisplayName

* proto

* Proto

* Update go dep

* fixme

* fix format

* config

* fmt

* fix

* Fix

* fix

* chore(UI): redirecting from workspace page if 404 (#6880)

* model

* CLI: Display parameter

* fix

* update dep

* fix

* fix

* fix

* UI changes

* fmt

---------

Co-authored-by: Kira Pilot <kira@coder.com>
2023-04-03 14:37:47 +02:00
Mathias Fredriksson d9d44c1188 ci: Print go test stats (#6855)
Fixes #6676
2023-04-03 11:07:25 +00:00
Colin Adler 7738274b3e feat(coderd): add DERP healthcheck (#6936) 2023-04-03 06:28:42 +00:00
Colin Adler f4d16a1ae5 fix: add span.SetStatus to codersdk.Request (#6964) 2023-04-03 05:52:42 +00:00
dependabot[bot] 47afafa4d4 chore: bump github.com/klauspost/compress from 1.15.15 to 1.16.3 (#6948)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-03 00:35:35 -05:00
Colin Adler a29fc7dd6f chore: update otel to v1.14.0 (#6963) 2023-04-03 00:31:39 -05:00
dependabot[bot] f6f927e44f chore: bump github.com/go-playground/validator/v10 from 10.11.0 to 10.12.0 (#6950)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-03 04:59:49 +00:00
Colin Adler 8683169e71 fix: agent metadata flake (#6962) 2023-04-03 04:45:23 +00:00
dependabot[bot] d2bfa2b9a0 chore: bump aquasecurity/trivy-action from 0.9.1 to 0.9.2 (#6945)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-02 23:37:06 -05:00
dependabot[bot] 390f29cf8c chore: bump actions/stale from 7.0.0 to 8.0.0 (#6944)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-02 23:32:22 -05:00
Eric Paulsen caec0b8aae rm: mac from docker quickstart (#6958) 2023-04-01 22:31:53 -05:00
dependabot[bot] 31690c4b3d chore: bump @xstate/react from 3.0.1 to 3.2.1 in /site (#6955)
Bumps [@xstate/react](https://github.com/statelyai/xstate) from 3.0.1 to 3.2.1.
- [Release notes](https://github.com/statelyai/xstate/releases)
- [Commits](https://github.com/statelyai/xstate/compare/@xstate/react@3.0.1...@xstate/react@3.2.1)

---
updated-dependencies:
- dependency-name: "@xstate/react"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-01 16:37:57 -05:00
Ammar Bandukwala 512fdbf634 chore: debounce agent watch-metadata stream (#6940) 2023-04-01 16:36:21 -05:00
dependabot[bot] e40b0778e9 chore: bump crate-ci/typos from 1.13.14 to 1.14.3 (#6942)
Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.13.14 to 1.14.3.
- [Release notes](https://github.com/crate-ci/typos/releases)
- [Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md)
- [Commits](https://github.com/crate-ci/typos/compare/v1.13.14...v1.14.3)

---
updated-dependencies:
- dependency-name: crate-ci/typos
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-01 16:35:19 -05:00
dependabot[bot] e60460b120 chore: bump jaxxstorm/action-install-gh-release from 1.9.0 to 1.10.0 (#6943)
Bumps [jaxxstorm/action-install-gh-release](https://github.com/jaxxstorm/action-install-gh-release) from 1.9.0 to 1.10.0.
- [Release notes](https://github.com/jaxxstorm/action-install-gh-release/releases)
- [Commits](https://github.com/jaxxstorm/action-install-gh-release/compare/v1.9.0...v1.10.0)

---
updated-dependencies:
- dependency-name: jaxxstorm/action-install-gh-release
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-01 16:35:11 -05:00
dependabot[bot] 5200591264 chore: bump actions/setup-go from 3 to 4 (#6946)
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 3 to 4.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-01 16:34:58 -05:00
dependabot[bot] 87d64baf7a chore: bump golang.org/x/crypto from 0.6.0 to 0.7.0 (#6949)
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.6.0 to 0.7.0.
- [Release notes](https://github.com/golang/crypto/releases)
- [Commits](https://github.com/golang/crypto/compare/v0.6.0...v0.7.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-01 16:34:50 -05:00
Ammar Bandukwala 34debbf837 fix(agent): prevent goroutine pile up in reportMetadataLoop (#6957) 2023-04-01 16:34:42 -05:00
Ammar Bandukwala ccadd0f286 docs: tweak some words and fix a typo in agent-metadata.md 2023-03-31 23:20:30 +00:00
Kyle Carberry 84956c16cc fix: reduce spacing when agent metadata doesn't exist (#6937) 2023-03-31 22:08:42 +00:00
Ammar Bandukwala ca4fa81570 feat: add agent metadata (#6614) 2023-03-31 15:26:19 -05:00
Ammar Bandukwala c191692751 chore(cli): send help to stdout (#6865)
Minimizes pesky `2>&1` when working with help.
2023-03-31 18:51:55 +00:00
Ammar Bandukwala c2a96bdc7c fix: compilation failure with (*OptionSet).SetDefaults
This slipped through CI due to a merge race.
2023-03-31 18:02:55 +00:00
Ammar Bandukwala 599699b3a9 fix: truly allow overridding default string array (#6874) 2023-03-31 12:12:03 -05:00
Cian Johnston 96ff400587 chore(clibase): add some more tests for parsing options from env (#6930) 2023-03-31 17:21:56 +01:00
Steven Masley ce51435507 chore: Merge some rbac files, move some functions around (#6916)
* chore: Merge some rbac files, move some functions around

* Fix imports
2023-03-31 09:46:38 -05:00
Steven Masley 27e17ff2c3 chore: Remove unused Experimental field (#6924) 2023-03-31 09:44:29 -05:00
Kyle Carberry cd807bc0c8 fix: delete old addresses from the active derp mesh mapping (#6926) 2023-03-31 14:25:01 +00:00
Cian Johnston 334d9820fa fix(coderd): update provisionderd authz policy to allow updating user data (#6925) 2023-03-31 15:11:07 +01:00
Bruno Quaresma 90e2bab078 feat(site): Display workspace build error + option to retry in debug mode (#6903) 2023-03-31 14:01:12 +00:00
Steven Masley 901045a95f fix: FE show correct config-ssh prefix (#6904)
* fix: Push correct ssh prefix to FE
2023-03-31 08:48:44 -05:00
Kira Pilot a364318462 chore(UI): redirecting from workspace page if 404 (#6880) 2023-03-31 06:31:48 -07:00
Marcin Tojek 56f00a82e1 chore: update sqlc to v1.17.2 (#6920)
* WIP

* chore: Update sqlc to v1.17.2
2023-03-31 14:05:20 +02:00
Marcin Tojek 2612e32bac chore: image for support links (#6902) 2023-03-30 18:07:27 +00:00
Kira Pilot 3b52d4f336 chore(UI): remove template link from workspaces page row (#6882)
* chore(UI): remove template link from workspaces page row

* remove stack and span as per PR comment
2023-03-30 10:32:23 -07:00
Kyle Carberry b5f5740d0b chore: ensure agent conn routine is closed before exit (#6900)
This caused a leak in `main`!
2023-03-30 17:20:14 +00:00
Kyle Carberry e496bdb687 chore: update slog to fix local leak with http.Transport (#6899) 2023-03-30 12:13:15 -05:00
Kyle Carberry a63c97b8de chore: wrap audit logs in a mutex to fix data race (#6898)
This was seen in `main`!
2023-03-30 12:13:03 -05:00
Kyle Carberry 5780006adb chore: use http-swagger/v2 for go:embed to reduce binary size (#6897)
I'm testing how much this will reduce the size, but it should
be by a few MB!
2023-03-30 16:46:58 +00:00
Cian Johnston afcc179244 chore: fix duplicated sentence in docs/auth.md (#6895) 2023-03-30 16:29:57 +00:00
Kyle Carberry 8f55f5c28b chore: ensure go.mod has proper references to forked deps (#6893)
There were a few that have been merged upstream!
2023-03-30 11:19:11 -05:00
Ben Potter 5953a46785 docs: Open in Coder (#6859)
* docs: git auth via template

* add page

* docs: Open in Coder

* fmt
2023-03-30 16:12:47 +00:00
Kyle Carberry a6b7e8c43a chore: use an older version of fastclock to resolve leak (#6892) 2023-03-30 10:58:56 -05:00
Kyle Carberry 04e404e448 chore: dial the remote socket continually until connect (#6891)
It's possible that the command starts but the socket isn't ready
even when the file exists.
2023-03-30 15:36:23 +00:00
Kyle Carberry 5686fc9983 chore: skip chdir template push test on windows (#6890)
See https://github.com/coder/coder/actions/runs/4565958214/jobs/8057842941
2023-03-30 10:21:13 -05:00
Kyle Carberry 401b9276ae chore: clone styles to prevent race (#6888)
See https://github.com/coder/coder/actions/runs/4565541977/jobs/8056830691?pr=6885
2023-03-30 10:18:24 -05:00
Kyle Carberry 5c1dc1b7fe fix: iterate through all workspace updates on logs overflow (#6885)
This was causing some flakes!
2023-03-30 10:05:45 -05:00
Kyle Carberry e470162305 chore: move away from set-output in GitHub Actions (#6884)
This is deprecated! See:
https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
2023-03-30 09:58:56 -05:00
Kyle Carberry 1f600fc526 chore: use defer instead of t.Cleanup for chdir (#6887)
This _might_ resolve the races in `TestTemplatePush`.
2023-03-30 09:48:03 -05:00
Bruno Quaresma b26f30688f feat(site): Duplicate template (#6853) 2023-03-30 11:42:29 -03:00
Kyle Carberry 6378294071 chore: upgrade from deprecated protobuf import (#6883)
This was displaying a warning when running `go get ./...`.
2023-03-30 14:17:44 +00:00
Marcin Tojek 0ba200c2a1 feat: Enable workspace debug logging (#6838)
* feat: Enable workspace debug logging

* Fix

* Fix

* Fix

* fix

* fix

* Enable RBAC

* unit tests

* Fix

* fix

* fix

* fix

* more tests

* fix: workspacebuild_test use roles

* fix: swagger comment

* fix: ctx.Done

* fix: address PR comments

* break loop
2023-03-30 16:00:33 +02:00
Dean Sheather 665b84de0d feat: use app tickets for web terminal (#6628) 2023-03-30 23:24:51 +10:00
Muhammad Atif Ali a07209efa1 fix: very small typo (#6877) 2023-03-30 07:56:19 -05:00
Bruno Quaresma 7d7aa789b3 fix(site): Only patch version name if name is changed (#6878) 2023-03-30 12:22:55 +00:00
Bruno Quaresma d8762c676f feat(site): Show main.tf file first on template files page (#6854) 2023-03-30 11:33:42 +00:00
Marcin Tojek b120247213 fix: extend regex for template version name (#6876) 2023-03-30 13:27:58 +02:00
Cian Johnston 563c3ade06 feat: allow configuring OIDC email claim and OIDC auth url parameters (#6867)
This commit:

- Allows configuring the OIDC claim Coder uses for email addresses (by default, this is still email)
- Allows customising the parameters sent to the upstream identity provider when requesting a token. This is still access_type=offline by default.
- Updates documentation related to the above.
2023-03-30 09:36:57 +01:00
Ammar Bandukwala 6981f89cd8 Revert "fix: allow overridding default string array (#6873)"
This reverts commit 58d650c2bb.
2023-03-29 20:24:07 -05:00
Ammar Bandukwala 58d650c2bb fix: allow overridding default string array (#6873)
* fix: allow overridding default string array

* Cleanup code

* fixup! Cleanup code

* fixup! Cleanup code

* fixup! Cleanup code

* fixup! Cleanup code
2023-03-30 01:09:20 +00:00
dependabot[bot] 1c7adc0ebd chore: bump github.com/fatih/color from 1.14.1 to 1.15.0 (#6868)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-29 21:42:35 +00:00
Rodrigo Maia 3d91fe8895 fix(site): fix redirection to login after logout/change password (#6870)
* fix(site): fix redirection to login after logout/change password

* chore: add login verification assert

* prettier
2023-03-29 21:39:56 +00:00
Steven Masley 90da09bc2c chore: Make deployment admin page show better durations (#6856)
* chore: Make deployment admin page show better durations

Also fix group mappings
2023-03-29 16:26:20 -05:00
Colin Adler 872037bf85 feat: allow http2 in coder server (#6871) 2023-03-29 14:45:57 -05:00
Bruno Quaresma 175dde1c52 chore(site): Try to fix flake test (#6848) 2023-03-29 16:10:04 -03:00
Mathias Fredriksson 90d18dd2e5 fix(agent): Close stdin and stdout separately to fix pty output loss (#6862)
Fixes #6656
Closes #6840
2023-03-29 21:58:38 +03:00
dependabot[bot] 349bfad2e9 chore: bump github.com/opencontainers/runc from 1.1.2 to 1.1.5 (#6864)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-29 17:46:54 +00:00
Ben Potter 311327cb11 docs: git auth via template (#6850) 2023-03-28 17:11:30 -05:00
Steven Masley a8346bd8ea feat: Allow unsetting ssh config options from deployment (#6847)
This allows deleting ssh config options
2023-03-28 11:06:42 -05:00
Ammar Bandukwala 1176256a44 feat: improve CLI error messages (#6778) 2023-03-28 16:03:34 +00:00
Cian Johnston b38d1ed4a5 Revert "fix(UI): redirect if user is not permissioned to see workspace (#6786)" (#6836)
This reverts commit fc21e159b8.
2023-03-28 09:38:39 +00:00
Mathias Fredriksson 891bbda995 fix(agent): More protection for lost output of SSH PTY commands (#6833)
Fixes #6656 (part 2)
2023-03-28 09:11:15 +00:00
Ammar Bandukwala 164528176a fix(clibase): allow empty values to unset defaults (#6832) 2023-03-28 01:58:06 +00:00
Ammar Bandukwala 773580c7c9 fix: correct minor formatting issues in CLI (#6813)
* fix: remove excess newlines from server startup

* Don't log benign closed pipe errors
2023-03-28 01:01:25 +00:00
Ammar Bandukwala 42b3d90221 chore: rename "InsertOrUpdate" to Upsert around the codebase (#6823)
* chore: rename "InsertOrUpdate" to Upsert around the codebase

The shorter name uses up less line width, is easier to read
and is used more often.

* make gen
2023-03-28 00:55:10 +00:00
Ammar Bandukwala f88f273cd6 fix: resolve template name from working directory "." (#6822) 2023-03-27 22:58:20 +00:00
Kyle Carberry a2d3635207 fix: update tailscale to resolve h2 vs http/1.1 (#6827)
DERP will always fallback to WebSockets if h2 is chosen now!
2023-03-27 21:05:10 +00:00
Kyle Carberry 5e01e6e448 fix: check if logs are completed before publishing (#6824) 2023-03-27 15:50:53 -05:00
Muhammad Atif Ali 48f9521fcb fix: fix PATH of flyctl cli in fly-docker-image template (#6772)
* Update main.tf

Upgrade coder provider

* fix path in startup_script

* Revert "Update main.tf"

This reverts commit 5037f87a36.
2023-03-27 20:04:03 +00:00
Kyle Carberry ad0c0df104 chore: update tailscale to fix http2 upgrade (#6811)
See https://github.com/coder/tailscale/pull/15
2023-03-27 14:22:11 -05:00
Kyle Carberry ffb4cd5962 chore: fix race when expecting parameters (#6814)
See https://github.com/coder/coder/actions/runs/4532378002/jobs/7983840014
2023-03-27 14:18:33 -05:00
Bruno Quaresma dd4e1f74ff feat(site): Ask for version name and if it is active when publishing a new version on editor (#6756) 2023-03-27 17:26:57 +00:00
Ammar Bandukwala b439c3e167 fix: permit SSH by default when startup script fails (#6798) 2023-03-27 14:59:58 +00:00
Steven Masley 7fa5afa268 fix: Users that can update a template can also read the file (#6776)
* fix: Users that can update a template can also read the file

This currently has a strange RBAC story. An issue will be filed
to streamline this.
This is a hotfix to resolve current functionality

* Only showsource code tab if the user has permission to edit the template


---------

Co-authored-by: Bruno Quaresma <bruno_nonato_quaresma@hotmail.com>
2023-03-27 09:21:41 -05:00
Kira Pilot fc21e159b8 fix(UI): redirect if user is not permissioned to see workspace (#6786)
* fix(UI): redirect if user is not permissioned to see workspace

* fix tests
2023-03-27 06:25:31 -07:00
Kira Pilot 08afe3cfad chore(UI): remove private icon from apps in dashboard (#6801)
* chore(UI): remove private icon from apps in dashboard

* clean up redudant snapshots
2023-03-27 06:24:42 -07:00
Muhammad Atif Ali 0b22c88538 fix(docs): fix broken links (#6796)
* Update change-management.md to fix broken links

* Update offline.md

* Update docker-in-docker.md

* fmt
2023-03-27 09:21:47 -04:00
Marcin Tojek 8187992e7f fix: Validate template version name (#6804)
* WIP

* Update

* Validation
2023-03-27 13:54:01 +02:00
Ammar Bandukwala e0cc4ee7f8 fix: correct english in CreateWorkspacePage (#6797) 2023-03-27 08:49:18 -03:00
Bruno Quaresma e3a965bcc9 fix(site): Add page header into permissions page (#6760) 2023-03-27 11:32:20 +00:00
Eric Paulsen b287ec5eec docs: clarify mac docker install (#6788)
* clarify mac docker install

* point MacOS users to standalone binary

* macOS
2023-03-26 12:39:20 +00:00
Ammar Bandukwala 6c0f37c28e fix: probably fix lipgloss race condition (#6784) 2023-03-24 21:24:51 +02:00
Mathias Fredriksson 76bdde7f1b fix(agent): Prevent SSH TTYs from losing command output on exit (#6777) 2023-03-24 18:23:41 +00:00
Kyle Carberry d7d210de36 Revert "chore: update tailscale to fix http2 upgrade (#6761)" (#6779)
This reverts commit 622fc6d9c2.
2023-03-24 12:40:05 -05:00
Kyle Carberry 622fc6d9c2 chore: update tailscale to fix http2 upgrade (#6761)
See https://github.com/coder/tailscale/pull/15
2023-03-24 11:20:21 -05:00
Marcin Tojek c9cbc63cd4 feat: Fine-tune logs presentation (#6771)
* Process debug mode logs

* Debug logs are grey

* Fix
2023-03-24 13:29:18 +01:00
Marcin Tojek c7fb5f960c feat: preserve original order of rich parameters (#6747)
* WIP

* orderedParameters

* fix

* WIP

* TestS
2023-03-24 09:37:27 +01:00
Ammar Bandukwala 9822745365 fix: accept CODER_AGENT_TOKEN (#6765) 2023-03-23 18:38:15 -05:00
Ammar Bandukwala 2bd6d2908e feat: convert entire CLI to clibase (#6491)
I'm sorry.
2023-03-23 17:42:20 -05:00
Bruno Quaresma b71b8daa21 fix(site): Add helper text and prevent undefined when deleting empty value (#6757) 2023-03-23 20:44:40 +00:00
Kyle Carberry 2383f64d89 fix: add dbauthz for streaming startup logs (#6758)
This was causing logs to end early!
2023-03-23 15:02:29 -05:00
Bruno Quaresma 88e24db643 refactor(site): Group template permissions, settings and variables under a settings layout (#6737) 2023-03-23 16:43:12 -03:00
Kyle Carberry cb7375450b feat: add startup script logs to the ui (#6558)
* Add startup script logs to the database

* Add coderd endpoints for startup script logs

* Push startup script logs from agent

* Pull startup script logs on frontend

* Rename queries

* Add constraint

* Start creating log sending loop

* Add log sending to the agent

* Add tests for streaming logs

* Shorten notify channel name

* Add FE

* Improve bulk log performance

* Finish UI display

* Fix startup log visibility

* Add warning for overflow

* Fix agent queue logs overflow

* Display staartup logs in a virtual DOM for performance

* Fix agent queue with loads of logs

* Fix authorize test

* Remove faulty test

* Fix startup and shutdown reporting error

* Fix gen

* Fix comments

* Periodically purge old database entries

* Add test fixture for migration

* Add Storybook

* Check if there are logs when displaying features

* Fix startup component overflow gap

* Fix startup log wrapping

---------

Co-authored-by: Asher <ash@coder.com>
2023-03-23 14:09:13 -05:00
Steven Masley a6fa8cac58 chore: add typescript api for ssh config (#6741)
* chore: add typescript api for ssh config
2023-03-23 17:46:39 +00:00
Bruno Quaresma 8857971552 feat(coder): Add PATCH /templateversions/:templateversion endpoint (#6698) 2023-03-23 13:26:50 -03:00
Kyle Carberry ed9a3b9251 fix: use a background context when piping derp connections (#6750)
This was causing boatloads of connects to reestablish every time...

See https://github.com/coder/coder/issues/6746
2023-03-23 09:54:07 -05:00
Eric Paulsen 7949db8e03 docs: add GHE token & auth URLs (#6751)
* docs: add GHE token & auth URLs

* cleanup
2023-03-23 09:53:42 -05:00
Bruno Quaresma eaacc26da7 fix(site): Fix missing parameters detection on update workspace (#6740) 2023-03-23 08:05:19 +01:00
Kyle Carberry dab4a0e6ef fix: add ResourceUserData to provisionerd to allow git auth (#6743)
This was breaking passing a git auth token through!
2023-03-22 17:23:49 -05:00
Kira Pilot 25e92fd2f4 fix(audit): audit login/logout for new 3rd-party auth (#6733)
* fix(audit): audit login/logout for new 3rd-party auth

* no longer auditing unknown users
2023-03-22 12:52:13 -07:00
Kyle Carberry df31636e72 feat: pass access_token to coder_git_auth resource (#6713)
This allows template authors to leverage git auth to perform
custom actions, like clone repositories.
2023-03-22 19:37:08 +00:00
Colin Adler 79ae7cd639 chore: add artifacthub-repo.yml (#6739) 2023-03-22 19:09:40 +00:00
Colin Adler c1e1c47c45 chore: bump github.com/u-root/u-root (#6738) 2023-03-22 13:52:50 -05:00
Eric Paulsen c71fa498b5 feat: podAnnotations (#6703)
* feat: podAnnotations

* rm: test values

* feedback

* fix: unknown revision
2023-03-22 14:35:24 -04:00
Steven Masley 250ee17933 fix: Page offset on workspace pagination was incorrect (#6693)
* fix: Page offset on workspace pagination was incorrect
2023-03-22 18:17:49 +00:00
Kira Pilot 1ccbd54ea2 chore(UI): update autocomplete no options text (#6735) 2023-03-22 11:14:07 -07:00
Marcin Tojek f1d7809ef0 chore: update terraform-provider-coder to v0.6.21 (#6736) 2023-03-22 18:04:56 +00:00
Kyle Carberry ad9c9b468f fix: block updating mutable parameters (#6717) 2023-03-22 11:05:04 -05:00
Steven Masley ab764db8c8 chore: dbgen passing nil slices to postgres is not valid (#6714) 2023-03-22 09:10:49 -05:00
Dean Sheather 5460ab4ba6 chore: switch to new wgtunnel via tunnelsdk (#6489) 2023-03-22 13:13:48 +00:00
Marcin Tojek e85a17b0c8 docs: describe list of strings (#6719) 2023-03-22 07:45:26 -05:00
Kyle Carberry 38d278ac46 fix: use the default value for a rich parameter if unset (#6715)
This fixes an error thrown on the workspace settings page when
a new parameter is added and the workspace hasn't been built yet.
2023-03-22 00:02:55 +00:00
Kyle Carberry abe1e89f80 chore: increase parallelism of TestWorkspaceQuota (#6710)
This does a lot of build operations, so having multiple provisioner
daemons is great.

We were actually approaching the ceiling here for test duration!
2023-03-21 22:44:01 +00:00
Bruno Quaresma 5cbe360176 fix(site): Fix CSP directives for monaco (#6709) 2023-03-21 12:51:02 -07:00
Colin Adler 00860cf1c8 feat: add group mapping option for group sync (#6705)
* feat: add group mapping option for group sync

* fixup! feat: add group mapping option for group sync
2023-03-21 14:25:45 -05:00
Bruno Quaresma 120bc4b750 refactor(site): Only show status after first edition (#6701) 2023-03-21 16:23:33 -03:00
Kyle Carberry 7e854adbb3 fix: poll audit logs to ensure write is last (#6708) 2023-03-21 19:19:09 +00:00
Kyle Carberry 71eecb3515 chore: embed build info in the html to reduce requests (#6605)
This will reduce a request on every page load of Coder!
2023-03-21 19:04:54 +00:00
Ben Potter 74be9c6c55 fix: dallas region in fly.io template (#6700) 2023-03-21 14:04:04 -05:00
Josh Vawdrey 97f77c4507 feat: allow DERP headers to be set (#6572)
* feat: allow DERP headers to be set

* chore: remove custom flag

* Clone DERP header on client create

* Adjust to use interface to cast headers

---------

Co-authored-by: Kyle Carberry <kyle@carberry.com>
2023-03-21 18:43:20 +00:00
Eric Paulsen d8aee26776 docs: clean up OIDC duplicates (#6583)
* docs: clean up OIDC duplicates

* make fmt

* add: upgrade command
2023-03-21 13:40:20 -05:00
Kyle Carberry e1c755be81 chore: remove fast metric cache interval for apps tests (#6702)
This wasn't helping CI run fast, that's for sure!
2023-03-21 18:13:34 +00:00
Kyle Carberry aaa3b31a0b chore: add echo helper to create an agent with token (#6576)
This should reduce some LOC and duplication in tests!
2023-03-21 18:03:38 +00:00
Kyle Carberry d05b48267a fix: update tailscale to resolve websocket stun fallback (#6696)
See https://github.com/coder/tailscale/pull/14
2023-03-21 12:37:34 -05:00
Bruno Quaresma 29d71bb3dd feat(site): Add source code tab on template page, group buttons and add edit file option (#6681) 2023-03-21 16:52:42 +00:00
Bruno Quaresma f97c22540a fix: Only show mutable parameters on workspace settings form (#6690) 2023-03-21 13:47:54 -03:00
Kyle Carberry 247470b1d6 fix: increase timeout of CreateTemplatePage initial render (#6694)
This might fix some test flakes we've been seeing!
2023-03-21 13:24:07 -03:00
Kyle Carberry 1b35ac80f2 fix: ensure agent DisconnectedAt is greater than or equal LastConnectedAt (#6692)
See https://github.com/coder/coder/actions/runs/4471502401/jobs/7856475920
2023-03-21 11:08:39 -05:00
Marcin Tojek fce8a4adf0 feat: preserve order of rich parameters (#6689)
* WIP

* TDD

* Implement

* WIP
2023-03-21 16:28:17 +01:00
Steven Masley 2321160c62 feat: Dbauthz is now default, remove out of experimental (#6650)
* feat: dbauthz always on, out of experimental
* Add ability to do rbac checks in unit tests
* Remove AuthorizeAllEndpoints
* Remove duplicate rbac checks
2023-03-21 09:10:22 -05:00
Dean Sheather 8aae0b64d3 chore: avoid logging http.ErrAbortHandler panics (#6686) 2023-03-21 03:51:21 +00:00
Ben Potter 4bf012cefb fix: typo in kubernetes template (#6683) 2023-03-20 22:39:45 +00:00
Steven Masley 65945aef16 chore: Return copied templates to prevent reference issues (#6679) 2023-03-20 13:13:21 -05:00
Bruno Quaresma cb846bab46 fix(site): Show job error on updating template variables (#6674) 2023-03-20 12:51:59 -03:00
Marcin Tojek de83723310 feat: show Terraform error details (#6643) 2023-03-20 13:23:40 +00:00
Bruno Quaresma a4d86e9d78 fix(site): Don't handle 304 as error (#6655) 2023-03-20 10:08:06 -03:00
Cian Johnston 331a49bf75 fix: dbauthz: fix RBAC call for GetTemplateVersionVariables (#6670)
In GetTemplateVersionVariables we were effectively asking the provisionerd role to call rbac.ActionCreate on rbac.ResourceTemplate, which will never work. Updated this to be rbac.ActionRead instead.
2023-03-20 10:22:16 +00:00
Eric Paulsen 39510f4163 docs: add openshift install (#6165)
* docs: add openshift install

* make: fmt

* Apply suggestions from code review

Update securityContext: set project-specific uid/gid, set readOnlyRootFilesystem=false

* add steps for creating compatible image and template

* Update docs/install/openshift.md

* make fmt

* docs: make changes on feedback

* combine helm steps

---------

Co-authored-by: Cian Johnston <cian@coder.com>
2023-03-20 03:48:53 -05:00
Eric Paulsen fadeb2ba3a docs: add k8s & aws to offline Dockerfile (#6663) 2023-03-20 03:47:36 -05:00
Muhammad Atif Ali 856a8028a5 chore: update fly-docker-image example template (#6661)
* update fly-docker-image example template

* Add unites for volume storage
2023-03-19 14:55:11 -05:00
Kyle Carberry c3fb1b325f feat: add owner_oidc_access_token to coder_workspace data source (#6042)
See the discussion in Discord here:
https://discord.com/channels/747933592273027093/1071182088490987542/1071182088490987542

Related provider PR: coder/terraform-provider-coder#91
2023-03-17 15:25:08 -05:00
Bruno Quaresma ca067cf004 feat(site): Support list(string) rich parameter field (#6653) 2023-03-17 18:53:11 +00:00
Kira Pilot 090e37fc46 feat(audit): auditing token addition and removal (#6649)
* auditing tokens

* adding diffs for token auditing

* added test

* generating docs

* auditing owner field
2023-03-17 10:41:44 -07:00
Kira Pilot 5b07f1e2a3 feat(tokens): improve delete confirmation dialog (#6651) 2023-03-17 10:29:51 -07:00
Marcin Tojek db40c29f26 fix: CLI do not ignore autostop (#6647)
* fix: CLI do not ignore autostop

* make gen
2023-03-17 18:14:46 +01:00
Muhammad Atif Ali e6d52b07b7 docs: add template to provision docker image based workspaces on fly.io (#6526)
* add fly.io example

* fix: `fly_volume` does not allow using - in name.

fix: `fly_volume` does not allow using - in the name.

* fix: provider versions  and settings

* fix: valid `fly_app` name

* chore: ipv6 is not used

* fix: names

strangely `fly_volume` does not allow `-` and `fly_app` does not allow `_`.

* chore: update max RAM

* add fly-auth-api managed variables

* Update README.md

* improve setup flow

- user is not prompted in UI for default values
- org slug is best fetched via CLI

* add metadata

* add to starter templates

---------

Co-authored-by: Ben <me@bpmct.net>
2023-03-17 11:46:44 -05:00
Steven Masley e55d921537 chore: Typescript generator TODOs resolved, adding explainations (#6633)
* chore: Explain usage of eslint comments

* Conform comment

* Fix wording

* Linting
2023-03-17 09:28:16 -05:00
Bruno Quaresma b1c1e1a8a6 refactor(site): Remove wave animation from skeleton (#6644) 2023-03-17 10:44:17 -03:00
Bruno Quaresma 01a6af98b4 fix(site): Do not require immutable parameters (#6637) 2023-03-17 10:09:10 -03:00
Dean Sheather 446bd30c32 chore: regenerate helm golden tests (#6642) 2023-03-17 12:56:40 +01:00
Michael H f59bf732c9 feat: Add ability to configure coder container lifecycle hooks in helm chart (#6432) 2023-03-17 00:55:24 +00:00
Colin Adler 1c05b46b02 chore: add debug logs for OIDC responses (#6641) 2023-03-16 19:33:45 -05:00
Kyle Carberry ffca3a5fb3 fix: remove noop templates plan command (#6617)
Co-authored-by: Colin Adler <colin1adler@gmail.com>
2023-03-16 21:28:22 +00:00
Cian Johnston a1d2c057a2 chore(lima): increase random password length from 8 to 12 (#6639) 2023-03-16 18:42:30 +00:00
Steven Masley fe247c86eb feat: Add deployment side config-ssh options (#6613)
* feat: Allow setting deployment wide ssh config settings
* feat: config-ssh respects deployment ssh config
* The '.' is now configurable
* Move buildinfo into deployment.go
2023-03-16 13:03:37 -05:00
Ben Potter 25e8abd63e chore: rewrite provisioner docs (#6445)
* chore: rewrite provisioner docs

* add checkout
2023-03-16 12:51:39 -05:00
Kyle Carberry b693b9f599 chore: fix workspace audit log flake (#6494)
This happened because sometimes a build would be queued
and completed intermittently in CI.

See https://github.com/coder/coder/actions/runs/4358121985/jobs/7618290591
2023-03-16 12:47:54 -05:00
Marcin Tojek 1f9ae15409 feat: CLI use multiselect for list(string) (#6631)
* feat: CLI use multiselect for list(string)

* fix

* select ui tests

* cli test

* Fix

* Fix
2023-03-16 17:17:48 +01:00
Bruno Quaresma 95177ad0e5 refactor(site): Remove change version from the UI (#6621) 2023-03-16 13:07:33 -03:00
Bruno Quaresma ab90651a7e refactor(site): Add skeletons for table loading state (#6626) 2023-03-16 13:06:15 -03:00
Kira Pilot 811a69f371 feat(site): add ability to create tokens from account tokens page (#6608)
* add token actions

* added basic token form

* removed token switch

* refined date field

* limiting lifetime days to maxTokenLifetime

* broke apart files

* added loader and error

* fixed form layout

* added some unit tests

* fixed be tests

* no authorize check
2023-03-16 08:25:08 -07:00
Bruno Quaresma af618477bd feat(site): Show stop button when workspace is failed (#6622) 2023-03-16 14:34:55 +00:00
Bruno Quaresma 107ae55642 feat(site): Add workspace settings page (#6612) 2023-03-16 11:00:19 -03:00
Bruno Quaresma 854bcce5e0 fix(site): Fix filter hover (#6624) 2023-03-16 06:31:41 -07:00
Marcin Tojek a7c734c60b feat: support list(string) as coder_parameter (#6618)
* feat: support list(string) as coder_parameter

* Fix
2023-03-16 11:07:10 +01:00
Benjamin Sejas 7076dee522 feat(agent): Add SSH max timeout option for coder agent (#6596)
* feat(agent): Add SSH max timeout option for coder agent

* Fix lint and update test golden snapshot
2023-03-15 09:08:50 -05:00
Eric Paulsen 2f3848e9b2 rm: aws windows count (#6485)
Co-authored-by: Ben Potter <ben@coder.com>
2023-03-15 13:53:32 +00:00
Muhammad Atif Ali c5475912c9 refactor(docs): refactoring to remove dublication (#6297) 2023-03-15 13:25:51 +00:00
Muhammad Atif Ali a0e096bcfe chore: update templates to use rich parameters (#6397) 2023-03-15 13:11:52 +00:00
Bruno Quaresma 3cf235c564 feat(site): Ask for parameter values when updating a workspace (#6586) 2023-03-14 13:20:49 -03:00
Kyle Carberry f91b3acf93 fix: group routine workspace agent stats by id (#6601)
Before this was creating separate rows for distinct stat entries, which
resulted in significantly more data being sent to telemetry.
2023-03-14 10:52:03 -05:00
Kyle Carberry 17bc5794d4 fix: direct embedded derp traffic directly to the server (#6595)
Prior to this change, DERP traffic would route from `coderd` to the
`CODER_ACCESS_URL` to reach the internal DERP server, which may have
resulted in slower connections due to proxying, or the failure of
web traffic entirely.

If your Coder deployment has a proxy in front of it, your traffic through
web terminals, apps, and port-forwarding is about to get a lot faster!
2023-03-14 14:46:47 +00:00
Bruno Quaresma e3768495e4 docs: Add more info about slow tests in the FE (#6584) 2023-03-14 06:54:17 -07:00
Bruno Quaresma b806d1cfcf fix(site): Display delete template error from the API (#6589) 2023-03-14 10:44:27 -03:00
Mathias Fredriksson 348530000f fix(coderd): Ensure agent disconnect happens after timeout (#6600)
Fixes #6598
2023-03-14 13:14:47 +00:00
Marcin Tojek 7587850a1c feat: import value from legacy variable to build parameter (#6556) 2023-03-14 12:02:44 +00:00
Marcin Tojek bc26c4a27f chore: skip scaletest/reconnectingpty (#6599) 2023-03-14 11:37:31 +00:00
Dean Sheather aafd2803bb chore: update dogfood IP for Sydney (#6597) 2023-03-14 15:29:52 +10:00
Kyle Carberry 35df1b10d0 feat: add workspace agent stat reporting to telemetry (#6577)
This aggregates stats periodically and sends them by agent ID to
our telemetry server. It should help us identify which editors are
primarily in use.
2023-03-13 14:16:54 -05:00
Bruno Quaresma 813b54942f chore(site): Make FE tests faster (#6543) 2023-03-13 13:35:09 -03:00
Cian Johnston 9b2abf0952 chore(helm): add unit tests for helm chart (#6557)
This PR adds a minimum set of Helm tests for the Helm chart.
It's heavily based on the approach in [1], but uses a golden-files-based approach instead.
It also runs helm template directly instead of importing the entire Kubernetes API.
Golden files can be updated by running go test ./helm/tests -update or by running make update-golden-files.

[1] https://github.com/coder/enterprise-helm

Fixes #6552
2023-03-13 13:48:44 +00:00
Mathias Fredriksson 179d9e0d24 fix(coderd): Detect agent disconnect via inactivity (#6528)
Fixes #5901
2023-03-13 11:54:53 +02:00
Kyle Carberry 7fa6483d84 fix: allow the BINARY_DIR to be configured in the agent script (#6567) 2023-03-11 19:39:40 +00:00
Steven Masley 37c859ec4c chore: Ensure all audit types in ResourceTable match APGL (#6563)
* chore: Ensure all audit types in ResourceTable match APGL
* Implement more checks to ensure all tracked fields are present
* Add unit test to ensure all types are represented in audit table
* Trade compile time safety for syntax
2023-03-10 13:59:42 -06:00
Ammar Bandukwala a65a16122d chore: early merge clibase foundations (#6542) 2023-03-10 13:41:32 -06:00
Cian Johnston 144f374f60 refactor(dbauthz): add authz for system-level functions (#6513)
- Introduces rbac.ResourceSystem
- Grants system.* to system and provisionerd rbac subjects
- Updates dbauthz system queries where applicable
- coderd: Avoid index out of bounds in api.workspaceBuilds
- dbauthz: move GetUsersByIDs out of system, modify RBAC check to ResourceUser
- workspaceapps: Add test case for when owner of app is not found
2023-03-10 18:09:28 +00:00
Kyle Carberry 1db2b12b8e chore: add a test to ensure audit code works with AGPL (#6561)
Fixes the regression seen in v0.19.1.
2023-03-10 17:04:40 +00:00
Kyle Carberry 7eb2c2ff6d Revert "chore: Implement joins with golang templates (#6429)" (#6560)
This reverts commit 8b125d6c5d.
2023-03-10 10:39:02 -06:00
Steven Masley a8433b18e4 fix: Prevent infinite redirects on oidc errors (#6550)
* fix: Prevent infinite redirects on bad oidc scopes
* Show oidc errors
2023-03-10 10:12:29 -06:00
Kyle Carberry 4a07fcd9d2 fix: ensure local derp uses the hostname (#6559)
This broke deployments that use a custom port with an access
URL. We should write a test for this!
2023-03-10 09:58:31 -06:00
Steven Masley 8b125d6c5d chore: Implement joins with golang templates (#6429)
* feat: Implement view for workspace builds to include rbac info

* Removes the need to fetch the workspace to run an rbac check.
* chore: Use workspace build as RBAC object
* chore: Use golang templates instead of sqlc files
2023-03-10 09:44:38 -06:00
Eric Paulsen a666539bfa helm: add value for labels (#6544) 2023-03-10 07:39:55 -05:00
Marcin Tojek 90901ca129 fix: panic on deleted template (#6553) 2023-03-10 12:26:11 +01:00
Marcin Tojek 6023264a81 fix: typo in error message (#6551)
* fix: typo in error message

* fix
2023-03-10 09:20:22 +00:00
Steven Masley 7f25d31745 feat: Allow changing the 'group' oidc claim field (#6546)
* feat: Allow changing the 'group' oidc claim field
* Enable empty groups support
* fix: Delete was wiping all groups, not just the single user's groups
* Update docs
* fix: Dbfake delete group member fixed
2023-03-09 23:31:38 -06:00
Steven Masley 11a930e779 !fix: Disallow access urls without valid scheme (#6548)
Existing deployments will need to prepend a scheme if they have not already.
2023-03-09 21:37:19 -06:00
Kyle Carberry 65878b04ce fix: remove "something went wrong" text for watching a workspace (#6541)
This text wasn't useful to a customer anyways, because we don't get
an error from EventSource. This can happen if you close your laptop
and open it again, so it's better if we don't display it.
2023-03-09 20:54:28 +00:00
Ammar Bandukwala 50432b89be fix: pass git auth config read from environment through server (#6540) 2023-03-09 20:27:54 +00:00
Kyle Carberry 1b3b0ea962 fix: adjust workspace filter query when the path changes (#6539)
Previously, when a status would change the filter wouldn't update.
This makes it update if a new value is passed in.
2023-03-09 14:23:23 -06:00
Kyle Carberry 9a7998301b fix: remove deployment bar info icon and adjust language (#6537)
Re @bpmct's feedback
2023-03-09 20:08:50 +00:00
Ammar Bandukwala 4c2977050d fix: treat empty env as defaults (#6538) 2023-03-09 19:58:58 +00:00
Ammar Bandukwala 62a64d5a34 fix: remove deprecation warnings when option unset (#6532)
Resolves #6531
2023-03-09 19:22:21 +00:00
Ammar Bandukwala 761ed7bf63 fix: rm pull request template (#6533)
It doesn't seem like this was helping anything.
2023-03-10 03:53:48 +10:00
Steven Masley 2abae42cec feat: Ignore agent pprof port in listening ports (#6515)
* feat: Ignore agent pprof port in listening ports
2023-03-09 10:53:00 -06:00
Steven Masley 3de29307b5 chore: Remove some of the external enum comments in typescript (#6530)
* chore: Remove some of the external enum comments in typescript

handle clibase types manually
2023-03-09 10:46:23 -06:00
Marcin Tojek c2787e3a8e docs: describe rich parameters (#6527)
* WIP

* WIP

* docs: describe rich parameters

* Update docs/templates/parameters.md

Co-authored-by: Cian Johnston <public@cianjohnston.ie>

* Update docs/templates/parameters.md

Co-authored-by: Cian Johnston <public@cianjohnston.ie>

* Update docs/templates/parameters.md

Co-authored-by: Cian Johnston <public@cianjohnston.ie>

* Update docs/templates/parameters.md

Co-authored-by: Cian Johnston <public@cianjohnston.ie>

* Update docs/templates/parameters.md

Co-authored-by: Cian Johnston <public@cianjohnston.ie>

* Update docs/templates/parameters.md

Co-authored-by: Cian Johnston <public@cianjohnston.ie>

* Update docs/templates/parameters.md

Co-authored-by: Cian Johnston <public@cianjohnston.ie>

* Update docs/templates/parameters.md

Co-authored-by: Cian Johnston <public@cianjohnston.ie>

* Update docs/templates/parameters.md

Co-authored-by: Cian Johnston <public@cianjohnston.ie>

* Strip migration

* Fix

---------

Co-authored-by: Cian Johnston <public@cianjohnston.ie>
2023-03-09 17:19:48 +01:00
Kyle Carberry 70b093ff2a fix: filter session count sums by created_at (#6529)
Fixes the session totals being waaaaay too high!
2023-03-09 17:08:41 +02:00
Kyle Carberry 1cc10f2ffb fix: only sum connection latencies when they are set (#6524)
This was producing a median that didn't make sense.
2023-03-09 03:53:09 +00:00
Ben Potter 1199a9330a chore: add fly.io install source (#6509) 2023-03-09 03:16:55 +00:00
Kyle Carberry a78786119d chore: resolve race when running load tests with logs (#6523)
See https://github.com/coder/coder/actions/runs/4370166746/jobs/7644793277
2023-03-08 21:12:20 -06:00
Kyle Carberry 5304b4e483 feat: add connection statistics for workspace agents (#6469)
* fix: don't make session counts cumulative

This made for some weird tracking... we want the point-in-time
number of counts!

* Add databasefake query for getting agent stats

* Add deployment stats endpoint

* The query... works?!?

* Fix aggregation query

* Select from multiple tables instead

* Fix continuous stats

* Increase period of stat refreshes

* Add workspace counts to deployment stats

* fmt

* Add a slight bit of responsiveness

* Fix template version editor overflow

* Add refresh button

* Fix font family on button

* Fix latest stat being reported

* Revert agent conn stats

* Fix linting error

* Fix tests

* Fix gen

* Fix migrations

* Block on sending stat updates

* Add test fixtures

* Fix response structure

* make gen
2023-03-08 21:05:45 -06:00
Kyle Carberry 9d40d2ffdc fix: remove create first user from the cli message (#6493)
This adjusts our setup to just show the Web UI, since you
can now create everything from there!
2023-03-09 02:54:46 +00:00
Kyle Carberry db2bdd1cab fix: pass sdk header transport to websocket connections (#6521)
Fixes #6520.
2023-03-09 02:29:02 +00:00
Kyle Carberry d67552f852 fix: add more cached certificates to azure instance identity (#6519)
This was failing for GovCloud. Now it falls back to fetch, and a test
has been added to notify when certificates are becoming outdated.
2023-03-08 19:32:10 -06:00
Bruno Quaresma 54bbed8c3c chore: Fix default password and add more docs about scripts/develop.sh (#6514) 2023-03-08 21:50:55 +00:00
Kyle Carberry 7df1e3bdd6 fix: centralize deployment config blocks to resolve race (#6512)
See https://github.com/coder/coder/actions/runs/4365865438/jobs/7635236079
2023-03-08 16:55:52 +00:00
Ammar Bandukwala 95626d2076 fix: use correct LOG env names (#6511) 2023-03-08 16:27:32 +00:00
Marcin Tojek 3b87316ad7 feat: propagate job error codes (#6507)
* feat: propagate job error_code

* fix

* Fix

* Fix

* Fix

* add errors to typesGenerated

* Address PR comments

* Fix
2023-03-08 16:32:00 +01:00
Kyle Carberry 524b14adbc fix: fetch provisioner logs after end of logs message (#6495)
I think this should _actually_ fix it. See
https://github.com/coder/coder/actions/runs/4358242625/jobs/7618562167

The problem was that this loop is ran async so even though
messages are sent in order, we were processing too slowly and
the end of logs was published first.
2023-03-09 01:13:08 +10:00
Cian Johnston 26a725f86d fix: provisionerd: add more context to logs emitted, fix log level (#6508)
- Previously, we were logging all provision response logs at level INFO, regardless of the log level of the log streamed from the provisioner. We now log these at the original level (defaulting to INFO).
- Now logging "provision failed" message at level ERROR WARN and including the error field in the message.
2023-03-08 15:12:52 +00:00
Bruno Quaresma 89008125c0 refactor(site): Highlight immutable parameters and do a few tweaks (#6490) 2023-03-08 10:52:42 -03:00
Cian Johnston fe10ba1157 fix: add audit information for WorkspaceBuild.MaxDeadilne (#6504)
* fix: add audit information for WorkspaceBuild.MaxDeadilne

* make gen
2023-03-08 12:41:57 +00:00
Ammar Bandukwala 3b73321a6c feat: refactor deployment config (#6347) 2023-03-07 15:10:01 -06:00
Kyle Carberry bb0a996fc2 chore: fix buffered provisioner job logs close flake (#6492)
See https://github.com/coder/coder/actions/runs/4357599919/jobs/7617111287
2023-03-07 20:08:13 +00:00
Dean Sheather 1bdd2abed7 feat: use JWT ticket to avoid DB queries on apps (#6148)
Issue a JWT ticket on the first request with a short expiry that
contains details about which workspace/agent/app combo the ticket is
valid for.
2023-03-07 19:38:11 +00:00
Hannes Rehburg f8494d2bac Update binary.md (#6415)
Fixed broken Link to release archive
2023-03-07 12:30:50 -06:00
Kyle Carberry f287889cd7 chore: move client pubsub for HA coordinator after register (#6487)
Similar fix that happened for the agent. See:
https://github.com/coder/coder/actions/runs/4356099388/jobs/7613634277
2023-03-07 16:46:54 +00:00
Kyle Carberry 4c204fc348 chore: ensure auto-approve-docs has a deep enough depth (#6484)
* chore: ensure auto-approve-docs has a deep enough depth

This was failing on numerous PRs.

* Remove check because it isn't working
2023-03-07 10:05:00 -06:00
Kyle Carberry 23bebb40e2 fix: bump migration to resolve duplicate id (#6486)
This happened because two PRs with different migrations
merged at the same time!
2023-03-07 10:04:06 -06:00
Marcin Tojek 2d4706ac33 feat: mark coder_parameter as "required" (#6433)
* Add required column

* Pass through providerd

* Pass the required property down

* Optional

* Fix

* Fix

* Fix

* fix

* CLI create: support for optional fields

* Use HTML API to mark fields required

* Fix

* Improve validation

* more fixes

* make fmt

* Fix

* WIP

* Fix: test

* CLI update tets

* OptionalParameterAdded

* Fix: migration
2023-03-07 16:38:31 +01:00
Kyle Carberry f19076cf06 chore: fix coordinator flake by moving pubsub below register (#6482)
After making the in-memory pubsub conform to the expectations of
PostgreSQL, this flake started appearing.

This fixes it because the agent socket is registered when a message
is received.
2023-03-07 09:38:18 -06:00
Kira Pilot ef2e86f309 increase default max-token-duration (#6467) 2023-03-07 06:35:48 -08:00
Kyle Carberry 87ed7a7dba chore: use nil map on agent stats to check if report interval should be returned (#6479)
See https://github.com/coder/coder/actions/runs/4350638262/jobs/7601537088
2023-03-07 14:25:04 +00:00
Dean Sheather 66a6b590a1 feat: add template max_ttl (#6114)
Co-authored-by: Bruno Quaresma <bruno@coder.com>
2023-03-07 14:14:58 +00:00
Cian Johnston 248c53d68d fix: install terraform in base Docker image (#6263)
Updates the base Docker image to install Terraform version 1.3.4 (max supported version) by default.
Also updates documentation to reflect this change.
2023-03-07 13:52:45 +00:00
Mathias Fredriksson 0c2b432c1b feat: Add migration fixer script (for branches) (#6466) 2023-03-07 14:47:33 +02:00
Kyle Carberry fd02f73708 chore: ensure pubsub messages are delivered in order for in-memory variant (#6474)
PostgreSQL provides this guarantee, which led to some flakes in tests.
See: https://github.com/coder/coder/actions/runs/4350034299/jobs/7600478096
2023-03-07 04:36:25 +00:00
Kyle Carberry 74632e460c fix: adjust build state permission to require template update (#6472) 2023-03-07 04:24:32 +00:00
Kyle Carberry 29ced72cda chore: fix stats leaking in tests (#6478)
See https://github.com/coder/coder/actions/runs/4350254306/jobs/7601134509
2023-03-07 04:09:02 +00:00
Kyle Carberry 034641dc77 chore: migrate security checks to run on a cron (#6477)
They were taking a long time and seemed to be reducing concurrency
for our other CI actions.
2023-03-06 21:46:40 -06:00
Kyle Carberry 7a8ccda40e chore: copy forced derp websockets to fix flake (#6475)
See: https://github.com/coder/coder/actions/runs/4350034299/jobs/7600478389
2023-03-06 21:29:41 -06:00
Kyle Carberry 964032d783 chore: ignore query cancel error in activitybump (#6476)
See https://github.com/coder/coder/actions/runs/4350254306/jobs/7600782432

It's fine to ignore this, because workspace agent stats happen async
and might occur when shutting down.
2023-03-06 21:27:21 -06:00
Kyle Carberry 09f87d1df1 chore: remove empty case for metricscache (#6473)
This wasn't necessary to test and just caused flakes.
See: https://github.com/coder/coder/actions/runs/4350034299/jobs/7600340648
2023-03-06 21:13:08 -06:00
Kyle Carberry cf75d7e1fb fix: clean up idle http conns on wsconncache close (#6471)
See https://github.com/coder/coder/actions/runs/4346769070/jobs/7593243836
2023-03-06 20:45:49 -06:00
Kyle Carberry e0137bcff1 fix: ensure tailnet websockets are closed (#6470)
See: https://github.com/coder/tailscale/pull/10
2023-03-06 20:45:24 -06:00
sharkymark d8abe37cd7 docs: AWS EKS sessionAffinity for LB external IP to be issued (#6425) 2023-03-06 23:40:05 +00:00
Steven Masley 8a6635bf5f chore: Never run v2 migrations on v1 database (#6438) 2023-03-06 13:49:03 -06:00
Mathias Fredriksson 22e3ff96be feat(agent): Add shutdown lifecycle states and shutdown_script support (#6139)
* feat(api): Add agent shutdown lifecycle states

* feat(agent): Add shutdown_script support

* feat(agent): Add shutdown_script timeout

* feat(site): Support new agent lifecycle states

---

Co-authored-by: Marcin Tojek <marcin@coder.com>
2023-03-06 21:34:00 +02:00
Ben Potter 02100c64b5 fix: docs auto-approval (#6450)
* fix: docs auto-approval

* empty commit
2023-03-06 13:31:07 -06:00
Bruno Quaresma 136f23fb4c refactor(site): Suport template version variables on template creation (#6434) 2023-03-06 18:36:19 +00:00
Steven Masley 84dd59ecc2 fix: 'coder update' should always start a workspace (#6437)
* fix: 'coder update' should always start a workspace
2023-03-06 08:37:11 -06:00
Steven Masley 260b2b2333 fix: 404 template shows error page (#6441) 2023-03-06 13:58:36 +00:00
Bruno Quaresma a3201bd658 fix(site): Fix template version editor rename (#6251) 2023-03-06 13:53:24 +00:00
Cian Johnston 1483b42259 fix(provisionerd): emit workspace build transition in lower case (#6455) 2023-03-06 11:14:19 +00:00
Steven Masley e78c272a72 chore: System context to oidc login (#6427) 2023-03-04 14:32:07 -06:00
Ammar Bandukwala 02f0968b33 chore: automatically approve Ben's docs PRs (#6444) 2023-03-04 08:07:45 -06:00
Ben Potter 573a8d5717 docs: external provisioners (#6443)
* docs: external provisioners

* better wording

* fix wording

* fix wording in various places

* keep fixing wording

* add another note about template management
2023-03-03 23:49:03 +00:00
Steven Masley 973df199b0 test: Check created_at for prepareData to ensure user order (#6436)
* test: Check created_at for prepareData to ensure user order

* test: Consistent user ordering in dbfake

* import order

* Linting
2023-03-03 13:09:04 -06:00
Muhammad Atif Ali 3cb9b3de24 docs: clarify how to set max token life in ci/cd docs (#6416)
* docs: clarify max token life in ci/cd docs

* Update docs/templates/change-management.md

---------

Co-authored-by: Ben Potter <me@bpmct.net>
2023-03-02 22:22:53 +00:00
Ben Potter 175a41567e docs: clarify requirements for offline deployments (#6418)
* docs: clarify requirements for offline deployments

* fix punctuation

* fix typo and add postgres

* mention update check

* disable update checks
2023-03-02 14:59:31 -06:00
Ben Potter 25b05ed8a4 fix: minimal AWS policy for templates (#6419) 2023-03-02 12:21:02 -06:00
Kira Pilot 71d1e63af0 feat: add ability to name tokens (#6365)
* add tokens switch

* reorged TokensPage

* using Trans component for description

* using Trans component on DeleteDialog

* add owner col

* simplify hook return

* lint

* type for response

* added flag for name

* fixed auth

* lint, prettier, tests

* added unique index for login type token

* remove tokens by name

* better check for unique constraint

* docs

* test: Fix dbfake to insert token name

* fix doc tests

* Update cli/tokens.go

Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>

* Update coderd/database/migrations/000102_add_apikey_name.down.sql

Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>

* add more specificity to IsUniqueViolation check

* fix tests

* Fix AutorizeAllEndpoints

* rename migration

---------

Co-authored-by: Steven Masley <stevenmasley@coder.com>
Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>
2023-03-02 09:39:38 -08:00
Muhammad Atif Ali e3a4861e93 docs: update example coder.conf file (#6319)
Updated example configuration file to match the configuration in tutorial.
2023-03-02 09:55:50 -06:00
Ben Potter ea7a80c5ff docs: clearer postgres sizing recommendations (#6302) 2023-03-02 15:53:55 +00:00
Kyle Carberry 2ff1c6d613 feat: add agent stats for different connection types (#6412)
This allows us to track when our extensions are used, when the
web terminal is used, and average connection latency to the agent.
2023-03-02 08:06:00 -06:00
Ben Potter 537547fcc3 fix: outdated message in latency tooltip (#6043) 2023-03-02 13:24:44 +00:00
Marcin Tojek 67db36bf81 feat: Add form to modify managed Template variables (#6257) 2023-03-02 14:11:16 +01:00
Steven Masley 8cf292f50a feat: Guard search queries against common mistakes (#6404)
* feat: Error on excessive invalid search keys
* feat: Guard search queries against common mistakes
* Raise errors in FE on workspaces table
* All errors should be on newlines
2023-03-01 23:28:56 -06:00
Kyle Carberry 1724cbf872 feat: automatically use websockets if DERP upgrade is unavailable (#6381)
* feat: automatically use websockets if DERP upgrade is unavailable

This might be our biggest hangup for deployments at the moment...

Load balancers by default do not support the DERP protocol, so many
of our prospects and customers run into failing workspace connections.
This automatically swaps to use WebSockets, and reports the reason to
coderd.

In a future contribution, a warning will appear by the agent if it was
forced to use WebSockets instead of DERP.

* Fix nil pointer type in Tailscale dep

* Fix requested changes
2023-03-01 22:18:14 +00:00
dependabot[bot] ce11400b56 chore: bump eslint-plugin-import from 2.26.0 to 2.27.5 in /site (#6391)
Bumps [eslint-plugin-import](https://github.com/import-js/eslint-plugin-import) from 2.26.0 to 2.27.5.
- [Release notes](https://github.com/import-js/eslint-plugin-import/releases)
- [Changelog](https://github.com/import-js/eslint-plugin-import/blob/main/CHANGELOG.md)
- [Commits](https://github.com/import-js/eslint-plugin-import/compare/v2.26.0...v2.27.5)

---
updated-dependencies:
- dependency-name: eslint-plugin-import
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-01 21:55:27 +00:00
dependabot[bot] 28e002e8bb chore: bump eslint-plugin-jest from 27.0.1 to 27.2.1 in /site (#6396)
Bumps [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) from 27.0.1 to 27.2.1.
- [Release notes](https://github.com/jest-community/eslint-plugin-jest/releases)
- [Changelog](https://github.com/jest-community/eslint-plugin-jest/blob/main/CHANGELOG.md)
- [Commits](https://github.com/jest-community/eslint-plugin-jest/compare/v27.0.1...v27.2.1)

---
updated-dependencies:
- dependency-name: eslint-plugin-jest
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-01 15:21:30 -06:00
dependabot[bot] 454da9e0ef chore: bump eslint from 8.33.0 to 8.35.0 in /site (#6395)
Bumps [eslint](https://github.com/eslint/eslint) from 8.33.0 to 8.35.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.33.0...v8.35.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-01 15:21:23 -06:00
dependabot[bot] 32ecb853ed chore: bump github.com/gohugoio/hugo from 0.109.0 to 0.110.0 (#6394)
Bumps [github.com/gohugoio/hugo](https://github.com/gohugoio/hugo) from 0.109.0 to 0.110.0.
- [Release notes](https://github.com/gohugoio/hugo/releases)
- [Changelog](https://github.com/gohugoio/hugo/blob/master/hugoreleaser.toml)
- [Commits](https://github.com/gohugoio/hugo/compare/v0.109.0...v0.110.0)

---
updated-dependencies:
- dependency-name: github.com/gohugoio/hugo
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-01 15:21:13 -06:00
dependabot[bot] 570b7f95d2 chore: bump aquasecurity/trivy-action from 0.8.0 to 0.9.1 (#6385)
Bumps [aquasecurity/trivy-action](https://github.com/aquasecurity/trivy-action) from 0.8.0 to 0.9.1.
- [Release notes](https://github.com/aquasecurity/trivy-action/releases)
- [Commits](https://github.com/aquasecurity/trivy-action/compare/9ab158e8597f3b310480b9a69402b419bc03dbd5...8bd2f9fbda2109502356ff8a6a89da55b1ead252)

---
updated-dependencies:
- dependency-name: aquasecurity/trivy-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-01 15:19:13 -06:00
dependabot[bot] b2671639a7 chore: bump crate-ci/typos from 1.13.9 to 1.13.14 (#6386)
Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.13.9 to 1.13.14.
- [Release notes](https://github.com/crate-ci/typos/releases)
- [Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md)
- [Commits](https://github.com/crate-ci/typos/compare/v1.13.9...v1.13.14)

---
updated-dependencies:
- dependency-name: crate-ci/typos
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-01 15:18:59 -06:00
dependabot[bot] 991c720c09 chore: bump github.com/cenkalti/backoff/v4 from 4.1.3 to 4.2.0 (#6390)
Bumps [github.com/cenkalti/backoff/v4](https://github.com/cenkalti/backoff) from 4.1.3 to 4.2.0.
- [Release notes](https://github.com/cenkalti/backoff/releases)
- [Commits](https://github.com/cenkalti/backoff/compare/v4.1.3...v4.2.0)

---
updated-dependencies:
- dependency-name: github.com/cenkalti/backoff/v4
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-01 15:18:48 -06:00
Dean Sheather 31a37025c4 fix: build for all platforms in depot release pt. 2 (#6407) 2023-03-01 19:48:22 +00:00
Dean Sheather 9af03d6180 fix: build for all platforms in depot release (#6406) 2023-03-01 18:29:02 +00:00
Bruno Quaresma 4dd95c5e01 fix(site): Fix long template descriptions (#6403) 2023-03-01 17:53:59 +00:00
Kyle Carberry 9ea21bf8ee fix: hardcode azure instance identity intermediate certificates (#6402)
This was broken for an airgapped customer!
2023-03-01 17:39:24 +00:00
Kira Pilot 6304bfb5c0 feat: add 'Show all tokens' toggle for owners (#6325)
* add tokens switch

* reorged TokensPage

* using Trans component for description

* using Trans component on DeleteDialog

* add owner col

* simplify hook return

* lint

* type for response

* PR feedback

* fix lint
2023-03-01 08:35:55 -08:00
dependabot[bot] b56e1bb002 chore: bump contributor-assistant/github-action from 2.2.1 to 2.3.0 (#6384)
Bumps [contributor-assistant/github-action](https://github.com/contributor-assistant/github-action) from 2.2.1 to 2.3.0.
- [Release notes](https://github.com/contributor-assistant/github-action/releases)
- [Commits](https://github.com/contributor-assistant/github-action/compare/v2.2.1...v2.3.0)

---
updated-dependencies:
- dependency-name: contributor-assistant/github-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-01 09:18:01 -06:00
dependabot[bot] c560d6d2ae chore: bump actions/upload-artifact from 2 to 3 (#6383)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 2 to 3.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-01 09:17:34 -06:00
Ammar Bandukwala 5f6dd0ca2a docs: fix very small typo 2023-02-28 16:51:53 -06:00
Kyle Carberry 8850ce0d9a fix: use bigint instead of integer in stats migration (#6380)
This broke dogfood!
2023-02-28 13:55:37 -06:00
Kyle Carberry 05e449943d chore: convert agent stats to use a table (#6374)
* chore: convert workspace agent stats from json to table

* chore: convert agent stats to use a table

Backwards compatibility becomes hard when all agent stats are in a JSON blob.
We also want to query this table for new agents that are failing health checks
so we can display it in the UI.

* Fix migration using default values
2023-02-28 13:33:33 -06:00
Ben Potter 7cf1e20aac docs: clarify alpha state of rich parameters (#6369) 2023-02-28 17:16:49 +00:00
Steven Masley 418a8a77dc chore: Skip authz on various functions used for api data building (#6366)
* chore: Skip authz on various functions used for api data building

API already fetches the parent object and does the rbac check. Until
these functions are optimized, skipping authz is better.
It leaves us no worse off than the status quo
2023-02-28 11:04:39 -06:00
Ammar Bandukwala d30da81f42 ci: make fmt 2023-02-27 21:43:14 +00:00
Ammar Bandukwala dc6639bf69 ci: automatically assign new PRs 2023-02-27 16:52:00 +00:00
Kyle Carberry 7f226d4f90 feat: add support for coder_git_auth data source (#6334)
* Add git auth providers schema

* Pipe git auth providers to the schema

* Add git auth providers to the API

* Add gitauth endpoint to query authenticated state

* Add endpoint to query git state

* Use BroadcastChannel to automatically authenticate with Git

* Add error validation for submitting the create workspace form

* Fix panic on template dry-run

* Add tests for the template version Git auth endpoint

* Show error if no gitauth is configured

* Add gitauth to cliui

* Fix unused method receiver

* Fix linting errors

* Fix dbauthz querier test

* Fix make gen

* Add JavaScript test for git auth

* Fix bad error message

* Fix provisionerd test race

See https://github.com/coder/coder/actions/runs/4277960646/jobs/7447232814

* Fix requested changes

* Add comment to CreateWorkspacePageView
2023-02-27 10:18:19 -06:00
Kyle Carberry 3d8b77d6f1 chore: improve clarity of the agent logs (#6345)
I looked through these logs when debugging and there was a bit of spam!
2023-02-27 09:20:24 -06:00
Marcin Tojek ec6f78d09e docs: Describe support links (#6353)
* docs: Describe support links

* Fix: size

* Address PR comments
2023-02-27 15:33:34 +01:00
Marcin Tojek 2e53fb55da feat: Enable custom support links (#6313)
* backend: support links

* frontend: Support links

* fmt

* test: CODER_SUPPORT_LINKS_0_NAME

* Go tests

* Use UpdateAppearanceConfig

* ui: UpdateAppearanceConfig

* fix: fmt

* Fix: site

* Fix: site tests

* fix: fmt

* fix

* test: check default support links
2023-02-27 09:25:04 +01:00
Eric Paulsen 16364db483 add: resource reqs/limits on K8s template (#6308) 2023-02-26 19:23:45 -05:00
Kyle Carberry 7c46f76c82 chore: fetch templates by id without lock in dbfake (#6351)
See https://github.com/coder/coder/actions/runs/4276632002/jobs/7444857508
2023-02-26 15:29:43 -06:00
Kyle Carberry acbe968f41 chore: increase activitybump deadline duration to fix flake (#6350)
This is a bad fix because the test is still dependant on time, but it's
still an improvement.
2023-02-26 13:42:01 -06:00
Kyle Carberry 1fb7365cb1 fix: use -U when installing with rpm (#6349)
Fixes #6275.
2023-02-26 18:11:23 +00:00
Kyle Carberry 17adfd1134 chore: improve times of ratelimit tests (#6346)
From 5s to 130ms!
2023-02-25 22:01:01 +00:00
Muhammad Atif Ali acf000aaa5 add common ml logos (#6318) 2023-02-25 11:22:07 -06:00
Kyle Carberry d613ba9987 security: add X-Content-Type-Options: nosniff to block MIME-sniffing (#6344)
coder/security#12
2023-02-25 11:18:45 -06:00
Mathias Fredriksson cae8b88f60 fix(tailnet): Avoid logging netmap (#6342) 2023-02-25 08:06:38 +00:00
Mathias Fredriksson 5876dc1f97 test(cli): Improve speedtest debugging (#6341) 2023-02-24 20:09:16 +02:00
Ben Potter 29dbfe067c docs: parameters (#6332)
* docs: parameters

* mention legacy parameters
2023-02-24 11:04:07 -07:00
Mathias Fredriksson 677721e4a1 fix(tailnet): Skip nodes without DERP, avoid use of RemoveAllPeers (#6320)
* fix(tailnet): Skip nodes without DERP, avoid use of RemoveAllPeers
2023-02-24 18:16:29 +02:00
Mathias Fredriksson a414de9e81 fix(tailnet): Improve tailnet setup and agentconn stability (#6292)
* fix(tailnet): Improve start and close to detect connection races

* fix: Prevent agentConn use before ready via AwaitReachable

* fix(tailnet): Ensure connstats are closed on conn close

* fix(codersdk): Use AwaitReachable in DialWorkspaceAgent

* fix(tailnet): Improve logging via slog.Helper()
2023-02-24 13:11:28 +02:00
Cian Johnston 473ab208af fix: replace owner_email with workspace_owner, change action to workspace_transition (#6337) 2023-02-24 04:38:58 +00:00
Marcin Tojek 16363fd1ff chore: update terraform-provider-coder (#6333) 2023-02-23 17:32:52 -07:00
Cian Johnston 282507f0fb fix(provisionerd): add more detailed workspace build logging (#6331) 2023-02-24 00:03:12 +00:00
Marcin Tojek 50db90c33d fix: rephrase rich parameters error (#6327) 2023-02-23 21:49:40 +00:00
Dean Sheather 8abe48c155 chore: update docs to recommend MFA via iDP (#6324) 2023-02-23 18:07:21 +00:00
Kyle Carberry 8a4a179565 fix: use proper generated cli.md for deploy (#6323) 2023-02-23 11:07:57 -06:00
Muhammad Atif Ali 7f65a837b1 docs: Update the troubleshooting section (#6287)
* docs: Update the troubleshooting section

Update the troubleshooting section to link web-server docs

* make fmt

* Update docs/templates.md

Co-authored-by: Ben Potter <me@bpmct.net>

---------

Co-authored-by: Ben Potter <me@bpmct.net>
2023-02-23 09:35:02 -07:00
Bruno Quaresma 0bf6229edb fix(site): Fix cancel button borders (#6315) 2023-02-23 15:47:09 +00:00
Cian Johnston 1ba6fab0e0 chore: skip flaky TestSpeedtest (#6322) 2023-02-23 15:29:57 +00:00
Bruno Quaresma 8298a924f6 fix(site): Fix login flow (#6294) 2023-02-23 15:25:12 +00:00
Kira Pilot a32169ccb5 feat: add flag to see all tokens if owner (#6227)
* added query for tokens by user id

* updated query args

* adding owner col

* fix request params

* update-golden-files

* added owners col to ls table output

* added ttoken translations

* prettier

* format table according to arg

* using slice.Contains

* refactored token state

* cleanup
2023-02-23 07:00:27 -08:00
Ammar Bandukwala 7a52a9cfc8 fix: flake in template pull (#6317) 2023-02-23 04:59:07 +00:00
Ammar Bandukwala f6a8c360e5 feat(docs): rework CLI docs (#6312) 2023-02-23 01:53:21 +00:00
Cian Johnston 43e8ba0811 feat(api): add prometheus metric coderd_workspace_builds_total (#6314)
This PR adds the prometheus metric coderd_workspace_builds_total.
It measures the total number of workspace builds, along with a number of labels intended to be useful for an operator debugging a failed workspace build trying to discover the scope of the issue.
2023-02-23 01:28:10 +00:00
Kyle Carberry 2a8a147e7d fix: don't log disconnect error when the database is shutting down (#6309)
* fix: don't log disconnect error when the database is shutting down

Seen in: https://github.com/coder/coder/actions/runs/4244980490/jobs/7379867681

* Generalize the query close error
2023-02-22 16:07:26 -06:00
Colin Adler bbdf24686d chore(examples): update provider versions (#6311) 2023-02-22 14:43:32 -07:00
Muhammad Atif Ali 457ad74d83 fix(docs): update Apache docs to correctly forward WebSockets (#6296)
This revolves #6295
2023-02-22 12:51:51 -07:00
Ammar Bandukwala f7c10adb04 feat(cli): extract tar in template pull (#6289) 2023-02-22 19:29:51 +00:00
Ammar Bandukwala 8231de94ca feat(cli): make minor improvements to speedtest (#6266)
- Remove mostly redundant "Transferred" column
- Rename "Bandwidth" to "Throughput"
- Replace "--reverse" (which has an ambiguous starting state) with "--direction=(up|down)"
- Tolerate AgentStartErrors which may be caused by failing startup
  script
2023-02-22 19:09:37 +00:00
Cian Johnston 6149905a83 fix: disallow deleting self (#6306)
* fix: api: disallow user self-deletion

* feat(site): TableRowMenu: allow disabling individual menu items

* fix(site): UsersTable: disallow deleting self
2023-02-22 16:48:16 +00:00
Bruno Quaresma b412ef0dbb chore(site): Fix chromatic errors (#6301) 2023-02-22 16:11:25 +00:00
Bruno Quaresma d993a97fee refactor(site): Minor design refactoring on template version editor (#6265) 2023-02-22 07:42:37 -07:00
Ammar Bandukwala 3f75f6b8cc chore: update potentially insecure deps (#6290) 2023-02-21 06:15:25 +00:00
Mathias Fredriksson 2bb9b4ac80 test: Fix azureidentity verification test (#6284) 2023-02-20 15:50:39 +00:00
Ammar Bandukwala f05609b4da chore: format Go more aggressively 2023-02-18 18:32:09 -06:00
Colin Adler 19ae411f05 fix: actually test httpapi.WebsocketCloseSprintf (#6261) 2023-02-17 17:50:21 +00:00
Kyle Carberry a79f4a095d fix: allow mapped resources in our terraform provider (#6255) 2023-02-17 16:05:38 +00:00
Bruno Quaresma 7a864bdb28 refactor(site): Refactor template settings (#6239) 2023-02-17 13:27:35 +00:00
Marcin Tojek e161c45b47 Revert "fix: allow mapped resources in our terraform provider (#6242)" (#6248)
This reverts commit d5af536ea2.
2023-02-17 12:55:54 +01:00
Marcin Tojek a69137b1f7 feat: Update CLI to handle managed variables (#6220)
* WIP

* hcl

* useManagedVariables

* fix

* Fix

* Fix

* fix

* go:build

* Fix

* fix: bool flag

* Insert template variables

* API

* fix

* Expose via API

* More wiring

* CLI for testing purposes

* WIP

* Delete FIXME

* planVars

* WIP

* WIP

* UserVariableValues

* no dry run

* Dry run

* Done FIXME

* Fix

* Fix: CLI

* Fix: migration

* API tests

* Test info

* Tests

* More tests

* fix: lint

* Fix: authz

* Address PR comments

* Fix

* fix

* fix

* CLI: create

* unit tests: create templates with variables

* Use last variables

* Fix

* Fix

* Fix

* Push tests

* fix: variable is required if Default is nil

* WIP

* Redact sensitive values

* Fixes

* Fixes

* Fix: arg description

* Fix

* Variable param

* Fix: gen

* Fix

* Fix: goldens
2023-02-17 09:07:45 +01:00
Kyle Carberry d5af536ea2 fix: allow mapped resources in our terraform provider (#6242)
Fixes #6234.
2023-02-16 13:04:40 -06:00
Bruno Quaresma 2c309194e9 refactor(site): Remove untar dep and support nested folders on template version page (#6244) 2023-02-16 18:38:14 +00:00
Bruno Quaresma 8360357834 refactor(site): Redesign dialogs (#6237) 2023-02-16 14:03:07 -03:00
Bruno Quaresma 909fbb6d2c fix(site): Upload template files on template version editor (#6222) 2023-02-16 13:59:48 -03:00
Ben 4c799798c6 fix: use autoplay for AWS quickstart 2023-02-16 16:45:53 +00:00
Ben Potter 779c6549b4 fix: proper video URL in AWS quickstart doc (#6238)
* chore: fixes video in AWS quickstart

* minor language tweaks
2023-02-16 10:39:14 -06:00
Cian Johnston 81c29c018a fix(coder): actually ignore email verified if config value is set (#6236) 2023-02-16 15:17:37 +00:00
Ben Potter fdad136905 fix: add notes to helm chart about access URL (#6231) 2023-02-16 08:46:49 -06:00
Ben Potter 9c22c51d3b docs: use marketplace for AWS quickstart (#6233) 2023-02-16 08:44:48 -06:00
Muhammad Atif Ali 26876dc734 docs: add apache reverse-proxy example (#6213)
* docs: apache reverse proxy

* fixed to correctly pass WebSocket headers

* add a sample configuration file

* updating with suggestions

* Update coder.conf

* fix http to https redirection

* fix: upgrade http to https

* Update examples/web-server/apache/README.md

Co-authored-by: Ben Potter <me@bpmct.net>

* add other dns providers documentation link

---------

Co-authored-by: Ben Potter <me@bpmct.net>
Co-authored-by: Ben Potter <ben@coder.com>
2023-02-16 04:50:18 +00:00
Muhammad Atif Ali 99306642bb docs: update caddy reverse proxy example (#6228)
Update caddy reverse proxy example to use `CODER_HTTP_ADDRESS` instead of deprecated `CODER_ADDRESS`

This resolved #5449
2023-02-16 04:31:43 +00:00
Ben Potter 22cc6a3fb6 docs: feature stages (#6223) 2023-02-15 15:51:31 -06:00
Muhammad Atif Ali 786ad8d8b1 docs: add nginx reverse-proxy example (#6185)
* docs: Add nginx reverse-proxy example

This PR adds nginx reverse-proxy example to provision coder with tls certificate using letsencrypt certbot.

This will partially resolve #6086.

* change nginx example to to absolute path

* Update examples/web-server/nginx/README.md

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/web-server/nginx/README.md

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/web-server/nginx/README.md

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/web-server/nginx/README.md

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/web-server/nginx/README.md

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/web-server/nginx/README.md

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/web-server/nginx/README.md

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/web-server/nginx/README.md

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/web-server/nginx/README.md

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/web-server/nginx/README.md

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/web-server/nginx/README.md

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/web-server/nginx/README.md

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/web-server/nginx/README.md

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/web-server/nginx/README.md

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/web-server/nginx/README.md

Co-authored-by: Ben Potter <me@bpmct.net>

* refactor: replaced bullets with numbered lists

* remove the ambiguous ip addr.

* fixed a typo

* correctly handle the wildcard subdomain

* simplified after testing

* fmt: prettier formatting

* Adapt to the coder style guide

* fix: agent disconnection

* Update examples/web-server/nginx/README.md

Co-authored-by: Ben Potter <me@bpmct.net>

* Update docs/admin/configure.md

Co-authored-by: Ben Potter <me@bpmct.net>

* Update examples/web-server/nginx/README.md

Co-authored-by: Ben Potter <me@bpmct.net>

* updated with suggested changes

* updated with requested changes

* add reference to certbot docs for other dns providers

---------

Co-authored-by: Ben Potter <me@bpmct.net>
2023-02-15 13:18:54 -06:00
Marcin Tojek 3b7b96ac28 feat: Expose managed variables via API (#6134)
* WIP

* hcl

* useManagedVariables

* fix

* Fix

* Fix

* fix

* go:build

* Fix

* fix: bool flag

* Insert template variables

* API

* fix

* Expose via API

* More wiring

* CLI for testing purposes

* WIP

* Delete FIXME

* planVars

* WIP

* WIP

* UserVariableValues

* no dry run

* Dry run

* Done FIXME

* Fix

* Fix: CLI

* Fix: migration

* API tests

* Test info

* Tests

* More tests

* fix: lint

* Fix: authz

* Address PR comments

* Fix

* fix

* fix
2023-02-15 18:24:15 +01:00
Cian Johnston f0f39b4892 chore: break down dbauthz.System into smaller roles (#6218)
- rbac: export rbac.Permissions
- dbauthz: move GetDeploymentDAUs, GetTemplateDAUs,
  GetTemplateAverageBuildTime from querier.go to system.go
  and removes auth checks
- dbauthz: remove AsSystem(), add individual roles for
  autostart, provisionerd, add restricted system role for 
  everything else
2023-02-15 16:14:37 +00:00
Eric Paulsen 84da6056b2 docs: add template-level URL override (#6212) 2023-02-15 10:27:40 -05:00
Steven Masley 4cbbd1376d feat: Turn on rbac check caching (#6202)
* chore: Turn on rbac check caching.

Should not affect much unless authz_querier experiment is
enabled
2023-02-15 08:56:07 -06:00
Mathias Fredriksson fac7c02eeb ci: Add support for release/experimental label (#6208)
Co-authored-by: Ben Potter <ben@coder.com>
2023-02-15 14:23:06 +00:00
Ammar Bandukwala 5e4931efaf chore: add comment that explains require_telemetry behavior (#6211) 2023-02-15 01:40:08 +00:00
Kira Pilot 5e60879fb8 feat: audit addition and removal of licenses (#6125)
* added license audit resource

* audit delete licenses

* added filtering

* remove logs

* making the best of the current UUID situation

* fixed lint

* fix tests

* regen docs

* PR feedback

* PR feedback
2023-02-14 16:34:13 -05:00
Ammar Bandukwala 6e3330a03f feat: add support for telemetry-required licenses (#6194) 2023-02-14 20:26:47 +00:00
Eric Paulsen 15c862fcb5 fix: set Coder read-only fs to null (#6207)
* fix: set Coder read-only fs to null

* chore: readme fixes

* chore: readme fixes v2
2023-02-14 11:04:16 -06:00
Steven Masley 80bde1e2c9 chore: Ensure cancelled errors return proper (#6200)
The authz library returns a 404 if the authorization fails. If the
context is cancelled, then a 404 message is inaccurate.
Add a unit test to ensure context cancelled errors are raised
properly
2023-02-14 10:57:19 -06:00
Mathias Fredriksson 860e2829c5 fix: Prevent race between provisionerd connect and close (#6206)
* fix: Prevent race between provisionerd connect and close

* test: Add detection for provisioner creation after test completion
2023-02-14 16:37:43 +00:00
Steven Masley cde7ff8a2d chore: Fix import rbac on userauth.go (#6205) 2023-02-14 15:57:34 +00:00
Kyle Carberry 51f17b1820 fix: allow disabling all password auth even if owner (#6193)
* fix: allow disabling all password auth even if owner

Removes any and all ability to auth with a password.

* Hide create user if password auth is disabled
2023-02-14 08:58:12 -06:00
Mathias Fredriksson 41ae01d2e9 fix: Improve closure of provisioner and agent tailnet dial (#6199) 2023-02-14 14:57:48 +00:00
Mathias Fredriksson 5df7872661 fix: Improve use of context in websocket.NetConn code paths (#6198) 2023-02-14 16:42:55 +02:00
Steven Masley 6fb8aff6d0 feat: Add initial AuthzQuerier implementation (#5919)
feat: Add initial AuthzQuerier implementation
- Adds package database/dbauthz that adds a database.Store implementation where each method goes through AuthZ checks
- Implements all database.Store methods on AuthzQuerier
- Updates and fixes unit tests where required
- Updates coderd initialization to use AuthzQuerier if codersdk.ExperimentAuthzQuerier is enabled
2023-02-14 14:27:06 +00:00
Mathias Fredriksson ebdfdc749d test: Make cli speedtest more reliable (#6187)
We now wait for the agent to be connected/ready before start.
2023-02-14 11:23:04 +02:00
dependabot[bot] 1c4e1d8ded chore: bump github.com/gin-gonic/gin from 1.7.0 to 1.7.7 (#6146)
Bumps [github.com/gin-gonic/gin](https://github.com/gin-gonic/gin) from 1.7.0 to 1.7.7.
- [Release notes](https://github.com/gin-gonic/gin/releases)
- [Changelog](https://github.com/gin-gonic/gin/blob/master/CHANGELOG.md)
- [Commits](https://github.com/gin-gonic/gin/compare/v1.7.0...v1.7.7)

---
updated-dependencies:
- dependency-name: github.com/gin-gonic/gin
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-13 19:33:11 -06:00
Kyle Carberry 2d0a69ba47 fix: require client pipe to be closed in provisionerd test (#6188)
https://github.com/coder/coder/actions/runs/4165019548/jobs/7207442687
2023-02-14 00:46:05 +00:00
Steven Masley 733f58c76d chore: Force license uuids to not be null (#6012)
* chore: Force license uuids to not be null

* All unit tests generate uuids for licenses

* Update migration files to new numbers

* Put migration in transaction
2023-02-13 18:21:58 -06:00
Colin Adler a54de6093b feat: add coder ping (#6161) 2023-02-13 10:38:00 -06:00
Mathias Fredriksson 2157bff13f fix: Clean up conn on NewStream error in memDRPC (#6182) 2023-02-13 17:27:10 +02:00
Mathias Fredriksson d355783faa test: Fix cli delete test (#6183)
We were waiting for Cleaning Up which never appeared:

https://github.com/coder/coder/actions/runs/4163971602/jobs/7205007285
2023-02-13 14:54:38 +00:00
Marcin Tojek a064678b8a fix: Update flake.lock to fix Go build (#6173) 2023-02-13 11:05:28 +01:00
Mathias Fredriksson a56df46d0f fix: Update github.com/coder/retry to remove initial delay (#6160) 2023-02-13 11:54:43 +02:00
Kyle Carberry c0c83f17b2 fix: follow tailscale idioms for when to update nodes (#6164) 2023-02-10 16:59:24 -06:00
Bruno Quaresma b171cb562c fix(site): Support underscore files (#6159) 2023-02-10 16:52:56 -03:00
Mathias Fredriksson 2dbe00ae44 fix(api): Allow workspace agent coordinate to report disconnect (#6152) 2023-02-10 20:23:02 +02:00
Steven Masley 6189035e98 feat: Add option to enable hsts header (#6147)
* feat: Add option to enable hsts header
* Update golden files
2023-02-10 10:52:49 -06:00
Bruno Quaresma 77afdf71dc fix(site): Show folders in the template version editor (#6145) 2023-02-10 13:22:20 -03:00
Steven Masley 32fbd10a1f chore: Optimize parial rego execution byte allocations (#6144)
* chore: Implement benchmark for authorizer.Prepare

Identify time + alloc cost before optimizing
2023-02-10 08:39:45 -06:00
Cian Johnston ab9cba9396 chore: update template examples and docs to install code-server under /tmp (#6138)
Updates templates examples and docs to pass the --method standalone argument
to code-server install script, and installs code-server under /tmp/code-server.

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

---------

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
2023-02-10 13:36:46 +00:00
Colin Adler 4432cd08d6 chore: update tailscale (#6091) 2023-02-09 21:43:18 -06:00
Steven Masley e6da7afd33 feat: Add cachable authorizer to elimate duplicate rbac calls (#6107)
* feat: Add cachable authorizer to elimate duplicate rbac calls

Cache is context bound, so only prevents duplicate rbac calls in
the same request context.
2023-02-09 20:14:31 -06:00
Mathias Fredriksson 6f3f7f2937 fix(agent): Allow signal propagation when running as PID 1 (#6141) 2023-02-09 23:07:21 +02:00
Steven Masley af59e2bcfa chore: Optimize rego policy input allocations (#6135)
* chore: Optimize rego policy evaluation allocations

Manually convert to ast.Value instead of using generic
json.Marshal conversion.

* Add a unit test that prevents regressions of rego input

The optimized input is always compared to the normal json
marshal parser.
2023-02-09 13:47:17 -06:00
Eric Paulsen 22f6400ea5 helm: add deployment securityContext values (#6136)
* helm: add deployment securityContext values

* rm: podSecurityContext
2023-02-09 13:26:35 -05:00
Mathias Fredriksson b46d0d693f fix: Extend migration fixture test with down and fix 000045 (#6130) 2023-02-09 16:59:54 +02:00
Marcin Tojek 049984ce7f docs: Add missing body parameter (#6132) 2023-02-09 14:02:03 +00:00
Bruno Quaresma 4493649d7e refactor(site): Add bottom spacing to the dashboard layout (#6084) 2023-02-08 21:53:42 -03:00
Kyle Carberry 4827d9edb8 fix: increase generated password length resolve flake (#6116) 2023-02-08 20:59:07 +00:00
Kyle Carberry d803bb76d5 feat: automatically open workspaces in vscode in the dir specified (#6115)
This makes a one-click magical experience not only possible, but really nice too!
2023-02-09 06:38:34 +10:00
Kyle Carberry 2ed0eafd75 feat: add minimum password entropy requirements (#6090)
* feat: add minimum password entropy requirements

* Fix all the tests

* Fix E2E tests
2023-02-08 14:10:08 -06:00
Marcin Tojek fe725f76bb fix: Allow to stop or remove workspaces using rich and old parameters (#6099)
* fix: Allow to stop or remove workspaces using rich and old parameters

* Fix
2023-02-08 14:09:52 -06:00
Kyle Carberry 1617268859 fix: stop redirecting away from wildcard url (#6113)
Fixes #6097.
2023-02-08 13:48:17 -06:00
Steven Masley 8dba66c535 chore: Use dbgen in unit test (#6111)
* chore: Use dbgen in unit test

- organizationparam_test
- templateparam_test

* Use dbgen in all unit tests vs insert methods

* fixup! Use dbgen in all unit tests vs insert methods

---------

Co-authored-by: Cian Johnston <cian@coder.com>
2023-02-08 13:47:05 -06:00
Kira Pilot 7a1731b620 chore: change build audit log string to be clearer (#6093)
* changed bbuild string

* clean up friendly string

* using Trans component

* general cleanup

* fixed tests

* fix lint

* fixing bolding

* removing dead strings in auditLogRow

* fix tests
2023-02-08 13:06:57 -05:00
Dean Sheather d60ec3e4bf feat: add JSON output format to many CLI commands (#6082) 2023-02-08 17:09:38 +00:00
Ben Potter 5655ec6862 Revert "fix: open terminal and coder_app in a new tab, not window (#6044)" (#6106)
This reverts commit a655f03a1e.
2023-02-08 15:57:27 +00:00
Ben Potter 0ccab0c420 fix: do not build Packer images on dry runs (#6105) 2023-02-08 15:51:16 +00:00
Dean Sheather b5e5959649 chore: fix flake in create-admin-user test (#6103) 2023-02-08 15:36:43 +00:00
Kira Pilot 3da33d23a4 chore: fix status color for redirects on audit page (#6096) 2023-02-08 09:40:51 -05:00
Dean Sheather e17ed9f5e6 chore: diable ironbank image scanning (#6104) 2023-02-08 14:40:27 +00:00
Mathias Fredriksson 33f2c8fef5 ci: Fix scripts/release/publish.sh execrelative path (#6101)
Behavior of `lib.sh` changed in: #5934
2023-02-08 13:32:06 +00:00
Mathias Fredriksson f6da0a6945 ci: Fix silent missing metadata for release notes (#6089)
* Fix use of `mapfile < <(cmd)` which silently hid errors

* Fix script paths since `SCRIPT_DIR` changed in `lib.sh`

* Set `GITHUB_TOKEN` in release.yaml
2023-02-08 14:40:52 +02:00
Marcin Tojek 1dc477819e feat: render Markdown in rich parameter descriptions (#6098) 2023-02-08 12:57:12 +01:00
Eric Paulsen f24547ecb1 feat: add iron bank Dockerfile & manifest (#5934)
* feat: add iron bank Dockerfile & manifest

Co-authored-by: Dean Sheather <dean@deansheather.com>

* add: tfrc file

* mv: ironbank/ /scripts

* fixup! Merge branch 'main' into iron-bank

* feat: add ironbank trivy scanning

* fixup! feat: add ironbank trivy scanning

* fixup! feat: add ironbank trivy scanning

* fixup! feat: add ironbank trivy scanning

* fixup! feat: add ironbank trivy scanning

---------

Co-authored-by: Dean Sheather <dean@deansheather.com>
2023-02-07 18:09:33 -05:00
Kyle Carberry 691495d761 feat: add expanded_directory to the agent for extension support (#6087)
This will enable opening the default `dir` of an agent in
the VS Code extension!
2023-02-07 21:35:09 +00:00
Kyle Carberry f6effdb63e fix: redirect the user to the home directory if dir is not set (#6085)
This was blocking SSH connections from being established if a dir
that wasn't created yet is set.
2023-02-07 20:28:41 +00:00
Colin Adler bde4ffebe5 docs: add auth paragraph about oidc group sync (#6064) 2023-02-07 13:22:02 -06:00
Mathias Fredriksson c63dcf13c2 fix(dogfood): Enable pipefail for startup_script (#6017) 2023-02-07 20:15:09 +02:00
Ben Potter a5f3f02ef8 fix: duplicate list when updating workspaces (#6032) 2023-02-07 10:26:04 -06:00
Kyle Carberry e7ebcb54dc fix: use workspace name when opening links via the terminal (#6077)
This was using the `<workspace>.<agent>` syntax before, which was invalid.
2023-02-07 09:58:11 -06:00
Ben Potter c82e38e2d8 docs: using Coder behind a corporate proxy (#6079)
* docs: using Coder with a corporate proxy

* fix typo
2023-02-07 15:11:03 +00:00
Kira Pilot 4155b085b7 feat: add preset filter for audit logins (#6066) 2023-02-07 09:17:06 -05:00
Kyle Carberry bed37b4208 feat: use wildcard url for local links in the web terminal (#6070) 2023-02-07 07:21:06 -06:00
Marcin Tojek 135a4d87f1 fix: use correct migration number (#6071) 2023-02-07 10:28:44 +01:00
Marcin Tojek b86bce8494 feat!: Validate monotonic numbers for rich parameters (#6046)
* Database changes

* protobuf

* Fix: docs

* workspaces_test

* Validation in coderd

* Fix: resources

* omitempty

* UI changes

* UI tests

* fix
2023-02-07 09:36:13 +01:00
Kyle Carberry e3ae664a29 fix: add typegen for templateVersionEditorXService (#6069)
This was borked before, and actually broken!
2023-02-06 20:30:54 -06:00
Kyle Carberry dd9e1f3d3f feat: add template editor to the ui (#5963)
* Add initial editor

* Fix editor file being reset onChange

* Add updating the active build version

* Update nav height

* Add tabs

* Fix title

* Hide timestamps in build logs

* Add create file dialog

* Add validation for empty path

* Hide resources tab

* Fix label names

* Add rename and delete

* Improve UX

* Add padding to the editor

* Add dirty state

* Hide build logs until a build is made

* Add stories

* Add experiment to enable the template editor

* Fix linting errors

* Fix duplicate fields

* Fix theme type
2023-02-07 01:24:04 +00:00
Kyle Carberry 71a893764e chore: remove CreateAnotherUserWithUser (#6068)
This was not idiomatic Go!
2023-02-06 23:48:21 +00:00
Colin Adler b81d8464df fix: audit log query when Postgres TZ isn't UTC (#6067) 2023-02-06 21:36:39 +00:00
Ben Potter d9e22d74ba fix: wrong URL in rootless podman docs (#6063) 2023-02-06 15:32:59 -06:00
Ammar Bandukwala 3724d81413 chore: simplify error handling in template push (#6065) 2023-02-06 20:35:48 +00:00
Kira Pilot 46fe59f5e7 feat: audit login (#5925)
* added migration for api key resource

* sort of working

* auditing login

* passing  the correct user id

* added and fixed tests

* gen documentation

* formatting and lint

* lint

* audit Github oauth and write tests

* audit oauth and write  tests

* added defer fn for login error auditing

* fixed test

* feat: audit logout (#5998)

* Update coderd/userauth.go

Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>

* fix test

* bypassing diff generation if login/logout

* lint

---------

Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>
2023-02-06 15:12:50 -05:00
Dean Sheather 060eeed5c3 chore: fix depot build pt.2 (#6059) 2023-02-07 03:26:29 +10:00
Kyle Carberry bdddc3e7ae fix: change auto-start to automatically update workspaces (#6053)
Fixes #6049.
2023-02-06 11:12:58 -06:00
Dean Sheather d6947aeaca chore: fix depot build (#6057) 2023-02-06 16:49:33 +00:00
Dean Sheather b45c445255 feat: add git to Docker image (#6034) 2023-02-07 02:30:35 +10:00
Ben Potter a655f03a1e fix: open terminal and coder_app in a new tab, not window (#6044)
* fix!: open coder_app in a new tab, not window

* terminal too
2023-02-06 10:22:24 -06:00
Dean Sheather 4fe221a700 feat: add flag to disable password auth (#5991)
Adds a flag --disable-password-auth that prevents the password login
endpoint from working unless the user has the "owner" (aka. site admin)
role.

Adds a subcommand `coder server create-admin-user` which creates a user
directly in the database with the "owner" role, the "admin" role in
every organization, and password auth. This is to avoid lock-out
situations where all accounts have the login type set to an identity
provider and nobody can login.
2023-02-06 14:58:21 +00:00
Ben Potter 968d7e4dc5 docs: rootless podman support (#6026)
* rootless podman WIP

* docs: rootless podman support
2023-02-06 08:05:38 -06:00
Ben Potter e70b3f2973 chore: add alias helper to develop.sh (#6031)
* chore: add alias helper to develop.sh

* restore formatting

* change alias from feedback
2023-02-06 05:02:34 +00:00
Ben Potter 5931d12d4b chore: use node 16 in dogfood images (#5939) 2023-02-05 22:48:41 -06:00
Ben Potter 90bc5d5b5f docs: add note around offline docs provider versions (#6018) 2023-02-06 04:36:20 +00:00
sharkymark a5e386e54b chore: remove jetbrains projector web ide docs, examples. specify no support (#6033) 2023-02-05 19:40:40 -06:00
Ammar Bandukwala f096915c27 chore(ci): automatically delete stale branches (#6036) 2023-02-04 15:18:11 -06:00
Ammar Bandukwala a422cc00e8 Stream template upload (#6035)
Resolves #5718
2023-02-04 20:07:09 +00:00
Steven Masley 77fd34be94 chore: Action consts should actually be typed as an Action (#6027) 2023-02-03 20:36:37 +00:00
Steven Masley b359dbbd8b chore: Allow RecordingAuthorizer to record multiple rbac authz calls (#6024)
* chore: Allow RecordingAuthorizer to record multiple rbac authz calls

Prior iteration only recorded the last call. This is required for
more comprehensive testing
2023-02-03 19:03:46 +00:00
Cian Johnston 571f5d0e02 chore: add log_statement=all for test-postgres-docker (#6025) 2023-02-03 18:58:31 +00:00
Kyle Carberry 2c2bbcc019 chore: update tests to support fish (#6023)
* fix: update tests to add fish support

* Track connections for SSH sessions to prevent leaks

* Revert SSH conn handling
2023-02-03 12:25:11 -06:00
Dean Sheather cf9abe3a6c feat: add session expiry control flags (#5976)
Adds --session-duration which lets admins customize the default session
expiration for browser sessions.

Adds --disable-session-expiry-refresh which allows admins to prevent
session expiry from being automatically bumped upon the API key being
used.
2023-02-03 17:38:36 +00:00
mh013370 2285a5e8a0 feat: add ability to deploy extra k8s yamls with helm chart (#5942) 2023-02-03 17:32:02 +00:00
Steven Masley a750b1948b test: Use database.Now() for UTC in all tests (#6022)
Fixes a lot of comparison issues with timezones
2023-02-03 17:13:54 +00:00
Mathias Fredriksson 95ff29c2be test: Fix golden gen for long wd paths (#6021) 2023-02-03 18:43:33 +02:00
Bruno Quaresma dffd7953bc fix(site): Minor UI fixes related to avatar components (#6019) 2023-02-03 13:09:16 -03:00
Kira Pilot 6c90701a73 chore: ignore trend line in storybook (#6003) 2023-02-03 09:05:38 -05:00
Steven Masley aab9e3a0f7 chore: Add more objects to dbgen (#6013)
* chore: Add WorkspaceApps to dbgen

* GitSSHKey, UserLink, GitAuthLink
2023-02-03 09:34:35 +00:00
Steven Masley fd2f9dc176 test: Fix unit test to use dbfake over databasefake (#6014) 2023-02-03 03:55:26 +00:00
Kyle Carberry 381d6674ca chore: add install_source to telemetry (#6008)
This will help determine the number of installs from marketplaces!
2023-02-03 01:30:54 +00:00
Steven Masley 8b424f03c2 chore: Rename databasefake --> dbfake (#6011) 2023-02-02 19:28:55 -06:00
Bruno Quaresma f60f06e2c6 fix(site): Only display fields with redisplay enabled during workspace creation (#6004)
* fix(site): Only display fields with redisplay_value during workspace creation

* Fix test

---------

Co-authored-by: Kyle Carberry <kyle@carberry.com>
2023-02-03 01:28:47 +00:00
Steven Masley 2384e9c565 fix: Do not try and write to malformed ssh configs (#6000)
Abort writing the ssh config if it has:
- Out of order coder headers
- More than 1 of each coder header
- Missing 1 or the other coder header
2023-02-02 19:23:42 -06:00
Ben Potter c16b93847a feat: build Packer images every release (#6009) 2023-02-03 01:01:06 +00:00
Steven Masley 2478012827 chore: Add organizationmember and parameter gen functions (#6007) 2023-02-02 18:24:59 -06:00
Steven Masley 41e52310bf chore: Add more dbgen functions (#6005) 2023-02-02 17:21:29 -06:00
Steven Masley 5fe4819669 chore: Pass through AllowUserCancelWorkspaceJobs value to fake db insert (#6006) 2023-02-02 23:08:57 +00:00
Kyle Carberry a5e8911d67 fix: index template versions by template and name (#5993)
* fix: index template versions by template and name

We were incorrectly returning template versions by name relative
to organizations. This could result in an incorrect version being
returned if multiple templates had versions with the same name.

* Fix auth referencing

* Fix route location

* Fix authorize route name

* Fix previous call

* Fix authorize route name
2023-02-02 15:47:53 -06:00
Bruno Quaresma ea7e55fcf9 refactor(site): Adjust icon sizes and show password btn in login page (#5992) 2023-02-02 18:28:30 -03:00
Bruno Quaresma 9ff313a260 refactor(site): Remove version and add template link in workspaces page (#5990) 2023-02-02 18:27:56 -03:00
Kira Pilot a70e722e7f fix: hide IP on workspace build logs (#5997) 2023-02-02 20:22:36 +00:00
Kyle Carberry 2fab310ca4 fix: match ubuntu tags on dogfood (#5996)
* fix: match ubuntu tags on dogfood

golangci-lint needs GLIBC>=2.32 which made me notice
that we're building binaries on a difference Ubuntu
version than we dev on.

* Fix sources
2023-02-02 13:58:53 -06:00
Colin Adler 496138b086 feat: assign users to groups returned by OIDC provider (#5965) 2023-02-02 19:53:48 +00:00
Kyle Carberry 026b1cd2a4 chore: update to go 1.20 (#5968)
Co-authored-by: Colin Adler <colin1adler@gmail.com>
2023-02-02 12:36:27 -06:00
Bruno Quaresma 4df1031f8b refactor(site): Add press any key option to reconnect on terminal screen (#5969) 2023-02-02 15:19:18 -03:00
Bruno Quaresma 7b49517c18 refactor(site): Add more info on agent outdated tooltip and update action (#5967) 2023-02-02 15:18:59 -03:00
dependabot[bot] 5f089cb5eb chore: bump aquasecurity/trivy-action from 0.5.0 to 0.8.0 (#5944)
Bumps [aquasecurity/trivy-action](https://github.com/aquasecurity/trivy-action) from 0.5.0 to 0.8.0.
- [Release notes](https://github.com/aquasecurity/trivy-action/releases)
- [Commits](https://github.com/aquasecurity/trivy-action/compare/7b7aa264d83dc58691451798b4d117d53d21edfe...9ab158e8597f3b310480b9a69402b419bc03dbd5)

---
updated-dependencies:
- dependency-name: aquasecurity/trivy-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-02 12:11:09 -06:00
dependabot[bot] 5d9263f050 chore: bump chromatic from 6.11.4 to 6.15.0 in /site (#5954)
Bumps [chromatic](https://github.com/chromaui/chromatic-cli) from 6.11.4 to 6.15.0.
- [Release notes](https://github.com/chromaui/chromatic-cli/releases)
- [Changelog](https://github.com/chromaui/chromatic-cli/blob/main/CHANGELOG.md)
- [Commits](https://github.com/chromaui/chromatic-cli/compare/v6.11.4...v6.15.0)

---
updated-dependencies:
- dependency-name: chromatic
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-02 12:06:51 -06:00
dependabot[bot] e6426d477f chore: bump google.golang.org/grpc from 1.51.0 to 1.52.3 (#5949)
Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.51.0 to 1.52.3.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](https://github.com/grpc/grpc-go/compare/v1.51.0...v1.52.3)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-02 12:05:41 -06:00
dependabot[bot] f5242be0d1 chore: bump github.com/valyala/fasthttp from 1.43.0 to 1.44.0 (#5951)
Bumps [github.com/valyala/fasthttp](https://github.com/valyala/fasthttp) from 1.43.0 to 1.44.0.
- [Release notes](https://github.com/valyala/fasthttp/releases)
- [Commits](https://github.com/valyala/fasthttp/compare/v1.43.0...v1.44.0)

---
updated-dependencies:
- dependency-name: github.com/valyala/fasthttp
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-02 12:05:30 -06:00
Kyle Carberry 944c9f6307 chore: downgrade linux runner size to 8 cores (#5984)
I doubt the difference in speed is worth the 2x cost.
2023-02-02 12:00:19 -06:00
Kyle Carberry be00e2541c chore: remove unused workspace_owner_count field (#5958)
This added unnecessary database load, because it's not used!
2023-02-02 17:59:43 +00:00
dependabot[bot] 92c5be971c chore: bump @typescript-eslint/eslint-plugin in /site (#5955)
Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 5.38.1 to 5.50.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.50.0/packages/eslint-plugin)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/eslint-plugin"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-02 11:45:48 -06:00
dependabot[bot] c4b70f3ae1 chore: bump eslint from 8.29.0 to 8.33.0 in /site (#5956)
Bumps [eslint](https://github.com/eslint/eslint) from 8.29.0 to 8.33.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.29.0...v8.33.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-02 11:45:29 -06:00
dependabot[bot] 57ad53c850 chore: bump github.com/moby/moby (#5947)
Bumps [github.com/moby/moby](https://github.com/moby/moby) from 20.10.21+incompatible to 20.10.23+incompatible.
- [Release notes](https://github.com/moby/moby/releases)
- [Commits](https://github.com/moby/moby/compare/v20.10.21...v20.10.23)

---
updated-dependencies:
- dependency-name: github.com/moby/moby
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-02 11:44:55 -06:00
dependabot[bot] f545586320 chore: bump ludeeus/action-shellcheck from 1.1.0 to 2.0.0 (#5945)
Bumps [ludeeus/action-shellcheck](https://github.com/ludeeus/action-shellcheck) from 1.1.0 to 2.0.0.
- [Release notes](https://github.com/ludeeus/action-shellcheck/releases)
- [Commits](https://github.com/ludeeus/action-shellcheck/compare/1.1.0...2.0.0)

---
updated-dependencies:
- dependency-name: ludeeus/action-shellcheck
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-02 11:44:43 -06:00
dependabot[bot] e8e61250a6 chore: bump docker/build-push-action from 3 to 4 (#5946)
Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 3 to 4.
- [Release notes](https://github.com/docker/build-push-action/releases)
- [Commits](https://github.com/docker/build-push-action/compare/v3...v4)

---
updated-dependencies:
- dependency-name: docker/build-push-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-02 11:44:27 -06:00
dependabot[bot] 445811b0e0 chore: bump golang.org/x/crypto from 0.3.0 to 0.5.0 (#5950)
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.3.0 to 0.5.0.
- [Release notes](https://github.com/golang/crypto/releases)
- [Commits](https://github.com/golang/crypto/compare/v0.3.0...v0.5.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-02 11:44:14 -06:00
Kyle Carberry b9b402cd0c feat!: generate a self-signed certificate if no certificates are specified (#5973)
* feat: generate a self-signed certificate if no certificates are specified

Clouds like AWS automatically navigate to https://<ip-here>. This
allows us to bind to that immediately, serve a self-signed certificate,
then reroute to the access URL.

* Add new flag and deprecate old one

* Fix redirect if not using tunnel

* Add deprecation notice

* Fix TLS redirect

* Run `make gen`

* Fix bad test

* Fix gen
2023-02-02 17:08:35 +00:00
Marcin Tojek e27f7accd7 feat: Group immutable and mutable rich parameters (#5975) 2023-02-02 18:01:18 +01:00
Steven Masley ab1f6ce090 fix: Deleting a user from a group should only delete from a single group (#5977) 2023-02-02 09:46:42 -06:00
Marcin Tojek 271d68c862 feat: Disallow using legacy params with rich params (#5974)
* feat: Disallow using legacy params with rich params

* Fix

* nolint
2023-02-02 16:44:57 +01:00
Bruno Quaresma 01ebfdc9dd fiix(site): Fix custom logo size in Safari (#5966) 2023-02-02 10:42:05 -03:00
Bruno Quaresma c9f3acabd3 fix(site): Don't hide/show errors during requests (#5962) 2023-02-02 10:38:05 -03:00
Bruno Quaresma 8ef0306c08 Revert "docs: Change console to shell and remove unused elements (#5960)" (#5964)
This reverts commit 61dcf643e8.
2023-02-01 17:05:45 -03:00
Ben Potter 936bd5b231 chore: fix broken link in offline docs 2023-02-01 13:16:46 -06:00
Ben Potter bca6244c4e chore: change docs links to latest release 2023-02-01 13:14:49 -06:00
Bruno Quaresma 61dcf643e8 docs: Change console to shell and remove unused elements (#5960) 2023-02-01 18:27:11 +00:00
Mathias Fredriksson e6f5623627 chore: Rename agent statistics server to http api server (#5961) 2023-02-01 20:05:57 +02:00
Marcin Tojek f9ae105a26 feat: Adjust forms to include Rich Parameters (#5856)
* XService: GetTemplateParameters

* Rich parameter input shows up

* Render option icons

* Icons

* WIP

* For testing purposes: template

* Fix: useState

* WIP: dynamic validation

* Yup validation

* Translations

* Remove temporary template

* make fmt

* WIP

* Fix: tests

* Fix: fmt

* URL param

* Refactor

* Test: rich param value

* Storybook

* Fix

* Refactor for testing purposes

* Typo

* test: string validation

* Button: build parameters

* Full screen page

* Fix: navigate

* XState done

* refactor: postWorkspaceBuild

* RichParameterInput rendered

* Fix: bad initial value

* Validation works

* Maybe

* Fix

* Go back button

* GoBack button

* Form

* Fix

* Storybook

* Fix: CreateWorkspacePage

* fmt

* Test

* ns

* fmt

* All tests

* feat: WorkspaceActions depend on template parameters

* Fix
2023-02-01 18:13:11 +01:00
Ben Potter d5e2454b1b chore: rework docker in docker docs (#5876)
* chore: rework docker in docker docs

* Update docs/templates/docker-in-docker.md

Co-authored-by: Kyle Carberry <kyle@coder.com>

* fix typos

---------

Co-authored-by: Kyle Carberry <kyle@coder.com>
2023-02-01 14:55:57 +00:00
Mathias Fredriksson 52ace4b207 fix(agent): Work around lumberjack reopening log file after close (#5941) 2023-02-01 16:04:09 +02:00
Ammar Bandukwala 89bf8dd169 docs: fix broken link in secrets.md
Resolves #5888
2023-01-31 22:49:08 +00:00
Steven Masley 4a6fc40949 feat: Add database data generator to make fakedbs easier to populate (#5922)
* feat: Add database data generator to make fakedbs easier to populate
2023-01-31 15:10:03 -06:00
Jon Ayers c162c0f284 fix: omit users for 'Everyone' group in response (#5937) 2023-01-31 13:30:20 -06:00
Arthur Normand 69fce0488e feat: Allow hiding password auth, changing OpenID Connect text and OpenID Connect icon (#5101)
* Allow hiding password entry, changing OpenID Connect text and OpenID Connect icon

* Docs

* Cleaning

* Fix Prettier and Go test and TS compile error

* Fix LoginPage test

* Prettier

* Fix storybook

* Add query param to un-hide password auth

* Cleaning

* Hide password by default when OIDC enabled

* Ran prettier, updated goldenfiles and ran "make gen"

* Fixed and added LoginPage test

* Ran prettier

* PR Feedback and split up SignInForm.tsx

* Updated golden files

* Fix auto-genned-files

* make gen -B

* Revert provisioner files?

* Fix lint error

---------

Co-authored-by: Kyle Carberry <kyle@coder.com>
2023-01-31 18:33:25 +00:00
Dean Sheather 480f3b6e43 fix: correct gpg key secret name (#5932) 2023-02-01 04:14:05 +10:00
Ben Potter aa53b86a2d chore: add some helpers to install/upgrade Coder (#5926)
* chore: add some helpers to install/upgrade Coder

* mention winget
2023-01-31 17:33:42 +00:00
Ben Potter ea4a845248 docs: dedicated instructions for Windows installer (#5924)
* docs: dedicated instructions for Windows installer

* changes from feedback
2023-01-31 17:26:37 +00:00
Spike Curtis ac4adabb0a feat: set service account name in helm (#5913)
Signed-off-by: Spike Curtis <spike@coder.com>
2023-01-31 10:35:32 +04:00
Eric Paulsen 5290d5b14a docs: add gitauth validate url var (#5927) 2023-01-30 20:35:22 -05:00
Kyle Carberry 9c1d67e192 docs: support dark and light mode in the readme (#5928)
Shoutout @cmoog
2023-01-30 16:53:54 -06:00
Eric Paulsen e6a3ce7180 docs: add GitLab auth docs (#5923) 2023-01-30 16:14:18 -05:00
Kira Pilot b31b0fd189 fix: audit log broken build links (#5895)
* pushing for guidance

* added test

* PR feedback

* fixed tests

* Update coderd/audit.go

Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>

* runnig make gen

---------

Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>
2023-01-30 18:43:29 +00:00
Kira Pilot 88b5d42967 chore: add more specificity to check_enterprise_imports script (#5920) 2023-01-30 12:00:19 -05:00
Mathias Fredriksson f4d6afb01d feat(agent): Allow specifying log directory via flag or env (#5915) 2023-01-30 18:39:52 +02:00
Kira Pilot fa5b6125a9 fix: ensure fields show up for group resource in docs (#5918)
* fix: ensure fields show up for group resource  in docs

* ran prettier
2023-01-30 10:54:58 -05:00
Marcin Tojek 23176bf036 feat: Support rich parameters in autobuilds (#5916) 2023-01-30 15:34:38 +01:00
Mathias Fredriksson cf8d4029fb feat(agent): Handle signals and shutdown gracefully (#5914)
This change allows the agent to handle common shutdown signals like
interrupt, hangup and terminate and initiate a graceful shutdown.

As long as terraform providers initiate graceful shutdowns via the
aforementioned signals, things like SSH connections will be closed
immediately on shutdown instead of being left hanging/timing out due to
the agent being abruptly killed.

Refs: #4677, #5901
2023-01-30 15:59:13 +02:00
sharkymark 91ef8d90d5 chore: remove code-server release limitation and add image push policy in kubernetes example template (#5831)
* chore: remove code-server release limitation and add image push policy

* restore code-server changes

* chore: remove spaces in pod space

* Format terraform

---------

Co-authored-by: Eric Paulsen <ericpaulsen@coder.com>
Co-authored-by: Kyle Carberry <kyle@carberry.com>
2023-01-30 06:58:45 -05:00
Kyle Carberry 896158c352 fix: remove authentication requirement for /users/login (#5717)
This was noticed by a member of our Discord being incorrectly documented!

https://discord.com/channels/747933592273027093/1063494965130432632/1063503805016182875
2023-01-30 02:46:04 +00:00
dependabot[bot] f5db4bc8be chore: bump ua-parser-js from 1.0.2 to 1.0.33 in /site (#5842)
Bumps [ua-parser-js](https://github.com/faisalman/ua-parser-js) from 1.0.2 to 1.0.33.
- [Release notes](https://github.com/faisalman/ua-parser-js/releases)
- [Changelog](https://github.com/faisalman/ua-parser-js/blob/master/changelog.md)
- [Commits](https://github.com/faisalman/ua-parser-js/compare/1.0.2...1.0.33)

---
updated-dependencies:
- dependency-name: ua-parser-js
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-29 20:33:45 -06:00
mh013370 d5d9cc8d8a feat: add init containers to the helm chart (#5874)
* add init containers to coder deployment

* fix formatting issues
2023-01-29 20:02:55 -06:00
dependabot[bot] 3980f15340 chore: bump crate-ci/typos from 1.13.3 to 1.13.9 (#5906)
Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.13.3 to 1.13.9.
- [Release notes](https://github.com/crate-ci/typos/releases)
- [Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md)
- [Commits](https://github.com/crate-ci/typos/compare/v1.13.3...v1.13.9)

---
updated-dependencies:
- dependency-name: crate-ci/typos
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-30 01:56:34 +00:00
Ammar Bandukwala 4eaa2d63b0 chore(.github): relax stale bot (#5902)
At 60 days it was more spammy than helpful.
2023-01-29 19:52:44 -06:00
Kyle Carberry 12314d7dc5 update readme (#5911) 2023-01-29 19:45:00 -06:00
Kyle Carberry b423218615 chore: remove markdown-lint-check
It's broken for some unfortunate reason!
2023-01-29 23:34:52 +00:00
Kyle Carberry b4a1c32ed3 chore: run markdown-link-check before linting types 2023-01-29 23:29:57 +00:00
Kyle Carberry 0d08065488 fix: use a waitgroup to ensure all connections are cleaned up in agent (#5910)
* fix: use a waitgroup to ensure all connections are cleaned up in agent

There was a race where connections would be created at the same time as close.
The `net.Conn` produced by Tailscale doesn't close then the listener does.

* Remove accidental test
2023-01-29 17:20:30 -06:00
Kyle Carberry ce36a84dd5 fix: specify folder path for markdown-lint-check
This was checking node_modules I believe causing it to hang.
2023-01-29 22:36:47 +00:00
Kyle Carberry a911ddaa7b fix: access GetUserByID in database fake without lock to resolve race (#5909)
See: https://github.com/coder/coder/actions/runs/4038615993/jobs/6942750837
2023-01-29 16:03:29 -06:00
Kyle Carberry 7ad87505c8 chore: move agent functions from codersdk into agentsdk (#5903)
* chore: rename `AgentConn` to `WorkspaceAgentConn`

The codersdk was becoming bloated with consts for the workspace
agent that made no sense to a reader. `Tailnet*` is an example
of these consts.

* chore: remove `Get` prefix from *Client functions

* chore: remove `BypassRatelimits` option in `codersdk.Client`

It feels wrong to have this as a direct option because it's so infrequently
needed by API callers. It's better to directly modify headers in the two
places that we actually use it.

* Merge `appearance.go` and `buildinfo.go` into `deployment.go`

* Merge `experiments.go` and `features.go` into `deployment.go`

* Fix `make gen` referencing old type names

* Merge `error.go` into `client.go`

`codersdk.Response` lived in `error.go`, which is wrong.

* chore: refactor workspace agent functions into agentsdk

It was odd conflating the codersdk that clients should use
with functions that only the agent should use. This separates
them into two SDKs that are closely coupled, but separate.

* Merge `insights.go` into `deployment.go`

* Merge `organizationmember.go` into `organizations.go`

* Merge `quota.go` into `workspaces.go`

* Rename `sse.go` to `serversentevents.go`

* Rename `codersdk.WorkspaceAppHostResponse` to `codersdk.AppHostResponse`

* Format `.vscode/settings.json`

* Fix outdated naming in `api.ts`

* Fix app host response

* Fix unsupported type

* Fix imported type
2023-01-29 15:47:24 -06:00
Kyle Carberry e49f41652f chore: merge codeql checks to run in parallel (#5907)
* chore: merge codeql checks to run in parallel

This reduces a check and should maintain ~the same CI time.

* fix: close reconnecting pty conn when exiting agent

Fixes https://github.com/coder/coder/actions/runs/4038282899/jobs/6942170850

* Fix closing when agent fails

* Fix conpty

* Fix contrib

* Skip runner tests for being flakes

* Fix gpg key test

* Fix golden files

* Fix comments

* Fix closed

* Fix capitalized title

* Add a timeout when checking for dead links
2023-01-29 15:28:22 -06:00
Kyle Carberry 8487127f5c chore: skip reconnecting pty scale tests (#5908)
* fix: close reconnecting pty conn when exiting agent

Fixes https://github.com/coder/coder/actions/runs/4038282899/jobs/6942170850

* Fix conpty

* Fix contrib

* Skip runner tests for being flakes

* Fix gpg key test

* Fix golden files

* Fix comments
2023-01-29 14:53:49 -06:00
Kyle Carberry 33c6260efb chore: merge CI linting jobs (#5904)
* chore: merge CI linting jobs

* Merge the `markdown-lint-check` step into `lint`

* Rename `coder.yaml` to `ci.yaml`

* Improve casing of security workflow

* Remove unused workflows and merge into contrib

* Format ci.yaml

* Fix CodeQL language

* Fix github action name
2023-01-29 13:16:48 -06:00
Kyle Carberry eaf1b95e70 chore: disable auto generated tag for CLI docs (#5905)
This was causing `make gen` to fail as the days went on!
2023-01-29 12:58:12 -06:00
sharkymark 2312bc4a6e docs: added alpha jetbrains gateway coder plugin | remove code-server version parameter (#5900) 2023-01-28 19:09:41 -06:00
Kyle Carberry 7880b941b8 docs: remove quote from README 2023-01-27 21:24:54 -06:00
Mathias Fredriksson a1212014df chore(examples): Add login_before_ready and startup_script_timeout (#5880) 2023-01-27 21:01:48 +00:00
Mathias Fredriksson 90c4d5d28a docs: Document agent readiness issues (startup script) (#5877)
Refs: #5749, #5851
2023-01-27 22:23:47 +02:00
Mathias Fredriksson 981cac5e28 chore: Invert delay_login_until_ready, now login_before_ready (#5893) 2023-01-27 20:07:47 +00:00
Kira Pilot 8a5760a2fe chore: replace AuditableGroup label in docs (#5894) 2023-01-27 13:36:00 -05:00
Bruno Quaresma e0d48e7d79 docs: Add CLI docs (#5879) 2023-01-27 18:10:40 +00:00
Mathias Fredriksson a753703e47 feat(cli): Add support for delay_login_until_ready (#5851) 2023-01-27 19:05:40 +02:00
Kira Pilot cf93fbd39a chore: update Audit docs to include Audit Actions (#5887)
* chore: update Audit docs to include Audit Actions

* regenerated audit docs

* adjusted check_enterprise_imports.sh

* PR feedback

* changing script back for now as CI faiiling
2023-01-27 11:50:21 -05:00
Kyle Carberry b20cb993bd fix: loop variable captured by func literal in parameters test (#5878)
I noticed this when adding a new parameter type. There's a test
case for an empty string that returned false for validation,
but appears like it could be true.

If there is no value for a string, then the default is used.
In this case there is no default, but that's technically fine
I believe.
2023-01-27 09:37:55 -06:00
Kira Pilot e663eaad96 chore: remove flaking e2e test (#5884) 2023-01-26 23:10:01 -03:00
Kira Pilot 3d58e6912a chore: removing unaudited resources (#5885)
* chore: removing unaudited resources

* cleaned up tests

* CI errors
2023-01-26 18:14:09 -05:00
Kira Pilot e2bea2d20f chore: autogenerate audit log documentation (#5862)
* added script for table creation

* added tags to audit-logs.md

* removed log

* removed empty block line

* PR feedback

* modify check_unstaged

* third times the charm maybe

* spelling

* relative path

* excluding from the right script this time

* sorted resources to ensure table order

* running make cmd

* running make again

* ensuring order on subtable
2023-01-26 18:12:12 -05:00
Colin Adler cc694a55bc feat: add debug info to HA coordinator (#5883) 2023-01-26 16:32:38 -06:00
Colin Adler 52ecd35c8f fix(wsconncache): only allow one peer per connection (#5886)
If an agent went away and reconnected, the wsconncache connection would
be polluted for about 10m because there would be two peers with the
same IP. The old peer always had priority, which caused the dashboard to
try and always dial the old peer until it was removed.

Fixes: https://github.com/coder/coder/issues/5292
2023-01-26 22:23:35 +00:00
Steven Masley b0a16150a3 chore: Implement standard rbac.Subject to be reused everywhere (#5881)
* chore: Implement standard rbac.Subject to be reused everywhere

An rbac subject is created in multiple spots because of the way we
expand roles, scopes, etc. This difference in use creates a list
of arguments which is unwieldy.

Use of the expander interface lets us conform to a single subject
in every case
2023-01-26 14:42:54 -06:00
ElliotG 5c54d8b8cd docs: create a SECURITY.md file (#5875) 2023-01-26 14:13:36 -06:00
Mathias Fredriksson 496beae807 Revert "feat(dogfood): install nix package manager (#5308)" (#5871) 2023-01-26 15:41:59 +00:00
Geoffrey Huntley bfc8a1094b feat(dogfood): install nix package manager (#5308)
Co-authored-by: Dean Sheather <dean@deansheather.com>
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
Co-authored-by: Kyle Carberry <kyle@carberry.com>
2023-01-26 16:39:30 +02:00
Bruno Quaresma 721957dee3 chore(site): Ignore progress build bar on Chromatic (#5869) 2023-01-26 10:45:59 -03:00
Josh Goldberg 43a441fe63 chore(site): align ESLint config to typescript-eslint's recommended-requiring-type-checking (#5797) 2023-01-26 10:32:50 -03:00
Colin Adler dd8eab5675 fix: cache disconnected agent names in tailnet coordinator debug (#5870) 2023-01-25 21:23:14 -06:00
Presley Pizzo 16d8cc4176 feat(site): Add deployment-wide DAU chart (#5810) 2023-01-25 22:03:47 -03:00
Bruno Quaresma e7b8318b87 refactor(site): Normalize avatar components (#5860) 2023-01-26 00:54:53 +00:00
Colin Adler 233492b75d fix: ensure coordinator debug output is always sorted (#5867) 2023-01-26 00:29:51 +00:00
Ammar Bandukwala 5da4b5358a docs: use and in enterprise feature matrix (#5866)
The grey X was ambiguous.
2023-01-25 22:58:53 +00:00
Eric Paulsen 98011570be fix: agent log location (#5742) 2023-01-25 17:45:50 -05:00
Cian Johnston 8735f51047 feat(coder): add authz_querier experiment (#5858)
* feat(coderd): add authz_querier experiment

* coderdtest: wire up authz_querier

* wire up AuthzQuerier in coderd

* remove things that do not yet exist in this timeline

* add newline

* comment unreachable code
2023-01-25 21:35:53 +00:00
Colin Adler 1cd5f38cb0 feat: add debug server for tailnet coordinators (#5861)
Implements a Tailscale-like debug server for our in-memory coordinator. This should provide some visibility into why connections could be failing.
Resolves: https://github.com/coder/coder/issues/5845

![image](https://user-images.githubusercontent.com/6332295/214680832-2724d633-2d54-44d6-a7ce-5841e5824ee5.png)
2023-01-25 21:27:36 +00:00
Kyle Carberry 8830ddfd56 docs: update the readme to reduce unnecessary text (#5837)
The README was starting to get quite large, and I felt it was a bit bloaty.

- Removes Twitter badge (the API was removed, so it wasn't working anyways)
- Adds tagline to the title (an experiment, but worth a shot)
- Reduces highlights
- Removes recommended reading (people want to get started asap on a repo)
- Updates doc links `/docs/coder-oss` -> `/docs/v2`
- Moves comparison to the bottom
- Removes adopters.md (we never promoted this, so it hasn't been used)
2023-01-25 14:49:15 -06:00
Steven Masley 08412fd1af chore: Remove unused SQL functions (#5857)
* chore: Remove unused sql functions
- GetProvisionerDaemonByID
- UpdateProvisionerDaemonByID
- GetUserGroups
- GetWorkspaceCountByUserID
- GetLatestAgentStat
2023-01-25 11:30:12 -06:00
Steven Masley b678309fc9 chore: Authz should support non-named roles (#5855)
* chore: Authz should support non-named roles

Named roles are a construct for users to assign/interact with roles.
For authzlayer implementation, we need to create "system" users.
To enforce strict security, we are making specific roles with
the exact required permissions for the system action.
These new roles should not be available to the user. There is a
clear code divide with this implementation that allows a RoleNames
implemenation for users to user, and system users can create their
own implementation
2023-01-25 10:54:16 -06:00
Bruno Quaresma de66f0d540 docs: Add frontend guide (#5852) 2023-01-25 16:15:06 +00:00
Mathias Fredriksson 5c5ddc6b23 fix(site): Hide agent lifecycle unless opted in via delay_login_until_ready (#5850)
Refs: #5835, #5749
2023-01-25 15:23:31 +02:00
Mathias Fredriksson 78ede50be8 ci: Add authors to release notes (#5834) 2023-01-25 11:13:42 +02:00
Kira Pilot 322a4d93e1 feat: add audit log filter for autostarted and autostopped workspace builds (#5830)
* added query

* fixed query

* added example to dropdown

* added documentation

* added test

* fixed formatting

* fixed format
2023-01-24 15:34:29 -05:00
Bruno Quaresma 36384aa3c1 chore(site): Use react-query and refactor the workspaces page to use it (#5838) 2023-01-24 16:22:42 -03:00
Bruno Quaresma bef9e72078 refactor(site): Update agent status to include the lifecycle (#5835) 2023-01-24 14:48:03 -03:00
Bruno Quaresma f65c7ca6b3 chore(site): Improve the e2e setup (#5840) 2023-01-24 14:45:44 -03:00
Kira Pilot 1213162163 feat: adding template version id to workspace build diff (#5841)
* adding template-version-id to build diff

* fix tests
2023-01-24 10:53:04 -05:00
Marcin Tojek 26c69525d1 feat: Validate workspace build parameters (#5807) 2023-01-24 14:22:00 +01:00
Mathias Fredriksson 138887de7e feat: Add workspace agent lifecycle state reporting (#5785) 2023-01-24 14:24:27 +02:00
Kyle Carberry dbfeb5630c fix: update docs link for configuration (#5827)
This was set to the old URL pre docs move!
2023-01-23 18:42:47 -06:00
Colin Adler c3731a1be0 fix: ensure agent websocket only removes its own conn (#5828) 2023-01-23 17:22:34 -06:00
Kira Pilot 443e2180fa feat: indicate when workspace builds are stopped/started by Coder (#5813)
* feat: indicate when workspace_builds are stopped/started by Coder

* added translattion

* added json tags and adjust type
2023-01-23 15:47:58 -05:00
Kira Pilot 882832cc51 chore: removed FE code owners (#5826) 2023-01-23 20:29:18 +00:00
Colin Adler d2ae16dd22 fix: routinely ping agent websocket to ensure liveness (#5824) 2023-01-23 20:05:29 +00:00
Kyle Carberry ba8dd496c3 chore: manually specify templates to embed (#5823)
This is part of a multi-step cleanup for the example templates.
The goal is to have a lot of templates here, and only embed
specific ones we feel are impactful during setup.
2023-01-23 18:12:11 +00:00
Marcin Tojek bbb208e29c feat: Add CLI support for workspace build parameters (#5768)
* WIP

* WIP

* CLI: handle workspace build parameters

* fix: golintci

* Fix: dry run

* fix

* CLI: is mutable

* coderd: mutable

* fix: golanci

* fix: richParameterFile

* CLI: create unit tests

* CLI: update test

* Fix

* fix: order

* fix
2023-01-23 15:01:22 +01:00
Mathias Fredriksson 6a245ab1cc test: Fix GPG test so it does not inherit parent parallelism (#5820)
* test: Fix GPG test so it does not inherit parent parallelism

Running a subtest in a parent with `t.Parallel()` and using `t.Setenv`
is not allowed in Go 1.20, so we move it to a separate test function.

* Fix shadowed import
2023-01-23 11:40:41 +00:00
Cian Johnston 73afdd7c09 chore: agent_test.go: use ptty.Peek() instead of expecting caret in TestAgent_SessionTTYShell (#5821) 2023-01-23 11:23:25 +00:00
Mathias Fredriksson 8afdf24d10 chore: Update sqlc to v1.16.0 (#5788)
* chore: Update sqlc to v1.16.0

* chore: Fix cases where types became Null-types

* chore: Set parameter_schemas default_destination_scheme and default_source_scheme to NOT NULL

* chore: Add enum validation to database fake

* chore: Fix all tests that skipping enum values

* fix: Use correct err in providionerdserver audit log failure log
2023-01-23 13:14:47 +02:00
sharkymark f67acac2b7 docs: updated diagram with git provider logos (#5816) 2023-01-21 11:07:39 -08:00
Dean Sheather 37628c8b5b fix: comment on winget PR correctly (#5789) 2023-01-21 00:27:58 +00:00
Bruno Quaresma b045734b6a feat: Add use template button to template row (#5811) 2023-01-20 17:29:16 -03:00
Kira Pilot 0e58772f5b fix: filter workspace_build resource on start/stop action (#5809)
* fix: ufilter workspace_build resource on start/stop action

* added preset filter for workspace_build filtering

* cleaning up the preset filters
2023-01-20 13:23:13 -05:00
Bruno Quaresma 918c37c358 chore: Ignore expired at on chromatic (#5808) 2023-01-20 12:41:54 -03:00
Colin Adler 8819f798f8 fix(helm): revert app.kubernetes.io/part-of as a selector (#5806)
Deployment selectors are immutable!
2023-01-20 05:31:05 +00:00
Kyle Carberry 546a8931aa chore: move vscode local out of experiments (#5773)
We've been dogfooding the VS Code extension for a while,
and it seems stable enough that it's overall positive
to release!
2023-01-20 04:32:59 +00:00
Ammar Bandukwala b91b4533d8 docs: fix typo 2023-01-19 20:30:50 -06:00
Bruno Quaresma ff69c0e70f refactor: Refactor auth provider (#5782) 2023-01-19 21:02:29 -03:00
Kira Pilot a0a959c7a5 feat: better display secret audit values (#5801) 2023-01-19 17:47:53 -05:00
Colin Adler 341b7caff6 fix(examples): move k8s email label to an annotation (#5802) 2023-01-19 22:03:53 +00:00
Mathias Fredriksson 320cd3f3bc feat(cli): Add restart subcommand (#5799)
Fixes #2464
2023-01-19 23:56:41 +02:00
Ben Potter 8e5aefb841 docs: architecture diagram improvements (#5784)
* docs: architecture diagram improvements

* use new diagram
2023-01-19 21:39:04 +00:00
Ben Potter 9c563af459 fix: disable autocomplete for deletion dialogs (#5794) 2023-01-19 20:24:41 +00:00
Steven Masley 08cce81ac8 feat: Implement allow_list for scopes for resource specific permissions (#5769)
* feat: Implement allow_list for scopes for resource specific permissions

Feature that adds an allow_list for scopes to specify particular resources.
This enables workspace agent tokens to use the same RBAC system as users.

- Add ID to compileSQL matchers
* Plumb through WithID on rbac objects
* Rename Scope -> ScopeName
* Update input.json with scope allow_list

Co-authored-by: Cian Johnston <cian@coder.com>
2023-01-19 13:41:36 -06:00
Mathias Fredriksson f0df0686f9 chore(dogfood): Avoid calling ~/personalize unless executable (#5793) 2023-01-19 19:02:15 +00:00
Mathias Fredriksson 2ed70c7af9 chore: Fix make gen for docs/manifest.json (#5792) 2023-01-19 18:16:36 +00:00
Bruno Quaresma 36e97e3fa1 chore: update JS teests in CI (#5786) 2023-01-19 16:48:32 +00:00
Ben Potter 9e346b3251 docs: scaling Coder (#5550)
* docs: scaling Coder

* change icon

* Update docs/admin/scale/index.md

Co-authored-by: Dean Sheather <dean@deansheather.com>

* Update docs/admin/scale/index.md

Co-authored-by: Dean Sheather <dean@deansheather.com>

* Update docs/admin/scale/index.md

Co-authored-by: Dean Sheather <dean@deansheather.com>

* add prom link

* add plumbing for gke doc

* add limits/requests

* changes from feedback

* change

* simplify

* changes from colin feedback

* more edits from testing

* more fixes from Colin feedback

* clarify providers have different resource requirments

* kylecarbs feedback

* format

* explain concurrency

* move doc

* consolidate table

* fix broken links

Co-authored-by: Dean Sheather <dean@deansheather.com>
2023-01-19 07:12:39 -08:00
Mathias Fredriksson 1f3b7b658f docs: Add documentation for releases and commit style (#5675) 2023-01-19 15:13:11 +02:00
Bruno Quaresma bd8437b679 refactor: Refactor tokens layout a bit (#5771) 2023-01-19 10:00:59 -03:00
Ben Potter a040bcc0cf docs: clarify access URL in install flow (#5626)
* fix: TLS disabled copy

* clarify default access URL

* add docs for coder address
2023-01-18 23:23:55 +00:00
Dean Sheather 0374af23b2 fix(security)!: path-based app sharing changes (#5772)
This commit disables path-based app sharing by default. It is possible
for a workspace app on a path (not a subdomain) to make API requests to
the Coder API. When accessing your own workspace, this is not much of a
problem. When accessing a shared workspace app, the workspace owner
could include malicious javascript in the page that makes requests to
the Coder API on behalf of the visitor.

This vulnerability does not affect subdomain apps.

- Disables path-based app sharing by default. Previous behavior can be
  restored using the `--dangerous-allow-path-app-sharing` flag which is
  not recommended.

- Disables users with the site "owner" role from accessing path-based
  apps from workspaces they do not own. Previous behavior can be
  restored using the `--dangerous-allow-path-app-site-owner-access` flag
  which is not recommended.

- Adds a flag `--disable-path-apps` which can be used by
  security-conscious admins to disable all path-based apps across the
  entire deployment. This check is enforced at app-access time, not at
  template-ingest time.
2023-01-18 22:56:14 +00:00
Colin Adler b42e2ae81f feat(examples): add labels and antiAffinity to k8s example (#5774) 2023-01-18 22:53:54 +00:00
Colin Adler 45eb26d5d0 fix(scaletest): increase time range check causing flake on MacOS (#5776) 2023-01-18 22:41:14 +00:00
Kyle Carberry 41145a6842 fix: improve error handling when posting workspace agent version (#5775)
A customer ran into an unfortunate error here that we miss!
2023-01-18 22:03:11 +00:00
Kira Pilot 6b68fbbf18 feat: Auditing group members as part of group resource (#5730)
* added AuditableGroup type

* added json tags

* Anonymizing gGroup struct

* adding support on the FE for nested group diffs

* added type for GroupMember

* Update coderd/database/modelmethods.go

Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>

* Update coderd/database/modelmethods.go

Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>

* fetching group members in group.delete

* passing through right error

* broke out into util function and added tests

Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>
2023-01-18 15:13:39 -05:00
Cian Johnston 56b996532f feat: add --experiments flag to replace --experimental (#5767)
- Deprecates the --experimental flag
- Adds a new flag --experiments which supports passing multiple comma-separated values or a wildcard value.
- Exposes a new endpoint /api/v2/experiments that returns the list of enabled experiments.
- Deprecates the field Features.Experimental in favour of this new API.
- Updates apidocgen to support type aliases (shoutout to @mtojek).
- Modifies apitypings to support generating slice types.
- Updates develop.sh to pass additional args after -- to $CODERD_SHIM.
2023-01-18 19:12:53 +00:00
Kyle Carberry 47c3d72294 docs: add support for the coder remote extension (#5764) 2023-01-18 13:02:26 -06:00
Bruno Quaresma 537b9df357 refactor: Form page loaders (#5762) 2023-01-18 17:51:48 +00:00
Bruno Quaresma 2117eb4f31 chore: Improve bundle size (#5761) 2023-01-18 17:31:31 +00:00
Colin Adler 6ed4e21e8b feat(examples): add labels and antiAffinity to k8s example (#5763) 2023-01-18 17:01:00 +00:00
Bruno Quaresma 6252f782d8 fix: Setup redirect state (#5759) 2023-01-18 15:28:46 +00:00
Ammar Bandukwala 501cfa9e8d refactor: deduplicate / type license feature code (#5734) 2023-01-17 17:04:29 -06:00
Bruno Quaresma ea1b03f7c9 chore: Remove FE dead code (#5760) 2023-01-17 23:00:10 +00:00
Bruno Quaresma a13614e93d feat: Pre-fill param inputs with query string values (#5758) 2023-01-17 22:56:29 +00:00
Bruno Quaresma 28b2bbd095 refactor: Make navbar and users tab href consistent (#5754) 2023-01-17 19:05:54 -03:00
Mathias Fredriksson c6fb469655 test: Improve TestSSH/ForwardAgent stability on macOS (#5745) 2023-01-17 23:38:27 +02:00
Bruno Quaresma 99f5f44482 fix: Only fetch groups when it is enabled (#5753) 2023-01-17 18:33:34 -03:00
Bruno Quaresma 35d4766810 chore: Remove unused deps (#5756) 2023-01-17 15:56:00 -03:00
Dean Sheather 53c456a442 feat: PGP sign the checksum file in releases (#5757) 2023-01-18 04:45:27 +10:00
Dean Sheather b19d644162 feat: add etag to slim binaries endpoint (#5750) 2023-01-18 04:38:08 +10:00
Bruno Quaresma c377cd0fa9 fix: Move CLI auth screen outside of dashboard (#5755) 2023-01-17 15:24:22 -03:00
Kira Pilot f0eddbaab4 chore: Support anonymously embedded fields for audit diffs (#5746)
- Anonymously embedded structs are expanded as top level fields.
- Unit tests for anonymously embedded structs

Co-authored-by: Steven Masley <stevenmasley@coder.com>
2023-01-17 12:13:16 -06:00
Ben Potter e37bff6a85 docs: REST API docs are now complete (#5748) 2023-01-17 09:47:54 -08:00
Presley Pizzo 63956eafbf chore: turn e2e tests back on with fixes (#5719)
* Improvement - wip

* Cut out extra waits, increase timeouts

* Fix timeout syntax

* Extend timeouts for safety

* Turn e2e back on

* Format
2023-01-17 12:12:37 -05:00
Dean Sheather 7f5dcc3d6c feat: remove server subcommand from slim binaries (#5747) 2023-01-17 16:58:00 +00:00
Marcin Tojek 1b0560ceb4 feat: Expose workspace build parameters via API (#5743) 2023-01-17 16:24:45 +01:00
Dean Sheather 985fac642e chore: combine dogfood regions, use tailscale (#5741) 2023-01-17 14:20:48 +00:00
Mathias Fredriksson 145d101512 test: Refactor ptytest to use contexts and less duplication (#5740) 2023-01-17 16:02:38 +02:00
Mathias Fredriksson 77e71f3ca4 test: Improve TestSSH/ForwardGPG stability on macOS via pty.ReadRune (#5739)
Writing to stdin for `coder ssh` too early could result in the input
being discarded. To work around this we add a new `ptytest` method
called `ReadRune` that lets us read one character of output. This will
indicate the command is ready to accept input.

It could be one character of the prompt, or of the loading message
waiting for connection to be established.
2023-01-17 15:30:47 +02:00
Mathias Fredriksson db7877012c test: Fix flaky TestServer/Logging/{Multiple,Stackdriver} (#5727)
* test: Fix flaky TestServer/Logging/Multiple

* test: Fix flaky TestServer/Logging/Stackdriver

* test: Add testutil.TempFile and testutil.CreateTemp, cleanup tests
        relying on temp file
2023-01-17 14:14:29 +02:00
Marcin Tojek 6ebadabe4e feat: Add basic support for rich parameters to coderd and provisionerd (#5710) 2023-01-17 11:22:11 +01:00
Kyle Carberry 70fd78673d fix: remove old versions from docs manifest (#5736) 2023-01-16 22:37:31 +00:00
Kyle Carberry bbc1a9a1d8 fix: use UserInfo endpoint with OIDC (#5735)
This resolves a user issue surfaced in Discord:
https://discord.com/channels/747933592273027093/1064566338875576361/1064566338875576361

Both methods of obtaining claims need to be used according
to the OIDC specification.
2023-01-16 16:06:39 -06:00
Ammar Bandukwala 592ce3b118 feat(cli): allow direct tar upload in template update/create (#5720) 2023-01-16 14:32:11 -06:00
Ammar Bandukwala 5f7cce775b fix(site): always use 95th percentile in progress bar (#5733)
This fixes the issue where the bar flickers from "Up to X seconds
remaining" to "X seconds remaining".
2023-01-16 20:31:44 +00:00
Ammar Bandukwala 4420985fad feat(coderd): activity bump for full TTL instead of 1h (#5732) 2023-01-16 20:13:34 +00:00
Kyle Carberry e558a252e7 chore: remove dead docs links from README.md (#5731) 2023-01-16 12:27:39 -06:00
Dean Sheather b55cb0cc73 chore: add trivy vulnerability scanning (#5729) 2023-01-17 03:43:37 +10:00
Mathias Fredriksson f3bbf627a3 chore: Update gotestsum to v1.9.0 and remove debugging (#5726)
* chore: Update gotestsum to v1.9.0 and remove debugging

* chore: Update cloud.google.gpg to fix dogfood build
2023-01-16 17:58:57 +02:00
Dean Sheather 1d777c41f2 chore: move winget publish into release pipeline (#5728) 2023-01-16 15:40:27 +00:00
Mathias Fredriksson 8ae28a321e ci: Add release labels job to pr.yaml to sync labels/title (#5724) 2023-01-16 09:40:42 +00:00
Ammar Bandukwala 8db87c6bae feat(dogfood): run personalize script (#5723) 2023-01-15 18:20:12 -06:00
Olivier Lance cd7b36d41a fix(examples): use correct build args for Docker template (#5721) 2023-01-13 17:24:19 -06:00
Steven Masley eb48341696 chore: More complete tracing for RBAC functions (#5690)
* chore: More complete tracing for RBAC functions
* Add input.json as example rbac input for rego cli

The input.json is required to play with the rego cli and debug
the policy without golang. It is good to have an example to run
the commands in the readme.md

* Add span events to capture authorize and prepared results
* chore: Add prometheus metrics to rbac authorizer
2023-01-13 16:07:15 -06:00
Mathias Fredriksson e821b98918 ci: Revert to local tag creation and push for releases (#5714) 2023-01-13 20:45:31 +02:00
Garrett Delfosse 0cf713869b feat: Manage tokens in dashboard (#5444) 2023-01-13 17:20:03 +00:00
Steven Masley f76ef98a32 chore!: Standardize prometheus time metrics to seconds (#5709)
* chore!: Standardize prometheus time metrics to seconds
* Update prometheus docs
2023-01-13 11:15:25 -06:00
Marcin Tojek f91a0d8c37 chore: mark apidoc files as linguist-generated (#5713) 2023-01-13 18:01:40 +01:00
Bruno Quaresma de16e29566 refactor: Refactor update check banner (#5708) 2023-01-13 13:48:45 -03:00
Presley Pizzo d6543c042f chore: skip e2e tests (#5711)
* Skip e2e tests

* Skip with if
2023-01-13 10:35:18 -06:00
Marcin Tojek dad242a788 feat: Add more swagger checks (#5707) 2023-01-13 16:47:38 +01:00
Ben A 54cc587dad Updated PreconditionFailed status occurences to more appropriate statuses. (#5513) 2023-01-13 08:30:48 -06:00
Ben Potter 967d25fdf7 docs: HA is not experimental (fix) (#5686) 2023-01-13 08:30:22 -06:00
Marcin Tojek deebfcbd53 feat: Validate swagger definitions (#5694)
* docs: audit, deploymentconfig, files, parameters

* Swagger comments in workspacebuilds.go

* structs in workspacebuilds.go

* workspaceagents: instance identity

* workspaceagents.go in progress

* workspaceagents.go in progress

* Agents

* workspacebuilds.go

* /workspaces

* templates.go, templateversions.go

* templateversion.go in progress

* cancel

* templateversions

* wip

* Merge

* x-apidocgen

* NullTime hack not needed anymore

* Fix: x-apidocgen

* Members

* Fixes

* Fix

* WIP

* WIP

* Users

* Logout

* User profile

* Status suspend activate

* User roles

* User tokens

* Keys

* SSH key

* All

* Typo

* Fix

* Entitlements

* Groups

* SCIM

* Fix

* Fix

* Clean templates

* Sort API pages

* Fix: HashedSecret

* WIP

* WIP

* WIP

* Fix: cover workspaceagents

* Assert: consistent ID and summary

* Assert: success or failure defined

* Fix: parallel

* Refactor

* Support enterprise

* Go comment goes to top

* Security

* assertPathParametersDefined

* assertUniqueRoutes

* assertRequestBody

* More fixes

* Fix: exceptions

* Fix field format

* Address PR comments

* Refactor
2023-01-13 12:27:21 +01:00
Colin Adler dcab87358e feat: add stackdriver and json log options to coder server (#5682) 2023-01-12 20:08:23 -06:00
Bruno Quaresma 1229fda1a6 refactor: Clean up routes (#5702)
* refactor: Clean up routes

* Fix tests
2023-01-12 21:03:38 -03:00
Kyle Carberry 67952cf95e fix: move the web terminal out of the dashboard authentication layout (#5699)
Fixes #5698. This was a regression.
2023-01-12 21:44:29 +00:00
Mathias Fredriksson 269e0b3261 ci: Fix release tag push (#5696) 2023-01-12 22:18:10 +02:00
Bruno Quaresma 3861d1c555 refactor: Wrap forms into dashboard layout (#5697) 2023-01-12 17:08:31 -03:00
sharkymark bef6f67b70 docs: remove plans to license restrict oidc and git auth (#5672) 2023-01-12 19:21:56 +00:00
Bruno Quaresma e6072eff59 refactor: Wrap authenticated routes (#5695) 2023-01-12 15:52:16 -03:00
Bruno Quaresma f9f7283e16 refactor: Move deploy settings machine to the layout (#5693) 2023-01-12 17:02:11 +00:00
Bruno Quaresma cd1a2d2d5d refactor: Refactor site roles machine to be used in the page (#5692) 2023-01-12 13:53:46 -03:00
Bruno Quaresma f5a7538637 refactor: Make the navbar wider (#5689) 2023-01-12 16:34:56 +00:00
Mathias Fredriksson a5073a8770 ci: Fix release workflow input booleans, remove snapshot (#5688)
* s/github.event.inputs/inputs/g

* Add run name and prevent non-dry-run releases on non-main branches

* Add logrun to lib.sh
2023-01-12 15:50:58 +00:00
Kira Pilot 575bfabfcb fix: audit log workspace build URL should form with the correct workspace owner (#5674)
* removing workspaceOwner

* querying for workspace build
2023-01-12 09:51:30 -05:00
Kyle Carberry 41b58cd027 fix: open VS Code Remote in the same window to prevent flashing (#5684)
Fixes #5676.
2023-01-11 23:47:44 +00:00
Mathias Fredriksson c7e1ecfe36 ci: Fix release workflow inputs (#5681) 2023-01-11 23:32:25 +00:00
Presley Pizzo 1df72ee093 fix: handle NaN in build time estimate (#5679) 2023-01-11 15:56:21 -05:00
Mathias Fredriksson c0d9e32300 ci: Allow missing commit metadata to be ignored in releases (#5678) 2023-01-11 20:14:04 +00:00
Presley Pizzo 627fbe5874 fix: make build table show empty instead of loading when none are recent (#5666)
* Fix builds to show empty instead of loading

* Switch to backend fix

* Increase e2e test timeout

* Format
2023-01-11 12:18:06 -05:00
Bruno Quaresma a5d39adf3e refactor: Extract ssh logic from auth service (#5670)
* refactor: Extract ssh logic from auth service

* Update site/src/i18n/en/userSettingsPage.json

Co-authored-by: Kira Pilot <kira@coder.com>

Co-authored-by: Kira Pilot <kira@coder.com>
2023-01-11 17:04:42 +00:00
Mathias Fredriksson 8e4af79cb2 ci: Do release tagging in CI and add --draft support (#5652)
* ci: Do release tagging in CI and add --draft support

* Add -h, --help to release.sh

* Add -h, --help to increment_version_tag.sh

* Limit release concurrency

* Add automatic release watching

* ci: Add git config, tag as "GitHub Actions Bot"

Co-authored-by: Dean Sheather <dean@deansheather.com>
2023-01-11 18:38:01 +02:00
Dean Sheather e72a2ad907 feat: add SIGQUIT/SIGTRAP handler for the CLI (#5665) 2023-01-11 16:22:20 +00:00
Steve Miller 69241d06e7 docs: Update WebIDE Section Headers (#5669)
* Update header indents

* Bump To Rerun CI
2023-01-11 15:48:29 +00:00
Marcin Tojek d9436fab69 docs: API enterprise (#5625)
* docs: audit, deploymentconfig, files, parameters

* Swagger comments in workspacebuilds.go

* structs in workspacebuilds.go

* workspaceagents: instance identity

* workspaceagents.go in progress

* workspaceagents.go in progress

* Agents

* workspacebuilds.go

* /workspaces

* templates.go, templateversions.go

* templateversion.go in progress

* cancel

* templateversions

* wip

* Merge

* x-apidocgen

* NullTime hack not needed anymore

* Fix: x-apidocgen

* Members

* Fixes

* Fix

* WIP

* WIP

* Users

* Logout

* User profile

* Status suspend activate

* User roles

* User tokens

* Keys

* SSH key

* All

* Typo

* Fix

* Entitlements

* Groups

* SCIM

* Fix

* Fix

* Clean templates

* Sort API pages

* Fix: HashedSecret

* General is first
2023-01-11 16:05:42 +01:00
Marcin Tojek 8e9cbdd71b docs: API users (#5620)
* docs: audit, deploymentconfig, files, parameters

* Swagger comments in workspacebuilds.go

* structs in workspacebuilds.go

* workspaceagents: instance identity

* workspaceagents.go in progress

* workspaceagents.go in progress

* Agents

* workspacebuilds.go

* /workspaces

* templates.go, templateversions.go

* templateversion.go in progress

* cancel

* templateversions

* wip

* Merge

* x-apidocgen

* NullTime hack not needed anymore

* Fix: x-apidocgen

* Members

* Fixes

* Fix

* WIP

* WIP

* Users

* Logout

* User profile

* Status suspend activate

* User roles

* User tokens

* Keys

* SSH key

* All

* Typo

* Fix

* Fix

* Fix: LoginWithPasswordRequest
2023-01-11 14:08:04 +01:00
Marcin Tojek 84120767a7 docs: API templateversions, templates, members, organizations (#5546)
* docs: audit, deploymentconfig, files, parameters

* Swagger comments in workspacebuilds.go

* structs in workspacebuilds.go

* workspaceagents: instance identity

* workspaceagents.go in progress

* workspaceagents.go in progress

* Agents

* workspacebuilds.go

* /workspaces

* templates.go, templateversions.go

* templateversion.go in progress

* cancel

* templateversions

* wip

* Merge

* x-apidocgen

* NullTime hack not needed anymore

* Fix: x-apidocgen

* Members

* Fixes

* Fix
2023-01-11 12:16:09 +01:00
Mathias Fredriksson 5a3985e6be test: Use global swagger handler to avoid data race in tests (#5668) 2023-01-11 12:42:49 +02:00
Ammar Bandukwala 41cefef95a docs: fix minor mistake about resource persistence 2023-01-11 02:12:51 +00:00
Muhammad Atif Ali 370934afdf ci: allow writing security events for CodeQL (#5514) 2023-01-10 19:40:32 -06:00
Joe Previte 2296432e8b docs: update space on prem link (#5628) 2023-01-10 19:37:35 -06:00
Kyle Carberry 01652e8afb fix: disable pointer events on app icons (#5664)
Ben accidentally clicked to open this in a new tab
which seemed kinda janky UX-wise on our part.
2023-01-10 21:42:33 +00:00
Bruno Quaresma f5d623ff3f refactor: User settings page (#5661) 2023-01-10 17:57:08 -03:00
Ammar Bandukwala d5ab06ed68 feat: improve copy in new template wizard (#5659) 2023-01-10 18:46:08 +00:00
Kira Pilot 0171ccbf62 chore: forbid direct react import (#5658) 2023-01-10 13:30:48 -05:00
Michel Racic efee03fdec fix(site): changing password no longer silently trims space chars in a password (#5640) 2023-01-10 11:34:58 -06:00
Presley Pizzo 56a69b7eea chore: add e2e tests for basic template and workspace flow (#5637)
* Fix type error in first user setup

* Save auth state

* Add template creation - wip

Remove saved auth state because it wasn't working

* Try adding the rest of the tests

Can't see if they work yet, waiting on a release

* Update playwright

* Update gitignore

* Write tests

* Format

* Update ignores

* Check that start worked

Co-authored-by: Ben Potter <ben@coder.com>

Co-authored-by: Ben Potter <ben@coder.com>
2023-01-10 12:30:44 -05:00
Cian Johnston 19ae42af53 chore: update lima example to use --with-terraform arg (#5655)
#5586 added the capability for install.sh to download and install Terraform automatically.
Using this now in the example Lima specification.
Also no longer hard-coding the instance name in favour of {{.Instance.Name}} in the output
that gets emitted upon successful instance provisioning.
2023-01-10 17:25:46 +00:00
Kira Pilot f96365a181 chore: remove redundant icon stories (#5656) 2023-01-10 11:53:51 -05:00
Muhammad Atif Ali dda8170427 fix(ci): fixed $vesrion being empty in packages.yaml (#5650) 2023-01-10 10:40:06 -06:00
Colin Adler 4f3ac95a39 fix(helm): use correct antiaffinity label (#5649) 2023-01-10 10:18:58 -06:00
Colin Adler 2effea5806 fix(helm): use correct prometheus port (#5644) 2023-01-10 10:16:56 -06:00
Colin Adler d34540ca30 fix: ignore EINVAL when fsyncing /dev/stdout (#5648) 2023-01-10 10:15:53 -06:00
Kyle Carberry d2ef727064 feat: add experimental button to open vscode locally (#5654)
* feat: add experimental button to open vscode locally

This uses the new Coder extension to open up any workspace
with a single click.

* Update site/src/components/VSCodeDesktopButton/VSCodeDesktopButton.stories.tsx

Co-authored-by: Kira Pilot <kira@coder.com>

Co-authored-by: Kira Pilot <kira@coder.com>
2023-01-10 16:07:40 +00:00
Marcin Tojek a23a471034 docs: update swaggo/swag v1.8.9 (#5590)
* docs: update swaggo/swag v1.8.9

* Fix: format

* swaggo: time.Duration

* swaggo: provisionertype

* Fix: AuthorizationObject

* Fix: enums

* Fix: netip.Addr

* Fix: clickable response properties
2023-01-10 15:47:08 +01:00
Mathias Fredriksson bbe33fef41 chore: Revert title case in release notes (#5653) 2023-01-10 16:04:33 +02:00
Kyle Carberry 52d7dfa253 docs: remove unfinished sentence in templates.md (#5647)
Fixes #5643.
2023-01-09 22:24:09 -06:00
Kyle Carberry 9f6edab53b feat: replace vscodeipc with vscodessh (#5645)
The VS Code extension has been refactored to use VS Code
Remote SSH instead of using the private API.

This changes the structure to continue using SSH, but
output network information periodically to a file.
2023-01-10 04:23:17 +00:00
Joe Previte fa7deaaa5c feat: add storybook for /deployment/security (#5610)
* refactor: move securitysettings to dir

* refactor: split page view SecuritySettingsPage

* feat: add storybook for security page

* fixup
2023-01-09 20:44:43 +00:00
Bruno Quaresma f70726b43c refactor: Extract security logic from auth service (#5635) 2023-01-09 13:18:32 -07:00
Bruno Quaresma fe16b2a06d refactor: Add spacing in the bottom of a page (#5633) 2023-01-09 13:17:48 -07:00
Colin Adler 7bcbf197c1 fix: print correct listen adress in coder server (#5634) 2023-01-09 13:59:23 -06:00
Mathias Fredriksson 68324c7263 chore: Add security section to release notes (#5636) 2023-01-09 19:57:42 +00:00
Muhammad Atif Ali eb8d5b4408 fix(ci): fix winget package submission (#5630)
* fix(ci): fix winget package submission

I removed the step to calculate the version, as somehow the $version was not populated with the version.
Also, GitHub actions suggest removing `:set-output:` as it is deprecated. 

This commit should probably fix the winget package submission using `wingetcreate` cli.

* fixed a typo
2023-01-09 19:46:10 +00:00
Mathias Fredriksson aec15905b5 chore: Add more categories and titles for release notes (#5632)
Co-authored-by: Dean Sheather <dean@deansheather.com>
2023-01-09 21:19:07 +02:00
Bruno Quaresma 70d71bc7bc refactor: Do not display port forward button if it is disabled (#5604) 2023-01-09 13:38:31 -03:00
dependabot[bot] 34225b0380 chore: bump luxon from 3.1.1 to 3.2.1 in /site (#5624)
Bumps [luxon](https://github.com/moment/luxon) from 3.1.1 to 3.2.1.
- [Release notes](https://github.com/moment/luxon/releases)
- [Changelog](https://github.com/moment/luxon/blob/master/CHANGELOG.md)
- [Commits](https://github.com/moment/luxon/compare/3.1.1...3.2.1)

---
updated-dependencies:
- dependency-name: luxon
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-09 13:16:42 -03:00
Joe Previte 6807ad0d1b feat: add storybook for /deployment/userauth (#5609)
* refactor: move deploysettingspage to dir

* refactor: split page/view UserAuthSettings

* feat: add storybook for user auth

* Update site/src/components/DeploySettingsLayout/OptionsTable.tsx
2023-01-09 16:01:22 +00:00
Colin Adler a4ca8ffa65 fix: don't hang forever getting pg version (#5614) 2023-01-06 21:07:22 -06:00
Colin Adler 888766c10d fix: respect global --url flag in coder login (#5613) 2023-01-06 20:57:25 -06:00
Nathanial Spearing 9b602f55e0 feat: Added --with-terraform argument to install coder and terraform together (#5586)
* - Added a `--install-terraform` argument
- Added a unzip command check to the standalone function
	- Cleaner error and help redirect the user to a solution
- Added help info for `--install-terraform` argument
- Fixed standalone install typo (ard64 -> arm64)

* - Corrected formatting errors, and renamed functions

* - Fixed typos
- Added recommend changes for consistency

* Removed unzip check in standalone function

* Fixed styling

* Moved the TERRAFORM_VERSION Var up
2023-01-06 11:54:06 -06:00
Joe Previte 763147e5f2 feat: add storybook for /deployment/network (#5603)
* refactor: move NetworkSettingsPage to dir

* refactor: split page/view NetworkSettings

* feat: add storybook for NetworkSettingsPage
2023-01-06 17:14:01 +00:00
Joe Previte 242676bac3 feat: add storybook for /deployment/gitauth (#5596)
* refactor: move GitAuthSettingsPage to dir

* refactor: split page and view GitAuthSettingsPage

* fixup!: formatting

* refactor: narrow props in git auth view

* feat: add storybook for GitAuthSettingsPageView

* fixup: formatting
2023-01-06 16:58:20 +00:00
Bruno Quaresma aa68e0f8c9 fix: Too many requests during watching template version (#5602) 2023-01-06 13:31:49 -03:00
Dean Sheather f1fe2b5c06 feat: add GPG forwarding to coder ssh (#5482) 2023-01-06 07:52:19 +00:00
Joe Previte 59e919ab4a feat: add storybook for /deployments/general (#5595)
* refactor: split GeneralSettings page <> View

* feat: add story for generalsettingspageview

* Update site/src/pages/DeploySettingsPage/GeneralSettingsPage/GeneralSettingsPageView.tsx

Co-authored-by: Asher <ash@coder.com>

Co-authored-by: Asher <ash@coder.com>
2023-01-05 23:06:16 +00:00
dependabot[bot] 421e529763 chore: bump json5 from 1.0.1 to 1.0.2 in /site (#5553)
Bumps [json5](https://github.com/json5/json5) from 1.0.1 to 1.0.2.
- [Release notes](https://github.com/json5/json5/releases)
- [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md)
- [Commits](https://github.com/json5/json5/compare/v1.0.1...v1.0.2)

---
updated-dependencies:
- dependency-name: json5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-05 15:55:56 -07:00
Joe Previte bb03df8148 feat: add storybook for /deployment/appearance page (#5582)
* wip

* wip: move appearancesettingspage

* refactor: separate page and view ApperanceSettings

* refactor: create storybook from AppearanceSettingsView

* fixup: formatting and types
2023-01-05 16:16:54 -05:00
Bruno Quaresma 0d30a1eb72 fix: Display service banner after login (#5594) 2023-01-05 21:10:15 +00:00
dependabot[bot] 8ee3e2c541 chore: bump chartjs-adapter-date-fns from 2.0.0 to 3.0.0 in /site (#5528)
* chore: bump chartjs-adapter-date-fns from 2.0.0 to 3.0.0 in /site

Bumps [chartjs-adapter-date-fns](https://github.com/chartjs/chartjs-adapter-date-fns) from 2.0.0 to 3.0.0.
- [Release notes](https://github.com/chartjs/chartjs-adapter-date-fns/releases)
- [Commits](https://github.com/chartjs/chartjs-adapter-date-fns/compare/v2.0.0...v3.0.0)

---
updated-dependencies:
- dependency-name: chartjs-adapter-date-fns
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* added transformer for esm

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Kira Pilot <kira.pilot23@gmail.com>
2023-01-05 15:58:04 -05:00
Dean Sheather 5a968e2f93 feat: add flag to disaable all rate limits (#5570) 2023-01-05 18:05:20 +00:00
Bruno Quaresma ab7e676b54 refactor: Refactor user menu (#5591) 2023-01-05 14:06:58 -03:00
Niklas Rosenstein dcf6c20132 feat: add coder.volumes parameter to Helm chart (#5551)
Co-authored-by: Dean Sheather <dean@deansheather.com>
2023-01-06 01:53:29 +10:00
Marcin Tojek 66fa2a1a8c docs: API workspace agents and builds (#5538) 2023-01-05 15:27:10 +01:00
Cian Johnston e6b17b6ea7 chore: update Lima example (#5588)
* chore: lima: update ubuntu image version

* fix: lima: make docker socket usable by Lima user without sudo

* fix: lima: set access URL to host.lima.internal

* apply suggestion from PR
2023-01-05 11:47:33 +00:00
Muhammad Atif Ali 0124289f1a fix(ci): fix winget installer workflow (#5569)
* fix(ci): add GH_TOKEN env

* chore: fix windows installer build filename

Co-authored-by: Dean Sheather <dean@deansheather.com>
2023-01-05 04:56:00 +00:00
Ben Potter 04d45f3c1c fix!: remove AUTO_IMPORT_TEMPLATE for Kubernetes installs (#5401)
* fix!: remove AUTO_IMPORT_TEMPLATE

* chore: remove template auto importing

Co-authored-by: Dean Sheather <dean@deansheather.com>
2023-01-05 04:04:32 +00:00
dependabot[bot] 24592332e2 chore: bump github.com/gohugoio/hugo from 0.107.0 to 0.109.0 (#5541)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-05 10:34:53 +10:30
dependabot[bot] 2db9df4491 chore: bump github.com/prometheus/common from 0.37.0 to 0.39.0 (#5544)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-04 23:42:13 +00:00
dependabot[bot] c0dfbdf143 chore: bump emoji-mart from 5.3.3 to 5.4.0 in /site (#5527)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-05 10:00:56 +10:30
Ammar Bandukwala 0b63825a07 site: fix copy in users roles view (#5583) 2023-01-04 17:13:04 -06:00
Joe Previte a231c1a384 fix: styles for <AlertBanner /> (#5579)
* feat: add new story for LoginPageView

* fix: update <AlertBanner /> styles

- align text to the left
- add padding to the top of span inside

* fixup: formatting
2023-01-04 14:46:41 -07:00
Kyle Carberry c51b5a05db fix: add case for non-entitled logo url (#5580)
This was missing from my prior contribution, which
would lead any user to believe they could customize the logo.
2023-01-04 21:39:54 +00:00
Kyle Carberry 0dba2defd1 feat: enable enterprise users to specify a custom logo (#5566)
* feat: enable enterprise users to specify a custom logo

This adds a field in deployment settings that allows users to specify
the URL to a custom logo that will display in the dashboard.

This also groups service banner into a new appearance settings page.
It adds a Fieldset component to allow for modular fields moving forward.

* Fix tests
2023-01-04 15:31:45 -06:00
Bruno Quaresma 175be621cf refactor: Improve roles UI (#5576) 2023-01-04 18:30:35 -03:00
Jan Losinski de0601d611 feat: allow configurable username claim field in OIDC (#5507)
Co-authored-by: Colin Adler <colin1adler@gmail.com>
2023-01-04 15:16:31 -06:00
Kyle Carberry 8968a00035 fix: add spacing between the copyright and login box (#5578)
I forgot to commit this before merging my prior PR!
2023-01-04 16:00:25 -03:00
Mathias Fredriksson ebe1b56c08 chore: Switch from npm to yarn in scripts/apidocgen (#5575) 2023-01-04 19:38:48 +01:00
Kyle Carberry a36cd0bd7b refactor: move footer items into the user dropdown (#5562)
* refactor: move footer items into the user dropdown

The items at the bottom looked unprofessional. Users don't
always need to be prompted to join our Discord or see the
active version of Coder.

This moves the items in the user dropdown which looks better.

* Update site/src/components/UserDropdownContent/UserDropdownContent.tsx

Co-authored-by: Asher <ash@coder.com>

* Fix import order

Co-authored-by: Asher <ash@coder.com>
2023-01-04 12:36:25 -06:00
Marcin Tojek 925b29836c docs: improve authentication page (#5567)
* docs: improve authentication page

* Update docs/admin/automation.md

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* Update docs/admin/automation.md

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* Fix

* Fix

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
2023-01-04 10:14:47 -08:00
Dean Sheather 91a4c2dce1 chore: remove address from deployment page (#5565) 2023-01-04 23:50:55 +10:00
Steven Masley 5e540e3439 chore: Log out the failed audit log on failures (#5561) 2023-01-03 17:22:57 -06:00
Bruno Quaresma 4e14cc5207 refactor: Remove template UI from experimental (#5555) 2023-01-03 19:29:38 +00:00
Steven Masley c5128db484 docs: Add auditor role to roles table (#5557)
* docs: Add auditor role to roles table
* make fmt
2023-01-03 12:55:26 -06:00
dependabot[bot] 3e2477f255 chore: bump actions/stale from 6.0.0 to 7.0.0 (#5515)
Bumps [actions/stale](https://github.com/actions/stale) from 6.0.0 to 7.0.0.
- [Release notes](https://github.com/actions/stale/releases)
- [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/stale/compare/v6.0.0...v7.0.0)

---
updated-dependencies:
- dependency-name: actions/stale
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-03 12:51:26 -06:00
dependabot[bot] ed114ec341 chore: bump golang.org/x/tools from 0.3.0 to 0.4.0 (#5542)
Bumps [golang.org/x/tools](https://github.com/golang/tools) from 0.3.0 to 0.4.0.
- [Release notes](https://github.com/golang/tools/releases)
- [Commits](https://github.com/golang/tools/compare/v0.3.0...v0.4.0)

---
updated-dependencies:
- dependency-name: golang.org/x/tools
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-03 12:44:37 -06:00
dependabot[bot] f1419bbc49 chore: bump golang.org/x/term from 0.2.0 to 0.3.0 (#5543)
Bumps [golang.org/x/term](https://github.com/golang/term) from 0.2.0 to 0.3.0.
- [Release notes](https://github.com/golang/term/releases)
- [Commits](https://github.com/golang/term/compare/v0.2.0...v0.3.0)

---
updated-dependencies:
- dependency-name: golang.org/x/term
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-03 12:44:31 -06:00
Marcin Tojek e67d131514 docs: audit, deploymentconfig, files, parameters (#5506)
* docs: audit, deploymentconfig, files, parameters

* Fix: mark as binary

* Fix: show format in docs

* Fix: use .swaggo

* Fix: swagger notice

* Swagger notice
2023-01-03 19:21:10 +01:00
Bruno Quaresma 829cfee29d refactor: Improve users table view for non admins (#5547) 2023-01-03 13:21:58 -03:00
dependabot[bot] 5e36fd522c chore: bump cronstrue from 2.14.0 to 2.21.0 in /site (#5545)
Bumps [cronstrue](https://github.com/bradymholt/cronstrue) from 2.14.0 to 2.21.0.
- [Release notes](https://github.com/bradymholt/cronstrue/releases)
- [Changelog](https://github.com/bradymholt/cRonstrue/blob/master/CHANGELOG.md)
- [Commits](https://github.com/bradymholt/cronstrue/compare/v2.14.0...v2.21.0)

---
updated-dependencies:
- dependency-name: cronstrue
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-03 13:21:42 -03:00
dependabot[bot] 3969a8b58b chore: bump prettier from 2.7.1 to 2.8.1 in /site (#5526)
Bumps [prettier](https://github.com/prettier/prettier) from 2.7.1 to 2.8.1.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.7.1...2.8.1)

---
updated-dependencies:
- dependency-name: prettier
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-03 10:00:14 -05:00
Mathias Fredriksson 856f0ab6f5 chore: Improve project-wide prettier formatting and ignored files (#5505)
* chore: Improve project-wide prettier formatting and ignored files

* chore: `Run make fmt/prettier`

* Fix gitignore for `.vscode` folder so that ! works

* Add comment in `.prettierrc.yaml` to explain `.editorconfig`

* Remove scripts/apidocgen/markdown-template/README.md

* Use `yq` for processing prettierrc, update lib.sh dependency check

* Add `yq` to Dockerfile and Nix
2023-01-03 15:11:13 +02:00
dependabot[bot] 5435bceaf0 chore: bump tj-actions/branch-names from 6.3 to 6.4 (#5518)
Bumps [tj-actions/branch-names](https://github.com/tj-actions/branch-names) from 6.3 to 6.4.
- [Release notes](https://github.com/tj-actions/branch-names/releases)
- [Changelog](https://github.com/tj-actions/branch-names/blob/main/HISTORY.md)
- [Commits](https://github.com/tj-actions/branch-names/compare/v6.3...v6.4)

---
updated-dependencies:
- dependency-name: tj-actions/branch-names
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-02 14:42:58 -06:00
Marcin Tojek 8bb7e17bf1 chore!: remove GET workspaceagents/me/report-stats (#5530)
* chore!: remove GET workspaceagents/me/report-stats

* Fix: tests
2023-01-02 21:38:51 +01:00
dependabot[bot] d124fab642 chore: bump jaxxstorm/action-install-gh-release from 1.7.1 to 1.9.0 (#5516)
Bumps [jaxxstorm/action-install-gh-release](https://github.com/jaxxstorm/action-install-gh-release) from 1.7.1 to 1.9.0.
- [Release notes](https://github.com/jaxxstorm/action-install-gh-release/releases)
- [Commits](https://github.com/jaxxstorm/action-install-gh-release/compare/v1.7.1...v1.9.0)

---
updated-dependencies:
- dependency-name: jaxxstorm/action-install-gh-release
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-02 14:37:17 -06:00
dependabot[bot] 4b093115e2 chore: bump google-github-actions/setup-gcloud from 0 to 1 (#5517)
Bumps [google-github-actions/setup-gcloud](https://github.com/google-github-actions/setup-gcloud) from 0 to 1.
- [Release notes](https://github.com/google-github-actions/setup-gcloud/releases)
- [Changelog](https://github.com/google-github-actions/setup-gcloud/blob/main/CHANGELOG.md)
- [Commits](https://github.com/google-github-actions/setup-gcloud/compare/v0...v1)

---
updated-dependencies:
- dependency-name: google-github-actions/setup-gcloud
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-02 14:37:06 -06:00
Ammar Bandukwala 05dc83e522 docs: add hero image to About (#5539)
A reddit comment recently linked to this page, so we want to
make it convert better.
2023-01-02 14:36:36 -06:00
dependabot[bot] b6dab5fbf7 chore: bump golang.org/x/text from 0.4.0 to 0.5.0 (#5521)
Bumps [golang.org/x/text](https://github.com/golang/text) from 0.4.0 to 0.5.0.
- [Release notes](https://github.com/golang/text/releases)
- [Commits](https://github.com/golang/text/compare/v0.4.0...v0.5.0)

---
updated-dependencies:
- dependency-name: golang.org/x/text
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-02 14:34:25 -06:00
dependabot[bot] 54eb6a5b42 chore: bump github.com/valyala/fasthttp from 1.41.0 to 1.43.0 (#5522)
Bumps [github.com/valyala/fasthttp](https://github.com/valyala/fasthttp) from 1.41.0 to 1.43.0.
- [Release notes](https://github.com/valyala/fasthttp/releases)
- [Commits](https://github.com/valyala/fasthttp/compare/v1.41.0...v1.43.0)

---
updated-dependencies:
- dependency-name: github.com/valyala/fasthttp
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-02 14:34:02 -06:00
dependabot[bot] 8d254bd94e chore: bump github.com/prometheus/client_model from 0.2.0 to 0.3.0 (#5523)
Bumps [github.com/prometheus/client_model](https://github.com/prometheus/client_model) from 0.2.0 to 0.3.0.
- [Release notes](https://github.com/prometheus/client_model/releases)
- [Commits](https://github.com/prometheus/client_model/compare/v0.2.0...v0.3.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_model
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-02 14:33:51 -06:00
dependabot[bot] f711abb236 chore: bump github.com/elastic/go-sysinfo from 1.8.1 to 1.9.0 (#5524)
Bumps [github.com/elastic/go-sysinfo](https://github.com/elastic/go-sysinfo) from 1.8.1 to 1.9.0.
- [Release notes](https://github.com/elastic/go-sysinfo/releases)
- [Changelog](https://github.com/elastic/go-sysinfo/blob/main/CHANGELOG.md)
- [Commits](https://github.com/elastic/go-sysinfo/compare/v1.8.1...v1.9.0)

---
updated-dependencies:
- dependency-name: github.com/elastic/go-sysinfo
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-02 14:33:41 -06:00
dependabot[bot] 86c1753e2b chore: bump react-i18next from 12.0.0 to 12.1.1 in /site (#5525)
Bumps [react-i18next](https://github.com/i18next/react-i18next) from 12.0.0 to 12.1.1.
- [Release notes](https://github.com/i18next/react-i18next/releases)
- [Changelog](https://github.com/i18next/react-i18next/blob/master/CHANGELOG.md)
- [Commits](https://github.com/i18next/react-i18next/compare/v12.0.0...v12.1.1)

---
updated-dependencies:
- dependency-name: react-i18next
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-02 10:35:39 -03:00
Geoffrey Huntley 26b54cd144 chore(autofix): upgrade-examples-terraform-provider-coder (#5498)
Automatically generated via https://github.com/coder/autofix
2022-12-23 12:25:56 +10:30
Dean Sheather 3e2e2ac49e fix: enforce unique agent names per workspace (#5497) 2022-12-22 15:20:35 -08:00
sharkymark 461c0d0d39 docs: v1 docs redirect (#5509)
* docs: v1 docs redirect

* fix link

Co-authored-by: Ben <me@bpmct.net>
2022-12-22 15:14:36 -08:00
Muhammad Atif Ali 341c4329f4 ci: enable CodeQL code scanning (#5279)
Co-authored-by: Dean Sheather <dean@deansheather.com>
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
Co-authored-by: Geoffrey Huntley <ghuntley@ghuntley.com>
2022-12-22 22:12:55 +02:00
Presley Pizzo c8f34bbad7 Test enabling deadline change buttons (#5508) 2022-12-22 13:47:07 -05:00
Presley Pizzo 418022943a fix: use template default ttl when enabling auto-stop (#5494)
* Fetch default ttl - wip

* Convert ms to hours

* Format

* Fix story

* Add test
2022-12-22 12:52:27 -05:00
Marcin Tojek cfd02d959c docs: api root, buildinfo, csp (#5493)
* docs: Applications

* WIP

* WIP

* WIP

* Fix: consume

* Fix: @Description

* Fix

* docs: apiroot, buildinfo, csp

* Fix: buildinfo

* docs: updatecheck

* docs: apiroot

* Fix: s/none//g

* Fix: godoc nice

* Fix: description

* Fix: It

* Fix: code sample trim empty line

* More fixes

* Fix: br

* Merge

* Fix: no-security on updatecheck

* Fix: code tags

* Fix: enumerated values in code tags

* Rephrased

* Address PR comments

* Fix: URL, id

* Fix: array items

* Fix: any property

* Fix: array item singular
2022-12-22 15:53:14 +01:00
Bruno Quaresma c505e8b207 feat: Add create template from the UI (#5427) 2022-12-21 18:07:00 -03:00
Dean Sheather 43b61ce33c chore: support underscores in agent bin filenames (#5496) 2022-12-21 21:06:38 +00:00
Mathias Fredriksson bae69df8f9 build: Fix site/bin tar/zstd build step in rare error cases (#5495) 2022-12-21 22:59:49 +02:00
Colin Adler ac27cf8c07 fix: properly apply metadata when multiple resources share the same id (#5443) 2022-12-21 13:48:49 -05:00
whitney-coder 308a0602b6 Update high-availability.md (#5473)
Capitalization corrections
2022-12-21 09:47:32 -08:00
Presley Pizzo 0eb25306ad fix: stop time incrementer on workspace page (#5406)
* Check template default ttl while setting max

* Lint

* Remove template default from max ttl consideration

* Finish removing template

* Fix disabling buttons

* Simplify, wip

* Handle NaN

* Format

* Add aria labels

* Explain NaN handling

* Use more realistic storybook args
2022-12-21 10:44:18 -05:00
Presley Pizzo 8d9528545a feat: offer to restart workspace when ttl is changed (#5391)
* Update xstate machine

* Fix autoStopChanged

* Add dialog

* Restart workspace

* Clearing location doesn't work and doesn't seem necessary

* Fix test

* Fix second test

* Format

* Lint

* Use i18n

* Switch to fire and forget restart

* Improve error handling

* Format

* Format

* Update site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.test.tsx

Co-authored-by: Kira Pilot <kira@coder.com>

* Fix name of guard

* Make done state final

* Format

Co-authored-by: Kira Pilot <kira@coder.com>
2022-12-21 10:11:54 -05:00
Marcin Tojek 2bbeff53f9 docs: applications and authorization (#5477)
* docs: Applications

* WIP

* WIP

* WIP

* Fix: consume

* Fix: @Description

* Fix

* Fix: s/none//g

* Fix: godoc nice

* Fix: description

* Fix: It

* Fix: code sample trim empty line

* More fixes

* Fix: br
2022-12-21 15:37:30 +01:00
Mathias Fredriksson 935bb99bed test: Merge env maps to simplify (#5481) 2022-12-20 20:40:41 +00:00
Dean Sheather 2ac31684f4 fix: use UIDs in Dockerfile (#5480) 2022-12-20 12:22:27 -08:00
Mathias Fredriksson c5cfefe3b2 test: Generate golden files for all (visible) CLI commands (#5479) 2022-12-20 22:17:51 +02:00
Mathias Fredriksson c7ce3e70da feat: Add --raw-url to coder server postgres-builtin-* commands (#5478) 2022-12-20 18:51:17 +00:00
Dean Sheather 50dfc2082b feat: endpoint to logout app subdomain URLs (#5428)
Co-authored-by: Bruno Quaresma <bruno@coder.com>
2022-12-20 18:45:13 +00:00
sharkymark 86257ce7fc docs: add contact us form for sales; improve enterprise page (#5459)
Co-authored-by: Geoffrey Huntley <ghuntley@ghuntley.com>
2022-12-20 13:01:28 +00:00
Mathias Fredriksson ca31f1b782 test: Update go-scp to fix data race (#5469) 2022-12-20 09:33:11 +00:00
Mathias Fredriksson a7e8f98e33 feat: Unhide workspace rename command (#5464) 2022-12-19 22:11:10 +02:00
Steven Masley e3cf759968 test: Unit tests creating fake audit logs require create permission (#5455) 2022-12-19 14:02:52 -06:00
Dean Sheather 1bc4eb5329 fix: fix security vulnerabilities reported by CodeQL (#5467) 2022-12-19 19:25:59 +00:00
Dean Sheather e359f3cd23 fix: change TLS client auth default to "none" (#5468) 2022-12-19 19:14:37 +00:00
Marcin Tojek dc6d271293 feat: Build framework for generating API docs (#5383)
* WIP

* Gen

* WIP

* chi swagger

* WIP

* WIP

* WIP

* GetWorkspaces

* GetWorkspaces

* Markdown

* Use widdershins

* WIP

* WIP

* WIP

* Markdown template

* Fix: makefile

* fmt

* Fix: comment

* Enable swagger conditionally

* fix: site

* Default false

* Flag tests

* fix

* fix

* template fixes

* Fix

* Fix

* Fix

* WIP

* Formatted

* Cleanup

* Templates

* BEGIN END SECTION

* subshell exit code

* Fix

* Fix merge

* WIP

* Fix

* Fix fmt

* Fix

* Generic api.md page

* Fix merge

* Link pages

* Fix

* Fix

* Fix: links

* Add icon

* Write manifest file

* Fix fmt

* Fix: enterprise

* Fix: Swagger.Enable

* Fix: rename apidocs to apidoc

* Fix: find -not -prune

* Fix: json not available

* Fix: rename Coderd API to Coder API

* Fix: npm exec

* Fix: api dir

* Fix: by ID

* Fix: string uuid

* Fix: include deleted

* Fix: indirect go.mod

* Fix: source lib.sh

* Fix: shellcheck

* Fix: pushd popd

* Fix: fmt

* Fix: improve workspaces

* Fix: swagger-enable

* Fix

* Fix: mention only HTTP 200

* Fix: IDs

* Fix: https

* Fix: icon

* More APis

* Fix: format swagger.json

* Fix: SwaggerEndpoint

* Fix: SCRIPT_DIR

* Fix: PROJECT_ROOT

* Fix: use code tags in schemas.md

* Fix: examples

* Fix: examples

* Fix: improve format

* Fix: date-time,enums

* Fix: include_deleted

* Fix: array of

* Fix: parameter, response

* Fix: string time or null

* Workspaces: more docs

* Workspaces: more docs

* Fix: renderDisplayName

* Fix: ActiveUserCount

* Fix

* Fix: typo

* Templates: docs

* Notice: incomplete
2022-12-19 18:43:46 +01:00
Kyle Carberry f239ca7ee3 fix: add the "workflow" scope for managing GitHub Actions with gitauth (#5461)
Seen in Discord: https://discord.com/channels/747933592273027093/1054155742871031858/1054155742871031858
2022-12-19 15:17:17 +02:00
Mathias Fredriksson 9983c07e13 build: Improve speed of find commands in Makefile (#5463) 2022-12-19 14:41:36 +02:00
Mathias Fredriksson 5a786edc3d test: Fix new name too long for cli/rename (#5462) 2022-12-19 11:58:22 +00:00
Kyle Carberry e61234f260 feat: Add vscodeipc subcommand for VS Code Extension (#5326)
* Add extio

* feat: Add `vscodeipc` subcommand for VS Code Extension

This enables the VS Code extension to communicate with a Coder client.
The extension will download the slim binary from `/bin/*` for the
respective client architecture and OS, then execute `coder vscodeipc`
for the connecting workspace.

* Add authentication header, improve comments, and add tests for the CLI

* Update cli/vscodeipc_test.go

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* Update cli/vscodeipc_test.go

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* Update cli/vscodeipc/vscodeipc_test.go

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* Fix requested changes

* Fix IPC tests

* Fix shell execution

* Fix nix flake

* Silence usage

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
2022-12-18 17:50:06 -06:00
Kyle Carberry d1f8fec1d3 fix: use static base date for timeline tests (#5460)
It was returning "yesterday" since today is Sunday ;p
2022-12-18 15:27:09 -06:00
Dean Sheather 88d3496a99 fix: fix helm prometheus block causing failures (#5458) 2022-12-19 04:48:08 +10:00
Joe Previte a19c6fc988 fix: update coder dotfiles in dogfood (#5451)
I wasn't calling the environment variable I set.
2022-12-16 12:08:13 -07:00
ElliotG e76f947da2 Added sessionAffinity to values.yaml (#5448) 2022-12-16 09:58:43 -07:00
Dean Sheather 0c0e3f0e4d fix: fix nested dirs in example tars (#5447) 2022-12-17 02:19:19 +10:00
Kyle Carberry fcd5511403 fix: add provisioner tags to template push (#5446)
This was previously only on template create!
2022-12-16 15:13:03 +00:00
Mathias Fredriksson ffb8df9655 test: Disable error on agent log in scaletest/reconnectingpty (#5445)
They way the reconnectingpty tests behave inherently will cause the
agent to occasionally log an error (e.g. due to test disconnecting at a
certain time), allowing these error logs to fail the test will cause
these tests to be flakey.

It's best for these tests to only rely on the observed behavior.
2022-12-16 16:13:31 +02:00
Mathias Fredriksson e2aec2709b test: Fix scaletest/reconnectingpty commands for use in powershell (#5439) 2022-12-16 12:18:14 +02:00
Steven Masley 79c71d2d2c chore: Upgrade to sqlc version 2 yaml configuration (#5442)
* chore: Upgrade to sqlc version 2 yaml configuration
2022-12-15 20:40:11 +00:00
Joe Previte fceac39143 refactor: pin code-server to 4.8.3 (#5440)
* chore(templates): pin code-server to 4.8.3

* docs: use code-server 4.8.3 in install snippets
2022-12-15 13:14:49 -07:00
Dean Sheather 31d38d4246 feat: allow http and https listening simultaneously (#5365) 2022-12-15 20:09:19 +00:00
Dean Sheather 787b8b2a51 fix: fix app hostname returning port number (#5441) 2022-12-16 04:43:00 +10:00
Mathias Fredriksson 44c10bbe3c build: Fix parallelism of make -j build (#5438) 2022-12-15 18:36:37 +02:00
Dean Sheather 6b6eac2518 feat: remove loadtest cmd, add new scaletest cmd (#5310) 2022-12-15 15:04:24 +00:00
Mathias Fredriksson 306fe4a91b ci: Fix release publish script (#5436) 2022-12-15 14:31:57 +00:00
Mathias Fredriksson e96fdbed26 feat: Add release.sh script and detect breaking changes (#5366)
This commit introduces three new scripts:

- `release.sh` To be run by a user on their local machine to preview and
  create a new release (tag + push)
- `check_commit_metadata.sh` For e.g. detecting breaking changes
- `genereate_release_notes.sh` To display the generated release notes,
  used for previews and in `publish_release.sh`

The `release.sh` script can be run without arguments, and it will
automatically determine if we're to do a patch or minor release. A minor
release can be forced via `--minor` flag.

Breaking changes can be annotated either via commit/merge title prefix
(`feat!:`, `feat(api)!:`), or by adding the `release/breaking` label to
the PR that was merged (on GitHub).

Related #5233
2022-12-15 15:41:30 +02:00
Mathias Fredriksson 4bc420dc48 test: Fix data race in loadtest/reconnectingpty (#5431) 2022-12-15 15:06:58 +02:00
Mathias Fredriksson 25ebebac5f ci: Improve gotestsum failure detection, prevent early exit (#5420) 2022-12-15 12:47:42 +02:00
Kyle Carberry d170d27e80 feat: add external property to coder_app (#5425)
* Add schema

* feat: add `external` property to `coder_app`

This allows exposing applications that open an external URL.
2022-12-14 15:54:18 -06:00
Kyle Carberry 8bc247d0c9 fix: use proper validate url for gitauth (#5426)
This was preventing custom validation URLs from being
used to verify git tokens.
2022-12-14 21:02:35 +00:00
Kyle Carberry 84995b7320 fix: preserve workspace resource metadata order (#5421)
Fixes #4511.
2022-12-14 19:08:22 +00:00
Kyle Carberry c0b251ac52 fix: improve error messages when the agent token is invalid (#5423)
I'm not sure why this issue is common, but it seems to be
based on: https://github.com/coder/coder/issues/4551.

This improves the error messages to be unique,
and also fixes a small edge-case bug a user ran into.
2022-12-14 12:24:22 -06:00
Mathias Fredriksson b39ba02bf0 ci: Increase Go mock db test timeout to 5m (#5413)
Our Windows test-runner often takes close to 3m to complete the test,
this was producing a few false failures due to us adding tests over time
and test times increasing.
2022-12-14 19:37:01 +02:00
Steven Masley 27386d49d0 fix: No org admins until organizations are in the UI (#5414)
* fix: No org admins until organizations are in the UI

Until organizations have management UI, we should not set any org
admins. This goes around the site wide perms transparently and
is confusing to users.

Default user is no longer an org admin, so the demotion test makes
no sense
2022-12-14 11:05:42 -06:00
Mathias Fredriksson 012a9e759e fix: Avoid deadlock in AgentReportStats Close during agent Close (#5415)
Since AgentReportStats takes a stats function which was doing mutex
locking on agent shutdown, it was possible for there to be a deadlock
depending on how the AgentReportsStats Close function is implemented.

This mostly seems to happen on Windows test runners as it's pretty hard
to hit this edge case. The bug currently only exists in the test
implementation of AgentReportStats, however, this was refactored to be
more robust in case of future changes.
2022-12-14 18:45:46 +02:00
Kyle Carberry 8e702d89bb fix: improve the warning mismatch to display the release assets on windows (#5418)
* fix: improve the warning mismatch to display the release assets on windows

Fixes #4226.

* Update cli/root.go

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* Update cli/root.go

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
2022-12-14 16:36:28 +00:00
Marcin Tojek b103685170 chore: Collect gotests.xml files (#5398)
* chore: Use datadog-ci to collect gotests.xml

* WIP

* Fix: github ref

* fix

* just store gotests.xml
2022-12-14 16:23:31 +01:00
Arthur Normand ad0dd1be5d fix: Add client certs to OAuth HTTPClient context (#5126) 2022-12-14 16:44:29 +02:00
Mathias Fredriksson 663f7a3f12 ci: Output tail of gotestsum.json if test timed out (#5411)
This is to eternalize the log in case "re-run failed" is used, which
erases artifacts from previous run.
2022-12-14 15:04:39 +02:00
Mathias Fredriksson 2a4ef38a4f fix(site): Use correct UUID for web terminal when first opened (#5404) 2022-12-14 15:03:47 +02:00
Geoffrey Huntley 90b0adabc1 docs(readme): uppercase H in Self-Hosted (#5412) 2022-12-14 13:01:51 +00:00
Geoffrey Huntley ec2293a4e4 docs(readme): update comparison table (#5405) 2022-12-14 10:35:20 +01:00
Mathias Fredriksson 1a018c571b chore: Add PR Lint workflow (#5387)
Fixes #5381
2022-12-14 16:34:08 +10:00
Ricky Grassmuck f7baf45ae3 feat: support partial parameter files (#5392)
Fixes https://github.com/coder/coder/issues/5390
2022-12-13 19:58:57 -06:00
Joe Previte 5a568d8a9b refactor: conditionally use dotfiles in dogfood template (#5332)
* feat: add dotfiles_uri var to dogfood template

* refactor: use dotfiles if dotfiles var exists

This ensures the `coder dotfiles` command only runs if the dotfiles var
in the template is not empty.

* Update dogfood/main.tf

* refactor: assign variable to shell variable

* Update dogfood/main.tf

* fixup!: add default value
2022-12-13 21:15:25 +00:00
sharkymark 8df02f42c0 docs: make it clear the CLI must be downloaded to use templates (#5373) 2022-12-13 19:31:09 +00:00
Mathias Fredriksson 4fc4c01cea fix: Enable reconnectingpty loadtest and fix/improve logging (#5403)
* fix: Enable reconnectingpty loadtest and fix/improve logging

This commit re-enabled reconnectingpty loadtests after a logging
refactor of `(*agent).handleReconnectingPTY`. The reasons the tests were
flaking was that `logger.Error` was being called and `slogtest` failing
the test.

We could have set the option for `slogtest` to disable failing, but that
could hide real issues. The current approach improves reconnectingpty
logging overall and provides more insight into what's happening. It's
expected that reconnectingpty sessions fail after the agent is closed,
so calling `logger.Error` at that point is not wanted.

Ref: #5322
2022-12-13 21:28:07 +02:00
Garrett Delfosse 560c8ce0f6 fix: allow example files to be reused and not error (#5402) 2022-12-13 16:27:37 +00:00
Marcin Tojek 50d1c7191a fix: double quote in fake_cancel.sh (#5399) 2022-12-13 11:03:34 +01:00
Colin Adler 1c42a20865 chore: add debugging to agent stats report (#5395) 2022-12-13 01:03:03 -06:00
Geoffrey Huntley d72d312e1f docs(readme): update comparison table (#5394) 2022-12-13 00:55:23 +00:00
Kira Pilot a071bfa8aa fix: Store dismissedBanner key in localStorage (#5388)
* fix: Store dismissedBanner key in localStorage

* cleanup

* removed comment

* spelling

* fixed eslint

* wote test
2022-12-12 16:17:29 -05:00
Garrett Delfosse 40a5c0476f feat: add flag for token lifetime (#5385) 2022-12-12 15:39:31 -05:00
Mathias Fredriksson 760419a965 chore: Refactor agent tests to avoid t.Run when not needed (#5376)
It turns out that writing tests that contain subtests should probably be
limited to table-based tests and tests that share a common setup shared
between tests.

Writing tests with a subtest like this:

```
func TestSomething(t *testing.T) {
	t.Run("Subtest", func(t *testing.t) {})
}
```

Has the following disadvantages:

- It can lead to multiple tests failing with `(unknown)` status when
  only one of the subtests hang (never exit)
- In Go 1.20rc1, using `t.Setenv` is no longer allowed if the parent
  test is parallel
2022-12-12 22:20:46 +02:00
Geoffrey Huntley 08a6a18226 docs(comparisons): update comparison table (#5371) 2022-12-12 19:14:15 +00:00
Bruno Quaresma e7fc21e285 chore: Add react-syntax-highlight back (#5369) 2022-12-12 15:46:33 -03:00
Kyle Carberry 2b864cee9e fix: Remove @main tag from pkg.go.dev in docs links (#5384)
This seems to have broken, but removing the `main` tag makes
it resolve to the latest version.

See: https://github.com/coder/coder/actions/runs/3675316304/jobs/6215503383
2022-12-12 18:06:58 +00:00
Mathias Fredriksson 88bb901283 fix: Close tailnet if agent is closed during creation (#5375) 2022-12-12 11:26:49 +00:00
Mathias Fredriksson 1907f13c5f fix(site): Use relative date in Timeline test (#5377) 2022-12-12 13:15:28 +02:00
Garrett Delfosse ca0374b94f feat: add examples to api (#5331)
Co-authored-by: Dean Sheather <dean@deansheather.com>
2022-12-09 14:29:50 -05:00
Bruno Quaresma 6cc864c048 chore: Add icons to templates (#5368) 2022-12-09 18:47:09 +00:00
Kira Pilot c6ae151f49 feat: amending audit string to show workspace owner (#5364)
* resolves #5269

* clean up

* fixed audit link
2022-12-09 12:19:30 -05:00
Joe Previte 66ec98f647 fix: pin code-server to 4.8.3 (#5363)
* fix: pin code-server to 4.8.3

We're having some terminal issues on macOS clients (i.e. iPad) with 4.9.0 so downgrading to 4.8.3 in the meantime.

* Update dogfood/main.tf
2022-12-09 17:07:27 +00:00
Marcin Tojek 971e36781b chore: improve logging in provisionerd_test (#5353) 2022-12-09 13:11:54 +01:00
Marcin Tojek cd04330ca6 fix: replace fireEvent with userEvent (#5361)
* fix: replace fireEvent with userEvent

* fmt
2022-12-09 13:11:36 +01:00
Marcin Tojek 935d2eb582 fix: fmt should check for unstaged files (#5362) 2022-12-09 12:00:39 +01:00
Mathias Fredriksson 05130db571 fix: Improve closing of services in agent tests (#5355) 2022-12-09 12:22:27 +02:00
Bruno Quaresma 92c5e97f85 fix: Fix CSP style directive for Monaco editor (#5360) 2022-12-08 16:53:50 -03:00
Bruno Quaresma 3c9dab34bf fix: Fix CSP for monaco editor (#5358) 2022-12-08 18:32:41 +00:00
Bruno Quaresma ce76d9d5a3 feat: Add diff and Dockerfile support for template version page (#5339) 2022-12-08 10:24:15 -05:00
Ben Potter f68a65697d fix: winget package releases (#5352)
* chore: fix winget package releases

* Update .github/workflows/packages.yaml

Co-authored-by: Dean Sheather <dean@deansheather.com>
2022-12-08 09:13:13 -06:00
dependabot[bot] 7eb3ab0498 chore: bump decode-uri-component from 0.2.0 to 0.2.2 in /site (#5251)
Bumps [decode-uri-component](https://github.com/SamVerschueren/decode-uri-component) from 0.2.0 to 0.2.2.
- [Release notes](https://github.com/SamVerschueren/decode-uri-component/releases)
- [Commits](https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.2)

---
updated-dependencies:
- dependency-name: decode-uri-component
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-08 09:52:30 -05:00
Mathias Fredriksson 687261c827 fix: Close coordinator in wsconncache test (#5348)
Possibly related to #5302
2022-12-08 11:44:03 +00:00
Marcin Tojek c063ac24a3 fix: use doWithRetries when making HTTP calls (#5344) 2022-12-08 10:24:50 +01:00
Eric Paulsen 59af8349c6 docs: add offical kubernetes provider runtime_class_name (#5157)
* add: offical kubernetes provider runtime_class_name

* fix: typos

* add: coder data source & vars
2022-12-07 23:30:57 -06:00
Eric Paulsen fd54512858 helm: add certs secret mount (#4641)
* helm: add certs secret mount

* fix: values ref

* fix: conditional brackets

* rm: comment

* refactor: cert secrets list

* fix: undefined var

* chore: remove deprecated value coder.tls.secretName

* chore: improve helm volumes logic

* feat: add support for multiple CA bundles to helm

* fix: grammar

* resolve: conflict

Co-authored-by: Dean Sheather <dean@deansheather.com>
2022-12-07 17:27:36 -06:00
Kyle Carberry 3d95c9256d chore: Add DatoCMS token to dogfood template (#5254)
* chore: Add DatoCMS token to dogfood template

This is used for developing coder.com!
2022-12-07 15:59:32 -06:00
dependabot[bot] 1ac1af7db8 chore: bump emoji-mart from 5.2.1 to 5.3.3 in /site (#5226)
Bumps [emoji-mart](https://github.com/missive/emoji-mart/tree/HEAD/packages/emoji-mart) from 5.2.1 to 5.3.3.
- [Release notes](https://github.com/missive/emoji-mart/releases)
- [Commits](https://github.com/missive/emoji-mart/commits/v5.3.3/packages/emoji-mart)

---
updated-dependencies:
- dependency-name: emoji-mart
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-08 02:55:38 +10:00
Marcin Tojek 534bff2ff5 fix: coderd/prometheusmetrics wait for all metrics in require.Eventually (#5338) 2022-12-07 17:50:17 +01:00
Presley Pizzo 8ea09235f9 fix: UX issues in template settings form's default auto-stop field (#5330)
* Fix helper text

- handles 0 ttl
- uses helper text typography
- pluralizes
- still doesn't override error (once considered touched)

* Show user friendly field name in error text

* Format

* Override label through Yup instead

* Switch to i18n - wip

* Fix i18n by thunking schema

* Fix template settings tests

* Replace third arg to getFieldHelpers -is used after all
2022-12-07 11:32:39 -05:00
Ammar Bandukwala ee605b34b6 fix: Don't show progress bar for new templates (#5298) 2022-12-07 16:22:20 +00:00
Mathias Fredriksson f7467cac50 fix: Improve ptytest closure on expect match timeout (#5337)
To ensure ptytest closure always happens the same way, we now define a
new `Close` function on `PTY` and always call the close function instead
of manually closing read/writers.

A few additional log messages have been added as well, to better
understand the shutdown process in case of errors.
2022-12-07 15:20:06 +00:00
Marcin Tojek a973c35a02 chore: collect gotestsum TestEvents as workflow artifacts (#5336) 2022-12-07 15:04:39 +01:00
Marcin Tojek 3cea5f96f0 fix: wait for creating template versions (#5335) 2022-12-07 14:19:18 +01:00
Marcin Tojek 2f3ff6ced8 fix: improve pty and ptytest (#5327)
* Fix: improve ptytest

* Disable skip

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* Fix

* WIP

* Fix

* fix: pty close on Windows

* Revert changes around workflow

* fix
2022-12-07 14:18:09 +01:00
Dean Sheather 161465db55 fix: do not canonicalize Sec-WebSocket-* headers in apps (#5334)
* fix: do not canonicalize Sec-WebSocket-* headers in apps

* chore: test for non-canonical header name subst
2022-12-07 22:55:02 +10:00
Kira Pilot 85945af55e fixed bug; wrote tests (#5329) 2022-12-06 16:58:32 -05:00
Ammar Bandukwala 1cfe5de1c5 Add Service Banners (#5272) 2022-12-06 18:38:38 +00:00
Kira Pilot df389d429c Add build number to workspace_build audit logs (#5267)
* got links working

* added translations

* fixed translation

* added translation for unavailable ip

* added support for group, template, user links

* cleaned up string

* added deleted label

* querying for workspace id

* remove prints

* fix/write tests

* added build number

* checking for existence of additional fields

* adjust documentation

* PR feedback
2022-12-06 13:33:21 -05:00
Dean Sheather 6651c1632d fix: avoid terraform state concurrent access, remove global mutex (#5273) 2022-12-06 17:05:14 +00:00
Marcin Tojek 85a6d14fbb skip: reconnectingpty tests (#5322) 2022-12-06 16:36:54 +01:00
Kyle Carberry c77c1b4bc2 fix: Retry if there is no git auth user yet (#5316)
Fixes part of #4900.
2022-12-06 16:06:41 +01:00
Marcin Tojek b2dc60c030 fix: markdown-link-check base-branch should not be set on main branch (#5311) 2022-12-06 15:41:06 +01:00
Bruno Quaresma e17fd0bb25 feat: Add GET previous template version endpoint (#5230) 2022-12-06 14:15:03 +00:00
Marcin Tojek 84872d970d fix: loadtest/reconnectingpty tweak timeout (#5300)
* flaky

* fix: load test increase timeout

* Remove flaky

* Improvement

* only Linux

* WaitSuperLong

* Fix

* Try longer

* Try: sleep 120
2022-12-06 14:40:38 +01:00
dependabot[bot] 03328d4f6d chore: bump eslint from 8.24.0 to 8.29.0 in /site (#5306)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-06 12:14:31 +00:00
dependabot[bot] 4a0ca4818f chore: bump @typescript-eslint/parser from 5.38.1 to 5.45.1 in /site (#5305)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-06 12:01:01 +00:00
dependabot[bot] 825480ae9b chore: bump crate-ci/typos from 1.12.12 to 1.13.3 (#5304)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Geoffrey Huntley <ghuntley@ghuntley.com>
2022-12-06 11:50:33 +00:00
Marcin Tojek 133b2de1ca chore: improve markdown-link-check workflow (#5303) 2022-12-06 21:46:17 +10:00
Joe Previte 9e4d213c2d feat: add lazygit, remove kubic, use dotfiles in dogfood image (#5271) 2022-12-06 20:11:44 +10:00
Presley Pizzo ee74df3d07 Fix scope of dbTTL (#5197) 2022-12-05 17:19:30 -05:00
Marcin Tojek d3200382f6 fix: agent panics on closed network (#5295)
* fix: agent panics on closed network

* Remove a.network = network

* Fix

* Fix

* Fix
2022-12-05 23:18:23 +01:00
Daniel Carrion 061635c36d feat: Allow multiple OIDC domains (#5210)
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
2022-12-05 20:20:53 +02:00
Bruno Quaresma 02bb052d09 Fix template Avatar (#5294) 2022-12-05 10:50:50 -07:00
Bruno Quaresma 02dcd0e20d fix: Fix resource avatar when icon is empty string (#5291) 2022-12-05 14:37:14 -03:00
Marcin Tojek e04877a638 fix: race conditions in replicasync (#5289) 2022-12-05 17:18:15 +01:00
Bruno Quaresma 9cfdbec2ef refactor: Remove login banner (#5239) 2022-12-05 11:24:53 -03:00
Marcin Tojek cec667d309 fix: prettier misses docs directory (#5285)
* chore: keep admin/prometheus.md if make target fails

* Address PR comments

* Formatted

* fix: prettier misses docs

* make fmt

* More md files
2022-12-05 12:21:09 +01:00
Muhammad Atif Ali b46035823e docs: add templates link to README.md (#5201) 2022-12-05 16:20:01 +10:00
Muhammad Atif Ali a3083f77c7 docs: fix community templates link on site. (#5278)
Fixes #5259
2022-12-05 04:59:53 +00:00
Colin Adler a02617b66b fix: remove unnecessary WHEREs from AcquireProvisionerJob (#5257) 2022-12-02 23:53:49 +00:00
Marcin Tojek 137a48c215 fix: workspaceapps: overloaded test server responds with 502s (#5255) 2022-12-02 23:16:07 +01:00
Ammar Bandukwala 91973e1e88 cli: remove redundant client creation requests (#5264) 2022-12-02 15:40:23 -06:00
Kira Pilot 65407462d1 Add audit links/kira pilot (#5156)
* got links working

* added translations

* fixed translation

* added translation for unavailable ip

* added support for group, template, user links

* cleaned up string

* added deleted label

* querying for workspace id

* remove prints

* fix/write tests

* PR feedback pt 1

* PR feedback part 2
2022-12-02 15:14:45 -05:00
Mathias Fredriksson fa641554e8 fix: Improve agent connection tracking when agent is closed (#5253) 2022-12-02 16:24:40 +02:00
Mathias Fredriksson 81c3948792 fix: Close tty first in ptytest cleanup (#5252) 2022-12-02 12:32:50 +00:00
Marcin Tojek ee4f0fc592 chore: enable debug logging for gotestsum (#5248) 2022-12-02 12:35:14 +01:00
Colin Adler 8469dbc045 fix: add index to provisioner_jobs.started_at (#5245) 2022-12-01 19:29:15 -06:00
Colin Adler 92c217bd85 fix: add index on workspace_agents.auth_token (#5244) 2022-12-02 01:29:05 +00:00
Dean Sheather 9e80322fe5 fix: do not truncate system PATH in win installer (#5243)
The path.nsh script in the NSIS installer provided methods for adding
paths to the PATH and removing them. It would do this by reading the
current PATH value from the registry, adding the new value (if it
doesn't exist) and then writing it to the registry.

Unfortunately, it would read from the user's PATH and write the updated
result to the system PATH, which would remove important PATH entries
like the following in the process:

- C:\Windows\System32
- C:\Windows
- C:\Windows\System32\wbem
- C:\Windows\System32\WindowsPowerShell\v1.0
- C:\Windows\System32\OpenSSH
- C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR
- C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common

and would copy all user environment variables in their place. The
variables listed above were the ones missing from my machine when I
compared with a friend's machine.

Recommended course of action for affected users:
1. Add the paths listed above to your system PATH if they aren't there
   already and exist on your system.
2. Remove any paths that are in your user's PATH from your system PATH.

The existing installers for the last couple of versions of Coder have
been yanked from GitHub releases and this message will be included in
the release notes for the next patch.

Thanks to @cmor for finding and reporting this bug in #5240.
2022-12-02 09:56:49 +10:00
Colin Adler ab3b3d5fca feat: add debouncing to provisionerd rpc calls (#5198) 2022-12-01 16:54:53 -06:00
Tao Yang 5457dd0c65 feat: Let port-forwarding support custom http(s) port (#5084) 2022-12-02 06:39:19 +10:00
Mathias Fredriksson 2ec3b09ca7 fix: Fix nil-pointer deref on checkAuthorization (#5236)
Remove call to `err.Error()` on a `nil` error in `checkAuthorization`.
2022-12-01 18:42:10 +00:00
dependabot[bot] f77a445bfe chore: bump cron-parser from 4.6.0 to 4.7.0 in /site (#5221)
Bumps [cron-parser](https://github.com/harrisiirak/cron-parser) from 4.6.0 to 4.7.0.
- [Release notes](https://github.com/harrisiirak/cron-parser/releases)
- [Commits](https://github.com/harrisiirak/cron-parser/compare/4.6.0...4.7.0)

---
updated-dependencies:
- dependency-name: cron-parser
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-01 18:34:56 +00:00
dependabot[bot] 9724dbd36d chore: bump github.com/gohugoio/hugo from 0.105.0 to 0.107.0 (#5222)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-01 18:11:58 +00:00
dependabot[bot] 9675ea90e2 chore: bump google.golang.org/api from 0.100.0 to 0.103.0 (#5219)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-01 18:08:12 +00:00
dependabot[bot] 6c68126486 chore: bump github.com/spf13/viper from 1.13.0 to 1.14.0 (#5220)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-01 17:56:45 +00:00
Ammar Bandukwala 9a0a6b7002 .github: remove "never stale" 2022-12-01 11:47:01 -06:00
dependabot[bot] 7f94235419 chore: bump google.golang.org/grpc from 1.50.1 to 1.51.0 (#5223)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-01 11:43:36 -06:00
Mathias Fredriksson d9f2aaf3b4 feat: Add support for update checks and notifications (#4810)
Co-authored-by: Kira Pilot <kira@coder.com>
2022-12-01 19:43:28 +02:00
dependabot[bot] 4f1cf6c9d8 chore: bump golang.org/x/crypto from 0.1.0 to 0.3.0 (#5224)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-01 11:42:54 -06:00
dependabot[bot] 82d4aaea0b chore: bump tj-actions/branch-names from 6.2 to 6.3 (#5217)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-01 17:40:54 +00:00
dependabot[bot] 785d8750ce chore: bump hmarr/auto-approve-action from 2 to 3 (#5216)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-01 17:39:23 +00:00
dependabot[bot] e3103f3a5e chore: bump google-github-actions/auth from 0 to 1 (#5218)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-01 11:37:33 -06:00
dependabot[bot] 9a1ffe4121 chore: bump golangci/golangci-lint-action from 3.3.0 to 3.3.1 (#5214)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-01 17:11:03 +00:00
ElliotG 07560eefc0 Refactored Quota Docs (#5195) 2022-12-01 09:37:50 -07:00
Marcin Tojek 916ed284ce feat: Define Prometheus port in the pod spec (#5213)
* WIP

* portSpec

* Done

* Docs

* Fix: env
2022-12-01 15:43:32 +00:00
Mathias Fredriksson 9557d456e8 fix: Generate trial in scripts/develop.sh (#5231) 2022-12-01 17:12:16 +02:00
Marcin Tojek 883cf8afa9 chore: Add missing metrics description (#5212)
* chore: Add missing metrics description

* Update provisionerd/provisionerd.go

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* Fix

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
2022-12-01 12:50:57 +01:00
Muhammad Atif Ali 8cd8b6d858 docs: add community templates link to docs. (#5200) 2022-12-01 11:59:59 +10:00
Kyle Carberry af2c47b1a3 fix: Update install script text to separate run and use (#5203) 2022-11-30 13:38:25 -08:00
Marcin Tojek 38bdae7016 docs: Prometheus metrics + generator (#5179)
* docs: Prometheus metrics

* Fix

* Typo

* Typo

* Typo

* Fix: link

* Update docs/admin/prometheus.md

Co-authored-by: Dean Sheather <dean@deansheather.com>

* Update docs/admin/prometheus.md

Co-authored-by: Dean Sheather <dean@deansheather.com>

* Update docs/admin/prometheus.md

Co-authored-by: Dean Sheather <dean@deansheather.com>

* Update docs/admin/prometheus.md

Co-authored-by: Dean Sheather <dean@deansheather.com>

* Update docs/admin/prometheus.md

Co-authored-by: Dean Sheather <dean@deansheather.com>

* Rephrase

* notice

* use ```shell

* Generator

* gosec

* fix: lint

* PR comments

* not needed anymore

Co-authored-by: Dean Sheather <dean@deansheather.com>
Co-authored-by: Geoffrey Huntley <ghuntley@ghuntley.com>
2022-11-30 17:39:51 +01:00
Bruno Quaresma be79ae7d48 refactor: Add coder tip pill on sign in page (#5196) 2022-11-30 13:38:12 -03:00
Kyle Carberry 2a73362026 fix: add mutex to MockAuditor export to prevent race (#5189)
See: https://github.com/coder/coder/actions/runs/3575201153/jobs/6011435900.
2022-11-30 16:25:30 +00:00
Bruno Quaresma 41f10e7b69 refactor: Show template version in the workspace page (#5194) 2022-11-30 09:13:07 -05:00
Marcin Tojek 5817d2a301 skip: loadtest/reconnectingpty Test_Runner/Timeout (#5199) 2022-11-30 11:04:01 +01:00
Presley Pizzo 2e3db274f1 fix: send auto start/stop api calls only when changed (#5184)
* Send auto start/stop api calls only when changed

* Format

* Extract and test util function
2022-11-29 15:12:36 -05:00
Kyle Carberry 8b73844f69 feat: Validate Git tokens before consuming them (#5167)
* feat: Validate Git tokens before consuming them

This works the exact same way that the Git credential manager does. It ensures the user token is valid before returning it to the client.

It's been manually tested on GitHub, GitLab, and BitBucket.

* Fix requested changes
2022-11-29 12:08:27 -06:00
Marcin Tojek a8f5af1245 skip: loadtest/reconnectingpty Test_Runner/ExpectOutput (#5188) 2022-11-29 15:05:04 +00:00
Mathias Fredriksson 085f1917db fix: Fix develop script pid tracking, improve logging and interrupt (#5186) 2022-11-29 15:45:14 +02:00
Dean Sheather 15f8967a8a feat: tracing improvements (#4988) 2022-11-29 07:22:10 +10:00
Bruno Quaresma d402914eb7 refactor: Return template version name in the workspace build API (#5178) 2022-11-28 19:53:56 +00:00
Steven Masley ab9298f382 chore: Rewrite rbac rego -> SQL clause (#5138)
* chore: Rewrite rbac rego -> SQL clause

Previous code was challenging to read with edge cases
- bug: OrgAdmin could not make new groups
- Also refactor some function names
2022-11-28 12:12:34 -06:00
Presley Pizzo d5ab4fdeb8 fix: auto-stop bumper works and refreshes (#5162)
* Publish updates to workspace deadline

* Fix sync between machines
2022-11-28 10:59:43 -05:00
Muhammad Atif Ali 898ba11ef0 fix: packages.yaml action is not running on release trigger (#5173)
This commit is a workaround to run the `packages.yaml` action after the release action
Fixes #5137.
Check #5137 for context.
2022-11-27 07:06:34 -06:00
Muhammad Atif Ali 25c80566e7 docs: Add GitHub action to push template changes automatically (#5166)
Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
2022-11-26 13:36:14 +00:00
Muhammad Atif Ali 5f31ea3ffb docs: add docs on how to allow public github signups (#5168) 2022-11-25 20:03:07 +02:00
Cian Johnston a4a319a76e feat: add CODER_OIDC_IGNORE_EMAIL_VERIFIED config knob (#5165)
* Adds a configuration knob CODER_OIDC_IGNORE_EMAIL_VERIFIED that allows
  ignoring the email_verified OIDC claim
* Adds warning message at startup if CODER_OIDC_IGNORE_EMAIL_VERIFIED=true
* Adds warning whenever an unverified OIDC email is let through
* Skips flaky test on non-linux platforms

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
2022-11-25 10:10:09 +00:00
Mathias Fredriksson 6ed12ade54 fix: Improve debuggability of ptytest cleanup (#5170)
There are sporadic flakes in some tests on Windows related to the use of
`ptytest`. Since it's not clear why they fail, this commit adds some
more logging and timeouts to the cleanup methods.
2022-11-24 15:20:17 +00:00
Marcin Tojek 25da224513 Filter query: has-agent connecting, connected, disconnected, timeout (#5145)
* WIP

* has-agent:connecting, connected

* Fix

* Fix

* has-agent:disconnected, timeout

* Fix: typo

* Fix

* TODOs

* databasefake

* Fix: typo

* More TODOs

* databasefake

* Timeout tests

* Address PR comments

* Implement FIXMEs

* Renamings

* Address PR comments

* Fix: readability

* Fix: refactor CASE logic

* CASE logic

* Fix

* Use CTE

* Polishing

* Comment

* WIP

* IS NOT NULL

* Without CTE

* One more optimization

* 2nd optimization
2022-11-24 15:33:13 +01:00
Bruno Quaresma 511bb469c4 feat: Change workspace version using the UI (#5158) 2022-11-24 13:36:50 +00:00
Mathias Fredriksson eff99f78fa feat: Add support for MOTD file in coder agents (#5147) 2022-11-24 12:22:20 +00:00
Mathias Fredriksson 8ff89c4288 fix: Fix flakeyness of TestProvisionerd/ReconnectAndComplete (#5169) 2022-11-24 14:09:56 +02:00
Presley Pizzo 913e461f79 Don't override 0 ttl with template default (#5151) 2022-11-23 10:30:38 -05:00
Bruno Quaresma 59355431d0 refactor: Refactor login page (#5148) 2022-11-23 14:53:42 +00:00
Presley Pizzo 71bc48dda4 feat: tweak timeline design (#5144)
* Tweak timeline design

* Extract timeline style into component
2022-11-22 17:30:43 -05:00
Kira Pilot 6786ca2854 Audit build outcomes/kira pilot (#5143)
* auditing failed builds

* logging workspace build successes

* remove duplicate workspace build entry

* fixed workspacebuilds_test

* PR feedback

* lint and migrations

* fix nil auditors

* workspace_build test

* fixed workspaces_teest

Co-authored-by: Colin Adler <colin1adler@gmail.com>
2022-11-22 13:22:56 -05:00
Colin Adler 1f20cab110 fix: don't use yamux for in-memory provisioner{,d} streams (#5136) 2022-11-22 12:19:32 -06:00
Mathias Fredriksson 2b6c229e4e fix: Trigger workspace event after agent timeout seconds (#5141)
Fixes #5116
2022-11-22 11:01:28 +00:00
Marcin Tojek e94b27bce4 fix: Adjust description for cancel in-progress workspace jobs (#5142)
* fix: Adjust description for cancel in-progress workspace jobs

* Update site/src/i18n/en/templatePage.json

Co-authored-by: Presley Pizzo <1290996+presleyp@users.noreply.github.com>

Co-authored-by: Presley Pizzo <1290996+presleyp@users.noreply.github.com>
2022-11-21 17:00:18 +00:00
Presley Pizzo 67941b4f80 chore: refactor audit page to use window function for count (#5133)
* Move count query to window function

* Unpack count and update types

* Remove count endpoint

* Update tests, wip

* Fix tests

* Update frontend, wip

* Remove space

* Fix frontend test

* Don't hang on error

* Handle no results

* Don't omit count

* Fix frontend tests
2022-11-21 11:30:41 -05:00
Bruno Quaresma 7a369e0a30 refactor: Minor build bar UI improvement (#5132) 2022-11-21 10:04:24 -05:00
Marcin Tojek e86539db11 feat: Allow user to cancel workspace jobs (#5115)
* Add database column allow_user_cancel_workspace_jobs

* Adjust API

* site: typesGenerated.ts

* Expose template.allow_ in Workspaces API

* Fix: site tests

* Fix: make fmt/prettier

* Fix: enterprise

* Database tests

* Add CLI tests

* Add checkbox

* i18n

* Logic: block cancelling

* Unit tests for conditional cancel

* Fix: message

* Address PR comment

* Address PR comments

* Fix: make
2022-11-21 11:43:53 +01:00
Bruno Quaresma 5fa3fdeca0 refactor: Improve empty views (#5134) 2022-11-19 01:46:11 +00:00
Bruno Quaresma a477d901d6 refactor: Fix up to date color (#5131) 2022-11-19 01:18:40 +00:00
Colin Adler ae38bbeab6 chore: refactor agent stats streaming (#5112) 2022-11-18 16:46:53 -06:00
Bruno Quaresma 13a4cfa670 chore: Remove unused test files and code (#5130) 2022-11-18 18:03:15 +00:00
Presley Pizzo 4c24adb471 Fix filter bug (#5124) 2022-11-18 09:53:16 -05:00
Bruno Quaresma 5866ca48a9 refactor: Reemove mono font from empty title (#5125) 2022-11-18 10:09:13 -03:00
Ben Potter edad2d01da chore: fix typo in cvm docs (#5120) 2022-11-18 06:01:01 +00:00
Dean Sheather 69e8c9e7b4 feat: add reconnectingpty loadtest (#5083) 2022-11-17 16:57:15 +00:00
Ammar Bandukwala acf34d4295 site: support high build time variation in progress bar (#4941) 2022-11-17 16:56:56 +00:00
Kyle Carberry 60cec022eb fix: Parse boolean in slice for gitauth (#5113)
This was causing a panic for the new `no_refesh` option!
2022-11-17 07:52:11 -06:00
Ben Potter 8e468c49cb chore: default to generic troubleshooting link (#5007) 2022-11-17 11:10:49 +00:00
Kyle Carberry fb9ca7b830 feat: Add the option to generate a trial license during setup (#5110)
This allows users to generate a 30 day free license during setup to
test out Enterprise features.
2022-11-16 17:09:49 -06:00
Kyle Carberry b6703b11c6 feat: Add external provisioner daemons (#4935)
* Start to port over provisioner daemons PR

* Move to Enterprise

* Begin adding tests for external registration

* Move provisioner daemons query to enterprise

* Move around provisioner daemons schema

* Add tags to provisioner daemons

* make gen

* Add user local provisioner daemons

* Add provisioner daemons

* Add feature for external daemons

* Add command to start a provisioner daemon

* Add provisioner tags to template push and create

* Rename migration files

* Fix tests

* Fix entitlements test

* PR comments

* Update migration

* Fix FE types
2022-11-16 16:34:06 -06:00
Colin Adler 66d20cabac fix: index GetWorkspaceAgentsByResourceIDs query (#5021) 2022-11-16 14:40:57 -06:00
Colin Adler e7f1192614 fix: add index for GetProvisionerLogsByIDBetween (#5020) 2022-11-16 14:32:29 -06:00
Ammar Bandukwala da758ba712 site: fix quota_allowance == 0 bug (#5108) 2022-11-16 18:20:07 +00:00
Steven Masley 894953db3d fix: Workspace ls show only me by default (#5107) 2022-11-16 17:58:50 +00:00
Steven Masley 015a6f9e26 fix: RBAC should default deny missing variables. (#5105)
* fix: RBAC should default deny missing variables.

The default behavior was to use 'true' for missing variables. This
was an incorrect assumption. If the variable is missing, the new
default is to deny (fail secure).

* Assert 1 workspace is returned for the owners
2022-11-16 11:01:09 -06:00
Bruno Quaresma 1fcc7caf99 fix: Fix tab default (#5104) 2022-11-16 16:43:35 +00:00
Presley Pizzo e6ead7d915 chore: refactor workspaces query to use window function (#5079)
* Use window function in query

* Convert workspace rows and unpack count

* Update types

* Fix Scan bug

* Remove getCountError
2022-11-16 10:16:37 -05:00
Presley Pizzo 560d3c9fd0 fix: remove pagination widget when filter is invalid (#5095)
* Clear count along with user, remove count error

* Format
2022-11-16 09:55:41 -05:00
Marcin Tojek 32927b1a24 feat: show template.display_name on Workspace pages (#5082)
* feat: expose template.display_name via Workspaces endpoint

* Fix: MockWorkspace

* UI: Workspace stats and row

* Show template.display_name on pages

* Fix: address PR comments

* Add helper function: getDisplayWorkspaceTemplateName
2022-11-16 15:50:32 +01:00
Mathias Fredriksson c1ecc91aab feat: Add fallback troubleshooting URL for coder agents (#5005) 2022-11-16 12:53:02 +02:00
Geoffrey Huntley 1f4f0cee2a chore(branding): update branding (#5028) 2022-11-16 07:15:33 -03:00
Ben Potter 09ee844389 fix: git docs link (#5099) 2022-11-15 21:19:52 +00:00
Kyle Carberry fc0a493b72 feat: Add no_refresh option to Git auth configs (#5097)
This allows organizations to disable refreshing Git tokens
and instead prompt for authentication again.
2022-11-15 21:06:13 +00:00
Bruno Quaresma 2a46702fc5 fix: Syntax highlighting with long lines and untar content with emojis (#5098) 2022-11-15 20:09:54 +00:00
Ammar Bandukwala 44d3225932 .github: remove issue templates
Developers prefer no template based on Slack poll.
2022-11-15 20:02:50 +00:00
Mathias Fredriksson d9a83fc723 fix: Refactor tailnet conn AwaitReachable to allow for pings >1s RTT (#5096) 2022-11-15 20:59:22 +02:00
Marcin Tojek eda7c66896 chore: TemplatesPage tests failing on M1 (#5088) 2022-11-15 19:45:01 +01:00
Bruno Quaresma e68923fa36 fix: Worker security policy (#5093) 2022-11-15 17:02:24 +00:00
Mathias Fredriksson 9fb710a04f feat: Add allow everyone option to GitHub OAuth2 logins (#5086)
* feat: Add allow everyone option for GitHub OAuth

* fix: Detect team when multiple orgs are present

Co-authored-by: 李董睿煊 <dongruixuan@hotmail.com>
2022-11-15 18:56:46 +02:00
Bruno Quaresma f262fb4811 feat: Add template version page (#5071) 2022-11-15 16:24:13 +00:00
Kyle Carberry 773fc73280 fix: Add debug logging for connecting to psql (#5078)
If a database connection hung, the output was unclear.
2022-11-14 20:10:37 -06:00
Kyle Carberry 50b5becfb0 fix: Invert err nil check for opening Git URL (#5077)
Thanks @kconley-sq! 🥳
2022-11-14 20:10:23 -06:00
Geoffrey Huntley b5181aacd7 feat(i18n): adjust language when deleting a template (#5056) 2022-11-15 10:12:53 +10:00
Garrett Delfosse 88f3691dcc feat: add count to get users endpoint (#5016) 2022-11-14 17:22:57 -05:00
Marcin Tojek 49b340e039 Show template.display_name in the site UI (#5069)
* Show display_name field in the template settings

* Show template.display_name on pages: Templates, CreateWorkspace

* Fix: template.display_name pattern

* make fmt/prettier

* Fix tests

* Fix: make fmt/prettier

* Fix: merge

* Fix: autoFocus

* i18n: display_name
2022-11-14 21:11:50 +01:00
Mathias Fredriksson e872e18883 chore: Set initialism for DefaultTTL (from DefaultTtl) (#4996) 2022-11-14 20:14:08 +02:00
Ammar Bandukwala 97dbd4dc5d Implement Quotas v3 (#5012)
* provisioner/terraform: add cost to resource_metadata

* provisionerd/runner: use Options struct

* Complete provisionerd implementation

* Add quota_allowance to groups

* Combine Quota and RBAC licenses

* Add Opts to InTx
2022-11-14 17:57:33 +00:00
Kira Pilot 3fb7892c07 fix: template permissions page never loads (#5014)
* removed redundant permissions loader

* fixed tests
2022-11-14 12:33:17 -05:00
Kyle Carberry fefacc5bfd chore: Expose additional agent options to telemetry (#5070)
This also adds a few properties for deployments!
2022-11-14 10:11:08 -06:00
Geoffrey Huntley 9692cc2e22 housekeeping: structure GitHub issues via templates (#5025) 2022-11-14 09:32:54 -06:00
Marcin Tojek cf5d48bb5a fix: do not skip properties on creating templates (#5060)
* fix: do not skip properties while creating templates

* test: empty edit
2022-11-14 15:32:18 +01:00
Mathias Fredriksson 4b3d211e00 fix: Use UTC in cli/cliui table test to match expected output (#5063) 2022-11-14 15:08:51 +02:00
Muhammad Atif Ali 990be63c60 feat: create winget package workflow (#4761)
Co-authored-by: Dean Sheather <dean@deansheather.com>
2022-11-14 12:59:08 +00:00
Marcin Tojek 1b6d0c39e1 docs: Rephrase Templates section (#5062)
* docs: Rephrase Templates section

* Update docs/templates.md

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* Update docs/templates.md

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* Update docs/templates.md

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

* Update docs/templates.md

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
2022-11-14 12:06:16 +00:00
Mathias Fredriksson e72927f3ab fix: Avoid running shell twice in coder agent (#5061)
The users login shell would be executed as:

	/bin/bash -c '/bin/bash -l'

This simplifies the command for login shells so that the executed
command is:

	/bin/bash -l
2022-11-14 14:01:22 +02:00
Mathias Fredriksson c515085450 fix: Unify context usage for agent cmd and logs (#5059) 2022-11-14 13:48:44 +02:00
Geoffrey Huntley cbb1e91372 feat(windows): default to PowerShell v7 over v6 and fallback to cmd.exe (#5053) 2022-11-14 15:43:40 +10:00
Mathias Fredriksson f017548a9c fix: Return correct exit code for SFTP sessions (#5044)
Fixes #5038
2022-11-13 23:22:50 +02:00
Kyle Carberry 2a6fff9227 fix: Set a default CODER_ACCESS_URL in Helm (#5041)
* fix: Set a default `CODER_ACCESS_URL` in Helm

This allows for a simple `helm apply` to create a full Coder
deployment that works for creating workspaces.

* Update docs
2022-11-13 14:49:57 -06:00
Ammar Bandukwala 73f91e4690 ci: use big runners (#4990)
* chore: Close idle connections on test cleanup

It's possible that this was the source of a leak on Windows...

* ci: use big runners

* fix: Improve tailnet connections by reducing timeouts

This awaits connection ping before running a dial. Before,
we were hitting the TCP retransmission and handshake timeouts,
which could intermittently add 1 or 5 seconds to a connection
being initialized.

* Add logging to Startupscript test

* Add better logging

* Write startup script logs to fs dir

* Fix startup script test

* Fix startup script test

* Reduce test timeout

* Use central tmp dir in agent

* Adjust output

* Skip startup script test on Windows

Co-authored-by: Kyle Carberry <kyle@carberry.com>
2022-11-13 14:23:23 -06:00
Arthur Normand 9578ce9f77 OAuth now uses client TLS certs (if configured) (#5042)
* OAuth now uses client TLS certs (if configured)

* Update docs

* Cleaning

* Fix lint errors and generate static files

* Fix lint error and regenerate more static files

* Suppress lint error
2022-11-13 14:15:06 -06:00
Kyle Carberry 49c7648af5 chore: Close idle connections on test cleanup (#4993)
It's possible that this was the source of a leak on Windows...
2022-11-13 14:06:03 -06:00
zhaozhiming 30e9ecbc96 docs: fix offline install docs some errors (#5039)
* docs: fix offline install docs some error

* retrigger checks
2022-11-13 14:05:19 -06:00
Kyle Carberry 82f494c99c fix: Improve tailnet connections by reducing timeouts (#5043)
* fix: Improve tailnet connections by reducing timeouts

This awaits connection ping before running a dial. Before,
we were hitting the TCP retransmission and handshake timeouts,
which could intermittently add 1 or 5 seconds to a connection
being initialized.

* Update Tailscale
2022-11-13 11:33:05 -06:00
Geoffrey Huntley 4646f58072 housekeeping(terraform): bump TerraformVersion (#4867) 2022-11-12 09:35:12 +10:00
Ammar Bandukwala 95fb59696e Refactor Provisioner to distinguish Plan and Apply (#5036) 2022-11-11 16:45:58 -06:00
Mathias Fredriksson 71601f4971 fix: Fix log wrapper for vite in scripts/develop.sh (#5030)
The pid tracking refactor resulted in the pipe while echo to block the
script from continuing and showing the banner at the end. This change
redirects the stdout for the `start_cmd` to a new fd which `while` is
reading from.
2022-11-11 12:39:33 +00:00
Eric Paulsen 823b02ac9c docs: deprecate name arg (#5026) 2022-11-11 06:16:14 +00:00
Kyle Carberry 4b7c710755 fix: Block creating workspaces with deleted templates (#5019)
@coadler and @deansheather bricked a Coder deployment with this...
2022-11-10 16:53:14 -06:00
Kyle Carberry 927c241995 fix: Debounce AcquireJob when no jobs are available (#5017)
This prevents constant database spam at scale to a maximum
of 60 queries/s per coderd instance.
2022-11-10 22:37:33 +00:00
Geoffrey Huntley f32748c929 housekeeping(stalebot): never close never stales (#4891) 2022-11-10 16:28:20 -06:00
Dean Sheather 8e5af82275 feat: add api-rate-limit flag (#5013) 2022-11-10 21:53:48 +00:00
Marcin Tojek 2042b575dc feat: Add template display name (backend) (#4966)
* Rename to nameValidator

* Refactor: NameValid

* Fix: comment

* Define new migration

* Include display_name

* Update typesGenerated.ts

* Update meta

* Adjust tests

* CLI tests

* Fix: audit

* Fix: omitempty

* site: display_name is optional

* unit: TestUsernameValid

* entities.ts: add display_name

* site: TemplateSettingsPage.test.tsx

* Fix: TemplateSettingsForm.tsx

* Adjust tests

* Add comment to display_name column

* Fix: rename

* Fix: make

* Loosen regexp

* Fix: err check

* Fix: template name length

* Allow for whitespaces

* Update migration number
2022-11-10 21:51:09 +01:00
Colin Adler f3eb662208 fix: add index for workspace_resource.job_id column (#5009) 2022-11-10 20:09:44 +00:00
Mathias Fredriksson 5e2253030f fix: Revert develop.sh timeout -> curl change (#5008)
It seems `--retry-all-errors` is not available on e.g. curl 7.68.0.
2022-11-10 19:49:11 +00:00
Colin Adler 8c8344ca13 fix: tolerate non-json lines in provisionerd logs (#5006)
Co-authored-by: Dean Sheather <dean@deansheather.com>
2022-11-10 13:26:57 -06:00
Mathias Fredriksson a25deb939b fix: Misc improvements to scripts/develop.sh (#4995)
* Use new `/healthz` endpoint for checking API liveness
* Improved credential handling/retrying in failure scenarios
* Separate site (`vite`) logs with prefix and date, additionally this
  method also disables the `vite` clearing of the screen
* Show all interfaces coder API is listening on (due to `0.0.0.0`)
* Improved shutdown procedure / interrupt handling
2022-11-10 20:47:42 +02:00
Garrett Delfosse 766a2ad590 chore: refactor workspace count to single route (#4809)
Co-authored-by: Presley Pizzo <presley@coder.com>
2022-11-10 13:25:46 -05:00
Mathias Fredriksson 5fb9c33ecd fix: Fix ssh message/spinner in VSCode integrated terminal (#5000)
* fix: Fix ssh message/spinner in VSCode integrated terminal

The messages never show up in VSCode integrated terminal due to the
defer `fmt.Fprintf`. There could be a race in VSCode in handling the
terminal codes but ultimately, we can simplify our logic by just
stopping the spinner for the duration of the update.

* Avoid race in starting spinner after exit
2022-11-10 18:21:38 +00:00
Dean Sheather e847276d74 feat: add cleanup strategy to loadtest (#4991) 2022-11-11 04:14:50 +10:00
Kira Pilot 1c9677d37a Template delete button/kira pilot (#4992)
* removed button

* ripped out delete dialog

* fixed tests

* added error message back

* redirecting after success
2022-11-10 10:41:36 -05:00
Mathias Fredriksson 0eed533b17 fix: Improve agent waiting/timeout message behavior in ssh (#4999) 2022-11-10 15:41:23 +00:00
Kyle Carberry aa9fa2bdff chore: Disable load test for flakes (#4998) 2022-11-10 15:31:35 +00:00
Marcin Tojek d64c73dd74 chore: ignore .envrc (#4994) 2022-11-10 11:55:55 +01:00
Mathias Fredriksson 570a1ffc2b fix: Improve docker example first user experience (#4972)
The base ubuntu image lands the user as root, but the terraform tempalte
expected /home/coder to be used. This change adds a user with the same
name as the Coder users username and allows them to sudo.
2022-11-10 12:55:39 +02:00
Mathias Fredriksson 4885ecc3ad fix: Allow dumping db with pg_dump, utilize make cache (#4964) 2022-11-10 12:54:47 +02:00
Eric Paulsen 18a97c6f59 helm: add affinity, nodeSelectors, tolerations (#4763) 2022-11-09 22:08:44 +00:00
Bruno Quaresma d225f2c6ba feat: Display warning on agent connection timeout (#4983) 2022-11-09 20:40:34 +00:00
Kyle Carberry 16e9b1eb1a fix: Add timeouts to every tailnet ping (#4986)
A ping isn't guaranteed to deliver, so these need to have a
tight timeout for tests to not flake.
2022-11-09 20:12:51 +00:00
Dean Sheather 45f81a7cd5 fix: prevent terraform init races (#4985) 2022-11-09 19:40:52 +00:00
Garrett Delfosse d277e28427 feat: change template max_ttl to default_ttl (#4843) 2022-11-09 19:36:25 +00:00
Dean Sheather ffc24dcbe0 feat: create tracing.SlogSink for storing logs as span events (#4962) 2022-11-09 12:58:23 -06:00
Dean Sheather 0ae8d5eeec fix: prevent races from processing build logs after channel close (#4984) 2022-11-10 04:32:59 +10:00
Kyle Carberry 3c10c7f5f4 fix: Subscribe to template updates on the workspace page (#4979)
Fixes #4969.
2022-11-09 11:01:34 -06:00
Mathias Fredriksson 5592f85c11 chore: Find source files once in Makefile targets (#4968) 2022-11-09 18:39:42 +02:00
Kyle Carberry 089659ffb1 fix: Move SQL connection limits to initialization (#4981)
The connection limit wasn't being applied to pubsub, which would
overload the server if a ton of logs were being published at once.

This should fix it, and improve scale a lot!
2022-11-09 16:25:25 +00:00
Mathias Fredriksson 90c34b74de feat: Add connection_timeout and troubleshooting_url to agent (#4937)
* feat: Add connection_timeout and troubleshooting_url to agent

This commit adds the connection timeout and troubleshooting url fields
to coder agents.

If an initial connection cannot be established within connection timeout
seconds, then the agent status will be marked as `"timeout"`.

The troubleshooting URL will be present, if configured in the Terraform
template, it can be presented to the user when the agent state is either
`"timeout"` or `"disconnected"`.

Fixes #4678
2022-11-09 17:27:05 +02:00
Mathias Fredriksson ed7de90a55 fix: Use immutable names for volumes in example templates (#4954)
* fix: Use immutable names for volumes in example templates

This contributes towards #3000, #3386

Related #3409

* Add lifecycle and labels
2022-11-09 16:18:19 +02:00
Mathias Fredriksson 26ab0d37c1 fix: Protect codersdk.Client SessionToken so it can be updated (#4965)
This feature is used by the coder agent to exchange a new token. By
protecting the SessionToken via mutex we ensure there are no data races
when accessing it.
2022-11-09 15:31:24 +02:00
sharkymark 8cadb33396 chore: remove sample jetbrains projector code, only use 2 kubernetes example repos (#4819) 2022-11-09 10:30:38 +00:00
sharkymark b6f2a29b7e docs: update port forwarding to state it works without a wildcard with tunnel (#4887) 2022-11-09 20:25:32 +10:00
Dean Sheather d82364b9b5 feat: make trace provider in loadtest, add tracing to sdk (#4939) 2022-11-09 08:10:48 +10:00
Presley Pizzo fa844d0878 Feat: hide pagination widget when not needed (#4957)
* Hide pagination widget when not needed. Don't merge until count is in.

* Format

* Refactor

* Remove story

* Fix bug

* Format
2022-11-08 13:29:32 -05:00
Mathias Fredriksson e906d0dc54 feat: Add database fixtures for testing migrations (#4858) 2022-11-08 19:59:44 +02:00
Kyle Carberry b97043850b fix: Remove action from build cancelation names (#4930)
This looked weird in the UI and didn't conform to our other states.
2022-11-08 17:12:06 +00:00
Garrett Delfosse 2789fb7cac fix: move experimental flag to server (#4959) 2022-11-08 16:59:39 +00:00
Mathias Fredriksson b2a16d46c6 chore: Unify Docker terraform templates (#4952)
Changes to terraform templates:

* Remove DNS (this can interfere with users running their own DNS
  servers)
* Remove `lower()` restriction from hostnames so that it will show the
  name set by the user, as-is (there is no restriction on upper case
  letters in hostnames)
* Remove superfluous `trap` in entrypoints, this is already handled by
  the init script
* Switch from `command` to `entrypoint` as the latter can support more
  Docker images out-of-the-box
2022-11-08 18:52:19 +02:00
dependabot[bot] 6baaf205c8 chore: bump loader-utils from 1.4.0 to 1.4.1 in /site (#4956)
Bumps [loader-utils](https://github.com/webpack/loader-utils) from 1.4.0 to 1.4.1.
- [Release notes](https://github.com/webpack/loader-utils/releases)
- [Changelog](https://github.com/webpack/loader-utils/blob/v1.4.1/CHANGELOG.md)
- [Commits](https://github.com/webpack/loader-utils/compare/v1.4.0...v1.4.1)

---
updated-dependencies:
- dependency-name: loader-utils
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-11-08 10:09:33 -06:00
Presley Pizzo 87b3fe1afb feat: add "on this page" to empty table message when you're past page 1 (#4886)
* Use empty page message on workspaces page

* Add prop for story

* AuditPage

* UsersPage

* Lint and format

* Fix tests

* Remove log

* Try to fix story

* Fix the right story
2022-11-08 11:08:51 -05:00
Presley Pizzo f496b149df feat: add count endpoint for users, enabling better pagination (#4848)
* Start on backend

* Hook up frontend

* Add to frontend test

* Add go test, wip

* Fix some test bugs

* Fix test

* Format

* Add to authorize.go

* copy user array into local variable

* Authorize route

* Log count error

* Authorize better

* Tweaks to authorization

* More authorization tweaks

* Make gen

* Fix test

Co-authored-by: Garrett <garrett@coder.com>
2022-11-08 10:58:44 -05:00
Kyle Carberry a4fbc74751 chore: Update gotestsum (#4955)
This was breaking CI!
2022-11-08 09:58:01 -06:00
Mathias Fredriksson d1c82f6c52 fix: Off-by-one created after notification for provisioner logs (#4949)
Fixes #4948
2022-11-08 17:56:16 +02:00
Bruno Quaresma e7bd04999f fix: Optimistically update the UI when a workspace action is triggered (#4929) 2022-11-08 09:35:19 -05:00
Marcin Tojek bf4a6fb5b5 feat: pprof is always on (#4951) 2022-11-08 15:02:07 +01:00
Marcin Tojek 16384f8594 feat: Add provisioner force-cancel flag (#4947)
* feat: Add provisionerd force cancel flag

* Golden files

* Fix: typesGenerated.ts

* Use single struct for Provisioner config
2022-11-08 14:19:40 +01:00
Bruno Quaresma f6130e25b2 refactor: Disable auto-complete for the new user form (#4933) 2022-11-08 13:10:25 +00:00
Bruno Quaresma 2af698c43d refactor: Remove workspace schedule banner (#4932) 2022-11-08 10:05:47 -03:00
Kyle Carberry da05bbbdf7 chore: Separate the provisionerd server into it's own package (#4940)
* chore: Separate the provisionerd server into it's own package

This code should be thoroughly tested now that we understand the abstraction.

I separated it to make our lives a bit easier for external provisioner daemons
as well!

* Add tests

* Add workspace builds

* Add test for workspace resources
2022-11-08 01:10:49 +00:00
Kyle Carberry bf2f7b575e chore: Disable docs.github.com for link checks (#4945)
This was causing CI to fail... maybe they have bot detection?
2022-11-07 18:39:46 -06:00
Kyle Carberry 165b6fbc6a fix: Use app slugs instead of the display name to report health (#4944)
All applications without display names were reporting broken health.
2022-11-07 23:35:01 +00:00
Colin Adler 50ad4a8535 fix: use backend for /healthz page (#4938) 2022-11-07 19:35:52 +00:00
Ben Potter bda76368bc docs: git auth (#4902) 2022-11-07 19:04:00 +00:00
sharkymark 1545979e6f docs: 1. fix closing ) on projector examples 2.update jupyter section for slug config and removal of owner and workspace baseURL (#4920) 2022-11-07 12:41:03 -06:00
Marcin Tojek 641aacf793 feat: show banner when workspace is outdated (#4926)
* feat: show banner when workspace is outdated

* Address PR comments

* Fix: writer
2022-11-07 19:12:39 +01:00
Bruno Quaresma f15854c179 fix: Fix long audit log string (#4931) 2022-11-07 14:39:37 -03:00
Dean Sheather 5f099ea488 feat: loadtest output formats (#4928) 2022-11-08 03:26:50 +10:00
Dean Sheather f9189772d7 feat: add new loadtest type agentconn (#4899) 2022-11-07 17:18:07 +00:00
Kyle Carberry 56b963a940 feat: Make workspace watching realtime instead of polling (#4922)
* feat: Make workspace watching realtime instead of polling

This was leading to performance issues on the frontend, where
the page should only be rendered if changes occur. While this
could be changed on the frontend, it was always the intention
to make this socket ~realtime anyways.

* Fix workspace tests waiting, erroring on workspace update, and add comments to workspace events
2022-11-07 15:25:18 +00:00
Muhammad Atif Ali a5cc1970cf bug: fixed prompt in .devcontainer/Dockerfile (#4820)
The user prompt was causing the GitHub codespaces build to fail.
2022-11-07 09:03:55 -03:00
Kyle Carberry 53f2449e4f chore: Fix changes from buffer provisioner logs (#4924)
Comments from #4918 were missed because of auto-merge.
2022-11-06 23:59:01 -06:00
Kyle Carberry 30281852d6 feat: Add buffering to provisioner job logs (#4918)
* feat: Add bufferring to provisioner job logs

This should improve overall build performance, and especially under load.

It removes the old `id` column on the `provisioner_job_logs` table
and replaces it with an auto-incrementing big integer to preserve order.

Funny enough, we never had to care about order before because inserts
would at minimum be 1ms different. Now they aren't, so the order needs
to be preserved.

* Fix log bufferring

* Fix frontend log streaming

* Fix JS test
2022-11-06 20:50:34 -06:00
sharkymark 531f7cd489 docs: adding sharkymark example templates to community page (#4911) 2022-11-06 17:03:37 -06:00
Colin Adler 65ffa20ba2 fix: use correct empty uuids (#4917) 2022-11-06 16:49:43 -06:00
2419 changed files with 267870 additions and 68670 deletions
+35 -35
View File
@@ -3,30 +3,30 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ENV EDITOR=vim
RUN apt-get update && apt-get upgrade
RUN apt-get update && apt-get upgrade --yes
RUN apt-get install --yes \
ca-certificates \
bash-completion \
build-essential \
curl \
cmake \
direnv \
emacs-nox \
gnupg \
htop \
jq \
less \
lsb-release \
lsof \
man-db \
nano \
neovim \
ssl-cert \
sudo \
unzip \
xz-utils \
zip
ca-certificates \
bash-completion \
build-essential \
curl \
cmake \
direnv \
emacs-nox \
gnupg \
htop \
jq \
less \
lsb-release \
lsof \
man-db \
nano \
neovim \
ssl-cert \
sudo \
unzip \
xz-utils \
zip
# configure locales to UTF8
RUN apt-get install locales && locale-gen en_US.UTF-8
@@ -39,25 +39,25 @@ RUN direnv hook bash >> $HOME/.bashrc
RUN sh <(curl -L https://nixos.org/nix/install) --daemon
RUN mkdir -p $HOME/.config/nix $HOME/.config/nixpkgs \
&& echo 'sandbox = false' >> $HOME/.config/nix/nix.conf \
&& echo '{ allowUnfree = true; }' >> $HOME/.config/nixpkgs/config.nix \
&& echo '. $HOME/.nix-profile/etc/profile.d/nix.sh' >> $HOME/.bashrc
&& echo 'sandbox = false' >> $HOME/.config/nix/nix.conf \
&& echo '{ allowUnfree = true; }' >> $HOME/.config/nixpkgs/config.nix \
&& echo '. $HOME/.nix-profile/etc/profile.d/nix.sh' >> $HOME/.bashrc
# install docker and configure daemon to use vfs as GitHub codespaces requires vfs
# https://github.com/moby/moby/issues/13742#issuecomment-725197223
RUN mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg \
&& echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null \
&& apt-get update \
&& apt-get install --yes docker-ce docker-ce-cli containerd.io docker-compose-plugin \
&& mkdir -p /etc/docker \
&& echo '{"cgroup-parent":"/actions_job","storage-driver":"vfs"}' >> /etc/docker/daemon.json
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg \
&& echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null \
&& apt-get update \
&& apt-get install --yes docker-ce docker-ce-cli containerd.io docker-compose-plugin \
&& mkdir -p /etc/docker \
&& echo '{"cgroup-parent":"/actions_job","storage-driver":"vfs"}' >> /etc/docker/daemon.json
# install golang and language tooling
ENV GO_VERSION=1.19
ENV GO_VERSION=1.20
ENV GOPATH=$HOME/go-packages
ENV GOROOT=$HOME/go
ENV PATH=$GOROOT/bin:$GOPATH/bin:$PATH
@@ -67,6 +67,7 @@ RUN echo 'export PATH=$GOPATH/bin:$PATH' >> $HOME/.bashrc
RUN bash -c ". $HOME/.bashrc \
go install -v golang.org/x/tools/gopls@latest \
&& go install -v mvdan.cc/sh/v3/cmd/shfmt@latest \
&& go install -v github.com/mikefarah/yq/v4@v4.30.6 \
"
# install nodejs
@@ -80,4 +81,3 @@ RUN bash -c "$(curl -fsSL https://raw.githubusercontent.com/horta/zstd.install/m
RUN echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | sudo tee /etc/apt/sources.list.d/goreleaser.list \
&& apt update \
&& apt install nfpm
+17 -11
View File
@@ -1,18 +1,24 @@
// For format details, see https://aka.ms/devcontainer.json
{
"name": "Development environments on your infrastructure",
"name": "Development environments on your infrastructure",
// Sets the run context to one level up instead of the .devcontainer folder.
"context": ".",
// Sets the run context to one level up instead of the .devcontainer folder.
"context": ".",
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerFile": "Dockerfile",
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerFile": "Dockerfile",
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
"postStartCommand": "dockerd",
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// privileged is required by GitHub codespaces - https://github.com/microsoft/vscode-dev-containers/issues/727
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined", "--privileged", "--init" ]
"postStartCommand": "dockerd",
// privileged is required by GitHub codespaces - https://github.com/microsoft/vscode-dev-containers/issues/727
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined",
"--privileged",
"--init"
]
}
+1 -1
View File
@@ -7,7 +7,7 @@ trim_trailing_whitespace = true
insert_final_newline = true
indent_style = tab
[*.{md,json,yaml,yml,tf,tfvars}]
[*.{md,json,yaml,yml,tf,tfvars,nix}]
indent_style = space
indent_size = 2
+2
View File
@@ -1,4 +1,6 @@
# Generated files
coderd/apidoc/docs.go linguist-generated=true
coderd/apidoc/swagger.json linguist-generated=true
coderd/database/dump.sql linguist-generated=true
peerbroker/proto/*.go linguist-generated=true
provisionerd/proto/*.go linguist-generated=true
-4
View File
@@ -1,4 +0,0 @@
site/ @coder/frontend
docs/ @coder/docs
README.md @coder/docs
ADOPTERS.md @coder/docs
@@ -1,9 +0,0 @@
<!--- Provide a general summary of the issue in the Title above -->
## Expected Behavior
<!--- Tell us what should happen -->
## Current Behavior
<!--- Tell us what happens instead of the expected behavior -->
+68
View File
@@ -0,0 +1,68 @@
name: "Setup Go"
description: |
Sets up the Go environment for tests, builds, etc.
inputs:
version:
description: "The Go version to use."
default: "1.20.5"
runs:
using: "composite"
steps:
- name: Cache go toolchain
uses: buildjet/cache@v3
with:
path: |
${{ runner.tool_cache }}/go/${{ inputs.version }}
key: gotoolchain-${{ runner.os }}-${{ inputs.version }}
restore-keys: |
gotoolchain-${{ runner.os }}-
- uses: buildjet/setup-go@v4
with:
# We do our own caching for implementation clarity.
cache: false
go-version: ${{ inputs.version }}
- name: Get cache dirs
shell: bash
run: |
set -x
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_ENV
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV
# We split up GOMODCACHE from GOCACHE because the latter must be invalidated
# on code change, but the former can be kept.
- name: Cache $GOMODCACHE
uses: buildjet/cache@v3
with:
path: |
${{ env.GOMODCACHE }}
key: gomodcache-${{ runner.os }}-${{ hashFiles('**/go.sum') }}-${{ github.job }}
restore-keys: |
gomodcache-${{ runner.os }}-${{ hashFiles('**/go.sum') }}-
gomodcache-${{ runner.os }}-
- name: Cache $GOCACHE
uses: buildjet/cache@v3
with:
path: |
${{ env.GOCACHE }}
# Job name must be included in the key for effective
# test cache reuse.
# The key format is intentionally different than GOMODCACHE, because any
# time a Go file changes we invalidate this cache, whereas GOMODCACHE
# is only invalidated when go.sum changes.
key: gocache-${{ runner.os }}-${{ github.job }}-${{ hashFiles('**/*.go', 'go.**') }}
restore-keys: |
gocache-${{ runner.os }}-${{ github.job }}-
gocache-${{ runner.os }}-
- name: Install gotestsum
shell: bash
run: go install gotest.tools/gotestsum@latest
# It isn't necessary that we ever do this, but it helps
# separate the "setup" from the "run" times.
- name: go mod download
shell: bash
run: go mod download -x
+15
View File
@@ -0,0 +1,15 @@
name: "Setup Node"
description: |
Sets up the node environment for tests, builds, etc.
runs:
using: "composite"
steps:
- uses: buildjet/setup-node@v3
with:
node-version: 16.16.0
# See https://github.com/actions/setup-node#caching-global-packages-data
cache: "yarn"
cache-dependency-path: "site/yarn.lock"
- name: Install node_modules
shell: bash
run: ./scripts/yarn_install.sh
+11
View File
@@ -0,0 +1,11 @@
name: "Setup Terraform"
description: |
Sets up Terraform for tests, builds, etc.
runs:
using: "composite"
steps:
- name: Install Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.5.2
terraform_wrapper: false
@@ -0,0 +1,27 @@
name: Upload tests to datadog
if: always()
inputs:
api-key:
description: "Datadog API key"
required: true
runs:
using: "composite"
steps:
- shell: bash
run: |
owner=${{ github.repository_owner }}
echo "owner: $owner"
if [[ $owner != "coder" ]]; then
echo "Not a pull request from the main repo, skipping..."
exit 0
fi
if [[ -z "${{ inputs.api-key }}" ]]; then
# This can happen for dependabot.
echo "No API key provided, skipping..."
exit 0
fi
npm install -g @datadog/datadog-ci@2.10.0
datadog-ci junit upload --service coder ./gotests.xml \
--tags os:${{runner.os}} --tags runner_name:${{runner.name}}
env:
DATADOG_API_KEY: ${{ inputs.api-key }}
+44 -4
View File
@@ -3,7 +3,7 @@ updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
interval: "weekly"
time: "06:00"
timezone: "America/Chicago"
labels: []
@@ -28,7 +28,7 @@ updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "monthly"
interval: "weekly"
time: "06:00"
timezone: "America/Chicago"
commit-message:
@@ -38,7 +38,22 @@ updates:
# Ignore patch updates for all dependencies
- dependency-name: "*"
update-types:
- version-update:semver-patch
- version-update:semver-patch
# Update our Dockerfile.
- package-ecosystem: "docker"
directory: "/scripts/"
schedule:
interval: "weekly"
time: "06:00"
timezone: "America/Chicago"
commit-message:
prefix: "chore"
labels: []
ignore:
# We need to coordinate terraform updates with the version hardcoded in
# our Go code.
- dependency-name: "terraform"
- package-ecosystem: "npm"
directory: "/site/"
@@ -46,6 +61,8 @@ updates:
interval: "monthly"
time: "06:00"
timezone: "America/Chicago"
reviewers:
- "coder/ts"
commit-message:
prefix: "chore"
labels: []
@@ -53,7 +70,7 @@ updates:
# Ignore patch updates for all dependencies
- dependency-name: "*"
update-types:
- version-update:semver-patch
- version-update:semver-patch
# Ignore major updates to Node.js types, because they need to
# correspond to the Node.js engine version
- dependency-name: "@types/node"
@@ -72,3 +89,26 @@ updates:
ignore:
# We likely want to update this ourselves.
- dependency-name: "coder/coder"
# Update dogfood.
- package-ecosystem: "docker"
directory: "/dogfood/"
schedule:
interval: "weekly"
time: "06:00"
timezone: "America/Chicago"
commit-message:
prefix: "chore"
labels: []
- package-ecosystem: "terraform"
directory: "/dogfood/"
schedule:
interval: "weekly"
time: "06:00"
timezone: "America/Chicago"
commit-message:
prefix: "chore"
labels: []
ignore:
- dependency-name: "coder/coder"
-3
View File
@@ -1,3 +0,0 @@
<!--
Check if your change requires documentation edits before merging: https://coder.com/docs/coder. Make edits in `docs/`.
-->
-56
View File
@@ -1,56 +0,0 @@
###############################################################################
# This file configures "Semantic Pull Requests", which is documented here:
# https://github.com/zeke/semantic-pull-requests
#
# This action/spec implements the "Conventional Commits" RFC which is
# available here:
# https://www.notion.so/coderhq/Conventional-commits-1d51287f58b64026bb29393f277734ed
###############################################################################
# We have no valid scopes right now.
# A scope should be added when commits aren't aligning with associated change anymore.
scopes:
# We only check that the PR title is semantic. The PR title is automatically
# applied to the "Squash & Merge" flow as the suggested commit message, so this
# should suffice unless someone drastically alters the message in that flow.
titleOnly: true
# Types are the 'tag' types in a commit or PR title. For example, in
#
# chore: fix thing
#
# 'chore' is the type.
types:
# A build of any kind.
- build
# Any code task that operates outside of CI, docs, or the product. Examples
# include configurations, linters etc.
- chore
# Any work performed on CI.
- ci
- example
# Work that directly implements or supports the implementation of a feature.
- feat
# A fix for either a released or unrelesed bug.
- fix
# A fix for a released bug (regression fix) that is intended for patch-release
# purposes.
- hotfix
# A refactor changes code structure without any behavioral change.
- refactor
# A git revert for any style of commit.
- revert
# Adding tests of any kind. Should be separate from feature or fix
# implementations. For example, if a commit adds a fix + test, it's a fix
# commit. If a commit is simply bumping coverage, it's a test commit.
- test
+576
View File
@@ -0,0 +1,576 @@
name: ci
on:
push:
branches:
- main
pull_request:
workflow_dispatch:
permissions:
actions: none
checks: none
contents: read
deployments: none
issues: none
packages: none
pull-requests: none
repository-projects: none
security-events: none
statuses: none
# Cancel in-progress runs for pull requests when developers push
# additional changes
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
changes:
runs-on: ubuntu-latest
outputs:
docs-only: ${{ steps.filter.outputs.docs_count == steps.filter.outputs.all_count }}
go: ${{ steps.filter.outputs.go }}
ts: ${{ steps.filter.outputs.ts }}
k8s: ${{ steps.filter.outputs.k8s }}
ci: ${{ steps.filter.outputs.ci }}
steps:
- uses: actions/checkout@v3
# For pull requests it's not necessary to checkout the code
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
all:
- "**"
docs:
- "docs/**"
- "README.md"
- "examples/templates/**"
- "examples/web-server/**"
- "examples/monitoring/**"
- "examples/lima/**"
go:
- "**.sql"
- "**.go"
- "**.golden"
- "go.mod"
- "go.sum"
# Other non-Go files that may affect Go code:
- "**.rego"
- "**.sh"
- "**.tpl"
- "**.gotmpl"
- "**.gotpl"
- "Makefile"
- "site/static/error.html"
# Main repo directories for completeness in case other files are
# touched:
- "agent/**"
- "cli/**"
- "cmd/**"
- "coderd/**"
- "enterprise/**"
- "examples/*"
- "provisioner/**"
- "provisionerd/**"
- "provisionersdk/**"
- "pty/**"
- "scaletest/**"
- "tailnet/**"
- "testutil/**"
ts:
- "site/**"
- "Makefile"
k8s:
- "helm/**"
- "scripts/Dockerfile"
- "scripts/Dockerfile.base"
- "scripts/helm.sh"
ci:
- ".github/actions/**"
- ".github/workflows/ci.yaml"
- id: debug
run: |
echo "${{ toJSON(steps.filter )}}"
lint:
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: ./.github/actions/setup-go
- uses: ./.github/actions/setup-node
- name: Get golangci-lint cache dir
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.2
dir=$(golangci-lint cache status | awk '/Dir/ { print $2 }')
echo "LINT_CACHE_DIR=$dir" >> $GITHUB_ENV
- name: golangci-lint cache
uses: buildjet/cache@v3
with:
path: |
${{ env.LINT_CACHE_DIR }}
key: golangci-lint-${{ runner.os }}-${{ hashFiles('**/*.go') }}
restore-keys: |
golangci-lint-${{ runner.os }}-
# Check for any typos
- name: Check for typos
uses: crate-ci/typos@v1.14.12
with:
config: .github/workflows/typos.toml
- name: Fix the typos
if: ${{ failure() }}
run: |
echo "::notice:: you can automatically fix typos from your CLI:
cargo install typos-cli
typos -c .github/workflows/typos.toml -w"
# Needed for helm chart linting
- name: Install helm
uses: azure/setup-helm@v3
with:
version: v3.9.2
- name: make lint
run: |
make --output-sync=line -j lint
gen:
timeout-minutes: 8
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
needs: changes
if: needs.changes.outputs.docs-only == 'false' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-node
- uses: ./.github/actions/setup-go
- name: Install sqlc
run: |
curl -sSL https://github.com/kyleconroy/sqlc/releases/download/v1.18.0/sqlc_1.18.0_linux_amd64.tar.gz | sudo tar -C /usr/bin -xz sqlc
- name: go install tools
run: |
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.30
go install storj.io/drpc/cmd/protoc-gen-go-drpc@v0.0.33
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/mikefarah/yq/v4@v4.30.6
go install github.com/golang/mock/mockgen@v1.6.0
- name: Install Protoc
run: |
# protoc must be in lockstep with our dogfood Dockerfile or the
# version in the comments will differ. This is also defined in
# security.yaml
set -x
cd dogfood
DOCKER_BUILDKIT=1 docker build . --target proto -t protoc
protoc_path=/usr/local/bin/protoc
docker run --rm --entrypoint cat protoc /tmp/bin/protoc > $protoc_path
chmod +x $protoc_path
protoc --version
- name: make gen
run: "make --output-sync -j -B gen"
- name: Check for unstaged files
run: ./scripts/check_unstaged.sh
fmt:
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: buildjet/setup-node@v3
with:
node-version: 16.16.0
- uses: buildjet/setup-go@v4
with:
# This doesn't need caching. It's super fast anyways!
cache: false
go-version: 1.20.5
- name: Install prettier
# We only need prettier for fmt, so do not install all dependencies.
# There is no way to install a single package with yarn, so we have to
# make a new package.json with only prettier listed as a dependency.
# Then running `yarn` will only install prettier.
run: |
cd site
mv package.json package.json.bak
jq '{dependencies: {prettier: .devDependencies.prettier}}' < package.json.bak > package.json
yarn --frozen-lockfile
mv package.json.bak package.json
- name: Install shfmt
run: go install mvdan.cc/sh/v3/cmd/shfmt@v3.5.0
- name: make fmt
run: |
export PATH=${PATH}:$(go env GOPATH)/bin
make --output-sync -j -B fmt
- name: Check for unstaged files
run: ./scripts/check_unstaged.sh
test-go:
runs-on: ${{ matrix.os == 'ubuntu-latest' && github.repository_owner == 'coder' && 'buildjet-4vcpu-ubuntu-2204' || matrix.os == 'macos-latest' && github.repository_owner == 'coder' && 'macos-latest-xl' || matrix.os == 'windows-2019' && github.repository_owner == 'coder' && 'windows-latest-8-cores' || matrix.os }}
needs: changes
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
timeout-minutes: 20
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-2019
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-go
- uses: ./.github/actions/setup-tf
- name: Test with Mock Database
id: test
shell: bash
run: |
# Code coverage is more computationally expensive and also
# prevents test caching, so we disable it on alternate operating
# systems.
if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
echo "cover=true" >> $GITHUB_OUTPUT
export COVERAGE_FLAGS='-covermode=atomic -coverprofile="gotests.coverage" -coverpkg=./...'
else
echo "cover=false" >> $GITHUB_OUTPUT
fi
# By default Go will use the number of logical CPUs, which
# is a fine default.
PARALLEL_FLAG=""
export TS_DEBUG_DISCO=true
gotestsum --junitfile="gotests.xml" --jsonfile="gotests.json" \
--packages="./..." -- $PARALLEL_FLAG -short -failfast $COVERAGE_FLAGS
- name: Print test stats
if: success() || failure()
run: |
# Artifacts are not available after rerunning a job,
# so we need to print the test stats to the log.
go run ./scripts/ci-report/main.go gotests.json | tee gotests_stats.json
- uses: ./.github/actions/upload-datadog
if: success() || failure()
with:
api-key: ${{ secrets.DATADOG_API_KEY }}
- uses: codecov/codecov-action@v3
# This action has a tendency to error out unexpectedly, it has
# the `fail_ci_if_error` option that defaults to `false`, but
# that is no guarantee, see:
# https://github.com/codecov/codecov-action/issues/788
continue-on-error: true
if: steps.test.outputs.cover && github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./gotests.coverage
flags: unittest-go-${{ matrix.os }}
test-go-pg:
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
needs: changes
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
# This timeout must be greater than the timeout set by `go test` in
# `make test-postgres` to ensure we receive a trace of running
# goroutines. Setting this to the timeout +5m should work quite well
# even if some of the preceding steps are slow.
timeout-minutes: 25
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-go
- uses: ./.github/actions/setup-tf
- name: Test with PostgreSQL Database
run: |
export TS_DEBUG_DISCO=true
make test-postgres
- name: Print test stats
if: success() || failure()
run: |
# Artifacts are not available after rerunning a job,
# so we need to print the test stats to the log.
go run ./scripts/ci-report/main.go gotests.json | tee gotests_stats.json
- uses: ./.github/actions/upload-datadog
if: success() || failure()
with:
api-key: ${{ secrets.DATADOG_API_KEY }}
- uses: codecov/codecov-action@v3
# This action has a tendency to error out unexpectedly, it has
# the `fail_ci_if_error` option that defaults to `false`, but
# that is no guarantee, see:
# https://github.com/codecov/codecov-action/issues/788
continue-on-error: true
if: github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./gotests.coverage
flags: unittest-go-postgres-linux
test-go-race:
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
needs: changes
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
timeout-minutes: 25
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-go
- uses: ./.github/actions/setup-tf
- name: Run Tests
run: |
gotestsum --junitfile="gotests.xml" -- -race ./...
- uses: ./.github/actions/upload-datadog
if: always()
with:
api-key: ${{ secrets.DATADOG_API_KEY }}
deploy:
name: "deploy"
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
timeout-minutes: 30
needs: changes
if: |
github.ref == 'refs/heads/main' && !github.event.pull_request.head.repo.fork
&& needs.changes.outputs.docs-only == 'false'
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
workload_identity_provider: projects/573722524737/locations/global/workloadIdentityPools/github/providers/github
service_account: coder-ci@coder-dogfood.iam.gserviceaccount.com
- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v1
- uses: ./.github/actions/setup-go
- uses: ./.github/actions/setup-node
- name: Install goimports
run: go install golang.org/x/tools/cmd/goimports@latest
- name: Install nfpm
run: go install github.com/goreleaser/nfpm/v2/cmd/nfpm@v2.16.0
- name: Install zstd
run: sudo apt-get install -y zstd
- name: Build Release
run: |
set -euo pipefail
go mod download
version="$(./scripts/version.sh)"
make gen/mark-fresh
make -j \
build/coder_"$version"_windows_amd64.zip \
build/coder_"$version"_linux_amd64.{tar.gz,deb}
- name: Install Release
run: |
set -euo pipefail
regions=(
# gcp-region-id instance-name systemd-service-name
"us-central1-a coder coder"
"australia-southeast1-b coder-sydney coder-workspace-proxy"
"europe-west3-c coder-europe coder-workspace-proxy"
"southamerica-east1-b coder-brazil coder-workspace-proxy"
)
deb_pkg="./build/coder_$(./scripts/version.sh)_linux_amd64.deb"
if [ ! -f "$deb_pkg" ]; then
echo "deb package not found: $deb_pkg"
ls -l ./build
exit 1
fi
gcloud config set project coder-dogfood
for region in "${regions[@]}"; do
echo "::group::$region"
set -- $region
set -x
gcloud config set compute/zone "$1"
gcloud compute scp "$deb_pkg" "${2}:/tmp/coder.deb"
gcloud compute ssh "$2" -- /bin/sh -c "set -eux; sudo dpkg -i --force-confdef /tmp/coder.deb; sudo systemctl daemon-reload; sudo service '$3' restart"
set +x
echo "::endgroup::"
done
- uses: actions/upload-artifact@v3
with:
name: coder
path: |
./build/*.zip
./build/*.tar.gz
./build/*.deb
retention-days: 7
test-js:
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
needs: changes
if: needs.changes.outputs.ts == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
timeout-minutes: 20
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-node
- run: yarn test:ci --max-workers $(nproc)
working-directory: site
- uses: codecov/codecov-action@v3
# This action has a tendency to error out unexpectedly, it has
# the `fail_ci_if_error` option that defaults to `false`, but
# that is no guarantee, see:
# https://github.com/codecov/codecov-action/issues/788
continue-on-error: true
if: github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./site/coverage/lcov.info
flags: unittest-js
test-e2e:
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
needs: changes
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ts == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
timeout-minutes: 20
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-node
- uses: ./.github/actions/setup-go
- uses: ./.github/actions/setup-tf
- name: Build
run: |
sudo npm install -g prettier
make -B site/out/index.html
- run: yarn playwright:install
working-directory: site
- run: yarn playwright:test
env:
DEBUG: pw:api
working-directory: site
- name: Upload Playwright Failed Tests
if: always() && github.actor != 'dependabot[bot]' && runner.os == 'Linux' && !github.event.pull_request.head.repo.fork
uses: actions/upload-artifact@v3
with:
name: failed-test-videos
path: ./site/test-results/**/*.webm
retention-days: 7
chromatic:
# REMARK: this is only used to build storybook and deploy it to Chromatic.
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.ts == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
with:
# Required by Chromatic for build-over-build history, otherwise we
# only get 1 commit on shallow checkout.
fetch-depth: 0
- uses: ./.github/actions/setup-node
# This step is not meant for mainline because any detected changes to
# storybook snapshots will require manual approval/review in order for
# the check to pass. This is desired in PRs, but not in mainline.
- name: Publish to Chromatic (non-mainline)
if: github.ref != 'refs/heads/main' && github.repository_owner == 'coder'
uses: chromaui/action@v1
env:
NODE_OPTIONS: "--max_old_space_size=4096"
STORYBOOK: true
with:
buildScriptName: "storybook:build"
exitOnceUploaded: true
# Chromatic states its fine to make this token public. See:
# https://www.chromatic.com/docs/github-actions#forked-repositories
projectToken: 695c25b6cb65
workingDir: "./site"
# This is a separate step for mainline only that auto accepts and changes
# instead of holding CI up. Since we squash/merge, this is defensive to
# avoid the same changeset from requiring review once squashed into
# main. Chromatic is supposed to be able to detect that we use squash
# commits, but it's good to be defensive in case, otherwise CI remains
# infinitely "in progress" in mainline unless we re-review each build.
- name: Publish to Chromatic (mainline)
if: github.ref == 'refs/heads/main' && github.repository_owner == 'coder'
uses: chromaui/action@v1
env:
NODE_OPTIONS: "--max_old_space_size=4096"
STORYBOOK: true
with:
autoAcceptChanges: true
buildScriptName: "storybook:build"
projectToken: 695c25b6cb65
workingDir: "./site"
required:
runs-on: ubuntu-latest
needs: [fmt, lint, gen, test-go, test-go-pg, test-go-race, test-js]
# Allow this job to run even if the needed jobs fail, are skipped or
# cancelled.
if: always()
steps:
- name: Ensure required checks
run: |
echo "Checking required checks"
echo "- fmt: ${{ needs.fmt.result }}"
echo "- lint: ${{ needs.lint.result }}"
echo "- gen: ${{ needs.gen.result }}"
echo "- test-go: ${{ needs.test-go.result }}"
echo "- test-go-pg: ${{ needs.test-go-pg.result }}"
echo "- test-go-race: ${{ needs.test-go-race.result }}"
echo "- test-js: ${{ needs.test-js.result }}"
echo
# We allow skipped jobs to pass, but not failed or cancelled jobs.
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" || "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
echo "One of the required checks has failed or has been cancelled"
exit 1
fi
echo "Required checks have passed"
-26
View File
@@ -1,26 +0,0 @@
name: "CLA Assistant"
on:
issue_comment:
types: [created]
pull_request_target:
types: [opened,closed,synchronize]
jobs:
CLAssistant:
runs-on: ubuntu-latest
steps:
- name: "CLA Assistant"
if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target'
uses: contributor-assistant/github-action@v2.2.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# the below token should have repo scope and must be manually added by you in the repository's secret
PERSONAL_ACCESS_TOKEN : ${{ secrets.CDRCOMMUNITY_GITHUB_TOKEN }}
with:
remote-organization-name: 'coder'
remote-repository-name: 'cla'
path-to-signatures: 'v2022-09-04/signatures.json'
path-to-document: 'https://github.com/coder/cla/blob/main/README.md'
# branch should not be protected
branch: 'main'
allowlist: dependabot*
-683
View File
@@ -1,683 +0,0 @@
name: coder
on:
push:
branches:
- main
pull_request:
workflow_dispatch:
permissions:
actions: none
checks: none
contents: read
deployments: none
issues: none
packages: none
pull-requests: none
repository-projects: none
security-events: none
statuses: none
# Cancel in-progress runs for pull requests when developers push
# additional changes
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
typos:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: typos-action
uses: crate-ci/typos@v1.12.12
with:
config: .github/workflows/typos.toml
- name: Fix Helper
if: ${{ failure() }}
run: |
echo "::notice:: you can automatically fix typos from your CLI:
cargo install typos-cli
typos -c .github/workflows/typos.toml -w"
changes:
runs-on: ubuntu-latest
outputs:
docs-only: ${{ steps.filter.outputs.docs_count == steps.filter.outputs.all_count }}
sh: ${{ steps.filter.outputs.sh }}
ts: ${{ steps.filter.outputs.ts }}
k8s: ${{ steps.filter.outputs.k8s }}
steps:
- uses: actions/checkout@v3
# For pull requests it's not necessary to checkout the code
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
all:
- '**'
docs:
- 'docs/**'
# For testing:
# - '.github/**'
sh:
- "**.sh"
ts:
- 'site/**'
k8s:
- 'helm/**'
- Dockerfile
- scripts/helm.sh
- id: debug
run: |
echo "${{ toJSON(steps.filter )}}"
# Debug step
debug-inputs:
needs:
- changes
runs-on: ubuntu-latest
steps:
- id: log
run: |
echo "${{ toJSON(needs) }}"
style-lint-golangci:
name: style/lint/golangci
timeout-minutes: 5
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "~1.19"
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.3.0
with:
version: v1.48.0
check-enterprise-imports:
name: check/enterprise-imports
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check imports of enterprise code
run: ./scripts/check_enterprise_imports.sh
style-lint-shellcheck:
name: style/lint/shellcheck
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@1.1.0
env:
SHELLCHECK_OPTS: --external-sources
with:
ignore: node_modules
style-lint-typescript:
name: "style/lint/typescript"
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Cache Node
id: cache-node
uses: actions/cache@v3
with:
path: |
**/node_modules
.eslintcache
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
js-${{ runner.os }}-
- name: Install node_modules
run: ./scripts/yarn_install.sh
- name: "yarn lint"
run: yarn lint
working-directory: site
style-lint-k8s:
name: "style/lint/k8s"
timeout-minutes: 5
needs: changes
if: needs.changes.outputs.k8s == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install helm
uses: azure/setup-helm@v3
with:
version: v3.9.2
- name: cd helm && make lint
run: |
cd helm
make lint
gen:
name: "style/gen"
timeout-minutes: 8
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
needs: changes
if: needs.changes.outputs.docs-only == 'false'
steps:
- uses: actions/checkout@v3
- name: Cache Node
id: cache-node
uses: actions/cache@v3
with:
path: |
**/node_modules
.eslintcache
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
js-${{ runner.os }}-
- name: Install node_modules
run: ./scripts/yarn_install.sh
- uses: actions/setup-go@v3
with:
go-version: "~1.19"
- name: Echo Go Cache Paths
id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- name: Go Build Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ github.job }}-go-build-${{ hashFiles('**/go.sum', '**/**.go') }}
- name: Go Mod Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ github.job }}-go-mod-${{ hashFiles('**/go.sum') }}
- name: Install sqlc
run: |
curl -sSL https://github.com/kyleconroy/sqlc/releases/download/v1.13.0/sqlc_1.13.0_linux_amd64.tar.gz | sudo tar -C /usr/bin -xz sqlc
- name: Install protoc-gen-go
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26
- name: Install protoc-gen-go-drpc
run: go install storj.io/drpc/cmd/protoc-gen-go-drpc@v0.0.26
- name: Install goimports
run: go install golang.org/x/tools/cmd/goimports@latest
- name: Install Protoc
run: |
# protoc must be in lockstep with our dogfood Dockerfile
# or the version in the comments will differ.
set -x
cd dogfood
DOCKER_BUILDKIT=1 docker build . --target proto -t protoc
protoc_path=/usr/local/bin/protoc
docker run --rm --entrypoint cat protoc /tmp/bin/protoc > $protoc_path
chmod +x $protoc_path
protoc --version
- name: make gen
run: "make --output-sync -j -B gen"
- name: Check for unstaged files
run: ./scripts/check_unstaged.sh
style-fmt:
name: "style/fmt"
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: true
- name: Cache Node
id: cache-node
uses: actions/cache@v3
with:
path: |
**/node_modules
.eslintcache
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
js-${{ runner.os }}-
- name: Install node_modules
run: ./scripts/yarn_install.sh
- name: Install shfmt
run: go install mvdan.cc/sh/v3/cmd/shfmt@v3.5.0
- name: make fmt
run: |
export PATH=${PATH}:$(go env GOPATH)/bin
make --output-sync -j -B fmt
test-go:
name: "test/go"
runs-on: ${{ matrix.os == 'ubuntu-latest' && github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || matrix.os }}
timeout-minutes: 20
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-2022
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "~1.19"
- name: Echo Go Cache Paths
id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- name: Go Build Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.**', '**.go') }}
- name: Go Mod Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
- name: Install gotestsum
uses: jaxxstorm/action-install-gh-release@v1.7.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
repo: gotestyourself/gotestsum
tag: v1.7.0
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.1.9
terraform_wrapper: false
- name: Test with Mock Database
id: test
shell: bash
run: |
# Code coverage is more computationally expensive and also
# prevents test caching, so we disable it on alternate operating
# systems.
if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
echo ::set-output name=cover::true
export COVERAGE_FLAGS='-covermode=atomic -coverprofile="gotests.coverage" -coverpkg=./...'
else
echo ::set-output name=cover::false
fi
set -x
test_timeout=5m
if [[ "${{ matrix.os }}" == windows* ]]; then
test_timeout=10m
fi
gotestsum --junitfile="gotests.xml" --packages="./..." -- -parallel=8 -timeout=$test_timeout -short -failfast $COVERAGE_FLAGS
- uses: codecov/codecov-action@v3
# This action has a tendency to error out unexpectedly, it has
# the `fail_ci_if_error` option that defaults to `false`, but
# that is no guarantee, see:
# https://github.com/codecov/codecov-action/issues/788
continue-on-error: true
if: steps.test.outputs.cover && github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./gotests.coverage
flags: unittest-go-${{ matrix.os }}
test-go-postgres:
name: "test/go/postgres"
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
# This timeout must be greater than the timeout set by `go test` in
# `make test-postgres` to ensure we receive a trace of running
# goroutines. Setting this to the timeout +5m should work quite well
# even if some of the preceding steps are slow.
timeout-minutes: 25
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "~1.19"
- name: Echo Go Cache Paths
id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- name: Go Build Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum', '**/**.go') }}
- name: Go Mod Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
- name: Install gotestsum
uses: jaxxstorm/action-install-gh-release@v1.7.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
repo: gotestyourself/gotestsum
tag: v1.7.0
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.1.9
terraform_wrapper: false
- name: Test with PostgreSQL Database
run: make test-postgres
- uses: codecov/codecov-action@v3
# This action has a tendency to error out unexpectedly, it has
# the `fail_ci_if_error` option that defaults to `false`, but
# that is no guarantee, see:
# https://github.com/codecov/codecov-action/issues/788
continue-on-error: true
if: github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./gotests.coverage
flags: unittest-go-postgres-${{ matrix.os }}
deploy:
name: "deploy"
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
timeout-minutes: 30
needs: changes
if: |
github.ref == 'refs/heads/main' && !github.event.pull_request.head.repo.fork
&& needs.changes.outputs.docs-only == 'false'
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v0
with:
workload_identity_provider: projects/573722524737/locations/global/workloadIdentityPools/github/providers/github
service_account: coder-ci@coder-dogfood.iam.gserviceaccount.com
- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v0
- uses: actions/setup-go@v3
with:
go-version: "~1.19"
- name: Echo Go Cache Paths
id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- name: Go Build Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-release-go-build-${{ hashFiles('**/go.sum') }}
- name: Go Mod Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-release-go-mod-${{ hashFiles('**/go.sum') }}
- name: Cache Node
id: cache-node
uses: actions/cache@v3
with:
path: |
**/node_modules
.eslintcache
key: js-${{ runner.os }}-release-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
js-${{ runner.os }}-
- name: Install goimports
run: go install golang.org/x/tools/cmd/goimports@latest
- name: Install nfpm
run: go install github.com/goreleaser/nfpm/v2/cmd/nfpm@v2.16.0
- name: Install zstd
run: sudo apt-get install -y zstd
- name: Build Release
run: |
set -euo pipefail
go mod download
version="$(./scripts/version.sh)"
make gen/mark-fresh
make -j \
build/coder_"$version"_windows_amd64.zip \
build/coder_"$version"_linux_amd64.{tar.gz,deb}
- name: Install Release
run: |
gcloud config set project coder-dogfood
gcloud config set compute/zone us-central1-a
gcloud compute scp ./build/coder_*_linux_amd64.deb coder:/tmp/coder.deb
gcloud compute ssh coder -- sudo dpkg -i --force-confdef /tmp/coder.deb
gcloud compute ssh coder -- sudo systemctl daemon-reload
- name: Start
run: gcloud compute ssh coder -- sudo service coder restart
- uses: actions/upload-artifact@v3
with:
name: coder
path: |
./build/*.zip
./build/*.tar.gz
./build/*.deb
retention-days: 7
test-js:
name: "test/js"
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v3
- name: Cache Node
id: cache-node
uses: actions/cache@v3
with:
path: |
**/node_modules
.eslintcache
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
js-${{ runner.os }}-
- uses: actions/setup-node@v3
with:
node-version: "14"
- name: Install node_modules
run: ./scripts/yarn_install.sh
- run: yarn test:coverage
working-directory: site
- uses: codecov/codecov-action@v3
# This action has a tendency to error out unexpectedly, it has
# the `fail_ci_if_error` option that defaults to `false`, but
# that is no guarantee, see:
# https://github.com/codecov/codecov-action/issues/788
continue-on-error: true
if: github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./site/coverage/lcov.info
flags: unittest-js
test-e2e:
name: "test/e2e/${{ matrix.os }}"
needs:
- changes
if: needs.changes.outputs.docs-only == 'false'
runs-on: ${{ matrix.os }}
timeout-minutes: 20
strategy:
matrix:
os:
- ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Node
id: cache-node
uses: actions/cache@v3
with:
path: |
**/node_modules
.eslintcache
key: js-${{ runner.os }}-e2e-${{ hashFiles('**/yarn.lock') }}
- uses: actions/setup-go@v3
with:
go-version: "~1.19"
- uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.1.9
terraform_wrapper: false
- uses: actions/setup-node@v3
with:
node-version: "14"
- name: Echo Go Cache Paths
id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- name: Go Build Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
- name: Go Mod Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
- name: Build
run: |
sudo npm install -g prettier
make -B site/out/index.html
- run: yarn playwright:install
working-directory: site
- run: yarn playwright:install-deps
working-directory: site
- run: yarn playwright:test
env:
DEBUG: pw:api
working-directory: site
- name: Upload Playwright Failed Tests
if: always() && github.actor != 'dependabot[bot]' && runner.os == 'Linux' && !github.event.pull_request.head.repo.fork
uses: actions/upload-artifact@v3
with:
name: failed-test-videos
path: ./site/test-results/**/*.webm
retention-days: 7
chromatic:
# REMARK: this is only used to build storybook and deploy it to Chromatic.
runs-on: ubuntu-latest
needs:
- changes
if: needs.changes.outputs.ts == 'true'
steps:
- uses: actions/checkout@v3
with:
# Required by Chromatic for build-over-build history, otherwise we
# only get 1 commit on shallow checkout.
fetch-depth: 0
- name: Install dependencies
run: cd site && yarn
# This step is not meant for mainline because any detected changes to
# storybook snapshots will require manual approval/review in order for
# the check to pass. This is desired in PRs, but not in mainline.
- name: Publish to Chromatic (non-mainline)
if: github.ref != 'refs/heads/main' && github.repository_owner == 'coder'
uses: chromaui/action@v1
with:
buildScriptName: "storybook:build"
exitOnceUploaded: true
# Chromatic states its fine to make this token public. See:
# https://www.chromatic.com/docs/github-actions#forked-repositories
projectToken: 695c25b6cb65
workingDir: "./site"
# This is a separate step for mainline only that auto accepts and changes
# instead of holding CI up. Since we squash/merge, this is defensive to
# avoid the same changeset from requiring review once squashed into
# main. Chromatic is supposed to be able to detect that we use squash
# commits, but it's good to be defensive in case, otherwise CI remains
# infinitely "in progress" in mainline unless we re-review each build.
- name: Publish to Chromatic (mainline)
if: github.ref == 'refs/heads/main' && github.repository_owner == 'coder'
uses: chromaui/action@v1
with:
autoAcceptChanges: true
buildScriptName: "storybook:build"
projectToken: 695c25b6cb65
workingDir: "./site"
markdown-link-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
config-file: .github/workflows/mlc_config.json
+156
View File
@@ -0,0 +1,156 @@
name: contrib
on:
issue_comment:
types: [created]
pull_request_target:
types:
- opened
- closed
- synchronize
- labeled
- unlabeled
- opened
- reopened
- edited
# Only run one instance per PR to ensure in-order execution.
concurrency: pr-${{ github.ref }}
jobs:
# Dependabot is annoying, but this makes it a bit less so.
auto-approve-dependabot:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request_target'
permissions:
pull-requests: write
steps:
- uses: hmarr/auto-approve-action@v3
if: github.actor == 'dependabot[bot]'
cla:
runs-on: ubuntu-latest
steps:
- name: cla
if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target'
uses: contributor-assistant/github-action@v2.3.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# the below token should have repo scope and must be manually added by you in the repository's secret
PERSONAL_ACCESS_TOKEN: ${{ secrets.CDRCOMMUNITY_GITHUB_TOKEN }}
with:
remote-organization-name: "coder"
remote-repository-name: "cla"
path-to-signatures: "v2022-09-04/signatures.json"
path-to-document: "https://github.com/coder/cla/blob/main/README.md"
# branch should not be protected
branch: "main"
allowlist: dependabot*
release-labels:
runs-on: ubuntu-latest
# Skip tagging for draft PRs.
if: ${{ github.event_name == 'pull_request_target' && success() && !github.event.pull_request.draft }}
steps:
- uses: actions/github-script@v6
with:
# This script ensures PR title and labels are in sync:
#
# When release/breaking label is:
# - Added, rename PR title to include ! (e.g. feat!:)
# - Removed, rename PR title to strip ! (e.g. feat:)
#
# When title is:
# - Renamed (+!), add the release/breaking label
# - Renamed (-!), remove the release/breaking label
script: |
const releaseLabels = {
breaking: "release/breaking",
}
const { action, changes, label, pull_request } = context.payload
const { title } = pull_request
const labels = pull_request.labels.map((label) => label.name)
const isBreakingTitle = isBreaking(title)
// Debug information.
console.log("Action: %s", action)
console.log("Title: %s", title)
console.log("Labels: %s", labels.join(", "))
const params = {
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
}
if (action === "opened" || action === "reopened") {
if (isBreakingTitle && !labels.includes(releaseLabels.breaking)) {
console.log('Add "%s" label', releaseLabels.breaking)
await github.rest.issues.addLabels({
...params,
labels: [releaseLabels.breaking],
})
}
}
if (action === "edited" && changes.title) {
if (isBreakingTitle && !labels.includes(releaseLabels.breaking)) {
console.log('Add "%s" label', releaseLabels.breaking)
await github.rest.issues.addLabels({
...params,
labels: [releaseLabels.breaking],
})
}
if (!isBreakingTitle && labels.includes(releaseLabels.breaking)) {
const wasBreakingTitle = isBreaking(changes.title.from)
if (wasBreakingTitle) {
console.log('Remove "%s" label', releaseLabels.breaking)
await github.rest.issues.removeLabel({
...params,
name: releaseLabels.breaking,
})
} else {
console.log('Rename title from "%s" to "%s"', title, toBreaking(title))
await github.rest.issues.update({
...params,
title: toBreaking(title),
})
}
}
}
if (action === "labeled") {
if (label.name === releaseLabels.breaking && !isBreakingTitle) {
console.log('Rename title from "%s" to "%s"', title, toBreaking(title))
await github.rest.issues.update({
...params,
title: toBreaking(title),
})
}
}
if (action === "unlabeled") {
if (label.name === releaseLabels.breaking && isBreakingTitle) {
console.log('Rename title from "%s" to "%s"', title, fromBreaking(title))
await github.rest.issues.update({
...params,
title: fromBreaking(title),
})
}
}
function isBreaking(t) {
return t.split(" ")[0].endsWith("!:")
}
function toBreaking(t) {
const parts = t.split(" ")
return [parts[0].replace(/:$/, "!:"), ...parts.slice(1)].join(" ")
}
function fromBreaking(t) {
const parts = t.split(" ")
return [parts[0].replace(/!:$/, ":"), ...parts.slice(1)].join(" ")
}
-13
View File
@@ -1,13 +0,0 @@
# Dependabot is annoying, but this makes it a bit less so.
name: Auto Approve Dependabot
on: pull_request_target
jobs:
auto-approve:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: hmarr/auto-approve-action@v2
if: github.actor == 'dependabot[bot]'
+90
View File
@@ -0,0 +1,90 @@
name: docker-base
on:
push:
branches:
- main
paths:
- scripts/Dockerfile.base
- scripts/Dockerfile
schedule:
# Run every week at 09:43 on Monday, Wednesday and Friday. We build this
# frequently to ensure that packages are up-to-date.
- cron: "43 9 * * 1,3,5"
workflow_dispatch:
permissions:
contents: read
# Necessary to push docker images to ghcr.io.
packages: write
# Necessary for depot.dev authentication.
id-token: write
# Avoid running multiple jobs for the same commit.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-docker-base
jobs:
build:
runs-on: ubuntu-latest
if: github.repository_owner == 'coder'
steps:
- uses: actions/checkout@v3
- name: Docker login
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create empty base-build-context directory
run: mkdir base-build-context
- name: Install depot.dev CLI
uses: depot/setup-action@v1
# This uses OIDC authentication, so no auth variables are required.
- name: Build base Docker image via depot.dev
uses: depot/build-push-action@v1
with:
project: wl5hnrrkns
context: base-build-context
file: scripts/Dockerfile.base
platforms: linux/amd64,linux/arm64,linux/arm/v7
pull: true
no-cache: true
push: true
tags: |
ghcr.io/coder/coder-base:latest
- name: Verify that images are pushed properly
run: |
# retry 10 times with a 5 second delay as the images may not be
# available immediately
for i in {1..10}; do
rc=0
raw_manifests=$(docker buildx imagetools inspect --raw ghcr.io/coder/coder-base:latest) || rc=$?
if [[ "$rc" -eq 0 ]]; then
break
fi
if [[ "$i" -eq 10 ]]; then
echo "Failed to pull manifests after 10 retries"
exit 1
fi
echo "Failed to pull manifests, retrying in 5 seconds"
sleep 5
done
manifests=$(
echo "$raw_manifests" | \
jq -r '.manifests[].platform | .os + "/" + .architecture + (if .variant then "/" + .variant else "" end)'
)
# Verify all 3 platforms are present.
set -euxo pipefail
echo "$manifests" | grep -q linux/amd64
echo "$manifests" | grep -q linux/arm64
echo "$manifests" | grep -q linux/arm/v7
+16 -13
View File
@@ -6,18 +6,21 @@ on:
- main
paths:
- "dogfood/**"
pull_request:
paths:
- "dogfood/**"
- ".github/workflows/dogfood.yaml"
# Uncomment these lines when testing with CI.
# pull_request:
# paths:
# - "dogfood/**"
# - ".github/workflows/dogfood.yaml"
workflow_dispatch:
jobs:
deploy_image:
runs-on: ubuntu-latest
runs-on: buildjet-4vcpu-ubuntu-2204
steps:
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v6.2
uses: tj-actions/branch-names@v6.5
- name: "Branch name to Docker tag name"
id: docker-tag-name
@@ -25,7 +28,7 @@ jobs:
tag=${{ steps.branch-name.outputs.current_branch }}
# Replace / with --, e.g. user/feature => user--feature.
tag=${tag//\//--}
echo "::set-output name=tag::${tag}"
echo "tag=${tag}" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
@@ -40,7 +43,7 @@ jobs:
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v3
uses: docker/build-push-action@v4
with:
context: "{{defaultContext}}:dogfood"
push: true
@@ -48,21 +51,21 @@ jobs:
cache-from: type=registry,ref=codercom/oss-dogfood:latest
cache-to: type=inline
deploy_template:
needs: deploy_image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get short commit SHA
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: "Install latest Coder"
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: "Get latest Coder binary from the server"
run: |
curl -L https://coder.com/install.sh | sh
# env:
# VERSION: 0.x
curl -fsSL "https://dev.coder.com/bin/coder-linux-amd64" -o "./coder"
chmod +x "./coder"
- name: "Push template"
run: |
coder templates push $CODER_TEMPLATE_NAME --directory $CODER_TEMPLATE_DIR --yes --name=$CODER_TEMPLATE_VERSION
./coder templates push $CODER_TEMPLATE_NAME --directory $CODER_TEMPLATE_DIR --yes --name=$CODER_TEMPLATE_VERSION
env:
# Consumed by Coder CLI
CODER_URL: https://dev.coder.com
+21 -14
View File
@@ -1,16 +1,23 @@
{
"ignorePatterns": [
{
"pattern": ":\/\/localhost"
},
{
"pattern": ":\/\/.*.?example\\.com"
},
{
"pattern": "developer.github.com"
},
{
"pattern": "tailscale.com"
}
]
"ignorePatterns": [
{
"pattern": "://localhost"
},
{
"pattern": "://.*.?example\\.com"
},
{
"pattern": "developer.github.com"
},
{
"pattern": "docs.github.com"
},
{
"pattern": "support.google.com"
},
{
"pattern": "tailscale.com"
}
],
"aliveStatusCodes": [200, 0]
}
+51
View File
@@ -0,0 +1,51 @@
# The nightly-gauntlet runs tests that are either too flaky or too slow to block
# every PR.
name: nightly-gauntlet
on:
schedule:
# Every day at midnight
- cron: "0 0 * * *"
workflow_dispatch:
jobs:
go-race:
# While GitHub's toaster runners are likelier to flake, we want consistency
# between this environment and the regular test environment for DataDog
# statistics and to only show real workflow threats.
runs-on: "buildjet-8vcpu-ubuntu-2204"
# This runner costs 0.016 USD per minute,
# so 0.016 * 240 = 3.84 USD per run.
timeout-minutes: 240
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-go
- uses: ./.github/actions/setup-tf
- name: Run Tests
run: |
# -race is likeliest to catch flaky tests
# due to correctness detection and its performance
# impact.
gotestsum --junitfile="gotests.xml" -- -timeout=240m -count=10 -race ./...
- uses: ./.github/actions/upload-datadog
if: always()
with:
api-key: ${{ secrets.DATADOG_API_KEY }}
go-timing:
# We run these tests with p=1 so we don't need a lot of compute.
runs-on: "buildjet-2vcpu-ubuntu-2204"
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-go
- name: Run Tests
run: |
gotestsum --junitfile="gotests.xml" -- --tags="timing" -p=1 -run='_Timing/' ./...
- uses: ./.github/actions/upload-datadog
if: always()
with:
api-key: ${{ secrets.DATADOG_API_KEY }}
+16
View File
@@ -0,0 +1,16 @@
# Filtering pull requests is much easier when we can reliably guarantee
# that the "Assignee" field is populated.
name: PR Auto Assign
on:
pull_request_target:
types: [opened]
permissions:
pull-requests: write
jobs:
assign-author:
runs-on: ubuntu-latest
steps:
- uses: toshimaru/auto-author-assign@v1.6.2
+50
View File
@@ -0,0 +1,50 @@
name: Cleanup PR
on:
pull_request:
types: [closed]
workflow_dispatch:
inputs:
pr_number:
description: "PR number"
required: true
permissions:
packages: write
jobs:
cleanup:
runs-on: "ubuntu-latest"
steps:
- name: Get PR number
id: pr_number
run: |
if [ -n "${{ github.event.pull_request.number }}" ]; then
echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
else
echo "PR_NUMBER=${{ github.event.inputs.pr_number }}" >> $GITHUB_OUTPUT
fi
- name: Delete image
continue-on-error: true
uses: bots-house/ghcr-delete-image-action@v1.1.0
with:
owner: coder
name: coder-preview
token: ${{ secrets.GITHUB_TOKEN }}
tag: pr${{ steps.pr_number.outputs.PR_NUMBER }}
- name: Set up kubeconfig
run: |
set -euxo pipefail
mkdir -p ~/.kube
echo "${{ secrets.DELIVERYBOT_KUBECONFIG }}" > ~/.kube/config
export KUBECONFIG=~/.kube/config
- name: Delete helm release
run: |
set -euxo pipefail
helm delete --namespace "pr${{ steps.pr_number.outputs.PR_NUMBER }}" "pr${{ steps.pr_number.outputs.PR_NUMBER }}" || echo "helm release not found"
- name: "Remove PR namespace"
run: |
kubectl delete namespace "pr${{ steps.pr_number.outputs.PR_NUMBER }}" || echo "namespace not found"
+207
View File
@@ -0,0 +1,207 @@
# This action will trigger when a PR is commentted containing /review-pr by a member of the org.
name: Deploy PR
on:
issue_comment:
workflow_dispatch:
inputs:
pr_number:
description: "PR number"
required: true
env:
REPO: ghcr.io/coder/coder-preview
permissions:
contents: read
packages: write
pull-requests: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
pr_commented:
if: github.event_name == 'issue_comment' && contains(github.event.comment.body, '/deploy-pr') && github.event.comment.author_association == 'MEMBER' || github.event_name == 'workflow_dispatch'
outputs:
PR_NUMBER: ${{ steps.pr_number.outputs.PR_NUMBER }}
PR_TITLE: ${{ steps.pr_number.outputs.PR_TITLE }}
PR_URL: ${{ steps.pr_number.outputs.PR_URL }}
COMMENT_ID: ${{ steps.comment_id.outputs.comment-id }}
CODER_BASE_IMAGE_TAG: ${{ steps.set_tags.outputs.CODER_BASE_IMAGE_TAG }}
CODER_IMAGE_TAG: ${{ steps.set_tags.outputs.CODER_IMAGE_TAG }}
runs-on: "ubuntu-latest"
steps:
- name: Get PR number and title
id: pr_number
run: |
set -euxo pipefail
if [[ ${{ github.event_name }} == "workflow_dispatch" ]]; then
PR_NUMBER=${{ github.event.inputs.pr_number }}
PR_TITLE=$(curl -sSL -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/coder/coder/pulls/$PR_NUMBER" | jq -r '.title')
else
PR_NUMBER=${{ github.event.issue.number }}
PR_TITLE='${{ github.event.issue.title }}'
fi
echo "PR_URL=https://github.com/coder/coder/pull/$PR_NUMBER" >> $GITHUB_OUTPUT
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_OUTPUT
echo "PR_TITLE=$PR_TITLE" >> $GITHUB_OUTPUT
- name: Set required tags
id: set_tags
run: |
set -euxo pipefail
echo "CODER_BASE_IMAGE_TAG=$CODER_BASE_IMAGE_TAG" >> $GITHUB_OUTPUT
echo "CODER_IMAGE_TAG=$CODER_IMAGE_TAG" >> $GITHUB_OUTPUT
env:
CODER_BASE_IMAGE_TAG: ghcr.io/coder/coder-preview-base:pr${{ steps.pr_number.outputs.PR_NUMBER }}
CODER_IMAGE_TAG: ghcr.io/coder/coder-preview:pr${{ steps.pr_number.outputs.PR_NUMBER }}
- name: Find Deploy Comment
if: github.event_name == 'issue_comment'
uses: peter-evans/find-comment@v2
id: fco
with:
issue-number: ${{ steps.pr_number.outputs.PR_NUMBER }}
comment-author: "github-actions[bot]"
body-includes: /deploy-pr
- name: React with Rocket
if: github.event_name == 'issue_comment'
id: comment_ido
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.fco.outputs.comment-id }}
reactions: rocket
- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ steps.pr_number.outputs.PR_NUMBER }}
comment-author: "github-actions[bot]"
body-includes: This deployment will be deleted when the PR is closed
- name: Comment on PR
id: comment_id
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ steps.pr_number.outputs.PR_NUMBER }}
edit-mode: replace
body: |
:rocket: Deploying PR ${{ steps.pr_number.outputs.PR_NUMBER }} ...
:warning: This deployment will be deleted when the PR is closed.
build:
needs: pr_commented
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
env:
DOCKER_CLI_EXPERIMENTAL: "enabled"
CODER_IMAGE_TAG: ${{ needs.pr_commented.outputs.coder_image_tag }}
PR_NUMBER: ${{ needs.pr_commented.outputs.pr_number }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: ./.github/actions/setup-go
- uses: ./.github/actions/setup-node
- name: Install sqlc
run: |
curl -sSL https://github.com/kyleconroy/sqlc/releases/download/v1.18.0/sqlc_1.18.0_linux_amd64.tar.gz | sudo tar -C /usr/bin -xz sqlc
- name: GHCR Login
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Linux amd64 Docker image
run: |
set -euxo pipefail
go mod download
make gen/mark-fresh
export DOCKER_IMAGE_NO_PREREQUISITES=true
version="$(./scripts/version.sh)"
export CODER_IMAGE_BUILD_BASE_TAG="$(CODER_IMAGE_BASE=coder-base ./scripts/image_tag.sh --version "$version")"
make -j build/coder_linux_amd64
./scripts/build_docker.sh \
--arch amd64 \
--target ${{ env.CODER_IMAGE_TAG }} \
--version $version \
--push \
build/coder_linux_amd64
deploy:
needs: [build, pr_commented]
if: needs.build.result == 'success'
runs-on: "ubuntu-latest"
env:
CODER_IMAGE_TAG: ${{ needs.pr_commented.outputs.CODER_IMAGE_TAG }}
PR_NUMBER: ${{ needs.pr_commented.outputs.PR_NUMBER }}
PR_TITLE: ${{ needs.pr_commented.outputs.PR_TITLE }}
PR_URL: ${{ needs.pr_commented.outputs.PR_URL }}
steps:
- uses: actions/checkout@v3
- name: "Set up kubeconfig"
run: |
set -euxo pipefail
mkdir -p ~/.kube
echo "${{ secrets.DELIVERYBOT_KUBECONFIG }}" > ~/.kube/config
export KUBECONFIG=~/.kube/config
- name: "Create PR namespace"
run: |
set -euxo pipefail
# try to delete the namespace, but don't fail if it doesn't exist
kubectl delete namespace "pr${{ env.PR_NUMBER }}" || true
kubectl create namespace "pr${{ env.PR_NUMBER }}"
- name: "Install Helm chart"
run: |
helm upgrade --install pr${{ env.PR_NUMBER }} ./helm \
--namespace "pr${{ env.PR_NUMBER }}" \
--set coder.image.repo=${{ env.REPO }} \
--set coder.image.tag=pr${{ env.PR_NUMBER }} \
--set coder.service.type=ClusterIP \
--set coder.env[0].name=CODER_ACCESS_URL \
--set coder.env[0].value="" \
--force
- name: "Get deployment URL"
id: deployment_url
run: |
set -euo pipefail
kubectl rollout status deployment/coder --namespace "pr${{ env.PR_NUMBER }}"
POD_NAME=$(kubectl get pods -n "pr${{ env.PR_NUMBER }}" | awk 'NR==2{print $1}')
CODER_ACCESS_URL=$(kubectl logs $POD_NAME -n "pr${{ env.PR_NUMBER }}" | grep "Web UI:" | awk -F ':' '{print $2":"$3}' | awk '{$1=$1};1')
echo "::add-mask::$CODER_ACCESS_URL"
echo "CODER_ACCESS_URL=$CODER_ACCESS_URL" >> $GITHUB_OUTPUT
- name: Send Slack notification
run: |
curl -s -o /dev/null -X POST -H 'Content-type: application/json' \
-d '{
"pr_number": "'"${{ env.PR_NUMBER }}"'",
"pr_url": "'"${{ env.PR_URL }}"'",
"pr_title": "'"${{ env.PR_TITLE }}"'",
"pr_access_url": "'"${{ steps.deployment_url.outputs.CODER_ACCESS_URL }}"'" }' ${{ secrets.PR_DEPLOYMENTS_SLACK_WEBHOOK }}
echo "Slack notification sent"
- name: Comment on PR
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ env.PR_NUMBER }}
edit-mode: replace
comment-id: ${{ needs.pr_commented.outputs.COMMENT_ID }}
body: |
:heavy_check_mark: Deployed PR ${{ env.PR_NUMBER }} successfully.
:rocket: Access the deployment link [here](https://codercom.slack.com/archives/C05DNE982E8).
:warning: This deployment will be deleted when the PR is closed.
reactions: "+1"
+234 -25
View File
@@ -1,19 +1,16 @@
# GitHub release workflow.
name: release
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
snapshot:
description: Force a dev version to be generated, implies dry_run.
type: boolean
required: true
dry_run:
description: Perform a dry-run release.
description: Perform a dry-run release (devel). Note that ref must be an annotated tag when run without dry-run.
type: boolean
required: true
default: false
permissions:
# Required to publish a release
@@ -23,15 +20,28 @@ permissions:
# Necessary for GCP authentication (https://github.com/google-github-actions/setup-gcloud#usage)
id-token: write
concurrency: ${{ github.workflow }}-${{ github.ref }}
env:
CODER_RELEASE: ${{ github.event.inputs.snapshot && 'false' || 'true' }}
# Use `inputs` (vs `github.event.inputs`) to ensure that booleans are actual
# booleans, not strings.
# https://github.blog/changelog/2022-06-10-github-actions-inputs-unified-across-manual-and-reusable-workflows/
CODER_RELEASE: ${{ !inputs.dry_run }}
CODER_DRY_RUN: ${{ inputs.dry_run }}
# For some reason, setup-go won't actually pick up a new patch version if
# it has an old one cached. We need to manually specify the versions so we
# can get the latest release. Never use "~1.xx" here!
CODER_GO_VERSION: "1.20.5"
jobs:
release:
name: Build and publish
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
env:
# Necessary for Docker manifest
DOCKER_CLI_EXPERIMENTAL: "enabled"
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v3
with:
@@ -45,6 +55,38 @@ jobs:
- name: Fetch git tags
run: git fetch --tags --force
- name: Print version
id: version
run: |
set -euo pipefail
version="$(./scripts/version.sh)"
echo "version=$version" >> $GITHUB_OUTPUT
# Speed up future version.sh calls.
echo "CODER_FORCE_VERSION=$version" >> $GITHUB_ENV
echo "$version"
- name: Create release notes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# We always have to set this since there might be commits on
# main that didn't have a PR.
CODER_IGNORE_MISSING_COMMIT_METADATA: "1"
run: |
set -euo pipefail
ref=HEAD
old_version="$(git describe --abbrev=0 "$ref^1")"
version="$(./scripts/version.sh)"
# Generate notes.
release_notes_file="$(mktemp -t release_notes.XXXXXX)"
./scripts/release/generate_release_notes.sh --old-version "$old_version" --new-version "$version" --ref "$ref" >> "$release_notes_file"
echo CODER_RELEASE_NOTES_FILE="$release_notes_file" >> $GITHUB_ENV
- name: Show release notes
run: |
set -euo pipefail
cat "$CODER_RELEASE_NOTES_FILE"
- name: Docker Login
uses: docker/login-action@v2
with:
@@ -52,13 +94,11 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-go@v3
with:
go-version: "~1.19"
- uses: ./.github/actions/setup-go
- name: Cache Node
id: cache-node
uses: actions/cache@v3
uses: buildjet/cache@v3
with:
path: |
**/node_modules
@@ -75,17 +115,17 @@ jobs:
set -euo pipefail
wget -O /tmp/nfpm.deb https://github.com/goreleaser/nfpm/releases/download/v2.18.1/nfpm_amd64.deb
sudo dpkg -i /tmp/nfpm.deb
rm /tmp/nfpm.deb
- name: Install rcodesign
run: |
set -euo pipefail
# Install a prebuilt binary of rcodesign for linux amd64. Once the
# following PR is merged and released upstream, we can download
# directly from GitHub releases instead:
# https://github.com/indygreg/PyOxidizer/pull/635
wget -O /tmp/rcodesign https://cdn.discordapp.com/attachments/283356472258199552/1016767245717872700/rcodesign
sudo install --mode 755 /tmp/rcodesign /usr/local/bin/rcodesign
wget -O /tmp/rcodesign.tar.gz https://github.com/indygreg/apple-platform-rs/releases/download/apple-codesign%2F0.22.0/apple-codesign-0.22.0-x86_64-unknown-linux-musl.tar.gz
sudo tar -xzf /tmp/rcodesign.tar.gz \
-C /usr/bin \
--strip-components=1 \
apple-codesign-0.22.0-x86_64-unknown-linux-musl/rcodesign
rm /tmp/rcodesign.tar.gz
- name: Setup Apple Developer certificate and API key
run: |
@@ -123,6 +163,69 @@ jobs:
- name: Delete Apple Developer certificate and API key
run: rm -f /tmp/{apple_cert.p12,apple_cert_password.txt,apple_apikey.p8}
- name: Determine base image tag
id: image-base-tag
run: |
set -euo pipefail
if [[ "${CODER_RELEASE:-}" != *t* ]] || [[ "${CODER_DRY_RUN:-}" == *t* ]]; then
# Empty value means use the default and avoid building a fresh one.
echo "tag=" >> $GITHUB_OUTPUT
else
echo "tag=$(CODER_IMAGE_BASE=ghcr.io/coder/coder-base ./scripts/image_tag.sh)" >> $GITHUB_OUTPUT
fi
- name: Create empty base-build-context directory
if: steps.image-base-tag.outputs.tag != ''
run: mkdir base-build-context
- name: Install depot.dev CLI
if: steps.image-base-tag.outputs.tag != ''
uses: depot/setup-action@v1
# This uses OIDC authentication, so no auth variables are required.
- name: Build base Docker image via depot.dev
if: steps.image-base-tag.outputs.tag != ''
uses: depot/build-push-action@v1
with:
project: wl5hnrrkns
context: base-build-context
file: scripts/Dockerfile.base
platforms: linux/amd64,linux/arm64,linux/arm/v7
pull: true
no-cache: true
push: true
tags: |
${{ steps.image-base-tag.outputs.tag }}
- name: Verify that images are pushed properly
run: |
# retry 10 times with a 5 second delay as the images may not be
# available immediately
for i in {1..10}; do
rc=0
raw_manifests=$(docker buildx imagetools inspect --raw "${{ steps.image-base-tag.outputs.tag }}") || rc=$?
if [[ "$rc" -eq 0 ]]; then
break
fi
if [[ "$i" -eq 10 ]]; then
echo "Failed to pull manifests after 10 retries"
exit 1
fi
echo "Failed to pull manifests, retrying in 5 seconds"
sleep 5
done
manifests=$(
echo "$raw_manifests" | \
jq -r '.manifests[].platform | .os + "/" + .architecture + (if .variant then "/" + .variant else "" end)'
)
# Verify all 3 platforms are present.
set -euxo pipefail
echo "$manifests" | grep -q linux/amd64
echo "$manifests" | grep -q linux/arm64
echo "$manifests" | grep -q linux/arm/v7
- name: Build Linux Docker images
run: |
set -euxo pipefail
@@ -151,14 +254,25 @@ jobs:
--target "$(./scripts/image_tag.sh --version latest)" \
$(cat build/coder_"$version"_linux_{amd64,arm64,armv7}.tag)
fi
env:
CODER_BASE_IMAGE_TAG: ${{ steps.image-base-tag.outputs.tag }}
- name: ls build
run: ls -lh build
- name: Publish release
run: |
./scripts/publish_release.sh \
${{ (github.event.inputs.dry_run || github.event.inputs.snapshot) && '--dry-run' }} \
set -euo pipefail
publish_args=()
if [[ $CODER_DRY_RUN == *t* ]]; then
publish_args+=(--dry-run)
fi
declare -p publish_args
./scripts/release/publish.sh \
"${publish_args[@]}" \
--release-notes-file "$CODER_RELEASE_NOTES_FILE" \
./build/*_installer.exe \
./build/*.zip \
./build/*.tar.gz \
@@ -168,17 +282,19 @@ jobs:
./build/*.rpm
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CODER_GPG_RELEASE_KEY_BASE64: ${{ secrets.GPG_RELEASE_KEY_BASE64 }}
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v0
uses: google-github-actions/auth@v1
with:
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_ID_PROVIDER }}
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
- name: Setup GCloud SDK
uses: 'google-github-actions/setup-gcloud@v0'
uses: "google-github-actions/setup-gcloud@v1"
- name: Publish Helm Chart
if: ${{ !inputs.dry_run }}
run: |
set -euo pipefail
version="$(./scripts/version.sh)"
@@ -188,13 +304,15 @@ jobs:
helm repo index build/helm --url https://helm.coder.com/v2 --merge build/helm/index.yaml
gsutil -h "Cache-Control:no-cache,max-age=0" cp build/helm/coder_helm_${version}.tgz gs://helm.coder.com/v2
gsutil -h "Cache-Control:no-cache,max-age=0" cp build/helm/index.yaml gs://helm.coder.com/v2
gsutil -h "Cache-Control:no-cache,max-age=0" cp helm/artifacthub-repo.yml gs://helm.coder.com/v2
- name: Upload artifacts to actions (if dry-run or snapshot)
if: ${{ github.event.inputs.dry_run || github.event.inputs.snapshot }}
uses: actions/upload-artifact@v2
- name: Upload artifacts to actions (if dry-run)
if: ${{ inputs.dry_run }}
uses: actions/upload-artifact@v3
with:
name: release-artifacts
path: |
./build/*_installer.exe
./build/*.zip
./build/*.tar.gz
./build/*.tgz
@@ -202,3 +320,94 @@ jobs:
./build/*.deb
./build/*.rpm
retention-days: 7
- name: Start Packer builds
if: ${{ !inputs.dry_run }}
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.CDRCI_GITHUB_TOKEN }}
repository: coder/packages
event-type: coder-release
client-payload: '{"coder_version": "${{ steps.version.outputs.version }}"}'
publish-winget:
name: Publish to winget-pkgs
runs-on: windows-latest
needs: release
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
# If the event that triggered the build was an annotated tag (which our
# tags are supposed to be), actions/checkout has a bug where the tag in
# question is only a lightweight tag and not a full annotated tag. This
# command seems to fix it.
# https://github.com/actions/checkout/issues/290
- name: Fetch git tags
run: git fetch --tags --force
- name: Install wingetcreate
run: |
Invoke-WebRequest https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe
- name: Submit updated manifest to winget-pkgs
run: |
# The package version is the same as the tag minus the leading "v".
# The version in this output already has the leading "v" removed but
# we do it again to be safe.
$version = "${{ needs.release.outputs.version }}".Trim('v')
$release_assets = gh release view --repo coder/coder "v${version}" --json assets | `
ConvertFrom-Json
# Get the installer URL from the release assets.
$installer_url = $release_assets.assets | `
Where-Object name -Match ".*_windows_amd64_installer.exe$" | `
Select -ExpandProperty url
echo "Installer URL: ${installer_url}"
echo "Package version: ${version}"
# Bail if dry-run.
if ($env:CODER_DRY_RUN -match "t") {
echo "Skipping submission due to dry-run."
exit 0
}
# The URL "|X64" suffix forces the architecture as it cannot be
# sniffed properly from the URL. wingetcreate checks both the URL and
# binary magic bytes for the architecture and they need to both match,
# but they only check for `x64`, `win64` and `_64` in the URL. Our URL
# contains `amd64` which doesn't match sadly.
#
# wingetcreate will still do the binary magic bytes check, so if we
# accidentally change the architecture of the installer, it will fail
# submission.
.\wingetcreate.exe update Coder.Coder `
--submit `
--version "${version}" `
--urls "${installer_url}|X64" `
--token "$env:WINGET_GH_TOKEN"
env:
# For gh CLI:
GH_TOKEN: ${{ github.token }}
# For wingetcreate. We need a real token since we're pushing a commit
# to GitHub and then making a PR in a different repo.
WINGET_GH_TOKEN: ${{ secrets.CDRCI_GITHUB_TOKEN }}
- name: Comment on PR
if: ${{ !inputs.dry_run }}
run: |
# Find the PR that wingetcreate just made.
$version = "${{ needs.release.outputs.version }}".Trim('v')
$pr_list = gh pr list --repo microsoft/winget-pkgs --search "author:cdrci Coder.Coder version ${version}" --limit 1 --json number | `
ConvertFrom-Json
$pr_number = $pr_list[0].number
gh pr comment --repo microsoft/winget-pkgs "${pr_number}" --body "🤖 cc: @deansheather @matifali"
env:
# For gh CLI. We need a real token since we're commenting on a PR in a
# different repo.
GH_TOKEN: ${{ secrets.CDRCI_GITHUB_TOKEN }}
+167
View File
@@ -0,0 +1,167 @@
name: "security"
permissions:
actions: read
contents: read
security-events: write
on:
workflow_dispatch:
schedule:
# Run every 6 hours Monday-Friday!
- cron: "0 0/6 * * 1-5"
# Cancel in-progress runs for pull requests when developers push
# additional changes
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-security
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
CODER_GO_VERSION: "1.20.5"
jobs:
codeql:
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
steps:
- uses: actions/checkout@v3
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: go, javascript
- uses: ./.github/actions/setup-go
# Workaround to prevent CodeQL from building the dashboard.
- name: Remove Makefile
run: |
rm Makefile
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
- name: Send Slack notification on failure
if: ${{ failure() }}
run: |
msg="❌ CodeQL Failed\n\nhttps://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
curl \
-qfsSL \
-X POST \
-H "Content-Type: application/json" \
--data "{\"content\": \"$msg\"}" \
"${{ secrets.SLACK_SECURITY_FAILURE_WEBHOOK_URL }}"
trivy:
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: ./.github/actions/setup-go
- name: Cache Node
id: cache-node
uses: buildjet/cache@v3
with:
path: |
**/node_modules
.eslintcache
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
js-${{ runner.os }}-
- name: Install sqlc
run: |
curl -sSL https://github.com/kyleconroy/sqlc/releases/download/v1.18.0/sqlc_1.18.0_linux_amd64.tar.gz | sudo tar -C /usr/bin -xz sqlc
- name: Install yq
run: go run github.com/mikefarah/yq/v4@v4.30.6
- name: Install mockgen
run: go install github.com/golang/mock/mockgen@v1.6.0
- name: Install protoc-gen-go
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.30
- name: Install protoc-gen-go-drpc
run: go install storj.io/drpc/cmd/protoc-gen-go-drpc@v0.0.33
- name: Install Protoc
run: |
# protoc must be in lockstep with our dogfood Dockerfile or the
# version in the comments will differ. This is also defined in
# ci.yaml.
set -x
cd dogfood
DOCKER_BUILDKIT=1 docker build . --target proto -t protoc
protoc_path=/usr/local/bin/protoc
docker run --rm --entrypoint cat protoc /tmp/bin/protoc > $protoc_path
chmod +x $protoc_path
protoc --version
- name: Build Coder linux amd64 Docker image
id: build
run: |
set -euo pipefail
version="$(./scripts/version.sh)"
image_job="build/coder_${version}_linux_amd64.tag"
# This environment variable force make to not build packages and
# archives (which the Docker image depends on due to technical reasons
# related to concurrent FS writes).
export DOCKER_IMAGE_NO_PREREQUISITES=true
# This environment variables forces scripts/build_docker.sh to build
# the base image tag locally instead of using the cached version from
# the registry.
export CODER_IMAGE_BUILD_BASE_TAG="$(CODER_IMAGE_BASE=coder-base ./scripts/image_tag.sh --version "$version")"
make -j "$image_job"
echo "image=$(cat "$image_job")" >> $GITHUB_OUTPUT
- name: Run Prisma Cloud image scan
uses: PaloAltoNetworks/prisma-cloud-scan@v1
with:
pcc_console_url: ${{ secrets.PRISMA_CLOUD_URL }}
pcc_user: ${{ secrets.PRISMA_CLOUD_ACCESS_KEY }}
pcc_pass: ${{ secrets.PRISMA_CLOUD_SECRET_KEY }}
image_name: ${{ steps.build.outputs.image }}
- name: Scan image
id: sysdig-scan
uses: sysdiglabs/scan-action@v3
with:
image-tag: ${{ steps.build.outputs.image }}
sysdig-secure-token: ${{ secrets.SYSDIG_API_TOKEN }}
input-type: docker-daemon
sysdig-secure-url: https://app.us4.sysdig.com
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@41f05d9ecffa2ed3f1580af306000f734b733e54
with:
image-ref: ${{ steps.build.outputs.image }}
format: sarif
output: trivy-results.sarif
severity: "CRITICAL,HIGH"
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: trivy-results.sarif
category: "Trivy"
- name: Upload Trivy scan results as an artifact
uses: actions/upload-artifact@v3
with:
name: trivy
path: trivy-results.sarif
retention-days: 7
- name: Send Slack notification on failure
if: ${{ failure() }}
run: |
msg="❌ Trivy Failed\n\nhttps://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
curl \
-qfsSL \
-X POST \
-H "Content-Type: application/json" \
--data "{\"content\": \"$msg\"}" \
"${{ secrets.SLACK_SECURITY_FAILURE_WEBHOOK_URL }}"
+46 -15
View File
@@ -1,35 +1,66 @@
name: Stale Issue Cron
name: Stale Issue, Banch and Old Workflows Cleanup
on:
schedule:
# Every day at midnight
- cron: "0 0 * * *"
workflow_dispatch:
jobs:
stale:
issues:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
actions: write
steps:
# v5.1.0 has a weird bug that makes stalebot add then remove its own label
# https://github.com/actions/stale/pull/775
- uses: actions/stale@v6.0.0
- uses: actions/stale@v8.0.0
with:
stale-issue-label: stale
stale-pr-label: stale
stale-issue-label: "stale"
stale-pr-label: "stale"
days-before-stale: 90
# Pull Requests become stale more quickly due to merge conflicts.
# Also, we promote minimizing WIP.
days-before-pr-stale: 7
days-before-pr-close: 3
stale-pr-message: >
This Pull Request is becoming stale. In order to minimize WIP,
prevent merge conflicts and keep the tracker readable, I'm going
close to this PR in 3 days if there isn't more activity.
stale-issue-message: >
This issue is becoming stale. In order to keep the tracker readable
and actionable, I'm going close to this issue in 7 days if there
isn't more activity.
# We rarely take action in response to the message, so avoid
# cluttering the issue and just close the oldies.
stale-pr-message: ""
stale-issue-message: ""
# Upped from 30 since we have a big tracker and was hitting the limit.
operations-per-run: 60
# Start with the oldest issues, always.
ascending: true
branches:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Run delete-old-branches-action
uses: beatlabs/delete-old-branches-action@v0.0.10
with:
repo_token: ${{ github.token }}
date: "6 months ago"
dry_run: false
delete_tags: false
# extra_protected_branch_regex: ^(foo|bar)$
exclude_open_pr_branches: true
del_runs:
runs-on: ubuntu-latest
steps:
- name: Delete PR Cleanup workflow runs
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: 1
keep_minimum_runs: 1
delete_workflow_pattern: pr-cleanup.yaml
- name: Delete PR Deploy workflow skipped runs
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: 0
keep_minimum_runs: 0
delete_run_by_conclusion_pattern: skipped
delete_workflow_pattern: pr-deploy.yaml
+6
View File
@@ -3,11 +3,16 @@ alog = "alog"
Jetbrains = "JetBrains"
IST = "IST"
MacOS = "macOS"
AKS = "AKS"
[default.extend-words]
AKS = "AKS"
# do as sudo replacement
doas = "doas"
darcula = "darcula"
Hashi = "Hashi"
trialer = "trialer"
encrypter = "encrypter"
[files]
extend-exclude = [
@@ -19,4 +24,5 @@ extend-exclude = [
# These files contain base64 strings that confuse the detector
"**XService**.ts",
"**identity.go",
"scripts/ci-report/testdata/**",
]
+32
View File
@@ -0,0 +1,32 @@
name: weekly-docs
# runs every monday at 9 am
on:
schedule:
- cron: "0 9 * * 1"
workflow_dispatch: # allows to run manually for testing
jobs:
check-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: Check Markdown links
uses: gaurav-nelson/github-action-markdown-link-check@v1
id: markdown-link-check
# checks all markdown files from /docs including all subfolders
with:
use-quiet-mode: "yes"
use-verbose-mode: "yes"
config-file: ".github/workflows/mlc_config.json"
folder-path: "docs/"
file-path: "./README.md"
- name: Send Slack notification
if: failure()
run: |
curl -X POST -H 'Content-type: application/json' -d '{"msg":"Broken links found in the documentation. Please check the logs at ${{ env.LOGS_URL }}"}' ${{ secrets.DOCS_LINK_SLACK_WEBHOOK }}
echo "Sent Slack notification"
env:
LOGS_URL: https://github.com/coder/coder/actions/runs/${{ github.run_id }}
-18
View File
@@ -1,18 +0,0 @@
name: Welcome
on:
pull_request:
types: [opened]
jobs:
test:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: wow-actions/welcome@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FIRST_PR_REACTIONS: '+1, hooray, rocket, heart'
FIRST_PR_COMMENT: |
👋 Welcome @{{ author }} to Coder! Yo @coder/docs this is @{{ author }}'s first pull-request here!
FIRST_PR_MERGED: |
🎉 Thanks for the contribution @{{ author }}! Yo @coder/docs @{{ author }}'s first contribution has been merged! 👀👀👀
+44 -32
View File
@@ -1,51 +1,63 @@
###############################################################################
# NOTICE #
# If you change this file, kindly copy-pasta your change into .prettierignore #
# and .eslintignore as well. See the following discussions to understand why #
# we have to resort to this duplication (at least for now): #
# #
# https://github.com/prettier/prettier/issues/8048 #
# https://github.com/prettier/prettier/issues/8506 #
# https://github.com/prettier/prettier/issues/8679 #
###############################################################################
node_modules
vendor
.eslintcache
yarn-error.log
gotests.coverage
.idea
.gitpod.yml
# Common ignore patterns, these rules applies in both root and subdirectories.
.DS_Store
.eslintcache
.gitpod.yml
.idea
**/*.swp
gotests.coverage
gotests.xml
gotests_stats.json
gotests.json
node_modules/
vendor/
yarn-error.log
# Make target for updating golden files.
cli/testdata/.gen-golden
# VSCode settings.
**/.vscode/*
# Allow VSCode recommendations and default settings in project root.
!/.vscode/extensions.json
!/.vscode/settings.json
# Front-end ignore
# Front-end ignore patterns.
.next/
site/.eslintcache
site/.next/
site/node_modules/
site/storybook-static/
site/test-results/
site/yarn-error.log
coverage/
site/**/*.typegen.ts
site/build-storybook.log
site/coverage/
site/storybook-static/
site/test-results/*
site/e2e/test-results/*
site/e2e/states/*.json
site/e2e/.auth.json
site/playwright-report/*
site/.swc
site/dist/
# Make target for updating golden files (any dir).
.gen-golden
# Build
/build/
/dist/
site/out/
# Bundle analysis
site/stats/
*.tfstate
*.tfstate.backup
*.tfplan
*.lock.hcl
.terraform/
.vscode/*.log
.vscode/launch.json
**/*.swp
.coderv2/*
**/.coderv2/*
**/__debug_bin
# direnv
.envrc
*.test
# Loadtesting
./scaletest/terraform/.terraform
./scaletest/terraform/.terraform.lock.hcl
scaletest/terraform/secrets.tfvars
.terraform.tfstate.*
+5 -6
View File
@@ -54,7 +54,6 @@ linters-settings:
# - importShadow
- indexAlloc
- initClause
- ioutilDeprecated
- mapKey
- methodExprCall
# - nestingReduce
@@ -103,7 +102,7 @@ linters-settings:
settings:
ruleguard:
failOn: all
rules: '${configDir}/scripts/rules.go'
rules: "${configDir}/scripts/rules.go"
staticcheck:
# https://staticcheck.io/docs/options#checks
@@ -123,6 +122,8 @@ linters-settings:
misspell:
locale: US
ignore-words:
- trialer
nestif:
min-complexity: 4 # Min complexity of if statements (def 5, goal 4)
@@ -192,18 +193,18 @@ issues:
linters:
# We use assertions rather than explicitly checking errors in tests
- errcheck
- forcetypeassert
fix: true
max-issues-per-linter: 0
max-same-issues: 0
run:
concurrency: 4
skip-dirs:
- node_modules
skip-files:
- scripts/rules.go
timeout: 5m
timeout: 10m
# Over time, add more and more linters from
# https://golangci-lint.run/usage/linters/ as the code improves.
@@ -213,7 +214,6 @@ linters:
- asciicheck
- bidichk
- bodyclose
- deadcode
- dogsled
- errcheck
- errname
@@ -257,4 +257,3 @@ linters:
- typecheck
- unconvert
- unused
- varcheck
+80
View File
@@ -0,0 +1,80 @@
# Code generated by Makefile (.gitignore .prettierignore.include). DO NOT EDIT.
# .gitignore:
# Common ignore patterns, these rules applies in both root and subdirectories.
.DS_Store
.eslintcache
.gitpod.yml
.idea
**/*.swp
gotests.coverage
gotests.xml
gotests_stats.json
gotests.json
node_modules/
vendor/
yarn-error.log
# VSCode settings.
**/.vscode/*
# Allow VSCode recommendations and default settings in project root.
!/.vscode/extensions.json
!/.vscode/settings.json
# Front-end ignore patterns.
.next/
site/**/*.typegen.ts
site/build-storybook.log
site/coverage/
site/storybook-static/
site/test-results/*
site/e2e/test-results/*
site/e2e/states/*.json
site/e2e/.auth.json
site/playwright-report/*
site/.swc
site/dist/
# Make target for updating golden files (any dir).
.gen-golden
# Build
/build/
/dist/
site/out/
# Bundle analysis
site/stats/
*.tfstate
*.tfstate.backup
*.tfplan
*.lock.hcl
.terraform/
**/.coderv2/*
**/__debug_bin
# direnv
.envrc
*.test
# Loadtesting
./scaletest/terraform/.terraform
./scaletest/terraform/.terraform.lock.hcl
scaletest/terraform/secrets.tfvars
.terraform.tfstate.*
# .prettierignore.include:
# Helm templates contain variables that are invalid YAML and can't be formatted
# by Prettier.
helm/templates/*.yaml
# Terraform state files used in tests, these are automatically generated.
# Example: provisioner/terraform/testdata/instance-id/instance-id.tfstate.json
**/testdata/**/*.tf*.json
# Testdata shouldn't be formatted.
scripts/apitypings/testdata/**/*.ts
# Generated files shouldn't be formatted.
site/e2e/provisionerGenerated.ts
+13
View File
@@ -0,0 +1,13 @@
# Helm templates contain variables that are invalid YAML and can't be formatted
# by Prettier.
helm/templates/*.yaml
# Terraform state files used in tests, these are automatically generated.
# Example: provisioner/terraform/testdata/instance-id/instance-id.tfstate.json
**/testdata/**/*.tf*.json
# Testdata shouldn't be formatted.
scripts/apitypings/testdata/**/*.ts
# Generated files shouldn't be formatted.
site/e2e/provisionerGenerated.ts
+16
View File
@@ -0,0 +1,16 @@
# This config file is used in conjunction with `.editorconfig` to specify
# formatting for prettier-supported files. See `.editorconfig` and
# `site/.editorconfig`for whitespace formatting options.
printWidth: 80
semi: false
trailingComma: all
overrides:
- files:
- README.md
options:
proseWrap: preserve
- files:
- "site/**/*.yaml"
- "site/**/*.yml"
options:
proseWrap: always
+8
View File
@@ -0,0 +1,8 @@
// Replace all NullTime with string
replace github.com/coder/coder/codersdk.NullTime string
// Prevent swaggo from rendering enums for time.Duration
replace time.Duration int64
// Do not expose "echo" provider
replace github.com/coder/coder/codersdk.ProvisionerType string
// Do not render netip.Addr
replace netip.Addr string
+1
View File
@@ -1,5 +1,6 @@
{
"recommendations": [
"github.vscode-codeql",
"golang.go",
"hashicorp.terraform",
"esbenp.prettier-vscode",
+22 -9
View File
@@ -1,8 +1,11 @@
{
"cSpell.words": [
"afero",
"agentsdk",
"apps",
"ASKPASS",
"authcheck",
"autostop",
"awsidentity",
"bodyclose",
"buildinfo",
@@ -17,6 +20,9 @@
"codersdk",
"cronstrue",
"databasefake",
"dbfake",
"dbgen",
"dbtype",
"DERP",
"derphttp",
"derpmap",
@@ -30,8 +36,10 @@
"Dsts",
"embeddedpostgres",
"enablements",
"enterprisemeta",
"errgroup",
"eventsourcemock",
"Failf",
"fatih",
"Formik",
"gitauth",
@@ -85,9 +93,9 @@
"pqtype",
"prometheusmetrics",
"promhttp",
"promptui",
"protobuf",
"provisionerd",
"provisionerdserver",
"provisionersdk",
"ptty",
"ptys",
@@ -104,15 +112,18 @@
"slogtest",
"sourcemapped",
"Srcs",
"stdbuf",
"stretchr",
"STTY",
"stuntest",
"tanstack",
"tailbroker",
"tailcfg",
"tailexchange",
"tailnet",
"tailnettest",
"Tailscale",
"tbody",
"TCGETS",
"tcpip",
"TCSETS",
@@ -124,8 +135,12 @@
"tfjson",
"tfplan",
"tfstate",
"thead",
"tios",
"tmpdir",
"tokenconfig",
"tparallel",
"trialer",
"trimprefix",
"tsdial",
"tslogger",
@@ -157,10 +172,7 @@
"xstate",
"yamux"
],
"cSpell.ignorePaths": [
"site/package.json",
".vscode/settings.json"
],
"cSpell.ignorePaths": ["site/package.json", ".vscode/settings.json"],
"emeraldwalk.runonsave": {
"commands": [
{
@@ -177,6 +189,10 @@
"files.exclude": {
"**/node_modules": true
},
"search.exclude": {
"scripts/metricsdocgen/metrics": true,
"docs/api/*.md": true
},
// Ensure files always have a newline.
"files.insertFinalNewline": true,
"go.lintTool": "golangci-lint",
@@ -192,10 +208,7 @@
// To reduce redundancy in tests, it's covered by other packages.
// Since package coverage pairing can't be defined, all packages cover
// all other packages.
"go.testFlags": [
"-short",
"-coverpkg=./..."
],
"go.testFlags": ["-short", "-coverpkg=./..."],
// We often use a version of TypeScript that's ahead of the version shipped
// with VS Code.
"typescript.tsdk": "./site/node_modules/typescript/lib"
-12
View File
@@ -1,12 +0,0 @@
# Adopters
[!["Join us on
Discord"](https://img.shields.io/badge/join-us%20on%20Discord-gray.svg?longCache=true&logo=discord&colorB=green)](https://coder.com/chat?utm_source=github.com/coder/coder&utm_medium=github&utm_campaign=adopters.md) [![Twitter
Follow](https://img.shields.io/twitter/follow/coderhq?label=%40coderhq&style=social)](https://twitter.com/coderhq)
🦩 _If you're using Coder in your organization, please try to add your company name to this list. It really helps the project to gain momentum and credibility. It's a small contribution back to the project with a big impact. You can do this by by editing this file and contributing your changes via a pull-request on GitHub._
> 👋 _If you are considering using Coder in your organization please introduce yourself via https://coder.com/demo_ 🙇🏻‍♂️
| Organization | Contact | Description of Use |
| --------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Coder](https://www.coder.com) | [@coderhq](https://twitter.com/coderhq) | Coder builds coder with Coder. |
+211 -40
View File
@@ -44,6 +44,18 @@ else
ZSTDFLAGS := -6
endif
# Common paths to exclude from find commands, this rule is written so
# that it can be it can be used in a chain of AND statements (meaning
# you can simply write `find . $(FIND_EXCLUSIONS) -name thing-i-want`).
# Note, all find statements should be written with `.` or `./path` as
# the search path so that these exclusions match.
FIND_EXCLUSIONS= \
-not \( \( -path '*/.git/*' -o -path './build/*' -o -path './vendor/*' -o -path './.coderv2/*' -o -path '*/node_modules/*' -o -path './site/out/*' -o -path './coderd/apidoc/*' \) -prune \)
# Source files used for make targets, evaluated on use.
GO_SRC_FILES := $(shell find . $(FIND_EXCLUSIONS) -type f -name '*.go')
# All the shell files in the repo, excluding ignored files.
SHELL_SRC_FILES := $(shell find . $(FIND_EXCLUSIONS) -type f -name '*.sh')
# All ${OS}_${ARCH} combos we build for. Windows binaries have the .exe suffix.
OS_ARCHES := \
linux_amd64 linux_arm64 linux_armv7 \
@@ -80,6 +92,19 @@ CODER_FAT_NOVERSION_BINARIES := $(addprefix build/coder_,$(OS_ARCHES))
CODER_ALL_NOVERSION_IMAGES := $(foreach arch, $(DOCKER_ARCHES), build/coder_linux_$(arch).tag) build/coder_linux.tag
CODER_ALL_NOVERSION_IMAGES_PUSHED := $(addprefix push/, $(CODER_ALL_NOVERSION_IMAGES))
# If callers are only building Docker images and not the packages and archives,
# we can skip those prerequisites as they are not actually required and only
# specified to avoid concurrent write failures.
ifdef DOCKER_IMAGE_NO_PREREQUISITES
CODER_ARCH_IMAGE_PREREQUISITES :=
else
CODER_ARCH_IMAGE_PREREQUISITES := \
build/coder_$(VERSION)_%.apk \
build/coder_$(VERSION)_%.deb \
build/coder_$(VERSION)_%.rpm \
build/coder_$(VERSION)_%.tar.gz
endif
clean:
rm -rf build site/out
@@ -96,19 +121,26 @@ build-fat build-full build: $(CODER_FAT_BINARIES)
release: $(CODER_FAT_BINARIES) $(CODER_ALL_ARCHIVES) $(CODER_ALL_PACKAGES) $(CODER_ARCH_IMAGES) build/coder_helm_$(VERSION).tgz
.PHONY: release
build/coder-slim_$(VERSION)_checksums.sha1 site/out/bin/coder.sha1: $(CODER_SLIM_BINARIES)
build/coder-slim_$(VERSION)_checksums.sha1: site/out/bin/coder.sha1
cp "$<" "$@"
site/out/bin/coder.sha1: $(CODER_SLIM_BINARIES)
pushd ./site/out/bin
openssl dgst -r -sha1 coder-* | tee coder.sha1
popd
cp "site/out/bin/coder.sha1" "build/coder-slim_$(VERSION)_checksums.sha1"
build/coder-slim_$(VERSION).tar: build/coder-slim_$(VERSION)_checksums.sha1 $(CODER_SLIM_BINARIES)
pushd ./site/out/bin
tar cf "../../../build/$(@F)" coder-*
popd
build/coder-slim_$(VERSION).tar.zst site/out/bin/coder.tar.zst: build/coder-slim_$(VERSION).tar
# delete the uncompressed binaries from the embedded dir
rm -f site/out/bin/coder-*
site/out/bin/coder.tar.zst: build/coder-slim_$(VERSION).tar.zst
cp "$<" "$@"
build/coder-slim_$(VERSION).tar.zst: build/coder-slim_$(VERSION).tar
zstd $(ZSTDFLAGS) \
--force \
--long \
@@ -116,10 +148,6 @@ build/coder-slim_$(VERSION).tar.zst site/out/bin/coder.tar.zst: build/coder-slim
-o "build/coder-slim_$(VERSION).tar.zst" \
"build/coder-slim_$(VERSION).tar"
cp "build/coder-slim_$(VERSION).tar.zst" "site/out/bin/coder.tar.zst"
# delete the uncompressed binaries from the embedded dir
rm site/out/bin/coder-*
# Redirect from version-less targets to the versioned ones. There is a similar
# target for slim binaries below.
#
@@ -171,7 +199,7 @@ endef
# You should probably use the non-version targets above instead if you're
# calling this manually.
$(CODER_ALL_BINARIES): go.mod go.sum \
$(shell find . -not -path './vendor/*' -type f -name '*.go') \
$(GO_SRC_FILES) \
$(shell find ./examples/templates)
$(get-mode-os-arch-ext)
@@ -281,13 +309,7 @@ $(CODER_ALL_NOVERSION_IMAGES_PUSHED): push/build/coder_%: push/build/coder_$(VER
#
# Images need to run after the archives and packages are built, otherwise they
# cause errors like "file changed as we read it".
$(CODER_ARCH_IMAGES): build/coder_$(VERSION)_%.tag: \
build/coder_$(VERSION)_% \
build/coder_$(VERSION)_%.apk \
build/coder_$(VERSION)_%.deb \
build/coder_$(VERSION)_%.rpm \
build/coder_$(VERSION)_%.tar.gz
$(CODER_ARCH_IMAGES): build/coder_$(VERSION)_%.tag: build/coder_$(VERSION)_% $(CODER_ARCH_IMAGE_PREREQUISITES)
$(get-mode-os-arch-ext)
image_tag="$$(./scripts/image_tag.sh --arch "$$arch" --version "$(VERSION)")"
@@ -333,7 +355,7 @@ build/coder_helm_$(VERSION).tgz:
--version "$(VERSION)" \
--output "$@"
site/out/index.html: $(shell find ./site -not -path './site/node_modules/*' -type f -name '*.tsx') $(shell find ./site -not -path './site/node_modules/*' -type f -name '*.ts') site/package.json
site/out/index.html: site/package.json $(shell find ./site $(FIND_EXCLUSIONS) -type f \( -name '*.ts' -o -name '*.tsx' \))
./scripts/yarn_install.sh
cd site
yarn build
@@ -346,9 +368,15 @@ install: build/coder_$(VERSION)_$(GOOS)_$(GOARCH)$(GOOS_BIN_EXT)
cp "$<" "$$output_file"
.PHONY: install
fmt: fmt/prettier fmt/terraform fmt/shfmt
fmt: fmt/prettier fmt/terraform fmt/shfmt fmt/go
.PHONY: fmt
fmt/go:
# VS Code users should check out
# https://github.com/mvdan/gofumpt#visual-studio-code
go run mvdan.cc/gofumpt@v0.4.0 -w -l .
.PHONY: fmt/go
fmt/prettier:
echo "--- prettier"
cd site
@@ -364,43 +392,82 @@ fmt/terraform: $(wildcard *.tf)
terraform fmt -recursive
.PHONY: fmt/terraform
fmt/shfmt: $(shell shfmt -f .)
fmt/shfmt: $(SHELL_SRC_FILES)
echo "--- shfmt"
# Only do diff check in CI, errors on diff.
ifdef CI
shfmt -d $(shell shfmt -f .)
shfmt -d $(SHELL_SRC_FILES)
else
shfmt -w $(shell shfmt -f .)
shfmt -w $(SHELL_SRC_FILES)
endif
.PHONY: fmt/shfmt
lint: lint/shellcheck lint/go
lint: lint/shellcheck lint/go lint/ts lint/helm
.PHONY: lint
lint/ts:
cd site
yarn && yarn lint
.PHONY: lint/ts
lint/go:
./scripts/check_enterprise_imports.sh
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.2
golangci-lint run
.PHONY: lint/go
# Use shfmt to determine the shell files, takes editorconfig into consideration.
lint/shellcheck: $(shell shfmt -f .)
lint/shellcheck: $(SHELL_SRC_FILES)
echo "--- shellcheck"
shellcheck --external-sources $(shell shfmt -f .)
shellcheck --external-sources $(SHELL_SRC_FILES)
.PHONY: lint/shellcheck
lint/helm:
cd helm
make lint
.PHONY: lint/helm
# all gen targets should be added here and to gen/mark-fresh
gen: \
coderd/database/dump.sql \
coderd/database/querier.go \
coderd/database/dbmock/dbmock.go \
provisionersdk/proto/provisioner.pb.go \
provisionerd/proto/provisionerd.pb.go \
site/src/api/typesGenerated.ts
site/src/api/typesGenerated.ts \
coderd/rbac/object_gen.go \
docs/admin/prometheus.md \
docs/cli.md \
docs/admin/audit-logs.md \
coderd/apidoc/swagger.json \
.prettierignore.include \
.prettierignore \
site/.prettierrc.yaml \
site/.prettierignore \
site/.eslintignore
.PHONY: gen
# Mark all generated files as fresh so make thinks they're up-to-date. This is
# used during releases so we don't run generation scripts.
gen/mark-fresh:
files="coderd/database/dump.sql coderd/database/querier.go provisionersdk/proto/provisioner.pb.go provisionerd/proto/provisionerd.pb.go site/src/api/typesGenerated.ts"
files="\
coderd/database/dump.sql \
coderd/database/querier.go \
coderd/database/dbmock/dbmock.go \
provisionersdk/proto/provisioner.pb.go \
provisionerd/proto/provisionerd.pb.go \
site/src/api/typesGenerated.ts \
coderd/rbac/object_gen.go \
docs/admin/prometheus.md \
docs/cli.md \
docs/admin/audit-logs.md \
coderd/apidoc/swagger.json \
.prettierignore.include \
.prettierignore \
site/.prettierrc.yaml \
site/.prettierignore \
site/.eslintignore \
"
for file in $$files; do
echo "$$file"
if [ ! -f "$$file" ]; then
@@ -419,9 +486,13 @@ coderd/database/dump.sql: coderd/database/gen/dump/main.go $(wildcard coderd/dat
go run ./coderd/database/gen/dump/main.go
# Generates Go code for querying the database.
coderd/database/querier.go: coderd/database/sqlc.yaml coderd/database/dump.sql $(wildcard coderd/database/queries/*.sql) coderd/database/gen/enum/main.go
coderd/database/querier.go: coderd/database/sqlc.yaml coderd/database/dump.sql $(wildcard coderd/database/queries/*.sql)
./coderd/database/generate.sh
coderd/database/dbmock/dbmock.go: coderd/database/db.go coderd/database/querier.go
go generate ./coderd/database/dbmock/
provisionersdk/proto/provisioner.pb.go: provisionersdk/proto/provisioner.proto
protoc \
--go_out=. \
@@ -438,31 +509,128 @@ provisionerd/proto/provisionerd.pb.go: provisionerd/proto/provisionerd.proto
--go-drpc_opt=paths=source_relative \
./provisionerd/proto/provisionerd.proto
site/src/api/typesGenerated.ts: scripts/apitypings/main.go $(shell find codersdk -type f -name '*.go')
site/src/api/typesGenerated.ts: scripts/apitypings/main.go $(shell find ./codersdk $(FIND_EXCLUSIONS) -type f -name '*.go')
go run scripts/apitypings/main.go > site/src/api/typesGenerated.ts
cd site
yarn run format:types
update-golden-files: cli/testdata/.gen-golden
coderd/rbac/object_gen.go: scripts/rbacgen/main.go coderd/rbac/object.go
go run scripts/rbacgen/main.go ./coderd/rbac > coderd/rbac/object_gen.go
docs/admin/prometheus.md: scripts/metricsdocgen/main.go scripts/metricsdocgen/metrics
go run scripts/metricsdocgen/main.go
cd site
yarn run format:write:only ../docs/admin/prometheus.md
docs/cli.md: scripts/clidocgen/main.go $(GO_SRC_FILES)
BASE_PATH="." go run ./scripts/clidocgen
cd site
yarn run format:write:only ../docs/cli.md ../docs/cli/*.md ../docs/manifest.json
docs/admin/audit-logs.md: scripts/auditdocgen/main.go enterprise/audit/table.go coderd/rbac/object_gen.go
go run scripts/auditdocgen/main.go
cd site
yarn run format:write:only ../docs/admin/audit-logs.md
coderd/apidoc/swagger.json: $(shell find ./scripts/apidocgen $(FIND_EXCLUSIONS) -type f) $(wildcard coderd/*.go) $(wildcard enterprise/coderd/*.go) $(wildcard codersdk/*.go) $(wildcard enterprise/wsproxy/wsproxysdk/*.go) coderd/database/querier.go .swaggo docs/manifest.json coderd/rbac/object_gen.go
./scripts/apidocgen/generate.sh
yarn run --cwd=site format:write:only ../docs/api ../docs/manifest.json ../coderd/apidoc/swagger.json
update-golden-files: cli/testdata/.gen-golden helm/tests/testdata/.gen-golden scripts/ci-report/testdata/.gen-golden enterprise/cli/testdata/.gen-golden
.PHONY: update-golden-files
cli/testdata/.gen-golden: $(wildcard cli/testdata/*.golden) \
$(shell find . -not -path './vendor/*' -type f -name '*.go')
go test ./cli -run=TestCommandHelp -update
cli/testdata/.gen-golden: $(wildcard cli/testdata/*.golden) $(wildcard cli/*.tpl) $(GO_SRC_FILES)
go test ./cli -run="Test(CommandHelp|ServerYAML)" -update
touch "$@"
enterprise/cli/testdata/.gen-golden: $(wildcard enterprise/cli/testdata/*.golden) $(wildcard cli/*.tpl) $(GO_SRC_FILES)
go test ./enterprise/cli -run="TestEnterpriseCommandHelp" -update
touch "$@"
helm/tests/testdata/.gen-golden: $(wildcard helm/tests/testdata/*.yaml) $(wildcard helm/tests/testdata/*.golden) $(GO_SRC_FILES)
go test ./helm/tests -run=TestUpdateGoldenFiles -update
touch "$@"
scripts/ci-report/testdata/.gen-golden: $(wildcard scripts/ci-report/testdata/*) $(wildcard scripts/ci-report/*.go)
go test ./scripts/ci-report -run=TestOutputMatchesGoldenFile -update
touch "$@"
# Generate a prettierrc for the site package that uses relative paths for
# overrides. This allows us to share the same prettier config between the
# site and the root of the repo.
site/.prettierrc.yaml: .prettierrc.yaml
. ./scripts/lib.sh
dependencies yq
echo "# Code generated by Makefile (../$<). DO NOT EDIT." > "$@"
echo "" >> "$@"
# Replace all listed override files with relative paths inside site/.
# - ./ -> ../
# - ./site -> ./
yq \
'.overrides[].files |= map(. | sub("^./"; "") | sub("^"; "../") | sub("../site/"; "./"))' \
"$<" >> "$@"
# Combine .gitignore with .prettierignore.include to generate .prettierignore.
.prettierignore: .gitignore .prettierignore.include
echo "# Code generated by Makefile ($^). DO NOT EDIT." > "$@"
echo "" >> "$@"
for f in $^; do
echo "# $${f}:" >> "$@"
cat "$$f" >> "$@"
done
# Generate ignore files based on gitignore into the site directory. We turn all
# rules into relative paths for the `site/` directory (where applicable),
# following the pattern format defined by git:
# https://git-scm.com/docs/gitignore#_pattern_format
#
# This is done for compatibility reasons, see:
# https://github.com/prettier/prettier/issues/8048
# https://github.com/prettier/prettier/issues/8506
# https://github.com/prettier/prettier/issues/8679
site/.eslintignore site/.prettierignore: .prettierignore Makefile
rm -f "$@"
touch "$@"
# Skip generated by header, inherit `.prettierignore` header as-is.
while read -r rule; do
# Remove leading ! if present to simplify rule, added back at the end.
tmp="$${rule#!}"
ignore="$${rule%"$$tmp"}"
rule="$$tmp"
case "$$rule" in
# Comments or empty lines (include).
\#*|'') ;;
# Generic rules (include).
\*\**) ;;
# Site prefixed rules (include).
site/*) rule="$${rule#site/}";;
./site/*) rule="$${rule#./site/}";;
# Rules that are non-generic and don't start with site (rewrite).
/*) rule=.."$$rule";;
*/?*) rule=../"$$rule";;
*) ;;
esac
echo "$${ignore}$${rule}" >> "$@"
done < "$<"
test: test-clean
gotestsum -- -v -short ./...
gotestsum --format standard-quiet -- -v -short ./...
.PHONY: test
# When updating -timeout for this test, keep in sync with
# test-go-postgres (.github/workflows/coder.yaml).
# Do add coverage flags so that test caching works.
test-postgres: test-clean test-postgres-docker
DB=ci DB_FROM=$(shell go run scripts/migrate-ci/main.go) gotestsum --junitfile="gotests.xml" --packages="./..." -- \
-covermode=atomic -coverprofile="gotests.coverage" -timeout=20m \
-coverpkg=./... \
-count=1 -race -failfast
# The postgres test is prone to failure, so we limit parallelism for
# more consistent execution.
DB=ci DB_FROM=$(shell go run scripts/migrate-ci/main.go) gotestsum \
--junitfile="gotests.xml" \
--jsonfile="gotests.json" \
--packages="./..." -- \
-timeout=20m \
-failfast
.PHONY: test-postgres
test-postgres-docker:
@@ -477,12 +645,15 @@ test-postgres-docker:
--name test-postgres-docker \
--restart no \
--detach \
postgres:13 \
gcr.io/coder-dev-1/postgres:13 \
-c shared_buffers=1GB \
-c work_mem=1GB \
-c effective_cache_size=1GB \
-c max_connections=1000 \
-c fsync=off \
-c synchronous_commit=off \
-c full_page_writes=off
-c full_page_writes=off \
-c log_statement=all
while ! pg_isready -h 127.0.0.1
do
echo "$(date) - waiting for database to start"
+76 -56
View File
@@ -1,65 +1,80 @@
# Coder
<div align="center">
<a href="https://coder.com#gh-light-mode-only">
<img src="./docs/images/logo-black.png" style="width: 128px">
</a>
<a href="https://coder.com#gh-dark-mode-only">
<img src="./docs/images/logo-white.png" style="width: 128px">
</a>
[!["Join us on
Discord"](https://img.shields.io/badge/join-us%20on%20Discord-gray.svg?longCache=true&logo=discord&colorB=green)](https://coder.com/chat?utm_source=github.com/coder/coder&utm_medium=github&utm_campaign=readme.md)
<h1>
Self-Hosted Remote Development Environments
</h1>
<a href="https://coder.com#gh-light-mode-only">
<img src="./docs/images/banner-black.png" style="width: 650px">
</a>
<a href="https://coder.com#gh-dark-mode-only">
<img src="./docs/images/banner-white.png" style="width: 650px">
</a>
<br>
<br>
[Quickstart](#quickstart) | [Docs](https://coder.com/docs) | [Why Coder](https://coder.com/why) | [Enterprise](https://coder.com/docs/v2/latest/enterprise)
[![discord](https://img.shields.io/discord/747933592273027093?label=discord)](https://discord.gg/coder)
[![codecov](https://codecov.io/gh/coder/coder/branch/main/graph/badge.svg?token=TNLW3OAP6G)](https://codecov.io/gh/coder/coder)
[![Go Reference](https://pkg.go.dev/badge/github.com/coder/coder.svg)](https://pkg.go.dev/github.com/coder/coder)
[![Twitter
Follow](https://img.shields.io/twitter/follow/coderhq?label=%40coderhq&style=social)](https://twitter.com/coderhq)
[![release](https://img.shields.io/github/v/release/coder/coder)](https://github.com/coder/coder/releases/latest)
[![godoc](https://pkg.go.dev/badge/github.com/coder/coder.svg)](https://pkg.go.dev/github.com/coder/coder)
[![Go Report Card](https://goreportcard.com/badge/github.com/coder/coder)](https://goreportcard.com/report/github.com/coder/coder)
[![license](https://img.shields.io/github/license/coder/coder)](./LICENSE)
Coder creates remote development machines so your team can develop from anywhere.
</div>
[Coder](https://coder.com) enables organizations to set up development environments in the cloud. Environments are defined with Terraform, connected through a secure high-speed Wireguard® tunnel, and are automatically shut down when not in use to save on costs. Coder gives engineering teams the flexibility to use the cloud for workloads that are most beneficial to them.
- Define development environments in Terraform
- EC2 VMs, Kubernetes Pods, Docker Containers, etc.
- Automatically shutdown idle resources to save on costs
- Onboard developers in seconds instead of days
<p align="center">
<img src="./docs/images/hero-image.png">
</p>
**Manage less**
## Quickstart
- Ensure your entire team is using the same tools and resources
- Rollout critical updates to your developers with one command
- Automatically shut down expensive cloud resources
- Keep your source code and data behind your firewall
The most convenient way to try Coder is to install it on your local machine and experiment with provisioning development environments using Docker (works on Linux, macOS, and Windows).
**Code more**
```
# First, install Coder
curl -L https://coder.com/install.sh | sh
- Build and test faster
- Leveraging cloud CPUs, RAM, network speeds, etc.
- Access your environment from any place on any client (even an iPad)
- Onboard instantly then stay up to date continuously
# Start the Coder server (caches data in ~/.cache/coder)
coder server
## Getting Started
# Navigate to http://localhost:3000 to create your initial user
# Create a Docker template, and provision a workspace
```
> **Note**:
> Coder is in a beta state. [Report issues here](https://github.com/coder/coder/issues/new).
## Install
The easiest way to install Coder is to use our
[install script](https://github.com/coder/coder/blob/main/install.sh) for Linux
and macOS. For Windows, use the latest `..._installer.exe` file from GitHub
Releases.
To install, run:
```bash
curl -L https://coder.com/install.sh | sh
```
You can preview what occurs during the install process:
```bash
curl -L https://coder.com/install.sh | sh -s -- --dry-run
```
You can modify the installation process by including flags. Run the help command for reference:
```bash
curl -L https://coder.com/install.sh | sh -s -- --help
```
You can run the install script with `--dry-run` to see the commands that will be used to install without executing them. You can modify the installation process by including flags. Run the install script with `--help` for reference.
> See [install](docs/install) for additional methods.
Once installed, you can start a production deployment<sup>1</sup> with a single command:
```sh
```console
# Automatically sets up an external access URL on *.try.coder.app
coder server
@@ -67,39 +82,44 @@ coder server
coder server --postgres-url <url> --access-url <url>
```
> <sup>1</sup> The embedded database is great for trying out Coder with small deployments, but do consider using an external database for increased assurance and control.
> <sup>1</sup> For production deployments, set up an external PostgreSQL instance for reliability.
Use `coder --help` to get a complete list of flags and environment variables. Use our [quickstart guide](https://coder.com/docs/coder-oss/latest/quickstart) for a full walkthrough.
Use `coder --help` to get a list of flags and environment variables. Use our [install guides](https://coder.com/docs/v2/latest/install) for a full walkthrough.
## Documentation
Visit our docs [here](https://coder.com/docs/coder-oss).
Browse our docs [here](https://coder.com/docs/v2) or visit a specific section below:
## Comparison
Please file [an issue](https://github.com/coder/coder/issues/new) if any information is out of date. Also refer to: [What Coder is not](https://coder.com/docs/coder-oss/latest/index#what-coder-is-not).
| Tool | Type | Delivery Model | Cost | Environments |
| :---------------------------------------------------------- | :------- | :----------------- | :---------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Coder](https://github.com/coder/coder) | Platform | OSS + Self-Managed | Pay your cloud | All [Terraform](https://www.terraform.io/registry/providers) resources, all clouds, multi-architecture: Linux, Mac, Windows, containers, VMs, amd64, arm64 |
| [code-server](https://github.com/cdr/code-server) | Web IDE | OSS + Self-Managed | Pay your cloud | Linux, Mac, Windows, containers, VMs, amd64, arm64 |
| [Coder (Classic)](https://coder.com/docs) | Platform | Self-Managed | Pay your cloud + license fees | Kubernetes Linux Containers |
| [GitHub Codespaces](https://github.com/features/codespaces) | Platform | SaaS | 2x Azure Compute | Linux containers |
---
_Last updated: 5/27/22_
- [**Templates**](https://coder.com/docs/v2/latest/templates): Templates are written in Terraform and describe the infrastructure for workspaces
- [**Workspaces**](https://coder.com/docs/v2/latest/workspaces): Workspaces contain the IDEs, dependencies, and configuration information needed for software development
- [**IDEs**](https://coder.com/docs/v2/latest/ides): Connect your existing editor to a workspace
- [**Administration**](https://coder.com/docs/v2/latest/admin): Learn how to operate Coder
- [**Enterprise**](https://coder.com/docs/v2/latest/enterprise): Learn about our paid features built for large teams
## Community and Support
Join our community on [Discord](https://coder.com/chat?utm_source=github.com/coder/coder&utm_medium=github&utm_campaign=readme.md) and [Twitter](https://twitter.com/coderhq)!
Feel free to [open an issue](https://github.com/coder/coder/issues/new) if you have questions, run into bugs, or have a feature request.
[Suggest improvements and report problems](https://github.com/coder/coder/issues/new/choose)
[Join our Discord](https://discord.gg/coder) to provide feedback on in-progress features, and chat with the community using Coder!
## Contributing
If you're using Coder in your organization, please try to add your company name to the [ADOPTERS.md](./ADOPTERS.md). It really helps the project to gain momentum and credibility. It's a small contribution back to the project with a big impact.
Read the [contributing docs](https://coder.com/docs/coder-oss/latest/CONTRIBUTING).
Contributions are welcome! Read the [contributing docs](https://coder.com/docs/v2/latest/CONTRIBUTING) to get started.
Find our list of contributors [here](https://github.com/coder/coder/graphs/contributors).
## Related
We are always working on new integrations. Feel free to open an issue to request an integration. Contributions are welcome in any official or community repositories.
### Official
- [**VS Code Extension**](https://marketplace.visualstudio.com/items?itemName=coder.coder-remote): Open any Coder workspace in VS Code with a single click
- [**JetBrains Gateway Extension**](https://plugins.jetbrains.com/plugin/19620-coder): Open any Coder workspace in JetBrains Gateway with a single click
- [**Self-Hosted VS Code Extension Marketplace**](https://github.com/coder/code-marketplace): A private extension marketplace that works in restricted or airgapped networks integrating with [code-server](https://github.com/coder/code-server).
### Community
- [**Provision Coder with Terraform**](https://github.com/ElliotG/coder-oss-tf): Provision Coder on Google GKE, Azure AKS, AWS EKS, DigitalOcean DOKS, IBMCloud K8s, OVHCloud K8s, and Scaleway K8s Kapsule with Terraform
- [**Coder GitHub Action**](https://github.com/marketplace/actions/update-coder-template): A GitHub Action that updates Coder templates
- [**Various Templates**](./examples/templates/community-templates.md): Hetzner Cloud, Docker in Docker, and other templates the community has built.
+73
View File
@@ -0,0 +1,73 @@
# Coder Security
Coder welcomes feedback from security researchers and the general public
to help improve our security. If you believe you have discovered a vulnerability,
privacy issue, exposed data, or other security issues in any of our assets, we
want to hear from you. This policy outlines steps for reporting vulnerabilities
to us, what we expect, what you can expect from us.
You can see the pretty version [here](https://coder.com/security/policy)
# Why Coder's security matters
If an attacker could fully compromise a Coder installation, they could spin
up expensive workstations, steal valuable credentials, or steal proprietary
source code. We take this risk very seriously and employ routine pen testing,
vulnerability scanning, and code reviews. We also welcome the contributions
from the community that helped make this product possible.
# Where should I report security issues?
Please report security issues to security@coder.com, providing
all relevant information. The more details you provide, the easier it will be
for us to triage and fix the issue.
# Out of Scope
Our primary concern is around an abuse of the Coder application that allows
an attacker to gain access to another users workspace, or spin up unwanted
workspaces.
- DOS/DDOS attacks affecting availability --> While we do support rate limiting
of requests, we primarily leave this to the owner of the Coder installation. Our
rationale is that a DOS attack only affecting availability is not a valuable
target for attackers.
- Abuse of a compromised user credential --> If a user credential is compromised
outside of the Coder ecosystem, then we consider it beyond the scope of our application.
However, if an unprivileged user could escalate their permissions or gain access
to another workspace, that is a cause for concern.
- Vulnerabilities in third party systems --> Vulnerabilities discovered in
out-of-scope systems should be reported to the appropriate vendor or applicable authority.
# Our Commitments
When working with us, according to this policy, you can expect us to:
- Respond to your report promptly, and work with you to understand and validate your report;
- Strive to keep you informed about the progress of a vulnerability as it is processed;
- Work to remediate discovered vulnerabilities in a timely manner, within our operational constraints; and
- Extend Safe Harbor for your vulnerability research that is related to this policy.
# Our Expectations
In participating in our vulnerability disclosure program in good faith, we ask that you:
- Play by the rules, including following this policy and any other relevant agreements.
If there is any inconsistency between this policy and any other applicable terms, the
terms of this policy will prevail;
- Report any vulnerability youve discovered promptly;
- Avoid violating the privacy of others, disrupting our systems, destroying data, and/or
harming user experience;
- Use only the Official Channels to discuss vulnerability information with us;
- Provide us a reasonable amount of time (at least 90 days from the initial report) to
resolve the issue before you disclose it publicly;
- Perform testing only on in-scope systems, and respect systems and activities which
are out-of-scope;
- If a vulnerability provides unintended access to data: Limit the amount of data you
access to the minimum required for effectively demonstrating a Proof of Concept; and
cease testing and submit a report immediately if you encounter any user data during testing,
such as Personally Identifiable Information (PII), Personal Healthcare Information (PHI),
credit card data, or proprietary information;
- You should only interact with test accounts you own or with explicit permission from
- the account holder; and
- Do not engage in extortion.
+1047 -553
View File
File diff suppressed because it is too large Load Diff
+2085 -568
View File
File diff suppressed because it is too large Load Diff
+848
View File
@@ -0,0 +1,848 @@
package agentssh
import (
"bufio"
"context"
"crypto/rand"
"crypto/rsa"
"errors"
"fmt"
"io"
"net"
"os"
"os/exec"
"os/user"
"path/filepath"
"runtime"
"strings"
"sync"
"time"
"github.com/gliderlabs/ssh"
"github.com/pkg/sftp"
"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/afero"
"go.uber.org/atomic"
gossh "golang.org/x/crypto/ssh"
"golang.org/x/xerrors"
"cdr.dev/slog"
"github.com/coder/coder/agent/usershell"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/codersdk/agentsdk"
"github.com/coder/coder/pty"
)
const (
// MagicSessionErrorCode indicates that something went wrong with the session, rather than the
// command just returning a nonzero exit code, and is chosen as an arbitrary, high number
// unlikely to shadow other exit codes, which are typically 1, 2, 3, etc.
MagicSessionErrorCode = 229
// MagicSessionTypeEnvironmentVariable is used to track the purpose behind an SSH connection.
// This is stripped from any commands being executed, and is counted towards connection stats.
MagicSessionTypeEnvironmentVariable = "CODER_SSH_SESSION_TYPE"
// MagicSessionTypeVSCode is set in the SSH config by the VS Code extension to identify itself.
MagicSessionTypeVSCode = "vscode"
// MagicSessionTypeJetBrains is set in the SSH config by the JetBrains extension to identify itself.
MagicSessionTypeJetBrains = "jetbrains"
)
type Server struct {
mu sync.RWMutex // Protects following.
fs afero.Fs
listeners map[net.Listener]struct{}
conns map[net.Conn]struct{}
sessions map[ssh.Session]struct{}
closing chan struct{}
// Wait for goroutines to exit, waited without
// a lock on mu but protected by closing.
wg sync.WaitGroup
logger slog.Logger
srv *ssh.Server
x11SocketDir string
Env map[string]string
AgentToken func() string
Manifest *atomic.Pointer[agentsdk.Manifest]
ServiceBanner *atomic.Pointer[codersdk.ServiceBannerConfig]
connCountVSCode atomic.Int64
connCountJetBrains atomic.Int64
connCountSSHSession atomic.Int64
metrics *sshServerMetrics
}
func NewServer(ctx context.Context, logger slog.Logger, prometheusRegistry *prometheus.Registry, fs afero.Fs, maxTimeout time.Duration, x11SocketDir string) (*Server, error) {
// Clients' should ignore the host key when connecting.
// The agent needs to authenticate with coderd to SSH,
// so SSH authentication doesn't improve security.
randomHostKey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
return nil, err
}
randomSigner, err := gossh.NewSignerFromKey(randomHostKey)
if err != nil {
return nil, err
}
if x11SocketDir == "" {
x11SocketDir = filepath.Join(os.TempDir(), ".X11-unix")
}
forwardHandler := &ssh.ForwardedTCPHandler{}
unixForwardHandler := &forwardedUnixHandler{log: logger}
metrics := newSSHServerMetrics(prometheusRegistry)
s := &Server{
listeners: make(map[net.Listener]struct{}),
fs: fs,
conns: make(map[net.Conn]struct{}),
sessions: make(map[ssh.Session]struct{}),
logger: logger,
x11SocketDir: x11SocketDir,
metrics: metrics,
}
srv := &ssh.Server{
ChannelHandlers: map[string]ssh.ChannelHandler{
"direct-tcpip": ssh.DirectTCPIPHandler,
"direct-streamlocal@openssh.com": directStreamLocalHandler,
"session": ssh.DefaultSessionHandler,
},
ConnectionFailedCallback: func(conn net.Conn, err error) {
s.logger.Warn(ctx, "ssh connection failed",
slog.F("remote_addr", conn.RemoteAddr()),
slog.F("local_addr", conn.LocalAddr()),
slog.Error(err))
metrics.failedConnectionsTotal.Add(1)
},
ConnectionCompleteCallback: func(conn *gossh.ServerConn, err error) {
s.logger.Info(ctx, "ssh connection complete",
slog.F("remote_addr", conn.RemoteAddr()),
slog.F("local_addr", conn.LocalAddr()),
slog.Error(err))
},
Handler: s.sessionHandler,
HostSigners: []ssh.Signer{randomSigner},
LocalPortForwardingCallback: func(ctx ssh.Context, destinationHost string, destinationPort uint32) bool {
// Allow local port forwarding all!
s.logger.Debug(ctx, "local port forward",
slog.F("destination_host", destinationHost),
slog.F("destination_port", destinationPort))
return true
},
PtyCallback: func(ctx ssh.Context, pty ssh.Pty) bool {
return true
},
ReversePortForwardingCallback: func(ctx ssh.Context, bindHost string, bindPort uint32) bool {
// Allow reverse port forwarding all!
s.logger.Debug(ctx, "local port forward",
slog.F("bind_host", bindHost),
slog.F("bind_port", bindPort))
return true
},
RequestHandlers: map[string]ssh.RequestHandler{
"tcpip-forward": forwardHandler.HandleSSHRequest,
"cancel-tcpip-forward": forwardHandler.HandleSSHRequest,
"streamlocal-forward@openssh.com": unixForwardHandler.HandleSSHRequest,
"cancel-streamlocal-forward@openssh.com": unixForwardHandler.HandleSSHRequest,
},
X11Callback: s.x11Callback,
ServerConfigCallback: func(ctx ssh.Context) *gossh.ServerConfig {
return &gossh.ServerConfig{
NoClientAuth: true,
}
},
SubsystemHandlers: map[string]ssh.SubsystemHandler{
"sftp": s.sessionHandler,
},
}
// The MaxTimeout functionality has been substituted with the introduction of the KeepAlive feature.
// In cases where very short timeouts are set, the SSH server will automatically switch to the connection timeout for both read and write operations.
if maxTimeout >= 3*time.Second {
srv.ClientAliveCountMax = 3
srv.ClientAliveInterval = maxTimeout / time.Duration(srv.ClientAliveCountMax)
srv.MaxTimeout = 0
} else {
srv.MaxTimeout = maxTimeout
}
s.srv = srv
return s, nil
}
type ConnStats struct {
Sessions int64
VSCode int64
JetBrains int64
}
func (s *Server) ConnStats() ConnStats {
return ConnStats{
Sessions: s.connCountSSHSession.Load(),
VSCode: s.connCountVSCode.Load(),
JetBrains: s.connCountJetBrains.Load(),
}
}
func (s *Server) sessionHandler(session ssh.Session) {
logger := s.logger.With(slog.F("remote_addr", session.RemoteAddr()), slog.F("local_addr", session.LocalAddr()))
logger.Info(session.Context(), "handling ssh session")
ctx := session.Context()
if !s.trackSession(session, true) {
// See (*Server).Close() for why we call Close instead of Exit.
_ = session.Close()
logger.Info(ctx, "unable to accept new session, server is closing")
return
}
defer s.trackSession(session, false)
extraEnv := make([]string, 0)
x11, hasX11 := session.X11()
if hasX11 {
handled := s.x11Handler(session.Context(), x11)
if !handled {
_ = session.Exit(1)
logger.Error(ctx, "x11 handler failed")
return
}
extraEnv = append(extraEnv, fmt.Sprintf("DISPLAY=:%d.0", x11.ScreenNumber))
}
switch ss := session.Subsystem(); ss {
case "":
case "sftp":
s.sftpHandler(session)
return
default:
logger.Warn(ctx, "unsupported subsystem", slog.F("subsystem", ss))
_ = session.Exit(1)
return
}
err := s.sessionStart(session, extraEnv)
var exitError *exec.ExitError
if xerrors.As(err, &exitError) {
logger.Info(ctx, "ssh session returned", slog.Error(exitError))
_ = session.Exit(exitError.ExitCode())
return
}
if err != nil {
logger.Warn(ctx, "ssh session failed", slog.Error(err))
// This exit code is designed to be unlikely to be confused for a legit exit code
// from the process.
_ = session.Exit(MagicSessionErrorCode)
return
}
logger.Info(ctx, "normal ssh session exit")
_ = session.Exit(0)
}
func (s *Server) sessionStart(session ssh.Session, extraEnv []string) (retErr error) {
ctx := session.Context()
env := append(session.Environ(), extraEnv...)
var magicType string
for index, kv := range env {
if !strings.HasPrefix(kv, MagicSessionTypeEnvironmentVariable) {
continue
}
magicType = strings.TrimPrefix(kv, MagicSessionTypeEnvironmentVariable+"=")
env = append(env[:index], env[index+1:]...)
}
switch magicType {
case MagicSessionTypeVSCode:
s.connCountVSCode.Add(1)
defer s.connCountVSCode.Add(-1)
case MagicSessionTypeJetBrains:
s.connCountJetBrains.Add(1)
defer s.connCountJetBrains.Add(-1)
case "":
s.connCountSSHSession.Add(1)
defer s.connCountSSHSession.Add(-1)
default:
s.logger.Warn(ctx, "invalid magic ssh session type specified", slog.F("type", magicType))
}
magicTypeLabel := magicTypeMetricLabel(magicType)
sshPty, windowSize, isPty := session.Pty()
cmd, err := s.CreateCommand(ctx, session.RawCommand(), env)
if err != nil {
ptyLabel := "no"
if isPty {
ptyLabel = "yes"
}
s.metrics.sessionErrors.WithLabelValues(magicTypeLabel, ptyLabel, "create_command").Add(1)
return err
}
if ssh.AgentRequested(session) {
l, err := ssh.NewAgentListener()
if err != nil {
ptyLabel := "no"
if isPty {
ptyLabel = "yes"
}
s.metrics.sessionErrors.WithLabelValues(magicTypeLabel, ptyLabel, "listener").Add(1)
return xerrors.Errorf("new agent listener: %w", err)
}
defer l.Close()
go ssh.ForwardAgentConnections(l, session)
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", "SSH_AUTH_SOCK", l.Addr().String()))
}
if isPty {
return s.startPTYSession(session, magicTypeLabel, cmd, sshPty, windowSize)
}
return s.startNonPTYSession(session, magicTypeLabel, cmd.AsExec())
}
func (s *Server) startNonPTYSession(session ssh.Session, magicTypeLabel string, cmd *exec.Cmd) error {
s.metrics.sessionsTotal.WithLabelValues(magicTypeLabel, "no").Add(1)
cmd.Stdout = session
cmd.Stderr = session.Stderr()
// This blocks forever until stdin is received if we don't
// use StdinPipe. It's unknown what causes this.
stdinPipe, err := cmd.StdinPipe()
if err != nil {
s.metrics.sessionErrors.WithLabelValues(magicTypeLabel, "no", "stdin_pipe").Add(1)
return xerrors.Errorf("create stdin pipe: %w", err)
}
go func() {
_, err := io.Copy(stdinPipe, session)
if err != nil {
s.metrics.sessionErrors.WithLabelValues(magicTypeLabel, "no", "stdin_io_copy").Add(1)
}
_ = stdinPipe.Close()
}()
err = cmd.Start()
if err != nil {
s.metrics.sessionErrors.WithLabelValues(magicTypeLabel, "no", "start_command").Add(1)
return xerrors.Errorf("start: %w", err)
}
return cmd.Wait()
}
// ptySession is the interface to the ssh.Session that startPTYSession uses
// we use an interface here so that we can fake it in tests.
type ptySession interface {
io.ReadWriter
Context() ssh.Context
DisablePTYEmulation()
RawCommand() string
}
func (s *Server) startPTYSession(session ptySession, magicTypeLabel string, cmd *pty.Cmd, sshPty ssh.Pty, windowSize <-chan ssh.Window) (retErr error) {
s.metrics.sessionsTotal.WithLabelValues(magicTypeLabel, "yes").Add(1)
ctx := session.Context()
// Disable minimal PTY emulation set by gliderlabs/ssh (NL-to-CRNL).
// See https://github.com/coder/coder/issues/3371.
session.DisablePTYEmulation()
if isLoginShell(session.RawCommand()) {
serviceBanner := s.ServiceBanner.Load()
if serviceBanner != nil {
err := showServiceBanner(session, serviceBanner)
if err != nil {
s.logger.Error(ctx, "agent failed to show service banner", slog.Error(err))
s.metrics.sessionErrors.WithLabelValues(magicTypeLabel, "yes", "service_banner").Add(1)
}
}
}
if !isQuietLogin(session.RawCommand()) {
manifest := s.Manifest.Load()
if manifest != nil {
err := showMOTD(session, manifest.MOTDFile)
if err != nil {
s.logger.Error(ctx, "agent failed to show MOTD", slog.Error(err))
s.metrics.sessionErrors.WithLabelValues(magicTypeLabel, "yes", "motd").Add(1)
}
} else {
s.logger.Warn(ctx, "metadata lookup failed, unable to show MOTD")
}
}
cmd.Env = append(cmd.Env, fmt.Sprintf("TERM=%s", sshPty.Term))
// The pty package sets `SSH_TTY` on supported platforms.
ptty, process, err := pty.Start(cmd, pty.WithPTYOption(
pty.WithSSHRequest(sshPty),
pty.WithLogger(slog.Stdlib(ctx, s.logger, slog.LevelInfo)),
))
if err != nil {
s.metrics.sessionErrors.WithLabelValues(magicTypeLabel, "yes", "start_command").Add(1)
return xerrors.Errorf("start command: %w", err)
}
defer func() {
closeErr := ptty.Close()
if closeErr != nil {
s.logger.Warn(ctx, "failed to close tty", slog.Error(closeErr))
s.metrics.sessionErrors.WithLabelValues(magicTypeLabel, "yes", "close").Add(1)
if retErr == nil {
retErr = closeErr
}
}
}()
go func() {
for win := range windowSize {
resizeErr := ptty.Resize(uint16(win.Height), uint16(win.Width))
// If the pty is closed, then command has exited, no need to log.
if resizeErr != nil && !errors.Is(resizeErr, pty.ErrClosed) {
s.logger.Warn(ctx, "failed to resize tty", slog.Error(resizeErr))
s.metrics.sessionErrors.WithLabelValues(magicTypeLabel, "yes", "resize").Add(1)
}
}
}()
go func() {
_, err := io.Copy(ptty.InputWriter(), session)
if err != nil {
s.metrics.sessionErrors.WithLabelValues(magicTypeLabel, "yes", "input_io_copy").Add(1)
}
}()
// We need to wait for the command output to finish copying. It's safe to
// just do this copy on the main handler goroutine because one of two things
// will happen:
//
// 1. The command completes & closes the TTY, which then triggers an error
// after we've Read() all the buffered data from the PTY.
// 2. The client hangs up, which cancels the command's Context, and go will
// kill the command's process. This then has the same effect as (1).
n, err := io.Copy(session, ptty.OutputReader())
s.logger.Debug(ctx, "copy output done", slog.F("bytes", n), slog.Error(err))
if err != nil {
s.metrics.sessionErrors.WithLabelValues(magicTypeLabel, "yes", "output_io_copy").Add(1)
return xerrors.Errorf("copy error: %w", err)
}
// We've gotten all the output, but we need to wait for the process to
// complete so that we can get the exit code. This returns
// immediately if the TTY was closed as part of the command exiting.
err = process.Wait()
var exitErr *exec.ExitError
// ExitErrors just mean the command we run returned a non-zero exit code, which is normal
// and not something to be concerned about. But, if it's something else, we should log it.
if err != nil && !xerrors.As(err, &exitErr) {
s.logger.Warn(ctx, "process wait exited with error", slog.Error(err))
s.metrics.sessionErrors.WithLabelValues(magicTypeLabel, "yes", "wait").Add(1)
}
if err != nil {
return xerrors.Errorf("process wait: %w", err)
}
return nil
}
func (s *Server) sftpHandler(session ssh.Session) {
s.metrics.sftpConnectionsTotal.Add(1)
ctx := session.Context()
// Typically sftp sessions don't request a TTY, but if they do,
// we must ensure the gliderlabs/ssh CRLF emulation is disabled.
// Otherwise sftp will be broken. This can happen if a user sets
// `RequestTTY force` in their SSH config.
session.DisablePTYEmulation()
var opts []sftp.ServerOption
// Change current working directory to the users home
// directory so that SFTP connections land there.
homedir, err := userHomeDir()
if err != nil {
s.logger.Warn(ctx, "get sftp working directory failed, unable to get home dir", slog.Error(err))
} else {
opts = append(opts, sftp.WithServerWorkingDirectory(homedir))
}
server, err := sftp.NewServer(session, opts...)
if err != nil {
s.logger.Debug(ctx, "initialize sftp server", slog.Error(err))
return
}
defer server.Close()
err = server.Serve()
if errors.Is(err, io.EOF) {
// Unless we call `session.Exit(0)` here, the client won't
// receive `exit-status` because `(*sftp.Server).Close()`
// calls `Close()` on the underlying connection (session),
// which actually calls `channel.Close()` because it isn't
// wrapped. This causes sftp clients to receive a non-zero
// exit code. Typically sftp clients don't echo this exit
// code but `scp` on macOS does (when using the default
// SFTP backend).
_ = session.Exit(0)
return
}
s.logger.Warn(ctx, "sftp server closed with error", slog.Error(err))
s.metrics.sftpServerErrors.Add(1)
_ = session.Exit(1)
}
// CreateCommand processes raw command input with OpenSSH-like behavior.
// If the script provided is empty, it will default to the users shell.
// This injects environment variables specified by the user at launch too.
func (s *Server) CreateCommand(ctx context.Context, script string, env []string) (*pty.Cmd, error) {
currentUser, err := user.Current()
if err != nil {
return nil, xerrors.Errorf("get current user: %w", err)
}
username := currentUser.Username
shell, err := usershell.Get(username)
if err != nil {
return nil, xerrors.Errorf("get user shell: %w", err)
}
manifest := s.Manifest.Load()
if manifest == nil {
return nil, xerrors.Errorf("no metadata was provided")
}
// OpenSSH executes all commands with the users current shell.
// We replicate that behavior for IDE support.
caller := "-c"
if runtime.GOOS == "windows" {
caller = "/c"
}
args := []string{caller, script}
// gliderlabs/ssh returns a command slice of zero
// when a shell is requested.
if len(script) == 0 {
args = []string{}
if runtime.GOOS != "windows" {
// On Linux and macOS, we should start a login
// shell to consume juicy environment variables!
args = append(args, "-l")
}
}
cmd := pty.CommandContext(ctx, shell, args...)
cmd.Dir = manifest.Directory
// If the metadata directory doesn't exist, we run the command
// in the users home directory.
_, err = os.Stat(cmd.Dir)
if cmd.Dir == "" || err != nil {
// Default to user home if a directory is not set.
homedir, err := userHomeDir()
if err != nil {
return nil, xerrors.Errorf("get home dir: %w", err)
}
cmd.Dir = homedir
}
cmd.Env = append(os.Environ(), env...)
executablePath, err := os.Executable()
if err != nil {
return nil, xerrors.Errorf("getting os executable: %w", err)
}
// Set environment variables reliable detection of being inside a
// Coder workspace.
cmd.Env = append(cmd.Env, "CODER=true")
cmd.Env = append(cmd.Env, fmt.Sprintf("USER=%s", username))
// Git on Windows resolves with UNIX-style paths.
// If using backslashes, it's unable to find the executable.
unixExecutablePath := strings.ReplaceAll(executablePath, "\\", "/")
cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_SSH_COMMAND=%s gitssh --`, unixExecutablePath))
// Specific Coder subcommands require the agent token exposed!
cmd.Env = append(cmd.Env, fmt.Sprintf("CODER_AGENT_TOKEN=%s", s.AgentToken()))
// Set SSH connection environment variables (these are also set by OpenSSH
// and thus expected to be present by SSH clients). Since the agent does
// networking in-memory, trying to provide accurate values here would be
// nonsensical. For now, we hard code these values so that they're present.
srcAddr, srcPort := "0.0.0.0", "0"
dstAddr, dstPort := "0.0.0.0", "0"
cmd.Env = append(cmd.Env, fmt.Sprintf("SSH_CLIENT=%s %s %s", srcAddr, srcPort, dstPort))
cmd.Env = append(cmd.Env, fmt.Sprintf("SSH_CONNECTION=%s %s %s %s", srcAddr, srcPort, dstAddr, dstPort))
// This adds the ports dialog to code-server that enables
// proxying a port dynamically.
cmd.Env = append(cmd.Env, fmt.Sprintf("VSCODE_PROXY_URI=%s", manifest.VSCodePortProxyURI))
// Hide Coder message on code-server's "Getting Started" page
cmd.Env = append(cmd.Env, "CS_DISABLE_GETTING_STARTED_OVERRIDE=true")
// Load environment variables passed via the agent.
// These should override all variables we manually specify.
for envKey, value := range manifest.EnvironmentVariables {
// Expanding environment variables allows for customization
// of the $PATH, among other variables. Customers can prepend
// or append to the $PATH, so allowing expand is required!
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", envKey, os.ExpandEnv(value)))
}
// Agent-level environment variables should take over all!
// This is used for setting agent-specific variables like "CODER_AGENT_TOKEN".
for envKey, value := range s.Env {
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", envKey, value))
}
return cmd, nil
}
func (s *Server) Serve(l net.Listener) (retErr error) {
s.logger.Info(context.Background(), "started serving listener", slog.F("listen_addr", l.Addr()))
defer func() {
s.logger.Info(context.Background(), "stopped serving listener",
slog.F("listen_addr", l.Addr()), slog.Error(retErr))
}()
defer l.Close()
s.trackListener(l, true)
defer s.trackListener(l, false)
for {
conn, err := l.Accept()
if err != nil {
return err
}
go s.handleConn(l, conn)
}
}
func (s *Server) handleConn(l net.Listener, c net.Conn) {
logger := s.logger.With(
slog.F("remote_addr", c.RemoteAddr()),
slog.F("local_addr", c.LocalAddr()),
slog.F("listen_addr", l.Addr()))
defer c.Close()
if !s.trackConn(l, c, true) {
// Server is closed or we no longer want
// connections from this listener.
logger.Info(context.Background(), "received connection after server closed")
return
}
defer s.trackConn(l, c, false)
logger.Info(context.Background(), "started serving connection")
// note: srv.ConnectionCompleteCallback logs completion of the connection
s.srv.HandleConn(c)
}
// trackListener registers the listener with the server. If the server is
// closing, the function will block until the server is closed.
//
//nolint:revive
func (s *Server) trackListener(l net.Listener, add bool) {
s.mu.Lock()
defer s.mu.Unlock()
if add {
for s.closing != nil {
closing := s.closing
// Wait until close is complete before
// serving a new listener.
s.mu.Unlock()
<-closing
s.mu.Lock()
}
s.wg.Add(1)
s.listeners[l] = struct{}{}
return
}
s.wg.Done()
delete(s.listeners, l)
}
// trackConn registers the connection with the server. If the server is
// closed or the listener is closed, the connection is not registered
// and should be closed.
//
//nolint:revive
func (s *Server) trackConn(l net.Listener, c net.Conn, add bool) (ok bool) {
s.mu.Lock()
defer s.mu.Unlock()
if add {
found := false
for ll := range s.listeners {
if l == ll {
found = true
break
}
}
if s.closing != nil || !found {
// Server or listener closed.
return false
}
s.wg.Add(1)
s.conns[c] = struct{}{}
return true
}
s.wg.Done()
delete(s.conns, c)
return true
}
// trackSession registers the session with the server. If the server is
// closing, the session is not registered and should be closed.
//
//nolint:revive
func (s *Server) trackSession(ss ssh.Session, add bool) (ok bool) {
s.mu.Lock()
defer s.mu.Unlock()
if add {
if s.closing != nil {
// Server closed.
return false
}
s.wg.Add(1)
s.sessions[ss] = struct{}{}
return true
}
s.wg.Done()
delete(s.sessions, ss)
return true
}
// Close the server and all active connections. Server can be re-used
// after Close is done.
func (s *Server) Close() error {
s.mu.Lock()
// Guard against multiple calls to Close and
// accepting new connections during close.
if s.closing != nil {
s.mu.Unlock()
return xerrors.New("server is closing")
}
s.closing = make(chan struct{})
// Close all active sessions to gracefully
// terminate client connections.
for ss := range s.sessions {
// We call Close on the underlying channel here because we don't
// want to send an exit status to the client (via Exit()).
// Typically OpenSSH clients will return 255 as the exit status.
_ = ss.Close()
}
// Close all active listeners and connections.
for l := range s.listeners {
_ = l.Close()
}
for c := range s.conns {
_ = c.Close()
}
// Close the underlying SSH server.
err := s.srv.Close()
s.mu.Unlock()
s.wg.Wait() // Wait for all goroutines to exit.
s.mu.Lock()
close(s.closing)
s.closing = nil
s.mu.Unlock()
return err
}
// Shutdown gracefully closes all active SSH connections and stops
// accepting new connections.
//
// Shutdown is not implemented.
func (*Server) Shutdown(_ context.Context) error {
// TODO(mafredri): Implement shutdown, SIGHUP running commands, etc.
return nil
}
func isLoginShell(rawCommand string) bool {
return len(rawCommand) == 0
}
// isQuietLogin checks if the SSH server should perform a quiet login or not.
//
// https://github.com/openssh/openssh-portable/blob/25bd659cc72268f2858c5415740c442ee950049f/session.c#L816
func isQuietLogin(rawCommand string) bool {
// We are always quiet unless this is a login shell.
if !isLoginShell(rawCommand) {
return true
}
// Best effort, if we can't get the home directory,
// we can't lookup .hushlogin.
homedir, err := userHomeDir()
if err != nil {
return false
}
_, err = os.Stat(filepath.Join(homedir, ".hushlogin"))
return err == nil
}
// showServiceBanner will write the service banner if enabled and not blank
// along with a blank line for spacing.
func showServiceBanner(session io.Writer, banner *codersdk.ServiceBannerConfig) error {
if banner.Enabled && banner.Message != "" {
// The banner supports Markdown so we might want to parse it but Markdown is
// still fairly readable in its raw form.
message := strings.TrimSpace(banner.Message) + "\n\n"
return writeWithCarriageReturn(strings.NewReader(message), session)
}
return nil
}
// showMOTD will output the message of the day from
// the given filename to dest, if the file exists.
//
// https://github.com/openssh/openssh-portable/blob/25bd659cc72268f2858c5415740c442ee950049f/session.c#L784
func showMOTD(dest io.Writer, filename string) error {
if filename == "" {
return nil
}
f, err := os.Open(filename)
if err != nil {
if xerrors.Is(err, os.ErrNotExist) {
// This is not an error, there simply isn't a MOTD to show.
return nil
}
return xerrors.Errorf("open MOTD: %w", err)
}
defer f.Close()
return writeWithCarriageReturn(f, dest)
}
// writeWithCarriageReturn writes each line with a carriage return to ensure
// that each line starts at the beginning of the terminal.
func writeWithCarriageReturn(src io.Reader, dest io.Writer) error {
s := bufio.NewScanner(src)
for s.Scan() {
_, err := fmt.Fprint(dest, s.Text()+"\r\n")
if err != nil {
return xerrors.Errorf("write line: %w", err)
}
}
if err := s.Err(); err != nil {
return xerrors.Errorf("read line: %w", err)
}
return nil
}
// userHomeDir returns the home directory of the current user, giving
// priority to the $HOME environment variable.
func userHomeDir() (string, error) {
// First we check the environment.
homedir, err := os.UserHomeDir()
if err == nil {
return homedir, nil
}
// As a fallback, we try the user information.
u, err := user.Current()
if err != nil {
return "", xerrors.Errorf("current user: %w", err)
}
return u.HomeDir, nil
}
+197
View File
@@ -0,0 +1,197 @@
//go:build !windows
package agentssh
import (
"bufio"
"context"
"io"
"net"
"testing"
gliderssh "github.com/gliderlabs/ssh"
"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/coder/coder/pty"
"github.com/coder/coder/testutil"
"cdr.dev/slog/sloggers/slogtest"
)
const longScript = `
echo "started"
sleep 30
echo "done"
`
// Test_sessionStart_orphan tests running a command that takes a long time to
// exit normally, and terminate the SSH session context early to verify that we
// return quickly and don't leave the command running as an "orphan" with no
// active SSH session.
func Test_sessionStart_orphan(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
defer cancel()
logger := slogtest.Make(t, nil)
s, err := NewServer(ctx, logger, prometheus.NewRegistry(), afero.NewMemMapFs(), 0, "")
require.NoError(t, err)
defer s.Close()
// Here we're going to call the handler directly with a faked SSH session
// that just uses io.Pipes instead of a network socket. There is a large
// variation in the time between closing the socket from the client side and
// the SSH server canceling the session Context, which would lead to a flaky
// test if we did it that way. So instead, we directly cancel the context
// in this test.
sessionCtx, sessionCancel := context.WithCancel(ctx)
toClient, fromClient, sess := newTestSession(sessionCtx)
ptyInfo := gliderssh.Pty{}
windowSize := make(chan gliderssh.Window)
close(windowSize)
// the command gets the session context so that Go will terminate it when
// the session expires.
cmd := pty.CommandContext(sessionCtx, "sh", "-c", longScript)
done := make(chan struct{})
go func() {
defer close(done)
// we don't really care what the error is here. In the larger scenario,
// the client has disconnected, so we can't return any error information
// to them.
_ = s.startPTYSession(sess, "ssh", cmd, ptyInfo, windowSize)
}()
readDone := make(chan struct{})
go func() {
defer close(readDone)
s := bufio.NewScanner(toClient)
assert.True(t, s.Scan())
txt := s.Text()
assert.Equal(t, "started", txt, "output corrupted")
}()
waitForChan(ctx, t, readDone, "read timeout")
// process is started, and should be sleeping for ~30 seconds
sessionCancel()
// now, we wait for the handler to complete. If it does so before the
// main test timeout, we consider this a pass. If not, it indicates
// that the server isn't properly shutting down sessions when they are
// disconnected client side, which could lead to processes hanging around
// indefinitely.
waitForChan(ctx, t, done, "handler timeout")
err = fromClient.Close()
require.NoError(t, err)
}
func waitForChan(ctx context.Context, t *testing.T, c <-chan struct{}, msg string) {
t.Helper()
select {
case <-c:
// OK!
case <-ctx.Done():
t.Fatal(msg)
}
}
type testSession struct {
ctx testSSHContext
// c2p is the client -> pty buffer
toPty *io.PipeReader
// p2c is the pty -> client buffer
fromPty *io.PipeWriter
}
type testSSHContext struct {
context.Context
}
func newTestSession(ctx context.Context) (toClient *io.PipeReader, fromClient *io.PipeWriter, s ptySession) {
toClient, fromPty := io.Pipe()
toPty, fromClient := io.Pipe()
return toClient, fromClient, &testSession{
ctx: testSSHContext{ctx},
toPty: toPty,
fromPty: fromPty,
}
}
func (s *testSession) Context() gliderssh.Context {
return s.ctx
}
func (*testSession) DisablePTYEmulation() {}
// RawCommand returns "quiet logon" so that the PTY handler doesn't attempt to
// write the message of the day, which will interfere with our tests. It writes
// the message of the day if it's a shell login (zero length RawCommand()).
func (*testSession) RawCommand() string { return "quiet logon" }
func (s *testSession) Read(p []byte) (n int, err error) {
return s.toPty.Read(p)
}
func (s *testSession) Write(p []byte) (n int, err error) {
return s.fromPty.Write(p)
}
func (testSSHContext) Lock() {
panic("not implemented")
}
func (testSSHContext) Unlock() {
panic("not implemented")
}
// User returns the username used when establishing the SSH connection.
func (testSSHContext) User() string {
panic("not implemented")
}
// SessionID returns the session hash.
func (testSSHContext) SessionID() string {
panic("not implemented")
}
// ClientVersion returns the version reported by the client.
func (testSSHContext) ClientVersion() string {
panic("not implemented")
}
// ServerVersion returns the version reported by the server.
func (testSSHContext) ServerVersion() string {
panic("not implemented")
}
// RemoteAddr returns the remote address for this connection.
func (testSSHContext) RemoteAddr() net.Addr {
panic("not implemented")
}
// LocalAddr returns the local address for this connection.
func (testSSHContext) LocalAddr() net.Addr {
panic("not implemented")
}
// Permissions returns the Permissions object used for this connection.
func (testSSHContext) Permissions() *gliderssh.Permissions {
panic("not implemented")
}
// SetValue allows you to easily write new values into the underlying context.
func (testSSHContext) SetValue(_, _ interface{}) {
panic("not implemented")
}
func (testSSHContext) KeepAlive() *gliderssh.SessionKeepAlive {
panic("not implemented")
}
+144
View File
@@ -0,0 +1,144 @@
// Package agentssh_test provides tests for basic functinoality of the agentssh
// package, more test coverage can be found in the `agent` and `cli` package(s).
package agentssh_test
import (
"bytes"
"context"
"net"
"strings"
"sync"
"testing"
"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/atomic"
"go.uber.org/goleak"
"golang.org/x/crypto/ssh"
"cdr.dev/slog/sloggers/slogtest"
"github.com/coder/coder/agent/agentssh"
"github.com/coder/coder/codersdk/agentsdk"
"github.com/coder/coder/pty/ptytest"
)
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
func TestNewServer_ServeClient(t *testing.T) {
t.Parallel()
ctx := context.Background()
logger := slogtest.Make(t, nil)
s, err := agentssh.NewServer(ctx, logger, prometheus.NewRegistry(), afero.NewMemMapFs(), 0, "")
require.NoError(t, err)
defer s.Close()
// The assumption is that these are set before serving SSH connections.
s.AgentToken = func() string { return "" }
s.Manifest = atomic.NewPointer(&agentsdk.Manifest{})
ln, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)
done := make(chan struct{})
go func() {
defer close(done)
err := s.Serve(ln)
assert.Error(t, err) // Server is closed.
}()
c := sshClient(t, ln.Addr().String())
var b bytes.Buffer
sess, err := c.NewSession()
sess.Stdout = &b
require.NoError(t, err)
err = sess.Start("echo hello")
require.NoError(t, err)
err = sess.Wait()
require.NoError(t, err)
require.Equal(t, "hello", strings.TrimSpace(b.String()))
err = s.Close()
require.NoError(t, err)
<-done
}
func TestNewServer_CloseActiveConnections(t *testing.T) {
t.Parallel()
ctx := context.Background()
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
s, err := agentssh.NewServer(ctx, logger, prometheus.NewRegistry(), afero.NewMemMapFs(), 0, "")
require.NoError(t, err)
defer s.Close()
// The assumption is that these are set before serving SSH connections.
s.AgentToken = func() string { return "" }
s.Manifest = atomic.NewPointer(&agentsdk.Manifest{})
ln, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
err := s.Serve(ln)
assert.Error(t, err) // Server is closed.
}()
pty := ptytest.New(t)
doClose := make(chan struct{})
go func() {
defer wg.Done()
c := sshClient(t, ln.Addr().String())
sess, err := c.NewSession()
sess.Stdin = pty.Input()
sess.Stdout = pty.Output()
sess.Stderr = pty.Output()
assert.NoError(t, err)
err = sess.Start("")
assert.NoError(t, err)
close(doClose)
err = sess.Wait()
assert.Error(t, err)
}()
<-doClose
err = s.Close()
require.NoError(t, err)
wg.Wait()
}
func sshClient(t *testing.T, addr string) *ssh.Client {
conn, err := net.Dial("tcp", addr)
require.NoError(t, err)
t.Cleanup(func() {
_ = conn.Close()
})
sshConn, channels, requests, err := ssh.NewClientConn(conn, "localhost:22", &ssh.ClientConfig{
HostKeyCallback: ssh.InsecureIgnoreHostKey(), //nolint:gosec // This is a test.
})
require.NoError(t, err)
t.Cleanup(func() {
_ = sshConn.Close()
})
c := ssh.NewClient(sshConn, channels, requests)
t.Cleanup(func() {
_ = c.Close()
})
return c
}
+47
View File
@@ -0,0 +1,47 @@
package agentssh
import (
"context"
"io"
"sync"
)
// Bicopy copies all of the data between the two connections and will close them
// after one or both of them are done writing. If the context is canceled, both
// of the connections will be closed.
func Bicopy(ctx context.Context, c1, c2 io.ReadWriteCloser) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
defer func() {
_ = c1.Close()
_ = c2.Close()
}()
var wg sync.WaitGroup
copyFunc := func(dst io.WriteCloser, src io.Reader) {
defer func() {
wg.Done()
// If one side of the copy fails, ensure the other one exits as
// well.
cancel()
}()
_, _ = io.Copy(dst, src)
}
wg.Add(2)
go copyFunc(c1, c2)
go copyFunc(c2, c1)
// Convert waitgroup to a channel so we can also wait on the context.
done := make(chan struct{})
go func() {
defer close(done)
wg.Wait()
}()
select {
case <-ctx.Done():
case <-done:
}
}
+203
View File
@@ -0,0 +1,203 @@
package agentssh
import (
"context"
"fmt"
"net"
"os"
"path/filepath"
"sync"
"github.com/gliderlabs/ssh"
gossh "golang.org/x/crypto/ssh"
"golang.org/x/xerrors"
"cdr.dev/slog"
)
// streamLocalForwardPayload describes the extra data sent in a
// streamlocal-forward@openssh.com containing the socket path to bind to.
type streamLocalForwardPayload struct {
SocketPath string
}
// forwardedStreamLocalPayload describes the data sent as the payload in the new
// channel request when a Unix connection is accepted by the listener.
type forwardedStreamLocalPayload struct {
SocketPath string
Reserved uint32
}
// forwardedUnixHandler is a clone of ssh.ForwardedTCPHandler that does
// streamlocal forwarding (aka. unix forwarding) instead of TCP forwarding.
type forwardedUnixHandler struct {
sync.Mutex
log slog.Logger
forwards map[string]net.Listener
}
func (h *forwardedUnixHandler) HandleSSHRequest(ctx ssh.Context, _ *ssh.Server, req *gossh.Request) (bool, []byte) {
h.Lock()
if h.forwards == nil {
h.forwards = make(map[string]net.Listener)
}
h.Unlock()
conn, ok := ctx.Value(ssh.ContextKeyConn).(*gossh.ServerConn)
if !ok {
h.log.Warn(ctx, "SSH unix forward request from client with no gossh connection")
return false, nil
}
switch req.Type {
case "streamlocal-forward@openssh.com":
var reqPayload streamLocalForwardPayload
err := gossh.Unmarshal(req.Payload, &reqPayload)
if err != nil {
h.log.Warn(ctx, "parse streamlocal-forward@openssh.com request payload from client", slog.Error(err))
return false, nil
}
addr := reqPayload.SocketPath
h.Lock()
_, ok := h.forwards[addr]
h.Unlock()
if ok {
h.log.Warn(ctx, "SSH unix forward request for socket path that is already being forwarded (maybe to another client?)",
slog.F("socket_path", addr),
)
return false, nil
}
// Create socket parent dir if not exists.
parentDir := filepath.Dir(addr)
err = os.MkdirAll(parentDir, 0o700)
if err != nil {
h.log.Warn(ctx, "create parent dir for SSH unix forward request",
slog.F("parent_dir", parentDir),
slog.F("socket_path", addr),
slog.Error(err),
)
return false, nil
}
ln, err := net.Listen("unix", addr)
if err != nil {
h.log.Warn(ctx, "listen on Unix socket for SSH unix forward request",
slog.F("socket_path", addr),
slog.Error(err),
)
return false, nil
}
// The listener needs to successfully start before it can be added to
// the map, so we don't have to worry about checking for an existing
// listener.
//
// This is also what the upstream TCP version of this code does.
h.Lock()
h.forwards[addr] = ln
h.Unlock()
ctx, cancel := context.WithCancel(ctx)
go func() {
<-ctx.Done()
_ = ln.Close()
}()
go func() {
defer cancel()
for {
c, err := ln.Accept()
if err != nil {
if !xerrors.Is(err, net.ErrClosed) {
h.log.Warn(ctx, "accept on local Unix socket for SSH unix forward request",
slog.F("socket_path", addr),
slog.Error(err),
)
}
// closed below
break
}
payload := gossh.Marshal(&forwardedStreamLocalPayload{
SocketPath: addr,
})
go func() {
ch, reqs, err := conn.OpenChannel("forwarded-streamlocal@openssh.com", payload)
if err != nil {
h.log.Warn(ctx, "open SSH channel to forward Unix connection to client",
slog.F("socket_path", addr),
slog.Error(err),
)
_ = c.Close()
return
}
go gossh.DiscardRequests(reqs)
Bicopy(ctx, ch, c)
}()
}
h.Lock()
ln2, ok := h.forwards[addr]
if ok && ln2 == ln {
delete(h.forwards, addr)
}
h.Unlock()
_ = ln.Close()
}()
return true, nil
case "cancel-streamlocal-forward@openssh.com":
var reqPayload streamLocalForwardPayload
err := gossh.Unmarshal(req.Payload, &reqPayload)
if err != nil {
h.log.Warn(ctx, "parse cancel-streamlocal-forward@openssh.com request payload from client", slog.Error(err))
return false, nil
}
h.Lock()
ln, ok := h.forwards[reqPayload.SocketPath]
h.Unlock()
if ok {
_ = ln.Close()
}
return true, nil
default:
return false, nil
}
}
// directStreamLocalPayload describes the extra data sent in a
// direct-streamlocal@openssh.com channel request containing the socket path.
type directStreamLocalPayload struct {
SocketPath string
Reserved1 string
Reserved2 uint32
}
func directStreamLocalHandler(_ *ssh.Server, _ *gossh.ServerConn, newChan gossh.NewChannel, ctx ssh.Context) {
var reqPayload directStreamLocalPayload
err := gossh.Unmarshal(newChan.ExtraData(), &reqPayload)
if err != nil {
_ = newChan.Reject(gossh.ConnectionFailed, "could not parse direct-streamlocal@openssh.com channel payload")
return
}
var dialer net.Dialer
dconn, err := dialer.DialContext(ctx, "unix", reqPayload.SocketPath)
if err != nil {
_ = newChan.Reject(gossh.ConnectionFailed, fmt.Sprintf("dial unix socket %q: %+v", reqPayload.SocketPath, err.Error()))
return
}
ch, reqs, err := newChan.Accept()
if err != nil {
_ = dconn.Close()
return
}
go gossh.DiscardRequests(reqs)
Bicopy(ctx, ch, dconn)
}
+82
View File
@@ -0,0 +1,82 @@
package agentssh
import (
"github.com/prometheus/client_golang/prometheus"
)
type sshServerMetrics struct {
failedConnectionsTotal prometheus.Counter
sftpConnectionsTotal prometheus.Counter
sftpServerErrors prometheus.Counter
x11HandlerErrors *prometheus.CounterVec
sessionsTotal *prometheus.CounterVec
sessionErrors *prometheus.CounterVec
}
func newSSHServerMetrics(registerer prometheus.Registerer) *sshServerMetrics {
failedConnectionsTotal := prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "agent", Subsystem: "ssh_server", Name: "failed_connections_total",
})
registerer.MustRegister(failedConnectionsTotal)
sftpConnectionsTotal := prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "agent", Subsystem: "ssh_server", Name: "sftp_connections_total",
})
registerer.MustRegister(sftpConnectionsTotal)
sftpServerErrors := prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "agent", Subsystem: "ssh_server", Name: "sftp_server_errors_total",
})
registerer.MustRegister(sftpServerErrors)
x11HandlerErrors := prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "agent",
Subsystem: "x11_handler",
Name: "errors_total",
},
[]string{"error_type"},
)
registerer.MustRegister(x11HandlerErrors)
sessionsTotal := prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "agent",
Subsystem: "sessions",
Name: "total",
},
[]string{"magic_type", "pty"},
)
registerer.MustRegister(sessionsTotal)
sessionErrors := prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "agent",
Subsystem: "sessions",
Name: "errors_total",
},
[]string{"magic_type", "pty", "error_type"},
)
registerer.MustRegister(sessionErrors)
return &sshServerMetrics{
failedConnectionsTotal: failedConnectionsTotal,
sftpConnectionsTotal: sftpConnectionsTotal,
sftpServerErrors: sftpServerErrors,
x11HandlerErrors: x11HandlerErrors,
sessionsTotal: sessionsTotal,
sessionErrors: sessionErrors,
}
}
func magicTypeMetricLabel(magicType string) string {
switch magicType {
case MagicSessionTypeVSCode:
case MagicSessionTypeJetBrains:
case "":
magicType = "ssh"
default:
magicType = "unknown"
}
return magicType
}
+200
View File
@@ -0,0 +1,200 @@
package agentssh
import (
"context"
"encoding/binary"
"encoding/hex"
"errors"
"fmt"
"net"
"os"
"path/filepath"
"strconv"
"time"
"github.com/gliderlabs/ssh"
"github.com/gofrs/flock"
"github.com/spf13/afero"
gossh "golang.org/x/crypto/ssh"
"golang.org/x/xerrors"
"cdr.dev/slog"
)
// x11Callback is called when the client requests X11 forwarding.
// It adds an Xauthority entry to the Xauthority file.
func (s *Server) x11Callback(ctx ssh.Context, x11 ssh.X11) bool {
hostname, err := os.Hostname()
if err != nil {
s.logger.Warn(ctx, "failed to get hostname", slog.Error(err))
s.metrics.x11HandlerErrors.WithLabelValues("hostname").Add(1)
return false
}
err = s.fs.MkdirAll(s.x11SocketDir, 0o700)
if err != nil {
s.logger.Warn(ctx, "failed to make the x11 socket dir", slog.F("dir", s.x11SocketDir), slog.Error(err))
s.metrics.x11HandlerErrors.WithLabelValues("socker_dir").Add(1)
return false
}
err = addXauthEntry(ctx, s.fs, hostname, strconv.Itoa(int(x11.ScreenNumber)), x11.AuthProtocol, x11.AuthCookie)
if err != nil {
s.logger.Warn(ctx, "failed to add Xauthority entry", slog.Error(err))
s.metrics.x11HandlerErrors.WithLabelValues("xauthority").Add(1)
return false
}
return true
}
// x11Handler is called when a session has requested X11 forwarding.
// It listens for X11 connections and forwards them to the client.
func (s *Server) x11Handler(ctx ssh.Context, x11 ssh.X11) bool {
serverConn, valid := ctx.Value(ssh.ContextKeyConn).(*gossh.ServerConn)
if !valid {
s.logger.Warn(ctx, "failed to get server connection")
return false
}
// We want to overwrite the socket so that subsequent connections will succeed.
socketPath := filepath.Join(s.x11SocketDir, fmt.Sprintf("X%d", x11.ScreenNumber))
err := os.Remove(socketPath)
if err != nil && !errors.Is(err, os.ErrNotExist) {
s.logger.Warn(ctx, "failed to remove existing X11 socket", slog.Error(err))
return false
}
listener, err := net.Listen("unix", socketPath)
if err != nil {
s.logger.Warn(ctx, "failed to listen for X11", slog.Error(err))
return false
}
s.trackListener(listener, true)
go func() {
defer listener.Close()
defer s.trackListener(listener, false)
handledFirstConnection := false
for {
conn, err := listener.Accept()
if err != nil {
if errors.Is(err, net.ErrClosed) {
return
}
s.logger.Warn(ctx, "failed to accept X11 connection", slog.Error(err))
return
}
if x11.SingleConnection && handledFirstConnection {
s.logger.Warn(ctx, "X11 connection rejected because single connection is enabled")
_ = conn.Close()
continue
}
handledFirstConnection = true
unixConn, ok := conn.(*net.UnixConn)
if !ok {
s.logger.Warn(ctx, fmt.Sprintf("failed to cast connection to UnixConn. got: %T", conn))
return
}
unixAddr, ok := unixConn.LocalAddr().(*net.UnixAddr)
if !ok {
s.logger.Warn(ctx, fmt.Sprintf("failed to cast local address to UnixAddr. got: %T", unixConn.LocalAddr()))
return
}
channel, reqs, err := serverConn.OpenChannel("x11", gossh.Marshal(struct {
OriginatorAddress string
OriginatorPort uint32
}{
OriginatorAddress: unixAddr.Name,
OriginatorPort: 0,
}))
if err != nil {
s.logger.Warn(ctx, "failed to open X11 channel", slog.Error(err))
return
}
go gossh.DiscardRequests(reqs)
go Bicopy(ctx, conn, channel)
}
}()
return true
}
// addXauthEntry adds an Xauthority entry to the Xauthority file.
// The Xauthority file is located at ~/.Xauthority.
func addXauthEntry(ctx context.Context, fs afero.Fs, host string, display string, authProtocol string, authCookie string) error {
// Get the Xauthority file path
homeDir, err := os.UserHomeDir()
if err != nil {
return xerrors.Errorf("failed to get user home directory: %w", err)
}
xauthPath := filepath.Join(homeDir, ".Xauthority")
lock := flock.New(xauthPath)
defer lock.Close()
ok, err := lock.TryLockContext(ctx, 100*time.Millisecond)
if !ok {
return xerrors.Errorf("failed to lock Xauthority file: %w", err)
}
if err != nil {
return xerrors.Errorf("failed to lock Xauthority file: %w", err)
}
// Open or create the Xauthority file
file, err := fs.OpenFile(xauthPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o600)
if err != nil {
return xerrors.Errorf("failed to open Xauthority file: %w", err)
}
defer file.Close()
// Convert the authCookie from hex string to byte slice
authCookieBytes, err := hex.DecodeString(authCookie)
if err != nil {
return xerrors.Errorf("failed to decode auth cookie: %w", err)
}
// Write Xauthority entry
family := uint16(0x0100) // FamilyLocal
err = binary.Write(file, binary.BigEndian, family)
if err != nil {
return xerrors.Errorf("failed to write family: %w", err)
}
err = binary.Write(file, binary.BigEndian, uint16(len(host)))
if err != nil {
return xerrors.Errorf("failed to write host length: %w", err)
}
_, err = file.WriteString(host)
if err != nil {
return xerrors.Errorf("failed to write host: %w", err)
}
err = binary.Write(file, binary.BigEndian, uint16(len(display)))
if err != nil {
return xerrors.Errorf("failed to write display length: %w", err)
}
_, err = file.WriteString(display)
if err != nil {
return xerrors.Errorf("failed to write display: %w", err)
}
err = binary.Write(file, binary.BigEndian, uint16(len(authProtocol)))
if err != nil {
return xerrors.Errorf("failed to write auth protocol length: %w", err)
}
_, err = file.WriteString(authProtocol)
if err != nil {
return xerrors.Errorf("failed to write auth protocol: %w", err)
}
err = binary.Write(file, binary.BigEndian, uint16(len(authCookieBytes)))
if err != nil {
return xerrors.Errorf("failed to write auth cookie length: %w", err)
}
_, err = file.Write(authCookieBytes)
if err != nil {
return xerrors.Errorf("failed to write auth cookie: %w", err)
}
return nil
}
+100
View File
@@ -0,0 +1,100 @@
package agentssh_test
import (
"context"
"encoding/hex"
"net"
"os"
"path/filepath"
"runtime"
"testing"
"github.com/gliderlabs/ssh"
"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/atomic"
gossh "golang.org/x/crypto/ssh"
"cdr.dev/slog"
"cdr.dev/slog/sloggers/slogtest"
"github.com/coder/coder/agent/agentssh"
"github.com/coder/coder/codersdk/agentsdk"
"github.com/coder/coder/testutil"
)
func TestServer_X11(t *testing.T) {
t.Parallel()
if runtime.GOOS != "linux" {
t.Skip("X11 forwarding is only supported on Linux")
}
ctx := context.Background()
logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
fs := afero.NewOsFs()
dir := t.TempDir()
s, err := agentssh.NewServer(ctx, logger, prometheus.NewRegistry(), fs, 0, dir)
require.NoError(t, err)
defer s.Close()
// The assumption is that these are set before serving SSH connections.
s.AgentToken = func() string { return "" }
s.Manifest = atomic.NewPointer(&agentsdk.Manifest{})
ln, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)
done := make(chan struct{})
go func() {
defer close(done)
err := s.Serve(ln)
assert.Error(t, err) // Server is closed.
}()
c := sshClient(t, ln.Addr().String())
sess, err := c.NewSession()
require.NoError(t, err)
reply, err := sess.SendRequest("x11-req", true, gossh.Marshal(ssh.X11{
AuthProtocol: "MIT-MAGIC-COOKIE-1",
AuthCookie: hex.EncodeToString([]byte("cookie")),
ScreenNumber: 0,
}))
require.NoError(t, err)
assert.True(t, reply)
err = sess.Shell()
require.NoError(t, err)
x11Chans := c.HandleChannelOpen("x11")
payload := "hello world"
require.Eventually(t, func() bool {
conn, err := net.Dial("unix", filepath.Join(dir, "X0"))
if err == nil {
_, err = conn.Write([]byte(payload))
assert.NoError(t, err)
_ = conn.Close()
}
return err == nil
}, testutil.WaitShort, testutil.IntervalFast)
x11 := <-x11Chans
ch, reqs, err := x11.Accept()
require.NoError(t, err)
go gossh.DiscardRequests(reqs)
got := make([]byte, len(payload))
_, err = ch.Read(got)
require.NoError(t, err)
assert.Equal(t, payload, string(got))
_ = ch.Close()
_ = s.Close()
<-done
// Ensure the Xauthority file was written!
home, err := os.UserHomeDir()
require.NoError(t, err)
_, err = fs.Stat(filepath.Join(home, ".Xauthority"))
require.NoError(t, err)
}
+14 -6
View File
@@ -11,7 +11,7 @@ import (
"github.com/coder/coder/codersdk"
)
func (*agent) statisticsHandler() http.Handler {
func (a *agent) apiHandler() http.Handler {
r := chi.NewRouter()
r.Get("/", func(rw http.ResponseWriter, r *http.Request) {
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.Response{
@@ -19,16 +19,24 @@ func (*agent) statisticsHandler() http.Handler {
})
})
lp := &listeningPortsHandler{}
// Make a copy to ensure the map is not modified after the handler is
// created.
cpy := make(map[int]string)
for k, b := range a.ignorePorts {
cpy[k] = b
}
lp := &listeningPortsHandler{ignorePorts: cpy}
r.Get("/api/v0/listening-ports", lp.handler)
return r
}
type listeningPortsHandler struct {
mut sync.Mutex
ports []codersdk.ListeningPort
mtime time.Time
mut sync.Mutex
ports []codersdk.WorkspaceAgentListeningPort
mtime time.Time
ignorePorts map[int]string
}
// handler returns a list of listening ports. This is tested by coderd's
@@ -43,7 +51,7 @@ func (lp *listeningPortsHandler) handler(rw http.ResponseWriter, r *http.Request
return
}
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.ListeningPortsResponse{
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.WorkspaceAgentListeningPortsResponse{
Ports: ports,
})
}
+19 -16
View File
@@ -6,10 +6,12 @@ import (
"sync"
"time"
"github.com/google/uuid"
"golang.org/x/xerrors"
"cdr.dev/slog"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/codersdk/agentsdk"
"github.com/coder/retry"
)
@@ -17,7 +19,7 @@ import (
type WorkspaceAgentApps func(context.Context) ([]codersdk.WorkspaceApp, error)
// PostWorkspaceAgentAppHealth updates the workspace app health.
type PostWorkspaceAgentAppHealth func(context.Context, codersdk.PostWorkspaceAppHealthsRequest) error
type PostWorkspaceAgentAppHealth func(context.Context, agentsdk.PostAppHealthsRequest) error
// WorkspaceAppHealthReporter is a function that checks and reports the health of the workspace apps until the passed context is canceled.
type WorkspaceAppHealthReporter func(ctx context.Context)
@@ -31,12 +33,13 @@ func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.Workspace
}
hasHealthchecksEnabled := false
health := make(map[string]codersdk.WorkspaceAppHealth, 0)
health := make(map[uuid.UUID]codersdk.WorkspaceAppHealth, 0)
for _, app := range apps {
health[app.DisplayName] = app.Health
if !hasHealthchecksEnabled && app.Health != codersdk.WorkspaceAppHealthDisabled {
hasHealthchecksEnabled = true
if app.Health == codersdk.WorkspaceAppHealthDisabled {
continue
}
health[app.ID] = app.Health
hasHealthchecksEnabled = true
}
// no need to run this loop if no health checks are configured.
@@ -46,7 +49,7 @@ func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.Workspace
// run a ticker for each app health check.
var mu sync.RWMutex
failures := make(map[string]int, 0)
failures := make(map[uuid.UUID]int, 0)
for _, nextApp := range apps {
if !shouldStartTicker(nextApp) {
continue
@@ -76,7 +79,7 @@ func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.Workspace
return err
}
// successful healthcheck is a non-5XX status code
res.Body.Close()
_ = res.Body.Close()
if res.StatusCode >= http.StatusInternalServerError {
return xerrors.Errorf("error status code: %d", res.StatusCode)
}
@@ -85,21 +88,21 @@ func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.Workspace
}()
if err != nil {
mu.Lock()
if failures[app.DisplayName] < int(app.Healthcheck.Threshold) {
if failures[app.ID] < int(app.Healthcheck.Threshold) {
// increment the failure count and keep status the same.
// we will change it when we hit the threshold.
failures[app.DisplayName]++
failures[app.ID]++
} else {
// set to unhealthy if we hit the failure threshold.
// we stop incrementing at the threshold to prevent the failure value from increasing forever.
health[app.DisplayName] = codersdk.WorkspaceAppHealthUnhealthy
health[app.ID] = codersdk.WorkspaceAppHealthUnhealthy
}
mu.Unlock()
} else {
mu.Lock()
// we only need one successful health check to be considered healthy.
health[app.DisplayName] = codersdk.WorkspaceAppHealthHealthy
failures[app.DisplayName] = 0
health[app.ID] = codersdk.WorkspaceAppHealthHealthy
failures[app.ID] = 0
mu.Unlock()
}
@@ -130,7 +133,7 @@ func NewWorkspaceAppHealthReporter(logger slog.Logger, apps []codersdk.Workspace
mu.Lock()
lastHealth = copyHealth(health)
mu.Unlock()
err := postWorkspaceAgentAppHealth(ctx, codersdk.PostWorkspaceAppHealthsRequest{
err := postWorkspaceAgentAppHealth(ctx, agentsdk.PostAppHealthsRequest{
Healths: lastHealth,
})
if err != nil {
@@ -155,7 +158,7 @@ func shouldStartTicker(app codersdk.WorkspaceApp) bool {
return app.Healthcheck.URL != "" && app.Healthcheck.Interval > 0 && app.Healthcheck.Threshold > 0
}
func healthChanged(old map[string]codersdk.WorkspaceAppHealth, new map[string]codersdk.WorkspaceAppHealth) bool {
func healthChanged(old map[uuid.UUID]codersdk.WorkspaceAppHealth, new map[uuid.UUID]codersdk.WorkspaceAppHealth) bool {
for name, newValue := range new {
oldValue, found := old[name]
if !found {
@@ -169,8 +172,8 @@ func healthChanged(old map[string]codersdk.WorkspaceAppHealth, new map[string]co
return false
}
func copyHealth(h1 map[string]codersdk.WorkspaceAppHealth) map[string]codersdk.WorkspaceAppHealth {
h2 := make(map[string]codersdk.WorkspaceAppHealth, 0)
func copyHealth(h1 map[uuid.UUID]codersdk.WorkspaceAppHealth) map[uuid.UUID]codersdk.WorkspaceAppHealth {
h2 := make(map[uuid.UUID]codersdk.WorkspaceAppHealth, 0)
for k, v := range h1 {
h2[k] = v
}
+128 -130
View File
@@ -16,151 +16,149 @@ import (
"github.com/coder/coder/agent"
"github.com/coder/coder/coderd/httpapi"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/codersdk/agentsdk"
"github.com/coder/coder/testutil"
)
func TestAppHealth(t *testing.T) {
func TestAppHealth_Healthy(t *testing.T) {
t.Parallel()
t.Run("Healthy", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
apps := []codersdk.WorkspaceApp{
{
DisplayName: "app1",
Healthcheck: codersdk.Healthcheck{},
Health: codersdk.WorkspaceAppHealthDisabled,
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
apps := []codersdk.WorkspaceApp{
{
Slug: "app1",
Healthcheck: codersdk.Healthcheck{},
Health: codersdk.WorkspaceAppHealthDisabled,
},
{
Slug: "app2",
Healthcheck: codersdk.Healthcheck{
// URL: We don't set the URL for this test because the setup will
// create a httptest server for us and set it for us.
Interval: 1,
Threshold: 1,
},
{
DisplayName: "app2",
Healthcheck: codersdk.Healthcheck{
// URL: We don't set the URL for this test because the setup will
// create a httptest server for us and set it for us.
Interval: 1,
Threshold: 1,
},
Health: codersdk.WorkspaceAppHealthInitializing,
},
}
handlers := []http.Handler{
nil,
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
httpapi.Write(r.Context(), w, http.StatusOK, nil)
}),
}
getApps, closeFn := setupAppReporter(ctx, t, apps, handlers)
defer closeFn()
Health: codersdk.WorkspaceAppHealthInitializing,
},
}
handlers := []http.Handler{
nil,
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
httpapi.Write(r.Context(), w, http.StatusOK, nil)
}),
}
getApps, closeFn := setupAppReporter(ctx, t, apps, handlers)
defer closeFn()
apps, err := getApps(ctx)
require.NoError(t, err)
require.EqualValues(t, codersdk.WorkspaceAppHealthDisabled, apps[0].Health)
require.Eventually(t, func() bool {
apps, err := getApps(ctx)
require.NoError(t, err)
require.EqualValues(t, codersdk.WorkspaceAppHealthDisabled, apps[0].Health)
require.Eventually(t, func() bool {
apps, err := getApps(ctx)
if err != nil {
return false
}
if err != nil {
return false
}
return apps[1].Health == codersdk.WorkspaceAppHealthHealthy
}, testutil.WaitLong, testutil.IntervalSlow)
})
return apps[1].Health == codersdk.WorkspaceAppHealthHealthy
}, testutil.WaitLong, testutil.IntervalSlow)
}
t.Run("500", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
apps := []codersdk.WorkspaceApp{
{
DisplayName: "app2",
Healthcheck: codersdk.Healthcheck{
// URL: We don't set the URL for this test because the setup will
// create a httptest server for us and set it for us.
Interval: 1,
Threshold: 1,
},
Health: codersdk.WorkspaceAppHealthInitializing,
func TestAppHealth_500(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
apps := []codersdk.WorkspaceApp{
{
Slug: "app2",
Healthcheck: codersdk.Healthcheck{
// URL: We don't set the URL for this test because the setup will
// create a httptest server for us and set it for us.
Interval: 1,
Threshold: 1,
},
Health: codersdk.WorkspaceAppHealthInitializing,
},
}
handlers := []http.Handler{
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
httpapi.Write(r.Context(), w, http.StatusInternalServerError, nil)
}),
}
getApps, closeFn := setupAppReporter(ctx, t, apps, handlers)
defer closeFn()
require.Eventually(t, func() bool {
apps, err := getApps(ctx)
if err != nil {
return false
}
handlers := []http.Handler{
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
httpapi.Write(r.Context(), w, http.StatusInternalServerError, nil)
}),
}
getApps, closeFn := setupAppReporter(ctx, t, apps, handlers)
defer closeFn()
require.Eventually(t, func() bool {
apps, err := getApps(ctx)
if err != nil {
return false
}
return apps[0].Health == codersdk.WorkspaceAppHealthUnhealthy
}, testutil.WaitLong, testutil.IntervalSlow)
})
return apps[0].Health == codersdk.WorkspaceAppHealthUnhealthy
}, testutil.WaitLong, testutil.IntervalSlow)
}
t.Run("Timeout", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
apps := []codersdk.WorkspaceApp{
{
DisplayName: "app2",
Healthcheck: codersdk.Healthcheck{
// URL: We don't set the URL for this test because the setup will
// create a httptest server for us and set it for us.
Interval: 1,
Threshold: 1,
},
Health: codersdk.WorkspaceAppHealthInitializing,
func TestAppHealth_Timeout(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
apps := []codersdk.WorkspaceApp{
{
Slug: "app2",
Healthcheck: codersdk.Healthcheck{
// URL: We don't set the URL for this test because the setup will
// create a httptest server for us and set it for us.
Interval: 1,
Threshold: 1,
},
Health: codersdk.WorkspaceAppHealthInitializing,
},
}
handlers := []http.Handler{
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// sleep longer than the interval to cause the health check to time out
time.Sleep(2 * time.Second)
httpapi.Write(r.Context(), w, http.StatusOK, nil)
}),
}
getApps, closeFn := setupAppReporter(ctx, t, apps, handlers)
defer closeFn()
require.Eventually(t, func() bool {
apps, err := getApps(ctx)
if err != nil {
return false
}
handlers := []http.Handler{
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// sleep longer than the interval to cause the health check to time out
time.Sleep(2 * time.Second)
httpapi.Write(r.Context(), w, http.StatusOK, nil)
}),
}
getApps, closeFn := setupAppReporter(ctx, t, apps, handlers)
defer closeFn()
require.Eventually(t, func() bool {
apps, err := getApps(ctx)
if err != nil {
return false
}
return apps[0].Health == codersdk.WorkspaceAppHealthUnhealthy
}, testutil.WaitLong, testutil.IntervalSlow)
})
return apps[0].Health == codersdk.WorkspaceAppHealthUnhealthy
}, testutil.WaitLong, testutil.IntervalSlow)
}
t.Run("NotSpamming", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
apps := []codersdk.WorkspaceApp{
{
DisplayName: "app2",
Healthcheck: codersdk.Healthcheck{
// URL: We don't set the URL for this test because the setup will
// create a httptest server for us and set it for us.
Interval: 1,
Threshold: 1,
},
Health: codersdk.WorkspaceAppHealthInitializing,
func TestAppHealth_NotSpamming(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
apps := []codersdk.WorkspaceApp{
{
Slug: "app2",
Healthcheck: codersdk.Healthcheck{
// URL: We don't set the URL for this test because the setup will
// create a httptest server for us and set it for us.
Interval: 1,
Threshold: 1,
},
}
Health: codersdk.WorkspaceAppHealthInitializing,
},
}
var counter = new(int32)
handlers := []http.Handler{
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
atomic.AddInt32(counter, 1)
}),
}
_, closeFn := setupAppReporter(ctx, t, apps, handlers)
defer closeFn()
// Ensure we haven't made more than 2 (expected 1 + 1 for buffer) requests in the last second.
// if there is a bug where we are spamming the healthcheck route this will catch it.
time.Sleep(time.Second)
require.LessOrEqual(t, *counter, int32(2))
})
counter := new(int32)
handlers := []http.Handler{
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
atomic.AddInt32(counter, 1)
}),
}
_, closeFn := setupAppReporter(ctx, t, apps, handlers)
defer closeFn()
// Ensure we haven't made more than 2 (expected 1 + 1 for buffer) requests in the last second.
// if there is a bug where we are spamming the healthcheck route this will catch it.
time.Sleep(time.Second)
require.LessOrEqual(t, atomic.LoadInt32(counter), int32(2))
}
func setupAppReporter(ctx context.Context, t *testing.T, apps []codersdk.WorkspaceApp, handlers []http.Handler) (agent.WorkspaceAgentApps, func()) {
@@ -183,11 +181,11 @@ func setupAppReporter(ctx context.Context, t *testing.T, apps []codersdk.Workspa
var newApps []codersdk.WorkspaceApp
return append(newApps, apps...), nil
}
postWorkspaceAgentAppHealth := func(_ context.Context, req codersdk.PostWorkspaceAppHealthsRequest) error {
postWorkspaceAgentAppHealth := func(_ context.Context, req agentsdk.PostAppHealthsRequest) error {
mu.Lock()
for name, health := range req.Healths {
for id, health := range req.Healths {
for i, app := range apps {
if app.DisplayName != name {
if app.ID != id {
continue
}
app.Health = health
+130
View File
@@ -0,0 +1,130 @@
package agent
import (
"context"
"fmt"
"strings"
"github.com/prometheus/client_golang/prometheus"
prompb "github.com/prometheus/client_model/go"
"tailscale.com/util/clientmetric"
"cdr.dev/slog"
"github.com/coder/coder/codersdk/agentsdk"
)
type agentMetrics struct {
connectionsTotal prometheus.Counter
reconnectingPTYErrors *prometheus.CounterVec
}
func newAgentMetrics(registerer prometheus.Registerer) *agentMetrics {
connectionsTotal := prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "agent", Subsystem: "reconnecting_pty", Name: "connections_total",
})
registerer.MustRegister(connectionsTotal)
reconnectingPTYErrors := prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "agent",
Subsystem: "reconnecting_pty",
Name: "errors_total",
},
[]string{"error_type"},
)
registerer.MustRegister(reconnectingPTYErrors)
return &agentMetrics{
connectionsTotal: connectionsTotal,
reconnectingPTYErrors: reconnectingPTYErrors,
}
}
func (a *agent) collectMetrics(ctx context.Context) []agentsdk.AgentMetric {
var collected []agentsdk.AgentMetric
// Tailscale internal metrics
metrics := clientmetric.Metrics()
for _, m := range metrics {
if isIgnoredMetric(m.Name()) {
continue
}
collected = append(collected, agentsdk.AgentMetric{
Name: m.Name(),
Type: asMetricType(m.Type()),
Value: float64(m.Value()),
})
}
metricFamilies, err := a.prometheusRegistry.Gather()
if err != nil {
a.logger.Error(ctx, "can't gather agent metrics", slog.Error(err))
return collected
}
for _, metricFamily := range metricFamilies {
for _, metric := range metricFamily.GetMetric() {
labels := toAgentMetricLabels(metric.Label)
if metric.Counter != nil {
collected = append(collected, agentsdk.AgentMetric{
Name: metricFamily.GetName(),
Type: agentsdk.AgentMetricTypeCounter,
Value: metric.Counter.GetValue(),
Labels: labels,
})
} else if metric.Gauge != nil {
collected = append(collected, agentsdk.AgentMetric{
Name: metricFamily.GetName(),
Type: agentsdk.AgentMetricTypeGauge,
Value: metric.Gauge.GetValue(),
Labels: labels,
})
} else {
a.logger.Error(ctx, "unsupported metric type", slog.F("type", metricFamily.Type.String()))
}
}
}
return collected
}
func toAgentMetricLabels(metricLabels []*prompb.LabelPair) []agentsdk.AgentMetricLabel {
if len(metricLabels) == 0 {
return nil
}
labels := make([]agentsdk.AgentMetricLabel, 0, len(metricLabels))
for _, metricLabel := range metricLabels {
labels = append(labels, agentsdk.AgentMetricLabel{
Name: metricLabel.GetName(),
Value: metricLabel.GetValue(),
})
}
return labels
}
// isIgnoredMetric checks if the metric should be ignored, as Coder agent doesn't use related features.
// Expected metric families: magicsock_*, derp_*, tstun_*, netcheck_*, portmap_*, etc.
func isIgnoredMetric(metricName string) bool {
if strings.HasPrefix(metricName, "dns_") ||
strings.HasPrefix(metricName, "controlclient_") ||
strings.HasPrefix(metricName, "peerapi_") ||
strings.HasPrefix(metricName, "profiles_") ||
strings.HasPrefix(metricName, "tstun_") {
return true
}
return false
}
func asMetricType(typ clientmetric.Type) agentsdk.AgentMetricType {
switch typ {
case clientmetric.TypeGauge:
return agentsdk.AgentMetricTypeGauge
case clientmetric.TypeCounter:
return agentsdk.AgentMetricTypeCounter
default:
panic(fmt.Sprintf("unknown metric type: %d", typ))
}
}
+12 -7
View File
@@ -11,13 +11,13 @@ import (
"github.com/coder/coder/codersdk"
)
func (lp *listeningPortsHandler) getListeningPorts() ([]codersdk.ListeningPort, error) {
func (lp *listeningPortsHandler) getListeningPorts() ([]codersdk.WorkspaceAgentListeningPort, error) {
lp.mut.Lock()
defer lp.mut.Unlock()
if time.Since(lp.mtime) < time.Second {
// copy
ports := make([]codersdk.ListeningPort, len(lp.ports))
ports := make([]codersdk.WorkspaceAgentListeningPort, len(lp.ports))
copy(ports, lp.ports)
return ports, nil
}
@@ -30,9 +30,14 @@ func (lp *listeningPortsHandler) getListeningPorts() ([]codersdk.ListeningPort,
}
seen := make(map[uint16]struct{}, len(tabs))
ports := []codersdk.ListeningPort{}
ports := []codersdk.WorkspaceAgentListeningPort{}
for _, tab := range tabs {
if tab.LocalAddr == nil || tab.LocalAddr.Port < uint16(codersdk.MinimumListeningPort) {
if tab.LocalAddr == nil || tab.LocalAddr.Port < codersdk.WorkspaceAgentMinimumListeningPort {
continue
}
// Ignore ports that we've been told to ignore.
if _, ok := lp.ignorePorts[int(tab.LocalAddr.Port)]; ok {
continue
}
@@ -47,9 +52,9 @@ func (lp *listeningPortsHandler) getListeningPorts() ([]codersdk.ListeningPort,
if tab.Process != nil {
procName = tab.Process.Name
}
ports = append(ports, codersdk.ListeningPort{
ports = append(ports, codersdk.WorkspaceAgentListeningPort{
ProcessName: procName,
Network: codersdk.ListeningPortNetworkTCP,
Network: "tcp",
Port: tab.LocalAddr.Port,
})
}
@@ -58,7 +63,7 @@ func (lp *listeningPortsHandler) getListeningPorts() ([]codersdk.ListeningPort,
lp.mtime = time.Now()
// copy
ports = make([]codersdk.ListeningPort, len(lp.ports))
ports = make([]codersdk.WorkspaceAgentListeningPort, len(lp.ports))
copy(ports, lp.ports)
return ports, nil
}
+2 -2
View File
@@ -4,9 +4,9 @@ package agent
import "github.com/coder/coder/codersdk"
func (lp *listeningPortsHandler) getListeningPorts() ([]codersdk.ListeningPort, error) {
func (lp *listeningPortsHandler) getListeningPorts() ([]codersdk.WorkspaceAgentListeningPort, error) {
// Can't scan for ports on non-linux or non-windows_amd64 systems at the
// moment. The UI will not show any "no ports found" message to the user, so
// the user won't suspect a thing.
return []codersdk.ListeningPort{}, nil
return []codersdk.WorkspaceAgentListeningPort{}, nil
}
+17 -4
View File
@@ -1,6 +1,10 @@
package reaper
import "github.com/hashicorp/go-reap"
import (
"os"
"github.com/hashicorp/go-reap"
)
type Option func(o *options)
@@ -22,7 +26,16 @@ func WithPIDCallback(ch reap.PidCh) Option {
}
}
type options struct {
ExecArgs []string
PIDs reap.PidCh
// WithCatchSignals sets the signals that are caught and forwarded to the
// child process. By default no signals are forwarded.
func WithCatchSignals(sigs ...os.Signal) Option {
return func(o *options) {
o.CatchSignals = sigs
}
}
type options struct {
ExecArgs []string
PIDs reap.PidCh
CatchSignals []os.Signal
}
+70 -34
View File
@@ -3,8 +3,11 @@
package reaper_test
import (
"fmt"
"os"
"os/exec"
"os/signal"
"syscall"
"testing"
"time"
@@ -15,52 +18,85 @@ import (
"github.com/coder/coder/testutil"
)
// TestReap checks that's the reaper is successfully reaping
// exited processes and passing the PIDs through the shared
// channel.
//
//nolint:paralleltest
func TestReap(t *testing.T) {
t.Parallel()
// Don't run the reaper test in CI. It does weird
// things like forkexecing which may have unintended
// consequences in CI.
if _, ok := os.LookupEnv("CI"); ok {
if testutil.InCI() {
t.Skip("Detected CI, skipping reaper tests")
}
// OK checks that's the reaper is successfully reaping
// exited processes and passing the PIDs through the shared
// channel.
t.Run("OK", func(t *testing.T) {
t.Parallel()
pids := make(reap.PidCh, 1)
err := reaper.ForkReap(
reaper.WithPIDCallback(pids),
// Provide some argument that immediately exits.
reaper.WithExecArgs("/bin/sh", "-c", "exit 0"),
)
require.NoError(t, err)
pids := make(reap.PidCh, 1)
err := reaper.ForkReap(
reaper.WithPIDCallback(pids),
// Provide some argument that immediately exits.
reaper.WithExecArgs("/bin/sh", "-c", "exit 0"),
)
require.NoError(t, err)
cmd := exec.Command("tail", "-f", "/dev/null")
err = cmd.Start()
require.NoError(t, err)
cmd := exec.Command("tail", "-f", "/dev/null")
err = cmd.Start()
require.NoError(t, err)
cmd2 := exec.Command("tail", "-f", "/dev/null")
err = cmd2.Start()
require.NoError(t, err)
cmd2 := exec.Command("tail", "-f", "/dev/null")
err = cmd2.Start()
require.NoError(t, err)
err = cmd.Process.Kill()
require.NoError(t, err)
err = cmd.Process.Kill()
require.NoError(t, err)
err = cmd2.Process.Kill()
require.NoError(t, err)
err = cmd2.Process.Kill()
require.NoError(t, err)
expectedPIDs := []int{cmd.Process.Pid, cmd2.Process.Pid}
expectedPIDs := []int{cmd.Process.Pid, cmd2.Process.Pid}
for i := 0; i < len(expectedPIDs); i++ {
select {
case <-time.After(testutil.WaitShort):
t.Fatalf("Timed out waiting for process")
case pid := <-pids:
require.Contains(t, expectedPIDs, pid)
}
for i := 0; i < len(expectedPIDs); i++ {
select {
case <-time.After(testutil.WaitShort):
t.Fatalf("Timed out waiting for process")
case pid := <-pids:
require.Contains(t, expectedPIDs, pid)
}
})
}
}
//nolint:paralleltest // Signal handling.
func TestReapInterrupt(t *testing.T) {
// Don't run the reaper test in CI. It does weird
// things like forkexecing which may have unintended
// consequences in CI.
if testutil.InCI() {
t.Skip("Detected CI, skipping reaper tests")
}
errC := make(chan error, 1)
pids := make(reap.PidCh, 1)
// Use signals to notify when the child process is ready for the
// next step of our test.
usrSig := make(chan os.Signal, 1)
signal.Notify(usrSig, syscall.SIGUSR1, syscall.SIGUSR2)
defer signal.Stop(usrSig)
go func() {
errC <- reaper.ForkReap(
reaper.WithPIDCallback(pids),
reaper.WithCatchSignals(os.Interrupt),
// Signal propagation does not extend to children of children, so
// we create a little bash script to ensure sleep is interrupted.
reaper.WithExecArgs("/bin/sh", "-c", fmt.Sprintf("pid=0; trap 'kill -USR2 %d; kill -TERM $pid' INT; sleep 10 &\npid=$!; kill -USR1 %d; wait", os.Getpid(), os.Getpid())),
)
}()
require.Equal(t, <-usrSig, syscall.SIGUSR1)
err := syscall.Kill(os.Getpid(), syscall.SIGINT)
require.NoError(t, err)
require.Equal(t, <-usrSig, syscall.SIGUSR2)
require.NoError(t, <-errC)
}
+26 -3
View File
@@ -4,6 +4,7 @@ package reaper
import (
"os"
"os/signal"
"syscall"
"github.com/hashicorp/go-reap"
@@ -15,6 +16,24 @@ func IsInitProcess() bool {
return os.Getpid() == 1
}
func catchSignals(pid int, sigs []os.Signal) {
if len(sigs) == 0 {
return
}
sc := make(chan os.Signal, 1)
signal.Notify(sc, sigs...)
defer signal.Stop(sc)
for {
s := <-sc
sig, ok := s.(syscall.Signal)
if ok {
_ = syscall.Kill(pid, sig)
}
}
}
// ForkReap spawns a goroutine that reaps children. In order to avoid
// complications with spawning `exec.Commands` in the same process that
// is reaping, we forkexec a child process. This prevents a race between
@@ -51,13 +70,17 @@ func ForkReap(opt ...Option) error {
}
//#nosec G204
pid, _ := syscall.ForkExec(opts.ExecArgs[0], opts.ExecArgs, pattrs)
pid, err := syscall.ForkExec(opts.ExecArgs[0], opts.ExecArgs, pattrs)
if err != nil {
return xerrors.Errorf("fork exec: %w", err)
}
go catchSignals(pid, opts.CatchSignals)
var wstatus syscall.WaitStatus
_, err = syscall.Wait4(pid, &wstatus, 0, nil)
for xerrors.Is(err, syscall.EINTR) {
_, err = syscall.Wait4(pid, &wstatus, 0, nil)
}
return nil
return err
}
-58
View File
@@ -1,58 +0,0 @@
package agent
import (
"net"
"sync/atomic"
"github.com/coder/coder/codersdk"
)
// statsConn wraps a net.Conn with statistics.
type statsConn struct {
*Stats
net.Conn `json:"-"`
}
var _ net.Conn = new(statsConn)
func (c *statsConn) Read(b []byte) (n int, err error) {
n, err = c.Conn.Read(b)
atomic.AddInt64(&c.RxBytes, int64(n))
return n, err
}
func (c *statsConn) Write(b []byte) (n int, err error) {
n, err = c.Conn.Write(b)
atomic.AddInt64(&c.TxBytes, int64(n))
return n, err
}
var _ net.Conn = new(statsConn)
// Stats records the Agent's network connection statistics for use in
// user-facing metrics and debugging.
// Each member value must be written and read with atomic.
type Stats struct {
NumConns int64 `json:"num_comms"`
RxBytes int64 `json:"rx_bytes"`
TxBytes int64 `json:"tx_bytes"`
}
func (s *Stats) Copy() *codersdk.AgentStats {
return &codersdk.AgentStats{
NumConns: atomic.LoadInt64(&s.NumConns),
RxBytes: atomic.LoadInt64(&s.RxBytes),
TxBytes: atomic.LoadInt64(&s.TxBytes),
}
}
// wrapConn returns a new connection that records statistics.
func (s *Stats) wrapConn(conn net.Conn) net.Conn {
atomic.AddInt64(&s.NumConns, 1)
cs := &statsConn{
Stats: s,
Conn: conn,
}
return cs
}
+5 -1
View File
@@ -4,7 +4,11 @@ import "os/exec"
// Get returns the command prompt binary name.
func Get(username string) (string, error) {
_, err := exec.LookPath("powershell.exe")
_, err := exec.LookPath("pwsh.exe")
if err == nil {
return "pwsh.exe", nil
}
_, err = exec.LookPath("powershell.exe")
if err == nil {
return "powershell.exe", nil
}
+21 -2
View File
@@ -21,8 +21,12 @@ var (
version string
readVersion sync.Once
// Injected with ldflags at build!
tag string
// Updated by buildinfo_slim.go on start.
slim bool
// Injected with ldflags at build, see scripts/build_go.sh
tag string
agpl string // either "true" or "false", ldflags does not support bools
)
const (
@@ -68,6 +72,21 @@ func VersionsMatch(v1, v2 string) bool {
return semver.MajorMinor(v1) == semver.MajorMinor(v2)
}
// IsDev returns true if this is a development build.
func IsDev() bool {
return strings.HasPrefix(Version(), develPrefix)
}
// IsSlim returns true if this is a slim build.
func IsSlim() bool {
return slim
}
// IsAGPL returns true if this is an AGPL build.
func IsAGPL() bool {
return strings.Contains(agpl, "t")
}
// ExternalURL returns a URL referencing the current Coder version.
// For production builds, this will link directly to a release.
// For development builds, this will link to a commit.
+7
View File
@@ -0,0 +1,7 @@
//go:build slim
package buildinfo
func init() {
slim = true
}
+366 -66
View File
@@ -3,144 +3,243 @@ package cli
import (
"context"
"fmt"
"io"
"net/http"
_ "net/http/pprof" //nolint: gosec
"net/http/pprof"
"net/url"
"os"
"os/signal"
"path/filepath"
"runtime"
"strconv"
"sync"
"time"
"cloud.google.com/go/compute/metadata"
"github.com/spf13/cobra"
"golang.org/x/xerrors"
"gopkg.in/natefinch/lumberjack.v2"
"tailscale.com/util/clientmetric"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/expfmt"
"cdr.dev/slog"
"cdr.dev/slog/sloggers/sloghuman"
"cdr.dev/slog/sloggers/slogjson"
"cdr.dev/slog/sloggers/slogstackdriver"
"github.com/coder/coder/agent"
"github.com/coder/coder/agent/reaper"
"github.com/coder/coder/buildinfo"
"github.com/coder/coder/cli/cliflag"
"github.com/coder/coder/cli/clibase"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/codersdk/agentsdk"
)
func workspaceAgent() *cobra.Command {
func (r *RootCmd) workspaceAgent() *clibase.Cmd {
var (
auth string
pprofEnabled bool
pprofAddress string
noReap bool
auth string
logDir string
pprofAddress string
noReap bool
sshMaxTimeout time.Duration
tailnetListenPort int64
prometheusAddress string
debugAddress string
slogHumanPath string
slogJSONPath string
slogStackdriverPath string
)
cmd := &cobra.Command{
Use: "agent",
cmd := &clibase.Cmd{
Use: "agent",
Short: `Starts the Coder workspace agent.`,
// This command isn't useful to manually execute.
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
rawURL, err := cmd.Flags().GetString(varAgentURL)
if err != nil {
return xerrors.Errorf("CODER_AGENT_URL must be set: %w", err)
}
coderURL, err := url.Parse(rawURL)
if err != nil {
return xerrors.Errorf("parse %q: %w", rawURL, err)
Handler: func(inv *clibase.Invocation) error {
ctx, cancel := context.WithCancel(inv.Context())
defer cancel()
var (
ignorePorts = map[int]string{}
isLinux = runtime.GOOS == "linux"
sinks = []slog.Sink{}
logClosers = []func() error{}
)
defer func() {
for _, closer := range logClosers {
_ = closer()
}
}()
addSinkIfProvided := func(sinkFn func(io.Writer) slog.Sink, loc string) error {
switch loc {
case "":
// Do nothing.
case "/dev/stderr":
sinks = append(sinks, sinkFn(inv.Stderr))
case "/dev/stdout":
sinks = append(sinks, sinkFn(inv.Stdout))
default:
fi, err := os.OpenFile(loc, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644)
if err != nil {
return xerrors.Errorf("open log file %q: %w", loc, err)
}
sinks = append(sinks, sinkFn(fi))
logClosers = append(logClosers, fi.Close)
}
return nil
}
logWriter := &lumberjack.Logger{
Filename: filepath.Join(os.TempDir(), "coder-agent.log"),
MaxSize: 5, // MB
if err := addSinkIfProvided(sloghuman.Sink, slogHumanPath); err != nil {
return xerrors.Errorf("add human sink: %w", err)
}
if err := addSinkIfProvided(slogjson.Sink, slogJSONPath); err != nil {
return xerrors.Errorf("add json sink: %w", err)
}
if err := addSinkIfProvided(slogstackdriver.Sink, slogStackdriverPath); err != nil {
return xerrors.Errorf("add stackdriver sink: %w", err)
}
defer logWriter.Close()
logger := slog.Make(sloghuman.Sink(cmd.ErrOrStderr()), sloghuman.Sink(logWriter)).Leveled(slog.LevelDebug)
isLinux := runtime.GOOS == "linux"
// Spawn a reaper so that we don't accumulate a ton
// of zombie processes.
if reaper.IsInitProcess() && !noReap && isLinux {
logger.Info(cmd.Context(), "spawning reaper process")
logWriter := &lumberjackWriteCloseFixer{w: &lumberjack.Logger{
Filename: filepath.Join(logDir, "coder-agent-init.log"),
MaxSize: 5, // MB
// Without this, rotated logs will never be deleted.
MaxBackups: 1,
}}
defer logWriter.Close()
sinks = append(sinks, sloghuman.Sink(logWriter))
logger := slog.Make(sinks...).Leveled(slog.LevelDebug)
logger.Info(ctx, "spawning reaper process")
// Do not start a reaper on the child process. It's important
// to do this else we fork bomb ourselves.
args := append(os.Args, "--no-reap")
err := reaper.ForkReap(reaper.WithExecArgs(args...))
err := reaper.ForkReap(
reaper.WithExecArgs(args...),
reaper.WithCatchSignals(InterruptSignals...),
)
if err != nil {
logger.Error(cmd.Context(), "failed to reap", slog.Error(err))
logger.Error(ctx, "agent process reaper unable to fork", slog.Error(err))
return xerrors.Errorf("fork reap: %w", err)
}
logger.Info(cmd.Context(), "reaper process exiting")
logger.Info(ctx, "reaper process exiting")
return nil
}
// Handle interrupt signals to allow for graceful shutdown,
// note that calling stopNotify disables the signal handler
// and the next interrupt will terminate the program (you
// probably want cancel instead).
//
// Note that we don't want to handle these signals in the
// process that runs as PID 1, that's why we do this after
// the reaper forked.
ctx, stopNotify := signal.NotifyContext(ctx, InterruptSignals...)
defer stopNotify()
// DumpHandler does signal handling, so we call it after the
// reaper.
go DumpHandler(ctx)
logWriter := &lumberjackWriteCloseFixer{w: &lumberjack.Logger{
Filename: filepath.Join(logDir, "coder-agent.log"),
MaxSize: 5, // MB
// Without this, rotated logs will never be deleted.
MaxBackups: 1,
}}
defer logWriter.Close()
sinks = append(sinks, sloghuman.Sink(logWriter))
logger := slog.Make(sinks...).Leveled(slog.LevelDebug)
version := buildinfo.Version()
logger.Info(cmd.Context(), "starting agent",
slog.F("url", coderURL),
logger.Info(ctx, "agent is starting now",
slog.F("url", r.agentURL),
slog.F("auth", auth),
slog.F("version", version),
)
client := codersdk.New(coderURL)
client := agentsdk.New(r.agentURL)
client.SDK.Logger = logger
// Set a reasonable timeout so requests can't hang forever!
client.HTTPClient.Timeout = 10 * time.Second
// The timeout needs to be reasonably long, because requests
// with large payloads can take a bit. e.g. startup scripts
// may take a while to insert.
client.SDK.HTTPClient.Timeout = 30 * time.Second
if pprofEnabled {
srvClose := serveHandler(cmd.Context(), logger, nil, pprofAddress, "pprof")
defer srvClose()
} else {
// If pprof wasn't enabled at startup, allow a
// `kill -USR1 $agent_pid` to start it (on Unix).
srvClose := agentStartPPROFOnUSR1(cmd.Context(), logger, pprofAddress)
defer srvClose()
// Enable pprof handler
// This prevents the pprof import from being accidentally deleted.
_ = pprof.Handler
pprofSrvClose := ServeHandler(ctx, logger, nil, pprofAddress, "pprof")
defer pprofSrvClose()
if port, err := extractPort(pprofAddress); err == nil {
ignorePorts[port] = "pprof"
}
if port, err := extractPort(prometheusAddress); err == nil {
ignorePorts[port] = "prometheus"
}
if port, err := extractPort(debugAddress); err == nil {
ignorePorts[port] = "debug"
}
// exchangeToken returns a session token.
// This is abstracted to allow for the same looping condition
// regardless of instance identity auth type.
var exchangeToken func(context.Context) (codersdk.WorkspaceAgentAuthenticateResponse, error)
var exchangeToken func(context.Context) (agentsdk.AuthenticateResponse, error)
switch auth {
case "token":
token, err := cmd.Flags().GetString(varAgentToken)
token, err := inv.ParsedFlags().GetString(varAgentToken)
if err != nil {
return xerrors.Errorf("CODER_AGENT_TOKEN must be set for token auth: %w", err)
}
client.SessionToken = token
client.SetSessionToken(token)
case "google-instance-identity":
// This is *only* done for testing to mock client authentication.
// This will never be set in a production scenario.
var gcpClient *metadata.Client
gcpClientRaw := cmd.Context().Value("gcp-client")
gcpClientRaw := ctx.Value("gcp-client")
if gcpClientRaw != nil {
gcpClient, _ = gcpClientRaw.(*metadata.Client)
}
exchangeToken = func(ctx context.Context) (codersdk.WorkspaceAgentAuthenticateResponse, error) {
return client.AuthWorkspaceGoogleInstanceIdentity(ctx, "", gcpClient)
exchangeToken = func(ctx context.Context) (agentsdk.AuthenticateResponse, error) {
return client.AuthGoogleInstanceIdentity(ctx, "", gcpClient)
}
case "aws-instance-identity":
// This is *only* done for testing to mock client authentication.
// This will never be set in a production scenario.
var awsClient *http.Client
awsClientRaw := cmd.Context().Value("aws-client")
awsClientRaw := ctx.Value("aws-client")
if awsClientRaw != nil {
awsClient, _ = awsClientRaw.(*http.Client)
if awsClient != nil {
client.HTTPClient = awsClient
client.SDK.HTTPClient = awsClient
}
}
exchangeToken = func(ctx context.Context) (codersdk.WorkspaceAgentAuthenticateResponse, error) {
return client.AuthWorkspaceAWSInstanceIdentity(ctx)
exchangeToken = func(ctx context.Context) (agentsdk.AuthenticateResponse, error) {
return client.AuthAWSInstanceIdentity(ctx)
}
case "azure-instance-identity":
// This is *only* done for testing to mock client authentication.
// This will never be set in a production scenario.
var azureClient *http.Client
azureClientRaw := cmd.Context().Value("azure-client")
azureClientRaw := ctx.Value("azure-client")
if azureClientRaw != nil {
azureClient, _ = azureClientRaw.(*http.Client)
if azureClient != nil {
client.HTTPClient = azureClient
client.SDK.HTTPClient = azureClient
}
}
exchangeToken = func(ctx context.Context) (codersdk.WorkspaceAgentAuthenticateResponse, error) {
return client.AuthWorkspaceAzureInstanceIdentity(ctx)
exchangeToken = func(ctx context.Context) (agentsdk.AuthenticateResponse, error) {
return client.AuthAzureInstanceIdentity(ctx)
}
}
@@ -153,32 +252,233 @@ func workspaceAgent() *cobra.Command {
return xerrors.Errorf("add executable to $PATH: %w", err)
}
closer := agent.New(agent.Options{
Client: client,
Logger: logger,
prometheusRegistry := prometheus.NewRegistry()
subsystem := inv.Environ.Get(agent.EnvAgentSubsystem)
agnt := agent.New(agent.Options{
Client: client,
Logger: logger,
LogDir: logDir,
TailnetListenPort: uint16(tailnetListenPort),
ExchangeToken: func(ctx context.Context) (string, error) {
if exchangeToken == nil {
return client.SessionToken, nil
return client.SDK.SessionToken(), nil
}
resp, err := exchangeToken(ctx)
if err != nil {
return "", err
}
client.SessionToken = resp.SessionToken
client.SetSessionToken(resp.SessionToken)
return resp.SessionToken, nil
},
EnvironmentVariables: map[string]string{
"GIT_ASKPASS": executablePath,
},
IgnorePorts: ignorePorts,
SSHMaxTimeout: sshMaxTimeout,
Subsystem: codersdk.AgentSubsystem(subsystem),
PrometheusRegistry: prometheusRegistry,
})
<-cmd.Context().Done()
return closer.Close()
prometheusSrvClose := ServeHandler(ctx, logger, prometheusMetricsHandler(prometheusRegistry, logger), prometheusAddress, "prometheus")
defer prometheusSrvClose()
debugSrvClose := ServeHandler(ctx, logger, agnt.HTTPDebug(), debugAddress, "debug")
defer debugSrvClose()
<-ctx.Done()
return agnt.Close()
},
}
cmd.Options = clibase.OptionSet{
{
Flag: "auth",
Default: "token",
Description: "Specify the authentication type to use for the agent.",
Env: "CODER_AGENT_AUTH",
Value: clibase.StringOf(&auth),
},
{
Flag: "log-dir",
Default: os.TempDir(),
Description: "Specify the location for the agent log files.",
Env: "CODER_AGENT_LOG_DIR",
Value: clibase.StringOf(&logDir),
},
{
Flag: "pprof-address",
Default: "127.0.0.1:6060",
Env: "CODER_AGENT_PPROF_ADDRESS",
Value: clibase.StringOf(&pprofAddress),
Description: "The address to serve pprof.",
},
{
Flag: "no-reap",
Env: "",
Description: "Do not start a process reaper.",
Value: clibase.BoolOf(&noReap),
},
{
Flag: "ssh-max-timeout",
// tcpip.KeepaliveIdleOption = 72h + 1min (forwardTCPSockOpts() in tailnet/conn.go)
Default: "72h",
Env: "CODER_AGENT_SSH_MAX_TIMEOUT",
Description: "Specify the max timeout for a SSH connection, it is advisable to set it to a minimum of 60s, but no more than 72h.",
Value: clibase.DurationOf(&sshMaxTimeout),
},
{
Flag: "tailnet-listen-port",
Default: "0",
Env: "CODER_AGENT_TAILNET_LISTEN_PORT",
Description: "Specify a static port for Tailscale to use for listening.",
Value: clibase.Int64Of(&tailnetListenPort),
},
{
Flag: "prometheus-address",
Default: "127.0.0.1:2112",
Env: "CODER_AGENT_PROMETHEUS_ADDRESS",
Value: clibase.StringOf(&prometheusAddress),
Description: "The bind address to serve Prometheus metrics.",
},
{
Flag: "debug-address",
Default: "127.0.0.1:2113",
Env: "CODER_AGENT_DEBUG_ADDRESS",
Value: clibase.StringOf(&debugAddress),
Description: "The bind address to serve a debug HTTP server.",
},
{
Name: "Human Log Location",
Description: "Output human-readable logs to a given file.",
Flag: "log-human",
Env: "CODER_AGENT_LOGGING_HUMAN",
Default: "/dev/stderr",
Value: clibase.StringOf(&slogHumanPath),
},
{
Name: "JSON Log Location",
Description: "Output JSON logs to a given file.",
Flag: "log-json",
Env: "CODER_AGENT_LOGGING_JSON",
Default: "",
Value: clibase.StringOf(&slogJSONPath),
},
{
Name: "Stackdriver Log Location",
Description: "Output Stackdriver compatible logs to a given file.",
Flag: "log-stackdriver",
Env: "CODER_AGENT_LOGGING_STACKDRIVER",
Default: "",
Value: clibase.StringOf(&slogStackdriverPath),
},
}
cliflag.StringVarP(cmd.Flags(), &auth, "auth", "", "CODER_AGENT_AUTH", "token", "Specify the authentication type to use for the agent")
cliflag.BoolVarP(cmd.Flags(), &pprofEnabled, "pprof-enable", "", "CODER_AGENT_PPROF_ENABLE", false, "Enable serving pprof metrics on the address defined by --pprof-address.")
cliflag.BoolVarP(cmd.Flags(), &noReap, "no-reap", "", "", false, "Do not start a process reaper.")
cliflag.StringVarP(cmd.Flags(), &pprofAddress, "pprof-address", "", "CODER_AGENT_PPROF_ADDRESS", "127.0.0.1:6060", "The address to serve pprof.")
return cmd
}
func ServeHandler(ctx context.Context, logger slog.Logger, handler http.Handler, addr, name string) (closeFunc func()) {
logger.Debug(ctx, "http server listening", slog.F("addr", addr), slog.F("name", name))
// ReadHeaderTimeout is purposefully not enabled. It caused some issues with
// websockets over the dev tunnel.
// See: https://github.com/coder/coder/pull/3730
//nolint:gosec
srv := &http.Server{
Addr: addr,
Handler: handler,
}
go func() {
err := srv.ListenAndServe()
if err != nil && !xerrors.Is(err, http.ErrServerClosed) {
logger.Error(ctx, "http server listen", slog.F("name", name), slog.Error(err))
}
}()
return func() {
_ = srv.Close()
}
}
// lumberjackWriteCloseFixer is a wrapper around an io.WriteCloser that
// prevents writes after Close. This is necessary because lumberjack
// re-opens the file on Write.
type lumberjackWriteCloseFixer struct {
w io.WriteCloser
mu sync.Mutex // Protects following.
closed bool
}
func (c *lumberjackWriteCloseFixer) Close() error {
c.mu.Lock()
defer c.mu.Unlock()
c.closed = true
return c.w.Close()
}
func (c *lumberjackWriteCloseFixer) Write(p []byte) (int, error) {
c.mu.Lock()
defer c.mu.Unlock()
if c.closed {
return 0, io.ErrClosedPipe
}
return c.w.Write(p)
}
// extractPort handles different url strings.
// - localhost:6060
// - http://localhost:6060
func extractPort(u string) (int, error) {
port, firstError := urlPort(u)
if firstError == nil {
return port, nil
}
// Try with a scheme
port, err := urlPort("http://" + u)
if err == nil {
return port, nil
}
return -1, xerrors.Errorf("invalid url %q: %w", u, firstError)
}
// urlPort extracts the port from a valid URL.
func urlPort(u string) (int, error) {
parsed, err := url.Parse(u)
if err != nil {
return -1, xerrors.Errorf("invalid url %q: %w", u, err)
}
if parsed.Port() != "" {
port, err := strconv.ParseUint(parsed.Port(), 10, 16)
if err == nil && port > 0 && port < 1<<16 {
return int(port), nil
}
}
return -1, xerrors.Errorf("invalid port: %s", u)
}
func prometheusMetricsHandler(prometheusRegistry *prometheus.Registry, logger slog.Logger) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
// Based on: https://github.com/tailscale/tailscale/blob/280255acae604796a1113861f5a84e6fa2dc6121/ipn/localapi/localapi.go#L489
clientmetric.WritePrometheusExpositionFormat(w)
metricFamilies, err := prometheusRegistry.Gather()
if err != nil {
logger.Error(context.Background(), "Prometheus handler can't gather metric families", slog.Error(err))
return
}
for _, metricFamily := range metricFamilies {
_, err = expfmt.MetricFamilyToText(w, metricFamily)
if err != nil {
logger.Error(context.Background(), "expfmt.MetricFamilyToText failed", slog.Error(err))
return
}
}
})
}
+69
View File
@@ -0,0 +1,69 @@
package cli
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func Test_extractPort(t *testing.T) {
t.Parallel()
tests := []struct {
name string
urlString string
want int
wantErr bool
}{
{
name: "Empty",
urlString: "",
wantErr: true,
},
{
name: "NoScheme",
urlString: "localhost:6060",
want: 6060,
},
{
name: "WithScheme",
urlString: "http://localhost:6060",
want: 6060,
},
{
name: "NoPort",
urlString: "http://localhost",
wantErr: true,
},
{
name: "NoPortNoScheme",
urlString: "localhost",
wantErr: true,
},
{
name: "OnlyPort",
urlString: "6060",
wantErr: true,
},
{
name: "127.0.0.1",
urlString: "127.0.0.1:2113",
want: 2113,
wantErr: false,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := extractPort(tt.urlString)
if tt.wantErr {
require.Error(t, err, fmt.Sprintf("extractPort(%v)", tt.urlString))
} else {
require.NoError(t, err, fmt.Sprintf("extractPort(%v)", tt.urlString))
require.Equal(t, tt.want, got, fmt.Sprintf("extractPort(%v)", tt.urlString))
}
})
}
}
+117 -58
View File
@@ -2,6 +2,8 @@ package cli_test
import (
"context"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
@@ -10,15 +12,57 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/coder/coder/agent"
"github.com/coder/coder/cli/clitest"
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/provisioner/echo"
"github.com/coder/coder/provisionersdk/proto"
"github.com/coder/coder/testutil"
"github.com/coder/coder/pty/ptytest"
)
func TestWorkspaceAgent(t *testing.T) {
t.Parallel()
t.Run("LogDirectory", func(t *testing.T) {
t.Parallel()
authToken := uuid.NewString()
client := coderdtest.New(t, &coderdtest.Options{
IncludeProvisionerDaemon: true,
})
user := coderdtest.CreateFirstUser(t, client)
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
Parse: echo.ParseComplete,
ProvisionApply: echo.ProvisionApplyWithAgent(authToken),
})
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
logDir := t.TempDir()
inv, _ := clitest.New(t,
"agent",
"--auth", "token",
"--agent-token", authToken,
"--agent-url", client.URL.String(),
"--log-dir", logDir,
)
pty := ptytest.New(t).Attach(inv)
clitest.Start(t, inv)
ctx := inv.Context()
pty.ExpectMatchContext(ctx, "agent is starting now")
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
info, err := os.Stat(filepath.Join(logDir, "coder-agent.log"))
require.NoError(t, err)
require.Greater(t, info.Size(), int64(0))
})
t.Run("Azure", func(t *testing.T) {
t.Parallel()
instanceID := "instanceidentifier"
@@ -30,7 +74,7 @@ func TestWorkspaceAgent(t *testing.T) {
user := coderdtest.CreateFirstUser(t, client)
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
Parse: echo.ParseComplete,
Provision: []*proto.Provision_Response{{
ProvisionApply: []*proto.Provision_Response{{
Type: &proto.Provision_Response_Complete{
Complete: &proto.Provision_Complete{
Resources: []*proto.Resource{{
@@ -51,16 +95,13 @@ func TestWorkspaceAgent(t *testing.T) {
workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
cmd, _ := clitest.New(t, "agent", "--auth", "azure-instance-identity", "--agent-url", client.URL.String())
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
errC := make(chan error)
go func() {
// A linting error occurs for weakly typing the context value here.
//nolint // The above seems reasonable for a one-off test.
ctx := context.WithValue(ctx, "azure-client", metadataClient)
errC <- cmd.ExecuteContext(ctx)
}()
inv, _ := clitest.New(t, "agent", "--auth", "azure-instance-identity", "--agent-url", client.URL.String())
inv = inv.WithContext(
//nolint:revive,staticcheck
context.WithValue(inv.Context(), "azure-client", metadataClient),
)
ctx := inv.Context()
clitest.Start(t, inv)
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
workspace, err := client.Workspace(ctx, workspace.ID)
require.NoError(t, err)
@@ -71,13 +112,7 @@ func TestWorkspaceAgent(t *testing.T) {
dialer, err := client.DialWorkspaceAgent(ctx, resources[0].Agents[0].ID, nil)
require.NoError(t, err)
defer dialer.Close()
require.Eventually(t, func() bool {
_, err := dialer.Ping(ctx)
return err == nil
}, testutil.WaitMedium, testutil.IntervalFast)
cancelFunc()
err = <-errC
require.NoError(t, err)
require.True(t, dialer.AwaitReachable(ctx))
})
t.Run("AWS", func(t *testing.T) {
@@ -91,7 +126,7 @@ func TestWorkspaceAgent(t *testing.T) {
user := coderdtest.CreateFirstUser(t, client)
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
Parse: echo.ParseComplete,
Provision: []*proto.Provision_Response{{
ProvisionApply: []*proto.Provision_Response{{
Type: &proto.Provision_Response_Complete{
Complete: &proto.Provision_Complete{
Resources: []*proto.Resource{{
@@ -112,16 +147,13 @@ func TestWorkspaceAgent(t *testing.T) {
workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
cmd, _ := clitest.New(t, "agent", "--auth", "aws-instance-identity", "--agent-url", client.URL.String())
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
errC := make(chan error)
go func() {
// A linting error occurs for weakly typing the context value here.
//nolint // The above seems reasonable for a one-off test.
ctx := context.WithValue(ctx, "aws-client", metadataClient)
errC <- cmd.ExecuteContext(ctx)
}()
inv, _ := clitest.New(t, "agent", "--auth", "aws-instance-identity", "--agent-url", client.URL.String())
inv = inv.WithContext(
//nolint:revive,staticcheck
context.WithValue(inv.Context(), "aws-client", metadataClient),
)
clitest.Start(t, inv)
ctx := inv.Context()
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
workspace, err := client.Workspace(ctx, workspace.ID)
require.NoError(t, err)
@@ -132,19 +164,13 @@ func TestWorkspaceAgent(t *testing.T) {
dialer, err := client.DialWorkspaceAgent(ctx, resources[0].Agents[0].ID, nil)
require.NoError(t, err)
defer dialer.Close()
require.Eventually(t, func() bool {
_, err := dialer.Ping(ctx)
return err == nil
}, testutil.WaitMedium, testutil.IntervalFast)
cancelFunc()
err = <-errC
require.NoError(t, err)
require.True(t, dialer.AwaitReachable(ctx))
})
t.Run("GoogleCloud", func(t *testing.T) {
t.Parallel()
instanceID := "instanceidentifier"
validator, metadata := coderdtest.NewGoogleInstanceIdentity(t, instanceID, false)
validator, metadataClient := coderdtest.NewGoogleInstanceIdentity(t, instanceID, false)
client := coderdtest.New(t, &coderdtest.Options{
GoogleTokenValidator: validator,
IncludeProvisionerDaemon: true,
@@ -152,7 +178,7 @@ func TestWorkspaceAgent(t *testing.T) {
user := coderdtest.CreateFirstUser(t, client)
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
Parse: echo.ParseComplete,
Provision: []*proto.Provision_Response{{
ProvisionApply: []*proto.Provision_Response{{
Type: &proto.Provision_Response_Complete{
Complete: &proto.Provision_Complete{
Resources: []*proto.Resource{{
@@ -173,16 +199,18 @@ func TestWorkspaceAgent(t *testing.T) {
workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
cmd, _ := clitest.New(t, "agent", "--auth", "google-instance-identity", "--agent-url", client.URL.String())
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
errC := make(chan error)
go func() {
// A linting error occurs for weakly typing the context value here.
//nolint // The above seems reasonable for a one-off test.
ctx := context.WithValue(ctx, "gcp-client", metadata)
errC <- cmd.ExecuteContext(ctx)
}()
inv, cfg := clitest.New(t, "agent", "--auth", "google-instance-identity", "--agent-url", client.URL.String())
ptytest.New(t).Attach(inv)
clitest.SetupConfig(t, client, cfg)
clitest.Start(t,
inv.WithContext(
//nolint:revive,staticcheck
context.WithValue(inv.Context(), "gcp-client", metadataClient),
),
)
ctx := inv.Context()
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
workspace, err := client.Workspace(ctx, workspace.ID)
require.NoError(t, err)
@@ -193,12 +221,8 @@ func TestWorkspaceAgent(t *testing.T) {
dialer, err := client.DialWorkspaceAgent(ctx, resources[0].Agents[0].ID, nil)
require.NoError(t, err)
defer dialer.Close()
require.Eventually(t, func() bool {
_, err := dialer.Ping(ctx)
return err == nil
}, testutil.WaitMedium, testutil.IntervalFast)
sshClient, err := dialer.SSHClient()
require.True(t, dialer.AwaitReachable(ctx))
sshClient, err := dialer.SSHClient(ctx)
require.NoError(t, err)
defer sshClient.Close()
session, err := sshClient.NewSession()
@@ -213,9 +237,44 @@ func TestWorkspaceAgent(t *testing.T) {
require.NoError(t, err)
_, err = uuid.Parse(strings.TrimSpace(string(token)))
require.NoError(t, err)
})
cancelFunc()
err = <-errC
require.NoError(t, err)
t.Run("PostStartup", func(t *testing.T) {
t.Parallel()
authToken := uuid.NewString()
client := coderdtest.New(t, &coderdtest.Options{
IncludeProvisionerDaemon: true,
})
user := coderdtest.CreateFirstUser(t, client)
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
Parse: echo.ParseComplete,
ProvisionApply: echo.ProvisionApplyWithAgent(authToken),
})
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
logDir := t.TempDir()
inv, _ := clitest.New(t,
"agent",
"--auth", "token",
"--agent-token", authToken,
"--agent-url", client.URL.String(),
"--log-dir", logDir,
)
// Set the subsystem for the agent.
inv.Environ.Set(agent.EnvAgentSubsystem, string(codersdk.AgentSubsystemEnvbox))
pty := ptytest.New(t).Attach(inv)
clitest.Start(t, inv)
pty.ExpectMatchContext(inv.Context(), "agent is starting now")
resources := coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
require.Len(t, resources, 1)
require.Len(t, resources[0].Agents, 1)
require.Equal(t, codersdk.AgentSubsystemEnvbox, resources[0].Agents[0].Subsystem)
})
}
-38
View File
@@ -1,38 +0,0 @@
//go:build !windows
package cli
import (
"context"
"os"
"os/signal"
"syscall"
"cdr.dev/slog"
)
func agentStartPPROFOnUSR1(ctx context.Context, logger slog.Logger, pprofAddress string) (srvClose func()) {
ctx, cancel := context.WithCancel(ctx)
usr1 := make(chan os.Signal, 1)
signal.Notify(usr1, syscall.SIGUSR1)
go func() {
defer close(usr1)
defer signal.Stop(usr1)
select {
case <-usr1:
signal.Stop(usr1)
srvClose := serveHandler(ctx, logger, nil, pprofAddress, "pprof")
defer srvClose()
case <-ctx.Done():
return
}
<-ctx.Done() // Prevent defer close until done.
}()
return func() {
cancel()
<-usr1 // Wait until usr1 is closed, ensures srvClose was run.
}
}
-12
View File
@@ -1,12 +0,0 @@
package cli
import (
"context"
"cdr.dev/slog"
)
// agentStartPPROFOnUSR1 is no-op on Windows (no SIGUSR1 signal).
func agentStartPPROFOnUSR1(ctx context.Context, logger slog.Logger, pprofAddress string) (srvClose func()) {
return func() {}
}
+80
View File
@@ -0,0 +1,80 @@
// Package clibase offers an all-in-one solution for a highly configurable CLI
// application. Within Coder, we use it for all of our subcommands, which
// demands more functionality than cobra/viber offers.
//
// The Command interface is loosely based on the chi middleware pattern and
// http.Handler/HandlerFunc.
package clibase
import (
"strings"
"golang.org/x/exp/maps"
)
// Group describes a hierarchy of groups that an option or command belongs to.
type Group struct {
Parent *Group `json:"parent,omitempty"`
Name string `json:"name,omitempty"`
YAML string `json:"yaml,omitempty"`
Description string `json:"description,omitempty"`
}
// Ancestry returns the group and all of its parents, in order.
func (g *Group) Ancestry() []Group {
if g == nil {
return nil
}
groups := []Group{*g}
for p := g.Parent; p != nil; p = p.Parent {
// Prepend to the slice so that the order is correct.
groups = append([]Group{*p}, groups...)
}
return groups
}
func (g *Group) FullName() string {
var names []string
for _, g := range g.Ancestry() {
names = append(names, g.Name)
}
return strings.Join(names, " / ")
}
// Annotations is an arbitrary key-mapping used to extend the Option and Command types.
// Its methods won't panic if the map is nil.
type Annotations map[string]string
// Mark sets a value on the annotations map, creating one
// if it doesn't exist. Mark does not mutate the original and
// returns a copy. It is suitable for chaining.
func (a Annotations) Mark(key string, value string) Annotations {
var aa Annotations
if a != nil {
aa = maps.Clone(a)
} else {
aa = make(Annotations)
}
aa[key] = value
return aa
}
// IsSet returns true if the key is set in the annotations map.
func (a Annotations) IsSet(key string) bool {
if a == nil {
return false
}
_, ok := a[key]
return ok
}
// Get retrieves a key from the map, returning false if the key is not found
// or the map is nil.
func (a Annotations) Get(key string) (string, bool) {
if a == nil {
return "", false
}
v, ok := a[key]
return v, ok
}
+567
View File
@@ -0,0 +1,567 @@
package clibase
import (
"context"
"errors"
"flag"
"fmt"
"io"
"os"
"strings"
"unicode"
"github.com/spf13/pflag"
"golang.org/x/exp/slices"
"golang.org/x/xerrors"
"gopkg.in/yaml.v3"
)
// Cmd describes an executable command.
type Cmd struct {
// Parent is the direct parent of the command.
Parent *Cmd
// Children is a list of direct descendants.
Children []*Cmd
// Use is provided in form "command [flags] [args...]".
Use string
// Aliases is a list of alternative names for the command.
Aliases []string
// Short is a one-line description of the command.
Short string
// Hidden determines whether the command should be hidden from help.
Hidden bool
// RawArgs determines whether the command should receive unparsed arguments.
// No flags are parsed when set, and the command is responsible for parsing
// its own flags.
RawArgs bool
// Long is a detailed description of the command,
// presented on its help page. It may contain examples.
Long string
Options OptionSet
Annotations Annotations
// Middleware is called before the Handler.
// Use Chain() to combine multiple middlewares.
Middleware MiddlewareFunc
Handler HandlerFunc
HelpHandler HandlerFunc
}
// AddSubcommands adds the given subcommands, setting their
// Parent field automatically.
func (c *Cmd) AddSubcommands(cmds ...*Cmd) {
for _, cmd := range cmds {
cmd.Parent = c
c.Children = append(c.Children, cmd)
}
}
// Walk calls fn for the command and all its children.
func (c *Cmd) Walk(fn func(*Cmd)) {
fn(c)
for _, child := range c.Children {
child.Parent = c
child.Walk(fn)
}
}
// PrepareAll performs initialization and linting on the command and all its children.
func (c *Cmd) PrepareAll() error {
if c.Use == "" {
return xerrors.New("command must have a Use field so that it has a name")
}
var merr error
for i := range c.Options {
opt := &c.Options[i]
if opt.Name == "" {
switch {
case opt.Flag != "":
opt.Name = opt.Flag
case opt.Env != "":
opt.Name = opt.Env
case opt.YAML != "":
opt.Name = opt.YAML
default:
merr = errors.Join(merr, xerrors.Errorf("option must have a Name, Flag, Env or YAML field"))
}
}
if opt.Description != "" {
// Enforce that description uses sentence form.
if unicode.IsLower(rune(opt.Description[0])) {
merr = errors.Join(merr, xerrors.Errorf("option %q description should start with a capital letter", opt.Name))
}
if !strings.HasSuffix(opt.Description, ".") {
merr = errors.Join(merr, xerrors.Errorf("option %q description should end with a period", opt.Name))
}
}
}
slices.SortFunc(c.Options, func(a, b Option) bool {
return a.Name < b.Name
})
slices.SortFunc(c.Children, func(a, b *Cmd) bool {
return a.Name() < b.Name()
})
for _, child := range c.Children {
child.Parent = c
err := child.PrepareAll()
if err != nil {
merr = errors.Join(merr, xerrors.Errorf("command %v: %w", child.Name(), err))
}
}
return merr
}
// Name returns the first word in the Use string.
func (c *Cmd) Name() string {
return strings.Split(c.Use, " ")[0]
}
// FullName returns the full invocation name of the command,
// as seen on the command line.
func (c *Cmd) FullName() string {
var names []string
if c.Parent != nil {
names = append(names, c.Parent.FullName())
}
names = append(names, c.Name())
return strings.Join(names, " ")
}
// FullName returns usage of the command, preceded
// by the usage of its parents.
func (c *Cmd) FullUsage() string {
var uses []string
if c.Parent != nil {
uses = append(uses, c.Parent.FullName())
}
uses = append(uses, c.Use)
return strings.Join(uses, " ")
}
// FullOptions returns the options of the command and its parents.
func (c *Cmd) FullOptions() OptionSet {
var opts OptionSet
if c.Parent != nil {
opts = append(opts, c.Parent.FullOptions()...)
}
opts = append(opts, c.Options...)
return opts
}
// Invoke creates a new invocation of the command, with
// stdio discarded.
//
// The returned invocation is not live until Run() is called.
func (c *Cmd) Invoke(args ...string) *Invocation {
return &Invocation{
Command: c,
Args: args,
Stdout: io.Discard,
Stderr: io.Discard,
Stdin: strings.NewReader(""),
}
}
// Invocation represents an instance of a command being executed.
type Invocation struct {
ctx context.Context
Command *Cmd
parsedFlags *pflag.FlagSet
Args []string
// Environ is a list of environment variables. Use EnvsWithPrefix to parse
// os.Environ.
Environ Environ
Stdout io.Writer
Stderr io.Writer
Stdin io.Reader
}
// WithOS returns the invocation as a main package, filling in the invocation's unset
// fields with OS defaults.
func (inv *Invocation) WithOS() *Invocation {
return inv.with(func(i *Invocation) {
i.Stdout = os.Stdout
i.Stderr = os.Stderr
i.Stdin = os.Stdin
i.Args = os.Args[1:]
i.Environ = ParseEnviron(os.Environ(), "")
})
}
func (inv *Invocation) Context() context.Context {
if inv.ctx == nil {
return context.Background()
}
return inv.ctx
}
func (inv *Invocation) ParsedFlags() *pflag.FlagSet {
if inv.parsedFlags == nil {
panic("flags not parsed, has Run() been called?")
}
return inv.parsedFlags
}
type runState struct {
allArgs []string
commandDepth int
flagParseErr error
}
func copyFlagSetWithout(fs *pflag.FlagSet, without string) *pflag.FlagSet {
fs2 := pflag.NewFlagSet("", pflag.ContinueOnError)
fs2.Usage = func() {}
fs.VisitAll(func(f *pflag.Flag) {
if f.Name == without {
return
}
fs2.AddFlag(f)
})
return fs2
}
// run recursively executes the command and its children.
// allArgs is wired through the stack so that global flags can be accepted
// anywhere in the command invocation.
func (inv *Invocation) run(state *runState) error {
err := inv.Command.Options.ParseEnv(inv.Environ)
if err != nil {
return xerrors.Errorf("parsing env: %w", err)
}
// Now the fun part, argument parsing!
children := make(map[string]*Cmd)
for _, child := range inv.Command.Children {
child.Parent = inv.Command
for _, name := range append(child.Aliases, child.Name()) {
if _, ok := children[name]; ok {
return xerrors.Errorf("duplicate command name: %s", name)
}
children[name] = child
}
}
if inv.parsedFlags == nil {
inv.parsedFlags = pflag.NewFlagSet(inv.Command.Name(), pflag.ContinueOnError)
// We handle Usage ourselves.
inv.parsedFlags.Usage = func() {}
}
// If we find a duplicate flag, we want the deeper command's flag to override
// the shallow one. Unfortunately, pflag has no way to remove a flag, so we
// have to create a copy of the flagset without a value.
inv.Command.Options.FlagSet().VisitAll(func(f *pflag.Flag) {
if inv.parsedFlags.Lookup(f.Name) != nil {
inv.parsedFlags = copyFlagSetWithout(inv.parsedFlags, f.Name)
}
inv.parsedFlags.AddFlag(f)
})
var parsedArgs []string
if !inv.Command.RawArgs {
// Flag parsing will fail on intermediate commands in the command tree,
// so we check the error after looking for a child command.
state.flagParseErr = inv.parsedFlags.Parse(state.allArgs)
parsedArgs = inv.parsedFlags.Args()
}
// Set value sources for flags.
for i, opt := range inv.Command.Options {
if fl := inv.parsedFlags.Lookup(opt.Flag); fl != nil && fl.Changed {
inv.Command.Options[i].ValueSource = ValueSourceFlag
}
}
// Read YAML configs, if any.
for _, opt := range inv.Command.Options {
path, ok := opt.Value.(*YAMLConfigPath)
if !ok || path.String() == "" {
continue
}
byt, err := os.ReadFile(path.String())
if err != nil {
return xerrors.Errorf("reading yaml: %w", err)
}
var n yaml.Node
err = yaml.Unmarshal(byt, &n)
if err != nil {
return xerrors.Errorf("decoding yaml: %w", err)
}
err = inv.Command.Options.UnmarshalYAML(&n)
if err != nil {
return xerrors.Errorf("applying yaml: %w", err)
}
}
err = inv.Command.Options.SetDefaults()
if err != nil {
return xerrors.Errorf("setting defaults: %w", err)
}
// Run child command if found (next child only)
// We must do subcommand detection after flag parsing so we don't mistake flag
// values for subcommand names.
if len(parsedArgs) > state.commandDepth {
nextArg := parsedArgs[state.commandDepth]
if child, ok := children[nextArg]; ok {
child.Parent = inv.Command
inv.Command = child
state.commandDepth++
return inv.run(state)
}
}
// Flag parse errors are irrelevant for raw args commands.
if !inv.Command.RawArgs && state.flagParseErr != nil && !errors.Is(state.flagParseErr, pflag.ErrHelp) {
return xerrors.Errorf(
"parsing flags (%v) for %q: %w",
state.allArgs,
inv.Command.FullName(), state.flagParseErr,
)
}
if inv.Command.RawArgs {
// If we're at the root command, then the name is omitted
// from the arguments, so we can just use the entire slice.
if state.commandDepth == 0 {
inv.Args = state.allArgs
} else {
argPos, err := findArg(inv.Command.Name(), state.allArgs, inv.parsedFlags)
if err != nil {
panic(err)
}
inv.Args = state.allArgs[argPos+1:]
}
} else {
// In non-raw-arg mode, we want to skip over flags.
inv.Args = parsedArgs[state.commandDepth:]
}
mw := inv.Command.Middleware
if mw == nil {
mw = Chain()
}
ctx := inv.ctx
if ctx == nil {
ctx = context.Background()
}
ctx, cancel := context.WithCancel(ctx)
defer cancel()
inv = inv.WithContext(ctx)
if inv.Command.Handler == nil || errors.Is(state.flagParseErr, pflag.ErrHelp) {
if inv.Command.HelpHandler == nil {
return xerrors.Errorf("no handler or help for command %s", inv.Command.FullName())
}
return inv.Command.HelpHandler(inv)
}
err = mw(inv.Command.Handler)(inv)
if err != nil {
return &RunCommandError{
Cmd: inv.Command,
Err: err,
}
}
return nil
}
type RunCommandError struct {
Cmd *Cmd
Err error
}
func (e *RunCommandError) Unwrap() error {
return e.Err
}
func (e *RunCommandError) Error() string {
return fmt.Sprintf("running command %q: %+v", e.Cmd.FullName(), e.Err)
}
// findArg returns the index of the first occurrence of arg in args, skipping
// over all flags.
func findArg(want string, args []string, fs *pflag.FlagSet) (int, error) {
for i := 0; i < len(args); i++ {
arg := args[i]
if !strings.HasPrefix(arg, "-") {
if arg == want {
return i, nil
}
continue
}
// This is a flag!
if strings.Contains(arg, "=") {
// The flag contains the value in the same arg, just skip.
continue
}
// We need to check if NoOptValue is set, then we should not wait
// for the next arg to be the value.
f := fs.Lookup(strings.TrimLeft(arg, "-"))
if f == nil {
return -1, xerrors.Errorf("unknown flag: %s", arg)
}
if f.NoOptDefVal != "" {
continue
}
if i == len(args)-1 {
return -1, xerrors.Errorf("flag %s requires a value", arg)
}
// Skip the value.
i++
}
return -1, xerrors.Errorf("arg %s not found", want)
}
// Run executes the command.
// If two command share a flag name, the first command wins.
//
//nolint:revive
func (inv *Invocation) Run() (err error) {
defer func() {
// Pflag is panicky, so additional context is helpful in tests.
if flag.Lookup("test.v") == nil {
return
}
if r := recover(); r != nil {
err = xerrors.Errorf("panic recovered for %s: %v", inv.Command.FullName(), r)
panic(err)
}
}()
// We close Stdin to prevent deadlocks, e.g. when the command
// has ended but an io.Copy is still reading from Stdin.
defer func() {
if inv.Stdin == nil {
return
}
rc, ok := inv.Stdin.(io.ReadCloser)
if !ok {
return
}
e := rc.Close()
err = errors.Join(err, e)
}()
err = inv.run(&runState{
allArgs: inv.Args,
})
return err
}
// WithContext returns a copy of the Invocation with the given context.
func (inv *Invocation) WithContext(ctx context.Context) *Invocation {
return inv.with(func(i *Invocation) {
i.ctx = ctx
})
}
// with returns a copy of the Invocation with the given function applied.
func (inv *Invocation) with(fn func(*Invocation)) *Invocation {
i2 := *inv
fn(&i2)
return &i2
}
// MiddlewareFunc returns the next handler in the chain,
// or nil if there are no more.
type MiddlewareFunc func(next HandlerFunc) HandlerFunc
func chain(ms ...MiddlewareFunc) MiddlewareFunc {
return MiddlewareFunc(func(next HandlerFunc) HandlerFunc {
if len(ms) > 0 {
return chain(ms[1:]...)(ms[0](next))
}
return next
})
}
// Chain returns a Handler that first calls middleware in order.
//
//nolint:revive
func Chain(ms ...MiddlewareFunc) MiddlewareFunc {
// We need to reverse the array to provide top-to-bottom execution
// order when defining a command.
reversed := make([]MiddlewareFunc, len(ms))
for i := range ms {
reversed[len(ms)-1-i] = ms[i]
}
return chain(reversed...)
}
func RequireNArgs(want int) MiddlewareFunc {
return RequireRangeArgs(want, want)
}
// RequireRangeArgs returns a Middleware that requires the number of arguments
// to be between start and end (inclusive). If end is -1, then the number of
// arguments must be at least start.
func RequireRangeArgs(start, end int) MiddlewareFunc {
if start < 0 {
panic("start must be >= 0")
}
return func(next HandlerFunc) HandlerFunc {
return func(i *Invocation) error {
got := len(i.Args)
switch {
case start == end && got != start:
switch start {
case 0:
if len(i.Command.Children) > 0 {
return xerrors.Errorf("unrecognized subcommand %q", i.Args[0])
}
return xerrors.Errorf("wanted no args but got %v %v", got, i.Args)
default:
return xerrors.Errorf(
"wanted %v args but got %v %v",
start,
got,
i.Args,
)
}
case start > 0 && end == -1:
switch {
case got < start:
return xerrors.Errorf(
"wanted at least %v args but got %v",
start,
got,
)
default:
return next(i)
}
case start > end:
panic("start must be <= end")
case got < start || got > end:
return xerrors.Errorf(
"wanted between %v and %v args but got %v",
start, end,
got,
)
default:
return next(i)
}
}
}
}
// HandlerFunc handles an Invocation of a command.
type HandlerFunc func(i *Invocation) error
+635
View File
@@ -0,0 +1,635 @@
package clibase_test
import (
"bytes"
"context"
"fmt"
"os"
"strings"
"testing"
"github.com/stretchr/testify/require"
"golang.org/x/xerrors"
"github.com/coder/coder/cli/clibase"
)
// ioBufs is the standard input, output, and error for a command.
type ioBufs struct {
Stdin bytes.Buffer
Stdout bytes.Buffer
Stderr bytes.Buffer
}
// fakeIO sets Stdin, Stdout, and Stderr to buffers.
func fakeIO(i *clibase.Invocation) *ioBufs {
var b ioBufs
i.Stdout = &b.Stdout
i.Stderr = &b.Stderr
i.Stdin = &b.Stdin
return &b
}
func TestCommand(t *testing.T) {
t.Parallel()
cmd := func() *clibase.Cmd {
var (
verbose bool
lower bool
prefix string
)
return &clibase.Cmd{
Use: "root [subcommand]",
Options: clibase.OptionSet{
clibase.Option{
Name: "verbose",
Flag: "verbose",
Value: clibase.BoolOf(&verbose),
},
clibase.Option{
Name: "prefix",
Flag: "prefix",
Value: clibase.StringOf(&prefix),
},
},
Children: []*clibase.Cmd{
{
Use: "toupper [word]",
Short: "Converts a word to upper case",
Middleware: clibase.Chain(
clibase.RequireNArgs(1),
),
Aliases: []string{"up"},
Options: clibase.OptionSet{
clibase.Option{
Name: "lower",
Flag: "lower",
Value: clibase.BoolOf(&lower),
},
},
Handler: (func(i *clibase.Invocation) error {
i.Stdout.Write([]byte(prefix))
w := i.Args[0]
if lower {
w = strings.ToLower(w)
} else {
w = strings.ToUpper(w)
}
_, _ = i.Stdout.Write(
[]byte(
w,
),
)
if verbose {
i.Stdout.Write([]byte("!!!"))
}
return nil
}),
},
},
}
}
t.Run("SimpleOK", func(t *testing.T) {
t.Parallel()
i := cmd().Invoke("toupper", "hello")
io := fakeIO(i)
i.Run()
require.Equal(t, "HELLO", io.Stdout.String())
})
t.Run("Alias", func(t *testing.T) {
t.Parallel()
i := cmd().Invoke(
"up", "hello",
)
io := fakeIO(i)
i.Run()
require.Equal(t, "HELLO", io.Stdout.String())
})
t.Run("NoSubcommand", func(t *testing.T) {
t.Parallel()
i := cmd().Invoke(
"na",
)
io := fakeIO(i)
err := i.Run()
require.Empty(t, io.Stdout.String())
require.Error(t, err)
})
t.Run("BadArgs", func(t *testing.T) {
t.Parallel()
i := cmd().Invoke(
"toupper",
)
io := fakeIO(i)
err := i.Run()
require.Empty(t, io.Stdout.String())
require.Error(t, err)
})
t.Run("UnknownFlags", func(t *testing.T) {
t.Parallel()
i := cmd().Invoke(
"toupper", "--unknown",
)
io := fakeIO(i)
err := i.Run()
require.Empty(t, io.Stdout.String())
require.Error(t, err)
})
t.Run("Verbose", func(t *testing.T) {
t.Parallel()
i := cmd().Invoke(
"--verbose", "toupper", "hello",
)
io := fakeIO(i)
require.NoError(t, i.Run())
require.Equal(t, "HELLO!!!", io.Stdout.String())
})
t.Run("Verbose=", func(t *testing.T) {
t.Parallel()
i := cmd().Invoke(
"--verbose=true", "toupper", "hello",
)
io := fakeIO(i)
require.NoError(t, i.Run())
require.Equal(t, "HELLO!!!", io.Stdout.String())
})
t.Run("PrefixSpace", func(t *testing.T) {
t.Parallel()
i := cmd().Invoke(
"--prefix", "conv: ", "toupper", "hello",
)
io := fakeIO(i)
require.NoError(t, i.Run())
require.Equal(t, "conv: HELLO", io.Stdout.String())
})
t.Run("GlobalFlagsAnywhere", func(t *testing.T) {
t.Parallel()
i := cmd().Invoke(
"toupper", "--prefix", "conv: ", "hello", "--verbose",
)
io := fakeIO(i)
require.NoError(t, i.Run())
require.Equal(t, "conv: HELLO!!!", io.Stdout.String())
})
t.Run("LowerVerbose", func(t *testing.T) {
t.Parallel()
i := cmd().Invoke(
"toupper", "--verbose", "hello", "--lower",
)
io := fakeIO(i)
require.NoError(t, i.Run())
require.Equal(t, "hello!!!", io.Stdout.String())
})
t.Run("ParsedFlags", func(t *testing.T) {
t.Parallel()
i := cmd().Invoke(
"toupper", "--verbose", "hello", "--lower",
)
_ = fakeIO(i)
require.NoError(t, i.Run())
require.Equal(t,
"true",
i.ParsedFlags().Lookup("verbose").Value.String(),
)
})
t.Run("NoDeepChild", func(t *testing.T) {
t.Parallel()
i := cmd().Invoke(
"root", "level", "level", "toupper", "--verbose", "hello", "--lower",
)
fio := fakeIO(i)
require.Error(t, i.Run(), fio.Stdout.String())
})
}
func TestCommand_DeepNest(t *testing.T) {
t.Parallel()
cmd := &clibase.Cmd{
Use: "1",
Children: []*clibase.Cmd{
{
Use: "2",
Children: []*clibase.Cmd{
{
Use: "3",
Handler: func(i *clibase.Invocation) error {
i.Stdout.Write([]byte("3"))
return nil
},
},
},
},
},
}
inv := cmd.Invoke("2", "3")
stdio := fakeIO(inv)
err := inv.Run()
require.NoError(t, err)
require.Equal(t, "3", stdio.Stdout.String())
}
func TestCommand_FlagOverride(t *testing.T) {
t.Parallel()
var flag string
cmd := &clibase.Cmd{
Use: "1",
Options: clibase.OptionSet{
{
Name: "flag",
Flag: "f",
Value: clibase.DiscardValue,
},
},
Children: []*clibase.Cmd{
{
Use: "2",
Options: clibase.OptionSet{
{
Name: "flag",
Flag: "f",
Value: clibase.StringOf(&flag),
},
},
Handler: func(i *clibase.Invocation) error {
return nil
},
},
},
}
err := cmd.Invoke("2", "--f", "mhmm").Run()
require.NoError(t, err)
require.Equal(t, "mhmm", flag)
}
func TestCommand_MiddlewareOrder(t *testing.T) {
t.Parallel()
mw := func(letter string) clibase.MiddlewareFunc {
return func(next clibase.HandlerFunc) clibase.HandlerFunc {
return (func(i *clibase.Invocation) error {
_, _ = i.Stdout.Write([]byte(letter))
return next(i)
})
}
}
cmd := &clibase.Cmd{
Use: "toupper [word]",
Short: "Converts a word to upper case",
Middleware: clibase.Chain(
mw("A"),
mw("B"),
mw("C"),
),
Handler: (func(i *clibase.Invocation) error {
return nil
}),
}
i := cmd.Invoke(
"hello", "world",
)
io := fakeIO(i)
require.NoError(t, i.Run())
require.Equal(t, "ABC", io.Stdout.String())
}
func TestCommand_RawArgs(t *testing.T) {
t.Parallel()
cmd := func() *clibase.Cmd {
return &clibase.Cmd{
Use: "root",
Options: clibase.OptionSet{
{
Name: "password",
Flag: "password",
Value: clibase.StringOf(new(string)),
},
},
Children: []*clibase.Cmd{
{
Use: "sushi <args...>",
Short: "Throws back raw output",
RawArgs: true,
Handler: (func(i *clibase.Invocation) error {
if v := i.ParsedFlags().Lookup("password").Value.String(); v != "codershack" {
return xerrors.Errorf("password %q is wrong!", v)
}
i.Stdout.Write([]byte(strings.Join(i.Args, " ")))
return nil
}),
},
},
}
}
t.Run("OK", func(t *testing.T) {
// Flag parsed before the raw arg command should still work.
t.Parallel()
i := cmd().Invoke(
"--password", "codershack", "sushi", "hello", "--verbose", "world",
)
io := fakeIO(i)
require.NoError(t, i.Run())
require.Equal(t, "hello --verbose world", io.Stdout.String())
})
t.Run("BadFlag", func(t *testing.T) {
// Verbose before the raw arg command should fail.
t.Parallel()
i := cmd().Invoke(
"--password", "codershack", "--verbose", "sushi", "hello", "world",
)
io := fakeIO(i)
require.Error(t, i.Run())
require.Empty(t, io.Stdout.String())
})
t.Run("NoPassword", func(t *testing.T) {
// Flag parsed before the raw arg command should still work.
t.Parallel()
i := cmd().Invoke(
"sushi", "hello", "--verbose", "world",
)
_ = fakeIO(i)
require.Error(t, i.Run())
})
}
func TestCommand_RootRaw(t *testing.T) {
t.Parallel()
cmd := &clibase.Cmd{
RawArgs: true,
Handler: func(i *clibase.Invocation) error {
i.Stdout.Write([]byte(strings.Join(i.Args, " ")))
return nil
},
}
inv := cmd.Invoke("hello", "--verbose", "--friendly")
stdio := fakeIO(inv)
err := inv.Run()
require.NoError(t, err)
require.Equal(t, "hello --verbose --friendly", stdio.Stdout.String())
}
func TestCommand_HyphenHyphen(t *testing.T) {
t.Parallel()
cmd := &clibase.Cmd{
Handler: (func(i *clibase.Invocation) error {
i.Stdout.Write([]byte(strings.Join(i.Args, " ")))
return nil
}),
}
inv := cmd.Invoke("--", "--verbose", "--friendly")
stdio := fakeIO(inv)
err := inv.Run()
require.NoError(t, err)
require.Equal(t, "--verbose --friendly", stdio.Stdout.String())
}
func TestCommand_ContextCancels(t *testing.T) {
t.Parallel()
var gotCtx context.Context
cmd := &clibase.Cmd{
Handler: (func(i *clibase.Invocation) error {
gotCtx = i.Context()
if err := gotCtx.Err(); err != nil {
return xerrors.Errorf("unexpected context error: %w", i.Context().Err())
}
return nil
}),
}
err := cmd.Invoke().Run()
require.NoError(t, err)
require.Error(t, gotCtx.Err())
}
func TestCommand_Help(t *testing.T) {
t.Parallel()
cmd := func() *clibase.Cmd {
return &clibase.Cmd{
Use: "root",
HelpHandler: (func(i *clibase.Invocation) error {
i.Stdout.Write([]byte("abdracadabra"))
return nil
}),
Handler: (func(i *clibase.Invocation) error {
return xerrors.New("should not be called")
}),
}
}
t.Run("NoHandler", func(t *testing.T) {
t.Parallel()
c := cmd()
c.HelpHandler = nil
err := c.Invoke("--help").Run()
require.Error(t, err)
})
t.Run("Long", func(t *testing.T) {
t.Parallel()
inv := cmd().Invoke("--help")
stdio := fakeIO(inv)
err := inv.Run()
require.NoError(t, err)
require.Contains(t, stdio.Stdout.String(), "abdracadabra")
})
t.Run("Short", func(t *testing.T) {
t.Parallel()
inv := cmd().Invoke("-h")
stdio := fakeIO(inv)
err := inv.Run()
require.NoError(t, err)
require.Contains(t, stdio.Stdout.String(), "abdracadabra")
})
}
func TestCommand_SliceFlags(t *testing.T) {
t.Parallel()
cmd := func(want ...string) *clibase.Cmd {
var got []string
return &clibase.Cmd{
Use: "root",
Options: clibase.OptionSet{
{
Name: "arr",
Flag: "arr",
Default: "bad,bad,bad",
Value: clibase.StringArrayOf(&got),
},
},
Handler: (func(i *clibase.Invocation) error {
require.Equal(t, want, got)
return nil
}),
}
}
err := cmd("good", "good", "good").Invoke("--arr", "good", "--arr", "good", "--arr", "good").Run()
require.NoError(t, err)
err = cmd("bad", "bad", "bad").Invoke().Run()
require.NoError(t, err)
}
func TestCommand_EmptySlice(t *testing.T) {
t.Parallel()
cmd := func(want ...string) *clibase.Cmd {
var got []string
return &clibase.Cmd{
Use: "root",
Options: clibase.OptionSet{
{
Name: "arr",
Flag: "arr",
Default: "def,def,def",
Env: "ARR",
Value: clibase.StringArrayOf(&got),
},
},
Handler: (func(i *clibase.Invocation) error {
require.Equal(t, want, got)
return nil
}),
}
}
// Base-case, uses default.
err := cmd("def", "def", "def").Invoke().Run()
require.NoError(t, err)
// Empty-env uses default, too.
inv := cmd("def", "def", "def").Invoke()
inv.Environ.Set("ARR", "")
require.NoError(t, err)
// Reset to nothing at all via flag.
inv = cmd().Invoke("--arr", "")
inv.Environ.Set("ARR", "cant see")
err = inv.Run()
require.NoError(t, err)
// Reset to a specific value with flag.
inv = cmd("great").Invoke("--arr", "great")
inv.Environ.Set("ARR", "")
err = inv.Run()
require.NoError(t, err)
}
func TestCommand_DefaultsOverride(t *testing.T) {
t.Parallel()
test := func(name string, want string, fn func(t *testing.T, inv *clibase.Invocation)) {
t.Run(name, func(t *testing.T) {
t.Parallel()
var (
got string
config clibase.YAMLConfigPath
)
cmd := &clibase.Cmd{
Options: clibase.OptionSet{
{
Name: "url",
Flag: "url",
Default: "def.com",
Env: "URL",
Value: clibase.StringOf(&got),
YAML: "url",
},
{
Name: "config",
Flag: "config",
Default: "",
Value: &config,
},
},
Handler: (func(i *clibase.Invocation) error {
_, _ = fmt.Fprintf(i.Stdout, "%s", got)
return nil
}),
}
inv := cmd.Invoke()
stdio := fakeIO(inv)
fn(t, inv)
err := inv.Run()
require.NoError(t, err)
require.Equal(t, want, stdio.Stdout.String())
})
}
test("DefaultOverNothing", "def.com", func(t *testing.T, inv *clibase.Invocation) {})
test("FlagOverDefault", "good.com", func(t *testing.T, inv *clibase.Invocation) {
inv.Args = []string{"--url", "good.com"}
})
test("EnvOverDefault", "good.com", func(t *testing.T, inv *clibase.Invocation) {
inv.Environ.Set("URL", "good.com")
})
test("FlagOverEnv", "good.com", func(t *testing.T, inv *clibase.Invocation) {
inv.Environ.Set("URL", "bad.com")
inv.Args = []string{"--url", "good.com"}
})
test("FlagOverYAML", "good.com", func(t *testing.T, inv *clibase.Invocation) {
fi, err := os.CreateTemp(t.TempDir(), "config.yaml")
require.NoError(t, err)
defer fi.Close()
_, err = fi.WriteString("url: bad.com")
require.NoError(t, err)
inv.Args = []string{"--config", fi.Name(), "--url", "good.com"}
})
test("YAMLOverDefault", "good.com", func(t *testing.T, inv *clibase.Invocation) {
fi, err := os.CreateTemp(t.TempDir(), "config.yaml")
require.NoError(t, err)
defer fi.Close()
_, err = fi.WriteString("url: good.com")
require.NoError(t, err)
inv.Args = []string{"--config", fi.Name()}
})
}
+76
View File
@@ -0,0 +1,76 @@
package clibase
import "strings"
// name returns the name of the environment variable.
func envName(line string) string {
return strings.ToUpper(
strings.SplitN(line, "=", 2)[0],
)
}
// value returns the value of the environment variable.
func envValue(line string) string {
tokens := strings.SplitN(line, "=", 2)
if len(tokens) < 2 {
return ""
}
return tokens[1]
}
// Var represents a single environment variable of form
// NAME=VALUE.
type EnvVar struct {
Name string
Value string
}
type Environ []EnvVar
func (e Environ) ToOS() []string {
var env []string
for _, v := range e {
env = append(env, v.Name+"="+v.Value)
}
return env
}
func (e Environ) Lookup(name string) (string, bool) {
for _, v := range e {
if v.Name == name {
return v.Value, true
}
}
return "", false
}
func (e Environ) Get(name string) string {
v, _ := e.Lookup(name)
return v
}
func (e *Environ) Set(name, value string) {
for i, v := range *e {
if v.Name == name {
(*e)[i].Value = value
return
}
}
*e = append(*e, EnvVar{Name: name, Value: value})
}
// ParseEnviron returns all environment variables starting with
// prefix without said prefix.
func ParseEnviron(environ []string, prefix string) Environ {
var filtered []EnvVar
for _, line := range environ {
name := envName(line)
if strings.HasPrefix(name, prefix) {
filtered = append(filtered, EnvVar{
Name: strings.TrimPrefix(name, prefix),
Value: envValue(line),
})
}
}
return filtered
}
+44
View File
@@ -0,0 +1,44 @@
package clibase_test
import (
"reflect"
"testing"
"github.com/coder/coder/cli/clibase"
)
func TestFilterNamePrefix(t *testing.T) {
t.Parallel()
type args struct {
environ []string
prefix string
}
tests := []struct {
name string
args args
want clibase.Environ
}{
{"empty", args{[]string{}, "SHIRE"}, nil},
{
"ONE",
args{
[]string{
"SHIRE_BRANDYBUCK=hmm",
},
"SHIRE_",
},
[]clibase.EnvVar{
{Name: "BRANDYBUCK", Value: "hmm"},
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := clibase.ParseEnviron(tt.args.environ, tt.args.prefix); !reflect.DeepEqual(got, tt.want) {
t.Errorf("FilterNamePrefix() = %v, want %v", got, tt.want)
}
})
}
}
+231
View File
@@ -0,0 +1,231 @@
package clibase
import (
"os"
"strings"
"github.com/hashicorp/go-multierror"
"github.com/spf13/pflag"
"golang.org/x/xerrors"
)
type ValueSource string
const (
ValueSourceNone ValueSource = ""
ValueSourceFlag ValueSource = "flag"
ValueSourceEnv ValueSource = "env"
ValueSourceYAML ValueSource = "yaml"
ValueSourceDefault ValueSource = "default"
)
// Option is a configuration option for a CLI application.
type Option struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
// Flag is the long name of the flag used to configure this option. If unset,
// flag configuring is disabled.
Flag string `json:"flag,omitempty"`
// FlagShorthand is the one-character shorthand for the flag. If unset, no
// shorthand is used.
FlagShorthand string `json:"flag_shorthand,omitempty"`
// Env is the environment variable used to configure this option. If unset,
// environment configuring is disabled.
Env string `json:"env,omitempty"`
// YAML is the YAML key used to configure this option. If unset, YAML
// configuring is disabled.
YAML string `json:"yaml,omitempty"`
// Default is parsed into Value if set.
Default string `json:"default,omitempty"`
// Value includes the types listed in values.go.
Value pflag.Value `json:"value,omitempty"`
// Annotations enable extensions to clibase higher up in the stack. It's useful for
// help formatting and documentation generation.
Annotations Annotations `json:"annotations,omitempty"`
// Group is a group hierarchy that helps organize this option in help, configs
// and other documentation.
Group *Group `json:"group,omitempty"`
// UseInstead is a list of options that should be used instead of this one.
// The field is used to generate a deprecation warning.
UseInstead []Option `json:"use_instead,omitempty"`
Hidden bool `json:"hidden,omitempty"`
ValueSource ValueSource `json:"value_source,omitempty"`
}
func (o Option) YAMLPath() string {
if o.YAML == "" {
return ""
}
var gs []string
for _, g := range o.Group.Ancestry() {
gs = append(gs, g.YAML)
}
return strings.Join(append(gs, o.YAML), ".")
}
// OptionSet is a group of options that can be applied to a command.
type OptionSet []Option
// Add adds the given Options to the OptionSet.
func (s *OptionSet) Add(opts ...Option) {
*s = append(*s, opts...)
}
// Filter will only return options that match the given filter. (return true)
func (s OptionSet) Filter(filter func(opt Option) bool) OptionSet {
cpy := make(OptionSet, 0)
for _, opt := range s {
if filter(opt) {
cpy = append(cpy, opt)
}
}
return cpy
}
// FlagSet returns a pflag.FlagSet for the OptionSet.
func (s *OptionSet) FlagSet() *pflag.FlagSet {
if s == nil {
return &pflag.FlagSet{}
}
fs := pflag.NewFlagSet("", pflag.ContinueOnError)
for _, opt := range *s {
if opt.Flag == "" {
continue
}
var noOptDefValue string
{
no, ok := opt.Value.(NoOptDefValuer)
if ok {
noOptDefValue = no.NoOptDefValue()
}
}
val := opt.Value
if val == nil {
val = DiscardValue
}
fs.AddFlag(&pflag.Flag{
Name: opt.Flag,
Shorthand: opt.FlagShorthand,
Usage: opt.Description,
Value: val,
DefValue: "",
Changed: false,
Deprecated: "",
NoOptDefVal: noOptDefValue,
Hidden: opt.Hidden,
})
}
fs.Usage = func() {
_, _ = os.Stderr.WriteString("Override (*FlagSet).Usage() to print help text.\n")
}
return fs
}
// ParseEnv parses the given environment variables into the OptionSet.
// Use EnvsWithPrefix to filter out prefixes.
func (s *OptionSet) ParseEnv(vs []EnvVar) error {
if s == nil {
return nil
}
var merr *multierror.Error
// We parse environment variables first instead of using a nested loop to
// avoid N*M complexity when there are a lot of options and environment
// variables.
envs := make(map[string]string)
for _, v := range vs {
envs[v.Name] = v.Value
}
for i, opt := range *s {
if opt.Env == "" {
continue
}
envVal, ok := envs[opt.Env]
// Currently, empty values are treated as if the environment variable is
// unset. This behavior is technically not correct as there is now no
// way for a user to change a Default value to an empty string from
// the environment. Unfortunately, we have old configuration files
// that rely on the faulty behavior.
//
// TODO: We should remove this hack in May 2023, when deployments
// have had months to migrate to the new behavior.
if !ok || envVal == "" {
continue
}
(*s)[i].ValueSource = ValueSourceEnv
if err := opt.Value.Set(envVal); err != nil {
merr = multierror.Append(
merr, xerrors.Errorf("parse %q: %w", opt.Name, err),
)
}
}
return merr.ErrorOrNil()
}
// SetDefaults sets the default values for each Option, skipping values
// that already have a value source.
func (s *OptionSet) SetDefaults() error {
if s == nil {
return nil
}
var merr *multierror.Error
for i, opt := range *s {
// Skip values that may have already been set by the user.
if opt.ValueSource != ValueSourceNone {
continue
}
if opt.Default == "" {
continue
}
if opt.Value == nil {
merr = multierror.Append(
merr,
xerrors.Errorf(
"parse %q: no Value field set\nFull opt: %+v",
opt.Name, opt,
),
)
continue
}
(*s)[i].ValueSource = ValueSourceDefault
if err := opt.Value.Set(opt.Default); err != nil {
merr = multierror.Append(
merr, xerrors.Errorf("parse %q: %w", opt.Name, err),
)
}
}
return merr.ErrorOrNil()
}
// ByName returns the Option with the given name, or nil if no such option
// exists.
func (s *OptionSet) ByName(name string) *Option {
for i := range *s {
opt := &(*s)[i]
if opt.Name == name {
return opt
}
}
return nil
}
+169
View File
@@ -0,0 +1,169 @@
package clibase_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/coder/coder/cli/clibase"
)
func TestOptionSet_ParseFlags(t *testing.T) {
t.Parallel()
t.Run("SimpleString", func(t *testing.T) {
t.Parallel()
var workspaceName clibase.String
os := clibase.OptionSet{
clibase.Option{
Name: "Workspace Name",
Value: &workspaceName,
Flag: "workspace-name",
FlagShorthand: "n",
},
}
var err error
err = os.FlagSet().Parse([]string{"--workspace-name", "foo"})
require.NoError(t, err)
require.EqualValues(t, "foo", workspaceName)
err = os.FlagSet().Parse([]string{"-n", "f"})
require.NoError(t, err)
require.EqualValues(t, "f", workspaceName)
})
t.Run("StringArray", func(t *testing.T) {
t.Parallel()
var names clibase.StringArray
os := clibase.OptionSet{
clibase.Option{
Name: "name",
Value: &names,
Flag: "name",
FlagShorthand: "n",
},
}
err := os.SetDefaults()
require.NoError(t, err)
err = os.FlagSet().Parse([]string{"--name", "foo", "--name", "bar"})
require.NoError(t, err)
require.EqualValues(t, []string{"foo", "bar"}, names)
})
t.Run("ExtraFlags", func(t *testing.T) {
t.Parallel()
var workspaceName clibase.String
os := clibase.OptionSet{
clibase.Option{
Name: "Workspace Name",
Value: &workspaceName,
},
}
err := os.FlagSet().Parse([]string{"--some-unknown", "foo"})
require.Error(t, err)
})
}
func TestOptionSet_ParseEnv(t *testing.T) {
t.Parallel()
t.Run("SimpleString", func(t *testing.T) {
t.Parallel()
var workspaceName clibase.String
os := clibase.OptionSet{
clibase.Option{
Name: "Workspace Name",
Value: &workspaceName,
Env: "WORKSPACE_NAME",
},
}
err := os.ParseEnv([]clibase.EnvVar{
{Name: "WORKSPACE_NAME", Value: "foo"},
})
require.NoError(t, err)
require.EqualValues(t, "foo", workspaceName)
})
t.Run("EmptyValue", func(t *testing.T) {
t.Parallel()
var workspaceName clibase.String
os := clibase.OptionSet{
clibase.Option{
Name: "Workspace Name",
Value: &workspaceName,
Default: "defname",
Env: "WORKSPACE_NAME",
},
}
err := os.SetDefaults()
require.NoError(t, err)
err = os.ParseEnv(clibase.ParseEnviron([]string{"CODER_WORKSPACE_NAME="}, "CODER_"))
require.NoError(t, err)
require.EqualValues(t, "defname", workspaceName)
})
t.Run("StringSlice", func(t *testing.T) {
t.Parallel()
var actual clibase.StringArray
expected := []string{"foo", "bar", "baz"}
os := clibase.OptionSet{
clibase.Option{
Name: "name",
Value: &actual,
Env: "NAMES",
},
}
err := os.SetDefaults()
require.NoError(t, err)
err = os.ParseEnv([]clibase.EnvVar{
{Name: "NAMES", Value: "foo,bar,baz"},
})
require.NoError(t, err)
require.EqualValues(t, expected, actual)
})
t.Run("StructMapStringString", func(t *testing.T) {
t.Parallel()
var actual clibase.Struct[map[string]string]
expected := map[string]string{"foo": "bar", "baz": "zap"}
os := clibase.OptionSet{
clibase.Option{
Name: "labels",
Value: &actual,
Env: "LABELS",
},
}
err := os.SetDefaults()
require.NoError(t, err)
err = os.ParseEnv([]clibase.EnvVar{
{Name: "LABELS", Value: `{"foo":"bar","baz":"zap"}`},
})
require.NoError(t, err)
require.EqualValues(t, expected, actual.Value)
})
}
+444
View File
@@ -0,0 +1,444 @@
package clibase
import (
"encoding/csv"
"encoding/json"
"fmt"
"net"
"net/url"
"reflect"
"strconv"
"strings"
"time"
"github.com/spf13/pflag"
"golang.org/x/xerrors"
"gopkg.in/yaml.v3"
)
// NoOptDefValuer describes behavior when no
// option is passed into the flag.
//
// This is useful for boolean or otherwise binary flags.
type NoOptDefValuer interface {
NoOptDefValue() string
}
// values.go contains a standard set of value types that can be used as
// Option Values.
type Int64 int64
func Int64Of(i *int64) *Int64 {
return (*Int64)(i)
}
func (i *Int64) Set(s string) error {
ii, err := strconv.ParseInt(s, 10, 64)
*i = Int64(ii)
return err
}
func (i Int64) Value() int64 {
return int64(i)
}
func (i Int64) String() string {
return strconv.Itoa(int(i))
}
func (Int64) Type() string {
return "int"
}
type Bool bool
func BoolOf(b *bool) *Bool {
return (*Bool)(b)
}
func (b *Bool) Set(s string) error {
if s == "" {
*b = Bool(false)
return nil
}
bb, err := strconv.ParseBool(s)
*b = Bool(bb)
return err
}
func (*Bool) NoOptDefValue() string {
return "true"
}
func (b Bool) String() string {
return strconv.FormatBool(bool(b))
}
func (b Bool) Value() bool {
return bool(b)
}
func (Bool) Type() string {
return "bool"
}
type String string
func StringOf(s *string) *String {
return (*String)(s)
}
func (*String) NoOptDefValue() string {
return ""
}
func (s *String) Set(v string) error {
*s = String(v)
return nil
}
func (s String) String() string {
return string(s)
}
func (s String) Value() string {
return string(s)
}
func (String) Type() string {
return "string"
}
var _ pflag.SliceValue = &StringArray{}
// StringArray is a slice of strings that implements pflag.Value and pflag.SliceValue.
type StringArray []string
func StringArrayOf(ss *[]string) *StringArray {
return (*StringArray)(ss)
}
func (s *StringArray) Append(v string) error {
*s = append(*s, v)
return nil
}
func (s *StringArray) Replace(vals []string) error {
*s = vals
return nil
}
func (s *StringArray) GetSlice() []string {
return *s
}
func readAsCSV(v string) ([]string, error) {
return csv.NewReader(strings.NewReader(v)).Read()
}
func writeAsCSV(vals []string) string {
var sb strings.Builder
err := csv.NewWriter(&sb).Write(vals)
if err != nil {
return fmt.Sprintf("error: %s", err)
}
return sb.String()
}
func (s *StringArray) Set(v string) error {
if v == "" {
*s = nil
return nil
}
ss, err := readAsCSV(v)
if err != nil {
return err
}
*s = append(*s, ss...)
return nil
}
func (s StringArray) String() string {
return writeAsCSV([]string(s))
}
func (s StringArray) Value() []string {
return []string(s)
}
func (StringArray) Type() string {
return "string-array"
}
type Duration time.Duration
func DurationOf(d *time.Duration) *Duration {
return (*Duration)(d)
}
func (d *Duration) Set(v string) error {
dd, err := time.ParseDuration(v)
*d = Duration(dd)
return err
}
func (d *Duration) Value() time.Duration {
return time.Duration(*d)
}
func (d *Duration) String() string {
return time.Duration(*d).String()
}
func (Duration) Type() string {
return "duration"
}
func (d *Duration) MarshalYAML() (interface{}, error) {
return yaml.Node{
Kind: yaml.ScalarNode,
Value: d.String(),
}, nil
}
func (d *Duration) UnmarshalYAML(n *yaml.Node) error {
return d.Set(n.Value)
}
type URL url.URL
func URLOf(u *url.URL) *URL {
return (*URL)(u)
}
func (u *URL) Set(v string) error {
uu, err := url.Parse(v)
if err != nil {
return err
}
*u = URL(*uu)
return nil
}
func (u *URL) String() string {
uu := url.URL(*u)
return uu.String()
}
func (u *URL) MarshalYAML() (interface{}, error) {
return yaml.Node{
Kind: yaml.ScalarNode,
Value: u.String(),
}, nil
}
func (u *URL) UnmarshalYAML(n *yaml.Node) error {
return u.Set(n.Value)
}
func (u *URL) MarshalJSON() ([]byte, error) {
return json.Marshal(u.String())
}
func (u *URL) UnmarshalJSON(b []byte) error {
var s string
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
return u.Set(s)
}
func (*URL) Type() string {
return "url"
}
func (u *URL) Value() *url.URL {
return (*url.URL)(u)
}
// HostPort is a host:port pair.
type HostPort struct {
Host string
Port string
}
func (hp *HostPort) Set(v string) error {
if v == "" {
return xerrors.Errorf("must not be empty")
}
var err error
hp.Host, hp.Port, err = net.SplitHostPort(v)
return err
}
func (hp *HostPort) String() string {
if hp.Host == "" && hp.Port == "" {
return ""
}
// Warning: net.JoinHostPort must be used over concatenation to support
// IPv6 addresses.
return net.JoinHostPort(hp.Host, hp.Port)
}
func (hp *HostPort) MarshalJSON() ([]byte, error) {
return json.Marshal(hp.String())
}
func (hp *HostPort) UnmarshalJSON(b []byte) error {
var s string
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
if s == "" {
hp.Host = ""
hp.Port = ""
return nil
}
return hp.Set(s)
}
func (hp *HostPort) MarshalYAML() (interface{}, error) {
return yaml.Node{
Kind: yaml.ScalarNode,
Value: hp.String(),
}, nil
}
func (hp *HostPort) UnmarshalYAML(n *yaml.Node) error {
return hp.Set(n.Value)
}
func (*HostPort) Type() string {
return "host:port"
}
var (
_ yaml.Marshaler = new(Struct[struct{}])
_ yaml.Unmarshaler = new(Struct[struct{}])
)
// Struct is a special value type that encodes an arbitrary struct.
// It implements the flag.Value interface, but in general these values should
// only be accepted via config for ergonomics.
//
// The string encoding type is YAML.
type Struct[T any] struct {
Value T
}
func (s *Struct[T]) Set(v string) error {
return yaml.Unmarshal([]byte(v), &s.Value)
}
func (s *Struct[T]) String() string {
byt, err := yaml.Marshal(s.Value)
if err != nil {
return "decode failed: " + err.Error()
}
return string(byt)
}
func (s *Struct[T]) MarshalYAML() (interface{}, error) {
var n yaml.Node
err := n.Encode(s.Value)
if err != nil {
return nil, err
}
return n, nil
}
func (s *Struct[T]) UnmarshalYAML(n *yaml.Node) error {
// HACK: for compatibility with flags, we use nil slices instead of empty
// slices. In most cases, nil slices and empty slices are treated
// the same, so this behavior may be removed at some point.
if typ := reflect.TypeOf(s.Value); typ.Kind() == reflect.Slice && len(n.Content) == 0 {
reflect.ValueOf(&s.Value).Elem().Set(reflect.Zero(typ))
return nil
}
return n.Decode(&s.Value)
}
func (s *Struct[T]) Type() string {
return fmt.Sprintf("struct[%T]", s.Value)
}
func (s *Struct[T]) MarshalJSON() ([]byte, error) {
return json.Marshal(s.Value)
}
func (s *Struct[T]) UnmarshalJSON(b []byte) error {
return json.Unmarshal(b, &s.Value)
}
// DiscardValue does nothing but implements the pflag.Value interface.
// It's useful in cases where you want to accept an option, but access the
// underlying value directly instead of through the Option methods.
var DiscardValue discardValue
type discardValue struct{}
func (discardValue) Set(string) error {
return nil
}
func (discardValue) String() string {
return ""
}
func (discardValue) Type() string {
return "discard"
}
var _ pflag.Value = (*Enum)(nil)
type Enum struct {
Choices []string
Value *string
}
func EnumOf(v *string, choices ...string) *Enum {
return &Enum{
Choices: choices,
Value: v,
}
}
func (e *Enum) Set(v string) error {
for _, c := range e.Choices {
if v == c {
*e.Value = v
return nil
}
}
return xerrors.Errorf("invalid choice: %s, should be one of %v", v, e.Choices)
}
func (e *Enum) Type() string {
return fmt.Sprintf("enum[%v]", strings.Join(e.Choices, "|"))
}
func (e *Enum) String() string {
return *e.Value
}
var _ pflag.Value = (*YAMLConfigPath)(nil)
// YAMLConfigPath is a special value type that encodes a path to a YAML
// configuration file where options are read from.
type YAMLConfigPath string
func (p *YAMLConfigPath) Set(v string) error {
*p = YAMLConfigPath(v)
return nil
}
func (p *YAMLConfigPath) String() string {
return string(*p)
}
func (*YAMLConfigPath) Type() string {
return "yaml-config-path"
}
+295
View File
@@ -0,0 +1,295 @@
package clibase
import (
"errors"
"fmt"
"strings"
"github.com/mitchellh/go-wordwrap"
"golang.org/x/xerrors"
"gopkg.in/yaml.v3"
)
var (
_ yaml.Marshaler = new(OptionSet)
_ yaml.Unmarshaler = new(OptionSet)
)
// deepMapNode returns the mapping node at the given path,
// creating it if it doesn't exist.
func deepMapNode(n *yaml.Node, path []string, headComment string) *yaml.Node {
if len(path) == 0 {
return n
}
// Name is every two nodes.
for i := 0; i < len(n.Content)-1; i += 2 {
if n.Content[i].Value == path[0] {
// Found matching name, recurse.
return deepMapNode(n.Content[i+1], path[1:], headComment)
}
}
// Not found, create it.
nameNode := yaml.Node{
Kind: yaml.ScalarNode,
Value: path[0],
HeadComment: headComment,
}
valueNode := yaml.Node{
Kind: yaml.MappingNode,
}
n.Content = append(n.Content, &nameNode)
n.Content = append(n.Content, &valueNode)
return deepMapNode(&valueNode, path[1:], headComment)
}
// MarshalYAML converts the option set to a YAML node, that can be
// converted into bytes via yaml.Marshal.
//
// The node is returned to enable post-processing higher up in
// the stack.
//
// It is isomorphic with FromYAML.
func (s *OptionSet) MarshalYAML() (any, error) {
root := yaml.Node{
Kind: yaml.MappingNode,
}
for _, opt := range *s {
if opt.YAML == "" {
continue
}
defValue := opt.Default
if defValue == "" {
defValue = "<unset>"
}
comment := wordwrap.WrapString(
fmt.Sprintf("%s\n(default: %s, type: %s)", opt.Description, defValue, opt.Value.Type()),
80,
)
nameNode := yaml.Node{
Kind: yaml.ScalarNode,
Value: opt.YAML,
HeadComment: comment,
}
var valueNode yaml.Node
if opt.Value == nil {
valueNode = yaml.Node{
Kind: yaml.ScalarNode,
Value: "null",
}
} else if m, ok := opt.Value.(yaml.Marshaler); ok {
v, err := m.MarshalYAML()
if err != nil {
return nil, xerrors.Errorf(
"marshal %q: %w", opt.Name, err,
)
}
valueNode, ok = v.(yaml.Node)
if !ok {
return nil, xerrors.Errorf(
"marshal %q: unexpected underlying type %T",
opt.Name, v,
)
}
} else {
// The all-other types case.
//
// A bit of a hack, we marshal and then unmarshal to get
// the underlying node.
byt, err := yaml.Marshal(opt.Value)
if err != nil {
return nil, xerrors.Errorf(
"marshal %q: %w", opt.Name, err,
)
}
var docNode yaml.Node
err = yaml.Unmarshal(byt, &docNode)
if err != nil {
return nil, xerrors.Errorf(
"unmarshal %q: %w", opt.Name, err,
)
}
if len(docNode.Content) != 1 {
return nil, xerrors.Errorf(
"unmarshal %q: expected one node, got %d",
opt.Name, len(docNode.Content),
)
}
valueNode = *docNode.Content[0]
}
var group []string
for _, g := range opt.Group.Ancestry() {
if g.YAML == "" {
return nil, xerrors.Errorf(
"group yaml name is empty for %q, groups: %+v",
opt.Name,
opt.Group,
)
}
group = append(group, g.YAML)
}
var groupDesc string
if opt.Group != nil {
groupDesc = wordwrap.WrapString(opt.Group.Description, 80)
}
parentValueNode := deepMapNode(
&root, group,
groupDesc,
)
parentValueNode.Content = append(
parentValueNode.Content,
&nameNode,
&valueNode,
)
}
return &root, nil
}
// mapYAMLNodes converts parent into a map with keys of form "group.subgroup.option"
// and values as the corresponding YAML nodes.
func mapYAMLNodes(parent *yaml.Node) (map[string]*yaml.Node, error) {
if parent.Kind != yaml.MappingNode {
return nil, xerrors.Errorf("expected mapping node, got type %v", parent.Kind)
}
if len(parent.Content)%2 != 0 {
return nil, xerrors.Errorf("expected an even number of k/v pairs, got %d", len(parent.Content))
}
var (
key string
m = make(map[string]*yaml.Node, len(parent.Content)/2)
merr error
)
for i, child := range parent.Content {
if i%2 == 0 {
if child.Kind != yaml.ScalarNode {
// We immediately because the rest of the code is bound to fail
// if we don't know to expect a key or a value.
return nil, xerrors.Errorf("expected scalar node for key, got type %v", child.Kind)
}
key = child.Value
continue
}
// We don't know if this is a grouped simple option or complex option,
// so we store both "key" and "group.key". Since we're storing pointers,
// the additional memory is of little concern.
m[key] = child
if child.Kind != yaml.MappingNode {
continue
}
sub, err := mapYAMLNodes(child)
if err != nil {
merr = errors.Join(merr, xerrors.Errorf("mapping node %q: %w", key, err))
continue
}
for k, v := range sub {
m[key+"."+k] = v
}
}
return m, nil
}
func (o *Option) setFromYAMLNode(n *yaml.Node) error {
o.ValueSource = ValueSourceYAML
if um, ok := o.Value.(yaml.Unmarshaler); ok {
return um.UnmarshalYAML(n)
}
switch n.Kind {
case yaml.ScalarNode:
return o.Value.Set(n.Value)
case yaml.SequenceNode:
// We treat empty values as nil for consistency with other option
// mechanisms.
if len(n.Content) == 0 {
o.Value = nil
return nil
}
return n.Decode(o.Value)
case yaml.MappingNode:
return xerrors.Errorf("mapping nodes must implement yaml.Unmarshaler")
default:
return xerrors.Errorf("unexpected node kind %v", n.Kind)
}
}
// UnmarshalYAML converts the given YAML node into the option set.
// It is isomorphic with ToYAML.
func (s *OptionSet) UnmarshalYAML(rootNode *yaml.Node) error {
// The rootNode will be a DocumentNode if it's read from a file. We do
// not support multiple documents in a single file.
if rootNode.Kind == yaml.DocumentNode {
if len(rootNode.Content) != 1 {
return xerrors.Errorf("expected one node in document, got %d", len(rootNode.Content))
}
rootNode = rootNode.Content[0]
}
yamlNodes, err := mapYAMLNodes(rootNode)
if err != nil {
return xerrors.Errorf("mapping nodes: %w", err)
}
matchedNodes := make(map[string]*yaml.Node, len(yamlNodes))
var merr error
for i := range *s {
opt := &(*s)[i]
if opt.YAML == "" {
continue
}
var group []string
for _, g := range opt.Group.Ancestry() {
if g.YAML == "" {
return xerrors.Errorf(
"group yaml name is empty for %q, groups: %+v",
opt.Name,
opt.Group,
)
}
group = append(group, g.YAML)
delete(yamlNodes, strings.Join(group, "."))
}
key := strings.Join(append(group, opt.YAML), ".")
node, ok := yamlNodes[key]
if !ok {
continue
}
matchedNodes[key] = node
if opt.ValueSource != ValueSourceNone {
continue
}
if err := opt.setFromYAMLNode(node); err != nil {
merr = errors.Join(merr, xerrors.Errorf("setting %q: %w", opt.YAML, err))
}
}
// Remove all matched nodes and their descendants from yamlNodes so we
// can accurately report unknown options.
for k := range yamlNodes {
var key string
for _, part := range strings.Split(k, ".") {
if key != "" {
key += "."
}
key += part
if _, ok := matchedNodes[key]; ok {
delete(yamlNodes, k)
}
}
}
for k := range yamlNodes {
merr = errors.Join(merr, xerrors.Errorf("unknown option %q", k))
}
return merr
}
+202
View File
@@ -0,0 +1,202 @@
package clibase_test
import (
"testing"
"github.com/spf13/pflag"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
"gopkg.in/yaml.v3"
"github.com/coder/coder/cli/clibase"
)
func TestOptionSet_YAML(t *testing.T) {
t.Parallel()
t.Run("RequireKey", func(t *testing.T) {
t.Parallel()
var workspaceName clibase.String
os := clibase.OptionSet{
clibase.Option{
Name: "Workspace Name",
Value: &workspaceName,
Default: "billie",
},
}
node, err := os.MarshalYAML()
require.NoError(t, err)
require.Len(t, node.(*yaml.Node).Content, 0)
})
t.Run("SimpleString", func(t *testing.T) {
t.Parallel()
var workspaceName clibase.String
os := clibase.OptionSet{
clibase.Option{
Name: "Workspace Name",
Value: &workspaceName,
Default: "billie",
Description: "The workspace's name.",
Group: &clibase.Group{YAML: "names"},
YAML: "workspaceName",
},
}
err := os.SetDefaults()
require.NoError(t, err)
n, err := os.MarshalYAML()
require.NoError(t, err)
// Visually inspect for now.
byt, err := yaml.Marshal(n)
require.NoError(t, err)
t.Logf("Raw YAML:\n%s", string(byt))
})
}
func TestOptionSet_YAMLUnknownOptions(t *testing.T) {
t.Parallel()
os := clibase.OptionSet{
{
Name: "Workspace Name",
Default: "billie",
Description: "The workspace's name.",
YAML: "workspaceName",
Value: new(clibase.String),
},
}
const yamlDoc = `something: else`
err := yaml.Unmarshal([]byte(yamlDoc), &os)
require.Error(t, err)
require.Empty(t, os[0].Value.String())
os[0].YAML = "something"
err = yaml.Unmarshal([]byte(yamlDoc), &os)
require.NoError(t, err)
require.Equal(t, "else", os[0].Value.String())
}
// TestOptionSet_YAMLIsomorphism tests that the YAML representations of an
// OptionSet converts to the same OptionSet when read back in.
func TestOptionSet_YAMLIsomorphism(t *testing.T) {
t.Parallel()
// This is used to form a generic.
//nolint:unused
type kid struct {
Name string `yaml:"name"`
Age int `yaml:"age"`
}
for _, tc := range []struct {
name string
os clibase.OptionSet
zeroValue func() pflag.Value
}{
{
name: "SimpleString",
os: clibase.OptionSet{
{
Name: "Workspace Name",
Default: "billie",
Description: "The workspace's name.",
Group: &clibase.Group{YAML: "names"},
YAML: "workspaceName",
},
},
zeroValue: func() pflag.Value {
return clibase.StringOf(new(string))
},
},
{
name: "Array",
os: clibase.OptionSet{
{
YAML: "names",
Default: "jill,jack,joan",
},
},
zeroValue: func() pflag.Value {
return clibase.StringArrayOf(&[]string{})
},
},
{
name: "ComplexObject",
os: clibase.OptionSet{
{
YAML: "kids",
Default: `- name: jill
age: 12
- name: jack
age: 13`,
},
},
zeroValue: func() pflag.Value {
return &clibase.Struct[[]kid]{}
},
},
{
name: "DeepGroup",
os: clibase.OptionSet{
{
YAML: "names",
Default: "jill,jack,joan",
Group: &clibase.Group{YAML: "kids", Parent: &clibase.Group{YAML: "family"}},
},
},
zeroValue: func() pflag.Value {
return clibase.StringArrayOf(&[]string{})
},
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
// Set initial values.
for i := range tc.os {
tc.os[i].Value = tc.zeroValue()
}
err := tc.os.SetDefaults()
require.NoError(t, err)
y, err := tc.os.MarshalYAML()
require.NoError(t, err)
toByt, err := yaml.Marshal(y)
require.NoError(t, err)
t.Logf("Raw YAML:\n%s", string(toByt))
var y2 yaml.Node
err = yaml.Unmarshal(toByt, &y2)
require.NoError(t, err)
os2 := slices.Clone(tc.os)
for i := range os2 {
os2[i].Value = tc.zeroValue()
os2[i].ValueSource = clibase.ValueSourceNone
}
// os2 values should be zeroed whereas tc.os should be
// set to defaults.
// This check makes sure we aren't mixing pointers.
require.NotEqual(t, tc.os, os2)
err = os2.UnmarshalYAML(&y2)
require.NoError(t, err)
want := tc.os
for i := range want {
want[i].ValueSource = clibase.ValueSourceYAML
}
require.Equal(t, tc.os, os2)
})
}
}
-185
View File
@@ -1,185 +0,0 @@
// Package cliflag extends flagset with environment variable defaults.
//
// Usage:
//
// cliflag.String(root.Flags(), &address, "address", "a", "CODER_ADDRESS", "127.0.0.1:3000", "The address to serve the API and dashboard")
//
// Will produce the following usage docs:
//
// -a, --address string The address to serve the API and dashboard (uses $CODER_ADDRESS). (default "127.0.0.1:3000")
package cliflag
import (
"fmt"
"os"
"strconv"
"strings"
"time"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/coder/coder/cli/cliui"
)
// IsSetBool returns the value of the boolean flag if it is set.
// It returns false if the flag isn't set or if any error occurs attempting
// to parse the value of the flag.
func IsSetBool(cmd *cobra.Command, name string) bool {
val, ok := IsSet(cmd, name)
if !ok {
return false
}
b, err := strconv.ParseBool(val)
return err == nil && b
}
// IsSet returns the string value of the flag and whether it was set.
func IsSet(cmd *cobra.Command, name string) (string, bool) {
flag := cmd.Flag(name)
if flag == nil {
return "", false
}
return flag.Value.String(), flag.Changed
}
// String sets a string flag on the given flag set.
func String(flagset *pflag.FlagSet, name, shorthand, env, def, usage string) {
v, ok := os.LookupEnv(env)
if !ok || v == "" {
v = def
}
flagset.StringP(name, shorthand, v, fmtUsage(usage, env))
}
// StringVarP sets a string flag on the given flag set.
func StringVarP(flagset *pflag.FlagSet, p *string, name string, shorthand string, env string, def string, usage string) {
v, ok := os.LookupEnv(env)
if !ok || v == "" {
v = def
}
flagset.StringVarP(p, name, shorthand, v, fmtUsage(usage, env))
}
func StringArray(flagset *pflag.FlagSet, name, shorthand, env string, def []string, usage string) {
v, ok := os.LookupEnv(env)
if !ok || v == "" {
if v == "" {
def = []string{}
} else {
def = strings.Split(v, ",")
}
}
flagset.StringArrayP(name, shorthand, def, fmtUsage(usage, env))
}
func StringArrayVarP(flagset *pflag.FlagSet, ptr *[]string, name string, shorthand string, env string, def []string, usage string) {
val, ok := os.LookupEnv(env)
if ok {
if val == "" {
def = []string{}
} else {
def = strings.Split(val, ",")
}
}
flagset.StringArrayVarP(ptr, name, shorthand, def, fmtUsage(usage, env))
}
// Uint8VarP sets a uint8 flag on the given flag set.
func Uint8VarP(flagset *pflag.FlagSet, ptr *uint8, name string, shorthand string, env string, def uint8, usage string) {
val, ok := os.LookupEnv(env)
if !ok || val == "" {
flagset.Uint8VarP(ptr, name, shorthand, def, fmtUsage(usage, env))
return
}
vi64, err := strconv.ParseUint(val, 10, 8)
if err != nil {
flagset.Uint8VarP(ptr, name, shorthand, def, fmtUsage(usage, env))
return
}
flagset.Uint8VarP(ptr, name, shorthand, uint8(vi64), fmtUsage(usage, env))
}
// IntVarP sets a uint8 flag on the given flag set.
func IntVarP(flagset *pflag.FlagSet, ptr *int, name string, shorthand string, env string, def int, usage string) {
val, ok := os.LookupEnv(env)
if !ok || val == "" {
flagset.IntVarP(ptr, name, shorthand, def, fmtUsage(usage, env))
return
}
vi64, err := strconv.ParseUint(val, 10, 8)
if err != nil {
flagset.IntVarP(ptr, name, shorthand, def, fmtUsage(usage, env))
return
}
flagset.IntVarP(ptr, name, shorthand, int(vi64), fmtUsage(usage, env))
}
func Bool(flagset *pflag.FlagSet, name, shorthand, env string, def bool, usage string) {
val, ok := os.LookupEnv(env)
if !ok || val == "" {
flagset.BoolP(name, shorthand, def, fmtUsage(usage, env))
return
}
valb, err := strconv.ParseBool(val)
if err != nil {
flagset.BoolP(name, shorthand, def, fmtUsage(usage, env))
return
}
flagset.BoolP(name, shorthand, valb, fmtUsage(usage, env))
}
// BoolVarP sets a bool flag on the given flag set.
func BoolVarP(flagset *pflag.FlagSet, ptr *bool, name string, shorthand string, env string, def bool, usage string) {
val, ok := os.LookupEnv(env)
if !ok || val == "" {
flagset.BoolVarP(ptr, name, shorthand, def, fmtUsage(usage, env))
return
}
valb, err := strconv.ParseBool(val)
if err != nil {
flagset.BoolVarP(ptr, name, shorthand, def, fmtUsage(usage, env))
return
}
flagset.BoolVarP(ptr, name, shorthand, valb, fmtUsage(usage, env))
}
// DurationVarP sets a time.Duration flag on the given flag set.
func DurationVarP(flagset *pflag.FlagSet, ptr *time.Duration, name string, shorthand string, env string, def time.Duration, usage string) {
val, ok := os.LookupEnv(env)
if !ok || val == "" {
flagset.DurationVarP(ptr, name, shorthand, def, fmtUsage(usage, env))
return
}
valb, err := time.ParseDuration(val)
if err != nil {
flagset.DurationVarP(ptr, name, shorthand, def, fmtUsage(usage, env))
return
}
flagset.DurationVarP(ptr, name, shorthand, valb, fmtUsage(usage, env))
}
func fmtUsage(u string, env string) string {
if env != "" {
// Avoid double dotting.
dot := "."
if strings.HasSuffix(u, ".") {
dot = ""
}
u = fmt.Sprintf("%s%s\n"+cliui.Styles.Placeholder.Render("Consumes $%s"), u, dot, env)
}
return u
}
-277
View File
@@ -1,277 +0,0 @@
package cliflag_test
import (
"fmt"
"strconv"
"testing"
"time"
"github.com/spf13/pflag"
"github.com/stretchr/testify/require"
"github.com/coder/coder/cli/cliflag"
"github.com/coder/coder/cryptorand"
)
// Testcliflag cannot run in parallel because it uses t.Setenv.
//
//nolint:paralleltest
func TestCliflag(t *testing.T) {
t.Run("StringDefault", func(t *testing.T) {
flagset, name, shorthand, env, usage := randomFlag()
def, _ := cryptorand.String(10)
cliflag.String(flagset, name, shorthand, env, def, usage)
got, err := flagset.GetString(name)
require.NoError(t, err)
require.Equal(t, def, got)
require.Contains(t, flagset.FlagUsages(), usage)
require.Contains(t, flagset.FlagUsages(), fmt.Sprintf("Consumes $%s", env))
})
t.Run("StringEnvVar", func(t *testing.T) {
flagset, name, shorthand, env, usage := randomFlag()
envValue, _ := cryptorand.String(10)
t.Setenv(env, envValue)
def, _ := cryptorand.String(10)
cliflag.String(flagset, name, shorthand, env, def, usage)
got, err := flagset.GetString(name)
require.NoError(t, err)
require.Equal(t, envValue, got)
})
t.Run("StringVarPDefault", func(t *testing.T) {
var ptr string
flagset, name, shorthand, env, usage := randomFlag()
def, _ := cryptorand.String(10)
cliflag.StringVarP(flagset, &ptr, name, shorthand, env, def, usage)
got, err := flagset.GetString(name)
require.NoError(t, err)
require.Equal(t, def, got)
require.Contains(t, flagset.FlagUsages(), usage)
require.Contains(t, flagset.FlagUsages(), fmt.Sprintf("Consumes $%s", env))
})
t.Run("StringVarPEnvVar", func(t *testing.T) {
var ptr string
flagset, name, shorthand, env, usage := randomFlag()
envValue, _ := cryptorand.String(10)
t.Setenv(env, envValue)
def, _ := cryptorand.String(10)
cliflag.StringVarP(flagset, &ptr, name, shorthand, env, def, usage)
got, err := flagset.GetString(name)
require.NoError(t, err)
require.Equal(t, envValue, got)
})
t.Run("EmptyEnvVar", func(t *testing.T) {
var ptr string
flagset, name, shorthand, _, usage := randomFlag()
def, _ := cryptorand.String(10)
cliflag.StringVarP(flagset, &ptr, name, shorthand, "", def, usage)
got, err := flagset.GetString(name)
require.NoError(t, err)
require.Equal(t, def, got)
require.Contains(t, flagset.FlagUsages(), usage)
require.NotContains(t, flagset.FlagUsages(), "Consumes")
})
t.Run("StringArrayDefault", func(t *testing.T) {
var ptr []string
flagset, name, shorthand, env, usage := randomFlag()
def := []string{"hello"}
cliflag.StringArrayVarP(flagset, &ptr, name, shorthand, env, def, usage)
got, err := flagset.GetStringArray(name)
require.NoError(t, err)
require.Equal(t, def, got)
})
t.Run("StringArrayEnvVar", func(t *testing.T) {
var ptr []string
flagset, name, shorthand, env, usage := randomFlag()
t.Setenv(env, "wow,test")
cliflag.StringArrayVarP(flagset, &ptr, name, shorthand, env, nil, usage)
got, err := flagset.GetStringArray(name)
require.NoError(t, err)
require.Equal(t, []string{"wow", "test"}, got)
})
t.Run("StringArrayEnvVarEmpty", func(t *testing.T) {
var ptr []string
flagset, name, shorthand, env, usage := randomFlag()
t.Setenv(env, "")
cliflag.StringArrayVarP(flagset, &ptr, name, shorthand, env, nil, usage)
got, err := flagset.GetStringArray(name)
require.NoError(t, err)
require.Equal(t, []string{}, got)
})
t.Run("UInt8Default", func(t *testing.T) {
var ptr uint8
flagset, name, shorthand, env, usage := randomFlag()
def, _ := cryptorand.Int63n(10)
cliflag.Uint8VarP(flagset, &ptr, name, shorthand, env, uint8(def), usage)
got, err := flagset.GetUint8(name)
require.NoError(t, err)
require.Equal(t, uint8(def), got)
require.Contains(t, flagset.FlagUsages(), usage)
require.Contains(t, flagset.FlagUsages(), fmt.Sprintf("Consumes $%s", env))
})
t.Run("UInt8EnvVar", func(t *testing.T) {
var ptr uint8
flagset, name, shorthand, env, usage := randomFlag()
envValue, _ := cryptorand.Int63n(10)
t.Setenv(env, strconv.FormatUint(uint64(envValue), 10))
def, _ := cryptorand.Int()
cliflag.Uint8VarP(flagset, &ptr, name, shorthand, env, uint8(def), usage)
got, err := flagset.GetUint8(name)
require.NoError(t, err)
require.Equal(t, uint8(envValue), got)
})
t.Run("UInt8FailParse", func(t *testing.T) {
var ptr uint8
flagset, name, shorthand, env, usage := randomFlag()
envValue, _ := cryptorand.String(10)
t.Setenv(env, envValue)
def, _ := cryptorand.Int63n(10)
cliflag.Uint8VarP(flagset, &ptr, name, shorthand, env, uint8(def), usage)
got, err := flagset.GetUint8(name)
require.NoError(t, err)
require.Equal(t, uint8(def), got)
})
t.Run("IntDefault", func(t *testing.T) {
var ptr int
flagset, name, shorthand, env, usage := randomFlag()
def, _ := cryptorand.Int63n(10)
cliflag.IntVarP(flagset, &ptr, name, shorthand, env, int(def), usage)
got, err := flagset.GetInt(name)
require.NoError(t, err)
require.Equal(t, int(def), got)
require.Contains(t, flagset.FlagUsages(), usage)
require.Contains(t, flagset.FlagUsages(), fmt.Sprintf("Consumes $%s", env))
})
t.Run("IntEnvVar", func(t *testing.T) {
var ptr int
flagset, name, shorthand, env, usage := randomFlag()
envValue, _ := cryptorand.Int63n(10)
t.Setenv(env, strconv.FormatUint(uint64(envValue), 10))
def, _ := cryptorand.Int()
cliflag.IntVarP(flagset, &ptr, name, shorthand, env, def, usage)
got, err := flagset.GetInt(name)
require.NoError(t, err)
require.Equal(t, int(envValue), got)
})
t.Run("IntFailParse", func(t *testing.T) {
var ptr int
flagset, name, shorthand, env, usage := randomFlag()
envValue, _ := cryptorand.String(10)
t.Setenv(env, envValue)
def, _ := cryptorand.Int63n(10)
cliflag.IntVarP(flagset, &ptr, name, shorthand, env, int(def), usage)
got, err := flagset.GetInt(name)
require.NoError(t, err)
require.Equal(t, int(def), got)
})
t.Run("BoolDefault", func(t *testing.T) {
var ptr bool
flagset, name, shorthand, env, usage := randomFlag()
def, _ := cryptorand.Bool()
cliflag.BoolVarP(flagset, &ptr, name, shorthand, env, def, usage)
got, err := flagset.GetBool(name)
require.NoError(t, err)
require.Equal(t, def, got)
require.Contains(t, flagset.FlagUsages(), usage)
require.Contains(t, flagset.FlagUsages(), fmt.Sprintf("Consumes $%s", env))
})
t.Run("BoolEnvVar", func(t *testing.T) {
var ptr bool
flagset, name, shorthand, env, usage := randomFlag()
envValue, _ := cryptorand.Bool()
t.Setenv(env, strconv.FormatBool(envValue))
def, _ := cryptorand.Bool()
cliflag.BoolVarP(flagset, &ptr, name, shorthand, env, def, usage)
got, err := flagset.GetBool(name)
require.NoError(t, err)
require.Equal(t, envValue, got)
})
t.Run("BoolFailParse", func(t *testing.T) {
var ptr bool
flagset, name, shorthand, env, usage := randomFlag()
envValue, _ := cryptorand.String(10)
t.Setenv(env, envValue)
def, _ := cryptorand.Bool()
cliflag.BoolVarP(flagset, &ptr, name, shorthand, env, def, usage)
got, err := flagset.GetBool(name)
require.NoError(t, err)
require.Equal(t, def, got)
})
t.Run("DurationDefault", func(t *testing.T) {
var ptr time.Duration
flagset, name, shorthand, env, usage := randomFlag()
def, _ := cryptorand.Duration()
cliflag.DurationVarP(flagset, &ptr, name, shorthand, env, def, usage)
got, err := flagset.GetDuration(name)
require.NoError(t, err)
require.Equal(t, def, got)
require.Contains(t, flagset.FlagUsages(), usage)
require.Contains(t, flagset.FlagUsages(), fmt.Sprintf("Consumes $%s", env))
})
t.Run("DurationEnvVar", func(t *testing.T) {
var ptr time.Duration
flagset, name, shorthand, env, usage := randomFlag()
envValue, _ := cryptorand.Duration()
t.Setenv(env, envValue.String())
def, _ := cryptorand.Duration()
cliflag.DurationVarP(flagset, &ptr, name, shorthand, env, def, usage)
got, err := flagset.GetDuration(name)
require.NoError(t, err)
require.Equal(t, envValue, got)
})
t.Run("DurationFailParse", func(t *testing.T) {
var ptr time.Duration
flagset, name, shorthand, env, usage := randomFlag()
envValue, _ := cryptorand.String(10)
t.Setenv(env, envValue)
def, _ := cryptorand.Duration()
cliflag.DurationVarP(flagset, &ptr, name, shorthand, env, def, usage)
got, err := flagset.GetDuration(name)
require.NoError(t, err)
require.Equal(t, def, got)
})
}
func randomFlag() (*pflag.FlagSet, string, string, string, string) {
fsname, _ := cryptorand.String(10)
flagset := pflag.NewFlagSet(fsname, pflag.PanicOnError)
name, _ := cryptorand.String(10)
shorthand, _ := cryptorand.String(1)
env, _ := cryptorand.String(10)
usage, _ := cryptorand.String(10)
return flagset, name, shorthand, env, usage
}
+314
View File
@@ -0,0 +1,314 @@
package clistat
import (
"bufio"
"bytes"
"strconv"
"strings"
"github.com/spf13/afero"
"golang.org/x/xerrors"
"tailscale.com/types/ptr"
)
// Paths for CGroupV1.
// Ref: https://www.kernel.org/doc/Documentation/cgroup-v1/cpuacct.txt
const (
// CPU usage of all tasks in cgroup in nanoseconds.
cgroupV1CPUAcctUsage = "/sys/fs/cgroup/cpu/cpuacct.usage"
// Alternate path
cgroupV1CPUAcctUsageAlt = "/sys/fs/cgroup/cpu,cpuacct/cpuacct.usage"
// CFS quota and period for cgroup in MICROseconds
cgroupV1CFSQuotaUs = "/sys/fs/cgroup/cpu,cpuacct/cpu.cfs_quota_us"
cgroupV1CFSPeriodUs = "/sys/fs/cgroup/cpu,cpuacct/cpu.cfs_period_us"
// Maximum memory usable by cgroup in bytes
cgroupV1MemoryMaxUsageBytes = "/sys/fs/cgroup/memory/memory.max_usage_in_bytes"
// Current memory usage of cgroup in bytes
cgroupV1MemoryUsageBytes = "/sys/fs/cgroup/memory/memory.usage_in_bytes"
// Other memory stats - we are interested in total_inactive_file
cgroupV1MemoryStat = "/sys/fs/cgroup/memory/memory.stat"
)
// Paths for CGroupV2.
// Ref: https://docs.kernel.org/admin-guide/cgroup-v2.html
const (
// Contains quota and period in microseconds separated by a space.
cgroupV2CPUMax = "/sys/fs/cgroup/cpu.max"
// Contains current CPU usage under usage_usec
cgroupV2CPUStat = "/sys/fs/cgroup/cpu.stat"
// Contains current cgroup memory usage in bytes.
cgroupV2MemoryUsageBytes = "/sys/fs/cgroup/memory.current"
// Contains max cgroup memory usage in bytes.
cgroupV2MemoryMaxBytes = "/sys/fs/cgroup/memory.max"
// Other memory stats - we are interested in total_inactive_file
cgroupV2MemoryStat = "/sys/fs/cgroup/memory.stat"
)
// ContainerCPU returns the CPU usage of the container cgroup.
// This is calculated as difference of two samples of the
// CPU usage of the container cgroup.
// The total is read from the relevant path in /sys/fs/cgroup.
// If there is no limit set, the total is assumed to be the
// number of host cores multiplied by the CFS period.
// If the system is not containerized, this always returns nil.
func (s *Statter) ContainerCPU() (*Result, error) {
// Firstly, check if we are containerized.
if ok, err := IsContainerized(s.fs); err != nil || !ok {
return nil, nil //nolint: nilnil
}
total, err := s.cGroupCPUTotal()
if err != nil {
return nil, xerrors.Errorf("get total cpu: %w", err)
}
used1, err := s.cGroupCPUUsed()
if err != nil {
return nil, xerrors.Errorf("get cgroup CPU usage: %w", err)
}
// The measurements in /sys/fs/cgroup are counters.
// We need to wait for a bit to get a difference.
// Note that someone could reset the counter in the meantime.
// We can't do anything about that.
s.wait(s.sampleInterval)
used2, err := s.cGroupCPUUsed()
if err != nil {
return nil, xerrors.Errorf("get cgroup CPU usage: %w", err)
}
if used2 < used1 {
// Someone reset the counter. Best we can do is count from zero.
used1 = 0
}
r := &Result{
Unit: "cores",
Used: used2 - used1,
Total: ptr.To(total),
Prefix: PrefixDefault,
}
return r, nil
}
func (s *Statter) cGroupCPUTotal() (used float64, err error) {
if s.isCGroupV2() {
return s.cGroupV2CPUTotal()
}
// Fall back to CGroupv1
return s.cGroupV1CPUTotal()
}
func (s *Statter) cGroupCPUUsed() (used float64, err error) {
if s.isCGroupV2() {
return s.cGroupV2CPUUsed()
}
return s.cGroupV1CPUUsed()
}
func (s *Statter) isCGroupV2() bool {
// Check for the presence of /sys/fs/cgroup/cpu.max
_, err := s.fs.Stat(cgroupV2CPUMax)
return err == nil
}
func (s *Statter) cGroupV2CPUUsed() (used float64, err error) {
usageUs, err := readInt64Prefix(s.fs, cgroupV2CPUStat, "usage_usec")
if err != nil {
return 0, xerrors.Errorf("get cgroupv2 cpu used: %w", err)
}
periodUs, err := readInt64SepIdx(s.fs, cgroupV2CPUMax, " ", 1)
if err != nil {
return 0, xerrors.Errorf("get cpu period: %w", err)
}
return float64(usageUs) / float64(periodUs), nil
}
func (s *Statter) cGroupV2CPUTotal() (total float64, err error) {
var quotaUs, periodUs int64
periodUs, err = readInt64SepIdx(s.fs, cgroupV2CPUMax, " ", 1)
if err != nil {
return 0, xerrors.Errorf("get cpu period: %w", err)
}
quotaUs, err = readInt64SepIdx(s.fs, cgroupV2CPUMax, " ", 0)
if err != nil {
// Fall back to number of cores
quotaUs = int64(s.nproc) * periodUs
}
return float64(quotaUs) / float64(periodUs), nil
}
func (s *Statter) cGroupV1CPUTotal() (float64, error) {
periodUs, err := readInt64(s.fs, cgroupV1CFSPeriodUs)
if err != nil {
return 0, xerrors.Errorf("read cpu period: %w", err)
}
quotaUs, err := readInt64(s.fs, cgroupV1CFSQuotaUs)
if err != nil {
return 0, xerrors.Errorf("read cpu quota: %w", err)
}
if quotaUs < 0 {
// Fall back to the number of cores
quotaUs = int64(s.nproc) * periodUs
}
return float64(quotaUs) / float64(periodUs), nil
}
func (s *Statter) cGroupV1CPUUsed() (float64, error) {
usageNs, err := readInt64(s.fs, cgroupV1CPUAcctUsage)
if err != nil {
// try alternate path
usageNs, err = readInt64(s.fs, cgroupV1CPUAcctUsageAlt)
if err != nil {
return 0, xerrors.Errorf("read cpu used: %w", err)
}
}
// usage is in ns, convert to us
usageNs /= 1000
periodUs, err := readInt64(s.fs, cgroupV1CFSPeriodUs)
if err != nil {
return 0, xerrors.Errorf("get cpu period: %w", err)
}
return float64(usageNs) / float64(periodUs), nil
}
// ContainerMemory returns the memory usage of the container cgroup.
// If the system is not containerized, this always returns nil.
func (s *Statter) ContainerMemory(p Prefix) (*Result, error) {
if ok, err := IsContainerized(s.fs); err != nil || !ok {
return nil, nil //nolint:nilnil
}
if s.isCGroupV2() {
return s.cGroupV2Memory(p)
}
// Fall back to CGroupv1
return s.cGroupV1Memory(p)
}
func (s *Statter) cGroupV2Memory(p Prefix) (*Result, error) {
maxUsageBytes, err := readInt64(s.fs, cgroupV2MemoryMaxBytes)
if err != nil {
return nil, xerrors.Errorf("read memory total: %w", err)
}
currUsageBytes, err := readInt64(s.fs, cgroupV2MemoryUsageBytes)
if err != nil {
return nil, xerrors.Errorf("read memory usage: %w", err)
}
inactiveFileBytes, err := readInt64Prefix(s.fs, cgroupV2MemoryStat, "inactive_file")
if err != nil {
return nil, xerrors.Errorf("read memory stats: %w", err)
}
return &Result{
Total: ptr.To(float64(maxUsageBytes)),
Used: float64(currUsageBytes - inactiveFileBytes),
Unit: "B",
Prefix: p,
}, nil
}
func (s *Statter) cGroupV1Memory(p Prefix) (*Result, error) {
maxUsageBytes, err := readInt64(s.fs, cgroupV1MemoryMaxUsageBytes)
if err != nil {
return nil, xerrors.Errorf("read memory total: %w", err)
}
// need a space after total_rss so we don't hit something else
usageBytes, err := readInt64(s.fs, cgroupV1MemoryUsageBytes)
if err != nil {
return nil, xerrors.Errorf("read memory usage: %w", err)
}
totalInactiveFileBytes, err := readInt64Prefix(s.fs, cgroupV1MemoryStat, "total_inactive_file")
if err != nil {
return nil, xerrors.Errorf("read memory stats: %w", err)
}
// Total memory used is usage - total_inactive_file
return &Result{
Total: ptr.To(float64(maxUsageBytes)),
Used: float64(usageBytes - totalInactiveFileBytes),
Unit: "B",
Prefix: p,
}, nil
}
// read an int64 value from path
func readInt64(fs afero.Fs, path string) (int64, error) {
data, err := afero.ReadFile(fs, path)
if err != nil {
return 0, xerrors.Errorf("read %s: %w", path, err)
}
val, err := strconv.ParseInt(string(bytes.TrimSpace(data)), 10, 64)
if err != nil {
return 0, xerrors.Errorf("parse %s: %w", path, err)
}
return val, nil
}
// read an int64 value from path at field idx separated by sep
func readInt64SepIdx(fs afero.Fs, path, sep string, idx int) (int64, error) {
data, err := afero.ReadFile(fs, path)
if err != nil {
return 0, xerrors.Errorf("read %s: %w", path, err)
}
parts := strings.Split(string(data), sep)
if len(parts) < idx {
return 0, xerrors.Errorf("expected line %q to have at least %d parts", string(data), idx+1)
}
val, err := strconv.ParseInt(strings.TrimSpace(parts[idx]), 10, 64)
if err != nil {
return 0, xerrors.Errorf("parse %s: %w", path, err)
}
return val, nil
}
// read the first int64 value from path prefixed with prefix
func readInt64Prefix(fs afero.Fs, path, prefix string) (int64, error) {
data, err := afero.ReadFile(fs, path)
if err != nil {
return 0, xerrors.Errorf("read %s: %w", path, err)
}
scn := bufio.NewScanner(bytes.NewReader(data))
for scn.Scan() {
line := scn.Text()
if !strings.HasPrefix(line, prefix) {
continue
}
parts := strings.Fields(line)
if len(parts) != 2 {
return 0, xerrors.Errorf("parse %s: expected two fields but got %s", path, line)
}
val, err := strconv.ParseInt(strings.TrimSpace(parts[1]), 10, 64)
if err != nil {
return 0, xerrors.Errorf("parse %s: %w", path, err)
}
return val, nil
}
return 0, xerrors.Errorf("parse %s: did not find line with prefix %s", path, prefix)
}
+61
View File
@@ -0,0 +1,61 @@
package clistat
import (
"bufio"
"bytes"
"os"
"github.com/spf13/afero"
"golang.org/x/xerrors"
)
const (
procMounts = "/proc/mounts"
procOneCgroup = "/proc/1/cgroup"
)
// IsContainerized returns whether the host is containerized.
// This is adapted from https://github.com/elastic/go-sysinfo/tree/main/providers/linux/container.go#L31
// with modifications to support Sysbox containers.
// On non-Linux platforms, it always returns false.
func IsContainerized(fs afero.Fs) (ok bool, err error) {
cgData, err := afero.ReadFile(fs, procOneCgroup)
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, xerrors.Errorf("read file %s: %w", procOneCgroup, err)
}
scn := bufio.NewScanner(bytes.NewReader(cgData))
for scn.Scan() {
line := scn.Bytes()
if bytes.Contains(line, []byte("docker")) ||
bytes.Contains(line, []byte(".slice")) ||
bytes.Contains(line, []byte("lxc")) ||
bytes.Contains(line, []byte("kubepods")) {
return true, nil
}
}
// Last-ditch effort to detect Sysbox containers.
// Check if we have anything mounted as type sysboxfs in /proc/mounts
mountsData, err := afero.ReadFile(fs, procMounts)
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, xerrors.Errorf("read file %s: %w", procMounts, err)
}
scn = bufio.NewScanner(bytes.NewReader(mountsData))
for scn.Scan() {
line := scn.Bytes()
if bytes.Contains(line, []byte("sysboxfs")) {
return true, nil
}
}
// If we get here, we are _probably_ not running in a container.
return false, nil
}
+27
View File
@@ -0,0 +1,27 @@
//go:build !windows
package clistat
import (
"syscall"
"tailscale.com/types/ptr"
)
// Disk returns the disk usage of the given path.
// If path is empty, it returns the usage of the root directory.
func (*Statter) Disk(p Prefix, path string) (*Result, error) {
if path == "" {
path = "/"
}
var stat syscall.Statfs_t
if err := syscall.Statfs(path, &stat); err != nil {
return nil, err
}
var r Result
r.Total = ptr.To(float64(stat.Blocks * uint64(stat.Bsize)))
r.Used = float64(stat.Blocks-stat.Bfree) * float64(stat.Bsize)
r.Unit = "B"
r.Prefix = p
return &r, nil
}
+36
View File
@@ -0,0 +1,36 @@
package clistat
import (
"golang.org/x/sys/windows"
"tailscale.com/types/ptr"
)
// Disk returns the disk usage of the given path.
// If path is empty, it defaults to C:\
func (*Statter) Disk(p Prefix, path string) (*Result, error) {
if path == "" {
path = `C:\`
}
pathPtr, err := windows.UTF16PtrFromString(path)
if err != nil {
return nil, err
}
var freeBytes, totalBytes, availBytes uint64
if err := windows.GetDiskFreeSpaceEx(
pathPtr,
&freeBytes,
&totalBytes,
&availBytes,
); err != nil {
return nil, err
}
var r Result
r.Total = ptr.To(float64(totalBytes))
r.Used = float64(totalBytes - freeBytes)
r.Unit = "B"
r.Prefix = p
return &r, nil
}
+236
View File
@@ -0,0 +1,236 @@
package clistat
import (
"math"
"runtime"
"strconv"
"strings"
"time"
"github.com/elastic/go-sysinfo"
"github.com/spf13/afero"
"golang.org/x/xerrors"
"tailscale.com/types/ptr"
sysinfotypes "github.com/elastic/go-sysinfo/types"
)
// Prefix is a scale multiplier for a result.
// Used when creating a human-readable representation.
type Prefix float64
const (
PrefixDefault = 1.0
PrefixKibi = 1024.0
PrefixMebi = PrefixKibi * 1024.0
PrefixGibi = PrefixMebi * 1024.0
PrefixTebi = PrefixGibi * 1024.0
)
var (
PrefixHumanKibi = "Ki"
PrefixHumanMebi = "Mi"
PrefixHumanGibi = "Gi"
PrefixHumanTebi = "Ti"
)
func (s *Prefix) String() string {
switch *s {
case PrefixKibi:
return "Ki"
case PrefixMebi:
return "Mi"
case PrefixGibi:
return "Gi"
case PrefixTebi:
return "Ti"
default:
return ""
}
}
func ParsePrefix(s string) Prefix {
switch s {
case PrefixHumanKibi:
return PrefixKibi
case PrefixHumanMebi:
return PrefixMebi
case PrefixHumanGibi:
return PrefixGibi
case PrefixHumanTebi:
return PrefixTebi
default:
return PrefixDefault
}
}
// Result is a generic result type for a statistic.
// Total is the total amount of the resource available.
// It is nil if the resource is not a finite quantity.
// Unit is the unit of the resource.
// Used is the amount of the resource used.
type Result struct {
Total *float64 `json:"total"`
Unit string `json:"unit"`
Used float64 `json:"used"`
Prefix Prefix `json:"-"`
}
// String returns a human-readable representation of the result.
func (r *Result) String() string {
if r == nil {
return "-"
}
scale := 1.0
if r.Prefix != 0.0 {
scale = float64(r.Prefix)
}
var sb strings.Builder
var usedScaled, totalScaled float64
usedScaled = r.Used / scale
_, _ = sb.WriteString(humanizeFloat(usedScaled))
if r.Total != (*float64)(nil) {
_, _ = sb.WriteString("/")
totalScaled = *r.Total / scale
_, _ = sb.WriteString(humanizeFloat(totalScaled))
}
_, _ = sb.WriteString(" ")
_, _ = sb.WriteString(r.Prefix.String())
_, _ = sb.WriteString(r.Unit)
if r.Total != (*float64)(nil) && *r.Total > 0 {
_, _ = sb.WriteString(" (")
pct := r.Used / *r.Total * 100.0
_, _ = sb.WriteString(strconv.FormatFloat(pct, 'f', 0, 64))
_, _ = sb.WriteString("%)")
}
return strings.TrimSpace(sb.String())
}
func humanizeFloat(f float64) string {
// humanize.FtoaWithDigits does not round correctly.
prec := precision(f)
rat := math.Pow(10, float64(prec))
rounded := math.Round(f*rat) / rat
return strconv.FormatFloat(rounded, 'f', -1, 64)
}
// limit precision to 3 digits at most to preserve space
func precision(f float64) int {
fabs := math.Abs(f)
if fabs == 0.0 {
return 0
}
if fabs < 1.0 {
return 3
}
if fabs < 10.0 {
return 2
}
if fabs < 100.0 {
return 1
}
return 0
}
// Statter is a system statistics collector.
// It is a thin wrapper around the elastic/go-sysinfo library.
type Statter struct {
hi sysinfotypes.Host
fs afero.Fs
sampleInterval time.Duration
nproc int
wait func(time.Duration)
}
type Option func(*Statter)
// WithSampleInterval sets the sample interval for the statter.
func WithSampleInterval(d time.Duration) Option {
return func(s *Statter) {
s.sampleInterval = d
}
}
// WithFS sets the fs for the statter.
func WithFS(fs afero.Fs) Option {
return func(s *Statter) {
s.fs = fs
}
}
func New(opts ...Option) (*Statter, error) {
hi, err := sysinfo.Host()
if err != nil {
return nil, xerrors.Errorf("get host info: %w", err)
}
s := &Statter{
hi: hi,
fs: afero.NewReadOnlyFs(afero.NewOsFs()),
sampleInterval: 100 * time.Millisecond,
nproc: runtime.NumCPU(),
wait: func(d time.Duration) {
<-time.After(d)
},
}
for _, opt := range opts {
opt(s)
}
return s, nil
}
// HostCPU returns the CPU usage of the host. This is calculated by
// taking two samples of CPU usage and calculating the difference.
// Total will always be equal to the number of cores.
// Used will be an estimate of the number of cores used during the sample interval.
// This is calculated by taking the difference between the total and idle HostCPU time
// and scaling it by the number of cores.
// Units are in "cores".
func (s *Statter) HostCPU() (*Result, error) {
r := &Result{
Unit: "cores",
Total: ptr.To(float64(s.nproc)),
Prefix: PrefixDefault,
}
c1, err := s.hi.CPUTime()
if err != nil {
return nil, xerrors.Errorf("get first cpu sample: %w", err)
}
s.wait(s.sampleInterval)
c2, err := s.hi.CPUTime()
if err != nil {
return nil, xerrors.Errorf("get second cpu sample: %w", err)
}
total := c2.Total() - c1.Total()
if total == 0 {
return r, nil // no change
}
idle := c2.Idle - c1.Idle
used := total - idle
scaleFactor := float64(s.nproc) / total.Seconds()
r.Used = used.Seconds() * scaleFactor
return r, nil
}
// HostMemory returns the memory usage of the host, in gigabytes.
func (s *Statter) HostMemory(p Prefix) (*Result, error) {
r := &Result{
Unit: "B",
Prefix: p,
}
hm, err := s.hi.Memory()
if err != nil {
return nil, xerrors.Errorf("get memory info: %w", err)
}
r.Total = ptr.To(float64(hm.Total))
// On Linux, hm.Used equates to MemTotal - MemFree in /proc/stat.
// This includes buffers and cache.
// So use MemAvailable instead, which only equates to physical memory.
// On Windows, this is also calculated as Total - Available.
r.Used = float64(hm.Total - hm.Available)
return r, nil
}
+345
View File
@@ -0,0 +1,345 @@
package clistat
import (
"testing"
"time"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"tailscale.com/types/ptr"
)
func TestResultString(t *testing.T) {
t.Parallel()
for _, tt := range []struct {
Expected string
Result Result
}{
{
Expected: "1.23/5.68 quatloos (22%)",
Result: Result{Used: 1.234, Total: ptr.To(5.678), Unit: "quatloos"},
},
{
Expected: "0/0 HP",
Result: Result{Used: 0.0, Total: ptr.To(0.0), Unit: "HP"},
},
{
Expected: "123 seconds",
Result: Result{Used: 123.01, Total: nil, Unit: "seconds"},
},
{
Expected: "12.3",
Result: Result{Used: 12.34, Total: nil, Unit: ""},
},
{
Expected: "1.5 KiB",
Result: Result{Used: 1536, Total: nil, Unit: "B", Prefix: PrefixKibi},
},
{
Expected: "1.23 things",
Result: Result{Used: 1.234, Total: nil, Unit: "things"},
},
{
Expected: "0/100 TiB (0%)",
Result: Result{Used: 1, Total: ptr.To(100.0 * float64(PrefixTebi)), Unit: "B", Prefix: PrefixTebi},
},
{
Expected: "0.5/8 cores (6%)",
Result: Result{Used: 0.5, Total: ptr.To(8.0), Unit: "cores"},
},
} {
assert.Equal(t, tt.Expected, tt.Result.String())
}
}
func TestStatter(t *testing.T) {
t.Parallel()
// We cannot make many assertions about the data we get back
// for host-specific measurements because these tests could
// and should run successfully on any OS.
// The best we can do is assert that it is non-zero.
t.Run("HostOnly", func(t *testing.T) {
t.Parallel()
fs := initFS(t, fsHostOnly)
s, err := New(WithFS(fs))
require.NoError(t, err)
t.Run("HostCPU", func(t *testing.T) {
t.Parallel()
cpu, err := s.HostCPU()
require.NoError(t, err)
// assert.NotZero(t, cpu.Used) // HostCPU can sometimes be zero.
assert.NotZero(t, cpu.Total)
assert.Equal(t, "cores", cpu.Unit)
})
t.Run("HostMemory", func(t *testing.T) {
t.Parallel()
mem, err := s.HostMemory(PrefixDefault)
require.NoError(t, err)
assert.NotZero(t, mem.Used)
assert.NotZero(t, mem.Total)
assert.Equal(t, "B", mem.Unit)
})
t.Run("HostDisk", func(t *testing.T) {
t.Parallel()
disk, err := s.Disk(PrefixDefault, "") // default to home dir
require.NoError(t, err)
assert.NotZero(t, disk.Used)
assert.NotZero(t, disk.Total)
assert.Equal(t, "B", disk.Unit)
})
})
// Sometimes we do need to "fake" some stuff
// that happens while we wait.
withWait := func(waitF func(time.Duration)) Option {
return func(s *Statter) {
s.wait = waitF
}
}
// Other times we just want things to run fast.
withNoWait := func(s *Statter) {
s.wait = func(time.Duration) {}
}
// We don't want to use the actual host CPU here.
withNproc := func(n int) Option {
return func(s *Statter) {
s.nproc = n
}
}
// For container-specific measurements, everything we need
// can be read from the filesystem. We control the FS, so
// we control the data.
t.Run("CGroupV1", func(t *testing.T) {
t.Parallel()
t.Run("ContainerCPU/Limit", func(t *testing.T) {
t.Parallel()
fs := initFS(t, fsContainerCgroupV1)
fakeWait := func(time.Duration) {
// Fake 1 second in ns of usage
mungeFS(t, fs, cgroupV1CPUAcctUsage, "100000000")
}
s, err := New(WithFS(fs), withWait(fakeWait))
require.NoError(t, err)
cpu, err := s.ContainerCPU()
require.NoError(t, err)
require.NotNil(t, cpu)
assert.Equal(t, 1.0, cpu.Used)
require.NotNil(t, cpu.Total)
assert.Equal(t, 2.5, *cpu.Total)
assert.Equal(t, "cores", cpu.Unit)
})
t.Run("ContainerCPU/NoLimit", func(t *testing.T) {
t.Parallel()
fs := initFS(t, fsContainerCgroupV1NoLimit)
fakeWait := func(time.Duration) {
// Fake 1 second in ns of usage
mungeFS(t, fs, cgroupV1CPUAcctUsage, "100000000")
}
s, err := New(WithFS(fs), withNproc(2), withWait(fakeWait))
require.NoError(t, err)
cpu, err := s.ContainerCPU()
require.NoError(t, err)
require.NotNil(t, cpu)
assert.Equal(t, 1.0, cpu.Used)
require.NotNil(t, cpu.Total)
assert.Equal(t, 2.0, *cpu.Total)
assert.Equal(t, "cores", cpu.Unit)
})
t.Run("ContainerMemory", func(t *testing.T) {
t.Parallel()
fs := initFS(t, fsContainerCgroupV1)
s, err := New(WithFS(fs), withNoWait)
require.NoError(t, err)
mem, err := s.ContainerMemory(PrefixDefault)
require.NoError(t, err)
require.NotNil(t, mem)
assert.Equal(t, 268435456.0, mem.Used)
assert.NotNil(t, mem.Total)
assert.Equal(t, 1073741824.0, *mem.Total)
assert.Equal(t, "B", mem.Unit)
})
})
t.Run("CGroupV2", func(t *testing.T) {
t.Parallel()
t.Run("ContainerCPU/Limit", func(t *testing.T) {
t.Parallel()
fs := initFS(t, fsContainerCgroupV2)
fakeWait := func(time.Duration) {
mungeFS(t, fs, cgroupV2CPUStat, "usage_usec 100000")
}
s, err := New(WithFS(fs), withWait(fakeWait))
require.NoError(t, err)
cpu, err := s.ContainerCPU()
require.NoError(t, err)
require.NotNil(t, cpu)
assert.Equal(t, 1.0, cpu.Used)
require.NotNil(t, cpu.Total)
assert.Equal(t, 2.5, *cpu.Total)
assert.Equal(t, "cores", cpu.Unit)
})
t.Run("ContainerCPU/NoLimit", func(t *testing.T) {
t.Parallel()
fs := initFS(t, fsContainerCgroupV2NoLimit)
fakeWait := func(time.Duration) {
mungeFS(t, fs, cgroupV2CPUStat, "usage_usec 100000")
}
s, err := New(WithFS(fs), withNproc(2), withWait(fakeWait))
require.NoError(t, err)
cpu, err := s.ContainerCPU()
require.NoError(t, err)
require.NotNil(t, cpu)
assert.Equal(t, 1.0, cpu.Used)
require.NotNil(t, cpu.Total)
assert.Equal(t, 2.0, *cpu.Total)
assert.Equal(t, "cores", cpu.Unit)
})
t.Run("ContainerMemory", func(t *testing.T) {
t.Parallel()
fs := initFS(t, fsContainerCgroupV2)
s, err := New(WithFS(fs), withNoWait)
require.NoError(t, err)
mem, err := s.ContainerMemory(PrefixDefault)
require.NoError(t, err)
require.NotNil(t, mem)
assert.Equal(t, 268435456.0, mem.Used)
assert.NotNil(t, mem.Total)
assert.Equal(t, 1073741824.0, *mem.Total)
assert.Equal(t, "B", mem.Unit)
})
})
}
func TestIsContainerized(t *testing.T) {
t.Parallel()
for _, tt := range []struct {
Name string
FS map[string]string
Expected bool
Error string
}{
{
Name: "Empty",
FS: map[string]string{},
Expected: false,
Error: "",
},
{
Name: "BareMetal",
FS: fsHostOnly,
Expected: false,
Error: "",
},
{
Name: "Docker",
FS: fsContainerCgroupV1,
Expected: true,
Error: "",
},
{
Name: "Sysbox",
FS: fsContainerSysbox,
Expected: true,
Error: "",
},
} {
tt := tt
t.Run(tt.Name, func(t *testing.T) {
t.Parallel()
fs := initFS(t, tt.FS)
actual, err := IsContainerized(fs)
if tt.Error == "" {
assert.NoError(t, err)
assert.Equal(t, tt.Expected, actual)
} else {
assert.ErrorContains(t, err, tt.Error)
assert.False(t, actual)
}
})
}
}
// helper function for initializing a fs
func initFS(t testing.TB, m map[string]string) afero.Fs {
t.Helper()
fs := afero.NewMemMapFs()
for k, v := range m {
mungeFS(t, fs, k, v)
}
return fs
}
// helper function for writing v to fs under path k
func mungeFS(t testing.TB, fs afero.Fs, k, v string) {
t.Helper()
require.NoError(t, afero.WriteFile(fs, k, []byte(v+"\n"), 0o600))
}
var (
fsHostOnly = map[string]string{
procOneCgroup: "0::/",
procMounts: "/dev/sda1 / ext4 rw,relatime 0 0",
}
fsContainerSysbox = map[string]string{
procOneCgroup: "0::/docker/aa86ac98959eeedeae0ecb6e0c9ddd8ae8b97a9d0fdccccf7ea7a474f4e0bb1f",
procMounts: `overlay / overlay rw,relatime,lowerdir=/some/path:/some/path,upperdir=/some/path:/some/path,workdir=/some/path:/some/path 0 0
sysboxfs /proc/sys proc ro,nosuid,nodev,noexec,relatime 0 0`,
cgroupV2CPUMax: "250000 100000",
cgroupV2CPUStat: "usage_usec 0",
}
fsContainerCgroupV2 = map[string]string{
procOneCgroup: "0::/docker/aa86ac98959eeedeae0ecb6e0c9ddd8ae8b97a9d0fdccccf7ea7a474f4e0bb1f",
procMounts: `overlay / overlay rw,relatime,lowerdir=/some/path:/some/path,upperdir=/some/path:/some/path,workdir=/some/path:/some/path 0 0
proc /proc/sys proc ro,nosuid,nodev,noexec,relatime 0 0`,
cgroupV2CPUMax: "250000 100000",
cgroupV2CPUStat: "usage_usec 0",
cgroupV2MemoryMaxBytes: "1073741824",
cgroupV2MemoryUsageBytes: "536870912",
cgroupV2MemoryStat: "inactive_file 268435456",
}
fsContainerCgroupV2NoLimit = map[string]string{
procOneCgroup: "0::/docker/aa86ac98959eeedeae0ecb6e0c9ddd8ae8b97a9d0fdccccf7ea7a474f4e0bb1f",
procMounts: `overlay / overlay rw,relatime,lowerdir=/some/path:/some/path,upperdir=/some/path:/some/path,workdir=/some/path:/some/path 0 0
proc /proc/sys proc ro,nosuid,nodev,noexec,relatime 0 0`,
cgroupV2CPUMax: "max 100000",
cgroupV2CPUStat: "usage_usec 0",
cgroupV2MemoryMaxBytes: "1073741824",
cgroupV2MemoryUsageBytes: "536870912",
cgroupV2MemoryStat: "inactive_file 268435456",
}
fsContainerCgroupV1 = map[string]string{
procOneCgroup: "0::/docker/aa86ac98959eeedeae0ecb6e0c9ddd8ae8b97a9d0fdccccf7ea7a474f4e0bb1f",
procMounts: `overlay / overlay rw,relatime,lowerdir=/some/path:/some/path,upperdir=/some/path:/some/path,workdir=/some/path:/some/path 0 0
proc /proc/sys proc ro,nosuid,nodev,noexec,relatime 0 0`,
cgroupV1CPUAcctUsage: "0",
cgroupV1CFSQuotaUs: "250000",
cgroupV1CFSPeriodUs: "100000",
cgroupV1MemoryMaxUsageBytes: "1073741824",
cgroupV1MemoryUsageBytes: "536870912",
cgroupV1MemoryStat: "total_inactive_file 268435456",
}
fsContainerCgroupV1NoLimit = map[string]string{
procOneCgroup: "0::/docker/aa86ac98959eeedeae0ecb6e0c9ddd8ae8b97a9d0fdccccf7ea7a474f4e0bb1f",
procMounts: `overlay / overlay rw,relatime,lowerdir=/some/path:/some/path,upperdir=/some/path:/some/path,workdir=/some/path:/some/path 0 0
proc /proc/sys proc ro,nosuid,nodev,noexec,relatime 0 0`,
cgroupV1CPUAcctUsage: "0",
cgroupV1CFSQuotaUs: "-1",
cgroupV1CFSPeriodUs: "100000",
cgroupV1MemoryMaxUsageBytes: "1073741824",
cgroupV1MemoryUsageBytes: "536870912",
cgroupV1MemoryStat: "total_inactive_file 268435456",
}
)
+181 -20
View File
@@ -3,47 +3,79 @@ package clitest
import (
"archive/tar"
"bytes"
"context"
"errors"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
"sync"
"sync/atomic"
"testing"
"time"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"cdr.dev/slog"
"cdr.dev/slog/sloggers/slogtest"
"github.com/coder/coder/cli"
"github.com/coder/coder/cli/clibase"
"github.com/coder/coder/cli/config"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/provisioner/echo"
"github.com/coder/coder/testutil"
)
// New creates a CLI instance with a configuration pointed to a
// temporary testing directory.
func New(t *testing.T, args ...string) (*cobra.Command, config.Root) {
return NewWithSubcommands(t, cli.AGPL(), args...)
func New(t *testing.T, args ...string) (*clibase.Invocation, config.Root) {
var root cli.RootCmd
cmd, err := root.Command(root.AGPL())
require.NoError(t, err)
return NewWithCommand(t, cmd, args...)
}
func NewWithSubcommands(
t *testing.T, subcommands []*cobra.Command, args ...string,
) (*cobra.Command, config.Root) {
cmd := cli.Root(subcommands)
dir := t.TempDir()
root := config.Root(dir)
cmd.SetArgs(append([]string{"--global-config", dir}, args...))
type logWriter struct {
prefix string
log slog.Logger
}
// We could consider using writers
// that log via t.Log here instead.
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
func (l *logWriter) Write(p []byte) (n int, err error) {
trimmed := strings.TrimSpace(string(p))
if trimmed == "" {
return len(p), nil
}
l.log.Info(
context.Background(),
l.prefix+": "+trimmed,
)
return len(p), nil
}
return cmd, root
func NewWithCommand(
t *testing.T, cmd *clibase.Cmd, args ...string,
) (*clibase.Invocation, config.Root) {
configDir := config.Root(t.TempDir())
logger := slogtest.Make(t, nil)
i := &clibase.Invocation{
Command: cmd,
Args: append([]string{"--global-config", string(configDir)}, args...),
Stdin: io.LimitReader(nil, 0),
Stdout: (&logWriter{prefix: "stdout", log: logger}),
Stderr: (&logWriter{prefix: "stderr", log: logger}),
}
t.Logf("invoking command: %s %s", cmd.Name(), strings.Join(i.Args, " "))
// These can be overridden by the test.
return i, configDir
}
// SetupConfig applies the URL and SessionToken of the client to the config.
func SetupConfig(t *testing.T, client *codersdk.Client, root config.Root) {
err := root.Session().Write(client.SessionToken)
err := root.Session().Write(client.SessionToken())
require.NoError(t, err)
err = root.URL().Write(client.URL.String())
require.NoError(t, err)
@@ -53,9 +85,12 @@ func SetupConfig(t *testing.T, client *codersdk.Client, root config.Root) {
// new temporary testing directory.
func CreateTemplateVersionSource(t *testing.T, responses *echo.Responses) string {
directory := t.TempDir()
f, err := ioutil.TempFile(directory, "*.tf")
f, err := os.CreateTemp(directory, "*.tf")
require.NoError(t, err)
f.Close()
_ = f.Close()
f, err = os.Create(filepath.Join(directory, ".terraform.lock.hcl"))
require.NoError(t, err)
_ = f.Close()
data, err := echo.Tar(responses)
require.NoError(t, err)
extractTar(t, data, directory)
@@ -70,11 +105,14 @@ func extractTar(t *testing.T, data []byte, directory string) {
break
}
require.NoError(t, err)
if header.Name == "." || strings.Contains(header.Name, "..") {
continue
}
// #nosec
path := filepath.Join(directory, header.Name)
mode := header.FileInfo().Mode()
if mode == 0 {
mode = 0600
mode = 0o600
}
switch header.Typeflag {
case tar.TypeDir:
@@ -94,3 +132,126 @@ func extractTar(t *testing.T, data []byte, directory string) {
}
}
}
// Start runs the command in a goroutine and cleans it up when the test
// completed.
func Start(t *testing.T, inv *clibase.Invocation) {
t.Helper()
closeCh := make(chan struct{})
// StartWithWaiter adds its own `t.Cleanup`, so we need to be sure it's added
// before ours.
waiter := StartWithWaiter(t, inv)
t.Cleanup(func() {
waiter.Cancel()
<-closeCh
})
go func() {
defer close(closeCh)
err := waiter.Wait()
switch {
case errors.Is(err, context.Canceled):
return
default:
assert.NoError(t, err)
}
}()
}
// Run runs the command and asserts that there is no error.
func Run(t *testing.T, inv *clibase.Invocation) {
t.Helper()
err := inv.Run()
require.NoError(t, err)
}
type ErrorWaiter struct {
waitOnce sync.Once
cachedError error
cancelFunc context.CancelFunc
c <-chan error
t *testing.T
}
func (w *ErrorWaiter) Cancel() {
w.cancelFunc()
}
func (w *ErrorWaiter) Wait() error {
w.waitOnce.Do(func() {
var ok bool
w.cachedError, ok = <-w.c
if !ok {
panic("unexpected channel close")
}
})
return w.cachedError
}
func (w *ErrorWaiter) RequireSuccess() {
require.NoError(w.t, w.Wait())
}
func (w *ErrorWaiter) RequireError() {
require.Error(w.t, w.Wait())
}
func (w *ErrorWaiter) RequireContains(s string) {
require.ErrorContains(w.t, w.Wait(), s)
}
func (w *ErrorWaiter) RequireIs(want error) {
require.ErrorIs(w.t, w.Wait(), want)
}
func (w *ErrorWaiter) RequireAs(want interface{}) {
require.ErrorAs(w.t, w.Wait(), want)
}
// StartWithWaiter runs the command in a goroutine but returns the error instead
// of asserting it. This is useful for testing error cases.
func StartWithWaiter(t *testing.T, inv *clibase.Invocation) *ErrorWaiter {
t.Helper()
var (
ctx = inv.Context()
cancel func()
cleaningUp atomic.Bool
errCh = make(chan error, 1)
doneCh = make(chan struct{})
)
if _, ok := ctx.Deadline(); !ok {
ctx, cancel = context.WithDeadline(ctx, time.Now().Add(testutil.WaitMedium))
} else {
ctx, cancel = context.WithCancel(inv.Context())
}
inv = inv.WithContext(ctx)
go func() {
defer close(doneCh)
defer close(errCh)
err := inv.Run()
if cleaningUp.Load() && errors.Is(err, context.DeadlineExceeded) {
// If we're cleaning up, this error is likely related to the CLI
// teardown process. E.g., the server could be slow to shut down
// Postgres.
t.Logf("command %q timed out during test cleanup", inv.Command.FullName())
}
// Whether or not this fails the test is left to the caller.
t.Logf("command %q exited with error: %v", inv.Command.FullName(), err)
errCh <- err
}()
// Don't exit test routine until server is done.
t.Cleanup(func() {
cancel()
cleaningUp.Store(true)
<-doneCh
})
return &ErrorWaiter{c: errCh, t: t, cancelFunc: cancel}
}
+3 -7
View File
@@ -18,13 +18,9 @@ func TestCli(t *testing.T) {
t.Parallel()
clitest.CreateTemplateVersionSource(t, nil)
client := coderdtest.New(t, nil)
cmd, config := clitest.New(t)
i, config := clitest.New(t)
clitest.SetupConfig(t, client, config)
pty := ptytest.New(t)
cmd.SetIn(pty.Input())
cmd.SetOut(pty.Output())
go func() {
_ = cmd.Execute()
}()
pty := ptytest.New(t).Attach(i)
clitest.Start(t, i)
pty.ExpectMatch("coder")
}
+222
View File
@@ -0,0 +1,222 @@
package clitest
import (
"bytes"
"context"
"flag"
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
"testing"
"github.com/charmbracelet/lipgloss"
"github.com/muesli/termenv"
"github.com/stretchr/testify/require"
"github.com/coder/coder/cli/clibase"
"github.com/coder/coder/cli/config"
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/coderd/database/dbtestutil"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/testutil"
)
// UpdateGoldenFiles indicates golden files should be updated.
// To update the golden files:
// make update-golden-files
var UpdateGoldenFiles = flag.Bool("update", false, "update .golden files")
var timestampRegex = regexp.MustCompile(`(?i)\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(.\d+)?Z`)
type CommandHelpCase struct {
Name string
Cmd []string
}
func DefaultCases() []CommandHelpCase {
return []CommandHelpCase{
{
Name: "coder --help",
Cmd: []string{"--help"},
},
{
Name: "coder server --help",
Cmd: []string{"server", "--help"},
},
}
}
// TestCommandHelp will test the help output of the given commands
// using golden files.
//
//nolint:tparallel,paralleltest
func TestCommandHelp(t *testing.T, getRoot func(t *testing.T) *clibase.Cmd, cases []CommandHelpCase) {
ogColorProfile := lipgloss.ColorProfile()
// ANSI256 escape codes are far easier for humans to parse in a diff,
// but TrueColor is probably more popular with modern terminals.
lipgloss.SetColorProfile(termenv.ANSI)
t.Cleanup(func() {
lipgloss.SetColorProfile(ogColorProfile)
})
rootClient, replacements := prepareTestData(t)
root := getRoot(t)
ExtractCommandPathsLoop:
for _, cp := range extractVisibleCommandPaths(nil, root.Children) {
name := fmt.Sprintf("coder %s --help", strings.Join(cp, " "))
cmd := append(cp, "--help")
for _, tt := range cases {
if tt.Name == name {
continue ExtractCommandPathsLoop
}
}
cases = append(cases, CommandHelpCase{Name: name, Cmd: cmd})
}
for _, tt := range cases {
tt := tt
t.Run(tt.Name, func(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitLong)
var outBuf bytes.Buffer
caseCmd := getRoot(t)
inv, cfg := NewWithCommand(t, caseCmd, tt.Cmd...)
inv.Stderr = &outBuf
inv.Stdout = &outBuf
inv.Environ.Set("CODER_URL", rootClient.URL.String())
inv.Environ.Set("CODER_SESSION_TOKEN", rootClient.SessionToken())
inv.Environ.Set("CODER_CACHE_DIRECTORY", "~/.cache")
SetupConfig(t, rootClient, cfg)
StartWithWaiter(t, inv.WithContext(ctx)).RequireSuccess()
actual := outBuf.Bytes()
if len(actual) == 0 {
t.Fatal("no output")
}
for k, v := range replacements {
actual = bytes.ReplaceAll(actual, []byte(k), []byte(v))
}
actual = NormalizeGoldenFile(t, actual)
goldenPath := filepath.Join("testdata", strings.Replace(tt.Name, " ", "_", -1)+".golden")
if *UpdateGoldenFiles {
t.Logf("update golden file for: %q: %s", tt.Name, goldenPath)
err := os.WriteFile(goldenPath, actual, 0o600)
require.NoError(t, err, "update golden file")
}
expected, err := os.ReadFile(goldenPath)
require.NoError(t, err, "read golden file, run \"make update-golden-files\" and commit the changes")
expected = NormalizeGoldenFile(t, expected)
require.Equal(
t, string(expected), string(actual),
"golden file mismatch: %s, run \"make update-golden-files\", verify and commit the changes",
goldenPath,
)
})
}
}
// NormalizeGoldenFile replaces any strings that are system or timing dependent
// with a placeholder so that the golden files can be compared with a simple
// equality check.
func NormalizeGoldenFile(t *testing.T, byt []byte) []byte {
// Replace any timestamps with a placeholder.
byt = timestampRegex.ReplaceAll(byt, []byte("[timestamp]"))
homeDir, err := os.UserHomeDir()
require.NoError(t, err)
configDir := config.DefaultDir()
byt = bytes.ReplaceAll(byt, []byte(configDir), []byte("~/.config/coderv2"))
byt = bytes.ReplaceAll(byt, []byte(codersdk.DefaultCacheDir()), []byte("[cache dir]"))
// The home directory changes depending on the test environment.
byt = bytes.ReplaceAll(byt, []byte(homeDir), []byte("~"))
for _, r := range []struct {
old string
new string
}{
{"\r\n", "\n"},
{`~\.cache\coder`, "~/.cache/coder"},
{`C:\Users\RUNNER~1\AppData\Local\Temp`, "/tmp"},
{os.TempDir(), "/tmp"},
} {
byt = bytes.ReplaceAll(byt, []byte(r.old), []byte(r.new))
}
return byt
}
func extractVisibleCommandPaths(cmdPath []string, cmds []*clibase.Cmd) [][]string {
var cmdPaths [][]string
for _, c := range cmds {
if c.Hidden {
continue
}
cmdPath := append(cmdPath, c.Name())
cmdPaths = append(cmdPaths, cmdPath)
cmdPaths = append(cmdPaths, extractVisibleCommandPaths(cmdPath, c.Children)...)
}
return cmdPaths
}
func prepareTestData(t *testing.T) (*codersdk.Client, map[string]string) {
t.Helper()
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
db, pubsub := dbtestutil.NewDB(t)
rootClient := coderdtest.New(t, &coderdtest.Options{
Database: db,
Pubsub: pubsub,
IncludeProvisionerDaemon: true,
})
firstUser := coderdtest.CreateFirstUser(t, rootClient)
secondUser, err := rootClient.CreateUser(ctx, codersdk.CreateUserRequest{
Email: "testuser2@coder.com",
Username: "testuser2",
Password: coderdtest.FirstUserParams.Password,
OrganizationID: firstUser.OrganizationID,
})
require.NoError(t, err)
version := coderdtest.CreateTemplateVersion(t, rootClient, firstUser.OrganizationID, nil)
version = coderdtest.AwaitTemplateVersionJob(t, rootClient, version.ID)
template := coderdtest.CreateTemplate(t, rootClient, firstUser.OrganizationID, version.ID, func(req *codersdk.CreateTemplateRequest) {
req.Name = "test-template"
})
workspace := coderdtest.CreateWorkspace(t, rootClient, firstUser.OrganizationID, template.ID, func(req *codersdk.CreateWorkspaceRequest) {
req.Name = "test-workspace"
})
workspaceBuild := coderdtest.AwaitWorkspaceBuildJob(t, rootClient, workspace.LatestBuild.ID)
replacements := map[string]string{
firstUser.UserID.String(): "[first user ID]",
secondUser.ID.String(): "[second user ID]",
firstUser.OrganizationID.String(): "[first org ID]",
version.ID.String(): "[version ID]",
version.Name: "[version name]",
version.Job.ID.String(): "[version job ID]",
version.Job.FileID.String(): "[version file ID]",
version.Job.WorkerID.String(): "[version worker ID]",
template.ID.String(): "[template ID]",
workspace.ID.String(): "[workspace ID]",
workspaceBuild.ID.String(): "[workspace build ID]",
workspaceBuild.Job.ID.String(): "[workspace build job ID]",
workspaceBuild.Job.FileID.String(): "[workspace build file ID]",
workspaceBuild.Job.WorkerID.String(): "[workspace build worker ID]",
}
return rootClient, replacements
}
+24
View File
@@ -0,0 +1,24 @@
package clitest
import (
"testing"
"github.com/coder/coder/cli/clibase"
)
// HandlersOK asserts that all commands have a handler.
// Without a handler, the command has no default behavior. Even for
// non-root commands (like 'groups' or 'users'), a handler is required.
// These handlers are likely just the 'help' handler, but this must be
// explicitly set.
func HandlersOK(t *testing.T, cmd *clibase.Cmd) {
cmd.Walk(func(cmd *clibase.Cmd) {
if cmd.Handler == nil {
// If you see this error, make the Handler a helper invoker.
// Handler: func(inv *clibase.Invocation) error {
// return inv.Command.HelpHandler(inv)
// },
t.Errorf("command %q has no handler, change to a helper invoker using: 'inv.Command.HelpHandler(inv)'", cmd.Name())
}
})
}
+197 -75
View File
@@ -2,24 +2,22 @@ package cliui
import (
"context"
"fmt"
"io"
"os"
"os/signal"
"sync"
"time"
"github.com/briandowns/spinner"
"github.com/google/uuid"
"golang.org/x/xerrors"
"github.com/coder/coder/codersdk"
)
var errAgentShuttingDown = xerrors.New("agent is shutting down")
type AgentOptions struct {
WorkspaceName string
Fetch func(context.Context) (codersdk.WorkspaceAgent, error)
FetchInterval time.Duration
WarnInterval time.Duration
Fetch func(context.Context) (codersdk.WorkspaceAgent, error)
FetchLogs func(ctx context.Context, agentID uuid.UUID, after int64, follow bool) (<-chan []codersdk.WorkspaceAgentStartupLog, io.Closer, error)
Wait bool // If true, wait for the agent to be ready (startup script).
}
// Agent displays a spinning indicator that waits for a workspace agent to connect.
@@ -27,81 +25,205 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
if opts.FetchInterval == 0 {
opts.FetchInterval = 500 * time.Millisecond
}
if opts.WarnInterval == 0 {
opts.WarnInterval = 30 * time.Second
if opts.FetchLogs == nil {
opts.FetchLogs = func(_ context.Context, _ uuid.UUID, _ int64, _ bool) (<-chan []codersdk.WorkspaceAgentStartupLog, io.Closer, error) {
c := make(chan []codersdk.WorkspaceAgentStartupLog)
close(c)
return c, closeFunc(func() error { return nil }), nil
}
}
var resourceMutex sync.Mutex
agent, err := opts.Fetch(ctx)
type fetchAgent struct {
agent codersdk.WorkspaceAgent
err error
}
fetchedAgent := make(chan fetchAgent, 1)
go func() {
t := time.NewTimer(0)
defer t.Stop()
for {
select {
case <-ctx.Done():
return
case <-t.C:
agent, err := opts.Fetch(ctx)
select {
case <-fetchedAgent:
default:
}
if err != nil {
fetchedAgent <- fetchAgent{err: xerrors.Errorf("fetch workspace agent: %w", err)}
return
}
fetchedAgent <- fetchAgent{agent: agent}
t.Reset(opts.FetchInterval)
}
}
}()
fetch := func() (codersdk.WorkspaceAgent, error) {
select {
case <-ctx.Done():
return codersdk.WorkspaceAgent{}, ctx.Err()
case f := <-fetchedAgent:
if f.err != nil {
return codersdk.WorkspaceAgent{}, f.err
}
return f.agent, nil
}
}
agent, err := fetch()
if err != nil {
return xerrors.Errorf("fetch: %w", err)
}
if agent.Status == codersdk.WorkspaceAgentConnected {
return nil
}
if agent.Status == codersdk.WorkspaceAgentDisconnected {
opts.WarnInterval = 0
}
spin := spinner.New(spinner.CharSets[78], 100*time.Millisecond, spinner.WithColor("fgHiGreen"))
spin.Writer = writer
spin.ForceOutput = true
spin.Suffix = " Waiting for connection from " + Styles.Field.Render(agent.Name) + "..."
spin.Start()
defer spin.Stop()
ctx, cancelFunc := context.WithCancel(ctx)
defer cancelFunc()
stopSpin := make(chan os.Signal, 1)
signal.Notify(stopSpin, os.Interrupt)
defer signal.Stop(stopSpin)
go func() {
select {
case <-ctx.Done():
return
case <-stopSpin:
}
signal.Stop(stopSpin)
spin.Stop()
// nolint:revive
os.Exit(1)
}()
sw := &stageWriter{w: writer}
ticker := time.NewTicker(opts.FetchInterval)
defer ticker.Stop()
timer := time.NewTimer(opts.WarnInterval)
defer timer.Stop()
go func() {
select {
case <-ctx.Done():
return
case <-timer.C:
}
resourceMutex.Lock()
defer resourceMutex.Unlock()
message := "Don't panic, your workspace is booting up!"
if agent.Status == codersdk.WorkspaceAgentDisconnected {
message = "The workspace agent lost connection! Wait for it to reconnect or restart your workspace."
}
// This saves the cursor position, then defers clearing from the cursor
// position to the end of the screen.
_, _ = fmt.Fprintf(writer, "\033[s\r\033[2K%s\n\n", Styles.Paragraph.Render(Styles.Prompt.String()+message))
defer fmt.Fprintf(writer, "\033[u\033[J")
}()
showStartupLogs := false
for {
select {
case <-ctx.Done():
return ctx.Err()
case <-ticker.C:
// It doesn't matter if we're connected or not, if the agent is
// shutting down, we don't know if it's coming back.
if agent.LifecycleState.ShuttingDown() {
return errAgentShuttingDown
}
resourceMutex.Lock()
agent, err = opts.Fetch(ctx)
if err != nil {
return xerrors.Errorf("fetch: %w", err)
switch agent.Status {
case codersdk.WorkspaceAgentConnecting, codersdk.WorkspaceAgentTimeout:
// Since we were waiting for the agent to connect, also show
// startup logs if applicable.
showStartupLogs = true
stage := "Waiting for the workspace agent to connect"
sw.Start(stage)
for agent.Status == codersdk.WorkspaceAgentConnecting {
if agent, err = fetch(); err != nil {
return xerrors.Errorf("fetch: %w", err)
}
}
if agent.Status == codersdk.WorkspaceAgentTimeout {
now := time.Now()
sw.Log(now, codersdk.LogLevelInfo, "The workspace agent is having trouble connecting, wait for it to connect or restart your workspace.")
sw.Log(now, codersdk.LogLevelInfo, troubleshootingMessage(agent, "https://coder.com/docs/v2/latest/templates#agent-connection-issues"))
for agent.Status == codersdk.WorkspaceAgentTimeout {
if agent, err = fetch(); err != nil {
return xerrors.Errorf("fetch: %w", err)
}
}
}
sw.Complete(stage, agent.FirstConnectedAt.Sub(agent.CreatedAt))
case codersdk.WorkspaceAgentConnected:
if !showStartupLogs && agent.LifecycleState == codersdk.WorkspaceAgentLifecycleReady {
// The workspace is ready, there's nothing to do but connect.
return nil
}
stage := "Running workspace agent startup script"
follow := opts.Wait
if !follow {
stage += " (non-blocking)"
}
sw.Start(stage)
err = func() error { // Use func because of defer in for loop.
logStream, logsCloser, err := opts.FetchLogs(ctx, agent.ID, 0, follow)
if err != nil {
return xerrors.Errorf("fetch workspace agent startup logs: %w", err)
}
defer logsCloser.Close()
for {
// This select is essentially and inline `fetch()`.
select {
case <-ctx.Done():
return ctx.Err()
case f := <-fetchedAgent:
if f.err != nil {
return xerrors.Errorf("fetch: %w", f.err)
}
// We could handle changes in the agent status here, like
// if the agent becomes disconnected, we may want to stop.
// But for now, we'll just keep going, hopefully the agent
// will reconnect and update its status.
agent = f.agent
case logs, ok := <-logStream:
if !ok {
return nil
}
for _, log := range logs {
sw.Log(log.CreatedAt, log.Level, log.Output)
}
}
}
}()
if err != nil {
return err
}
for follow && agent.LifecycleState.Starting() {
if agent, err = fetch(); err != nil {
return xerrors.Errorf("fetch: %w", err)
}
}
switch agent.LifecycleState {
case codersdk.WorkspaceAgentLifecycleReady:
sw.Complete(stage, agent.ReadyAt.Sub(*agent.StartedAt))
case codersdk.WorkspaceAgentLifecycleStartError:
sw.Fail(stage, agent.ReadyAt.Sub(*agent.StartedAt))
// Use zero time (omitted) to separate these from the startup logs.
sw.Log(time.Time{}, codersdk.LogLevelWarn, "Warning: The startup script exited with an error and your workspace may be incomplete.")
sw.Log(time.Time{}, codersdk.LogLevelWarn, troubleshootingMessage(agent, "https://coder.com/docs/v2/latest/templates#startup-script-exited-with-an-error"))
default:
switch {
case agent.LifecycleState.Starting():
// Use zero time (omitted) to separate these from the startup logs.
sw.Log(time.Time{}, codersdk.LogLevelWarn, "Notice: The startup script is still running and your workspace may be incomplete.")
sw.Log(time.Time{}, codersdk.LogLevelWarn, troubleshootingMessage(agent, "https://coder.com/docs/v2/latest/templates#your-workspace-may-be-incomplete"))
// Note: We don't complete or fail the stage here, it's
// intentionally left open to indicate this stage didn't
// complete.
case agent.LifecycleState.ShuttingDown():
// We no longer know if the startup script failed or not,
// but we need to tell the user something.
sw.Complete(stage, agent.ReadyAt.Sub(*agent.StartedAt))
return errAgentShuttingDown
}
}
return nil
case codersdk.WorkspaceAgentDisconnected:
// If the agent was still starting during disconnect, we'll
// show startup logs.
showStartupLogs = agent.LifecycleState.Starting()
stage := "The workspace agent lost connection"
sw.Start(stage)
sw.Log(time.Now(), codersdk.LogLevelWarn, "Wait for it to reconnect or restart your workspace.")
sw.Log(time.Now(), codersdk.LogLevelWarn, troubleshootingMessage(agent, "https://coder.com/docs/v2/latest/templates#agent-connection-issues"))
for agent.Status == codersdk.WorkspaceAgentDisconnected {
if agent, err = fetch(); err != nil {
return xerrors.Errorf("fetch: %w", err)
}
}
sw.Complete(stage, agent.LastConnectedAt.Sub(*agent.DisconnectedAt))
}
if agent.Status != codersdk.WorkspaceAgentConnected {
resourceMutex.Unlock()
continue
}
resourceMutex.Unlock()
return nil
}
}
func troubleshootingMessage(agent codersdk.WorkspaceAgent, url string) string {
m := "For more information and troubleshooting, see " + url
if agent.TroubleshootingURL != "" {
m += " and " + agent.TroubleshootingURL
}
return m
}
type closeFunc func() error
func (c closeFunc) Close() error {
return c()
}
+337 -35
View File
@@ -1,51 +1,353 @@
package cliui_test
import (
"bufio"
"bytes"
"context"
"io"
"strings"
"testing"
"time"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"go.uber.org/atomic"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"golang.org/x/xerrors"
"github.com/coder/coder/cli/clibase"
"github.com/coder/coder/cli/clitest"
"github.com/coder/coder/cli/cliui"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/pty/ptytest"
"github.com/coder/coder/testutil"
)
func TestAgent(t *testing.T) {
t.Parallel()
var disconnected atomic.Bool
ptty := ptytest.New(t)
cmd := &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
err := cliui.Agent(cmd.Context(), cmd.OutOrStdout(), cliui.AgentOptions{
WorkspaceName: "example",
Fetch: func(ctx context.Context) (codersdk.WorkspaceAgent, error) {
agent := codersdk.WorkspaceAgent{
Status: codersdk.WorkspaceAgentDisconnected,
}
if disconnected.Load() {
agent.Status = codersdk.WorkspaceAgentConnected
}
return agent, nil
},
FetchInterval: time.Millisecond,
WarnInterval: 10 * time.Millisecond,
})
return err
},
ptrTime := func(t time.Time) *time.Time {
return &t
}
for _, tc := range []struct {
name string
iter []func(context.Context, *codersdk.WorkspaceAgent, chan []codersdk.WorkspaceAgentStartupLog) error
logs chan []codersdk.WorkspaceAgentStartupLog
opts cliui.AgentOptions
want []string
wantErr bool
}{
{
name: "Initial connection",
opts: cliui.AgentOptions{
FetchInterval: time.Millisecond,
},
iter: []func(context.Context, *codersdk.WorkspaceAgent, chan []codersdk.WorkspaceAgentStartupLog) error{
func(_ context.Context, agent *codersdk.WorkspaceAgent, _ chan []codersdk.WorkspaceAgentStartupLog) error {
agent.Status = codersdk.WorkspaceAgentConnecting
return nil
},
func(_ context.Context, agent *codersdk.WorkspaceAgent, logs chan []codersdk.WorkspaceAgentStartupLog) error {
agent.Status = codersdk.WorkspaceAgentConnected
agent.FirstConnectedAt = ptrTime(time.Now())
close(logs)
return nil
},
},
want: []string{
"⧗ Waiting for the workspace agent to connect",
"✔ Waiting for the workspace agent to connect",
"⧗ Running workspace agent startup script (non-blocking)",
"Notice: The startup script is still running and your workspace may be incomplete.",
"For more information and troubleshooting, see",
},
},
{
name: "Initial connection timeout",
opts: cliui.AgentOptions{
FetchInterval: 1 * time.Millisecond,
},
iter: []func(context.Context, *codersdk.WorkspaceAgent, chan []codersdk.WorkspaceAgentStartupLog) error{
func(_ context.Context, agent *codersdk.WorkspaceAgent, _ chan []codersdk.WorkspaceAgentStartupLog) error {
agent.Status = codersdk.WorkspaceAgentConnecting
agent.LifecycleState = codersdk.WorkspaceAgentLifecycleStarting
agent.StartedAt = ptrTime(time.Now())
return nil
},
func(_ context.Context, agent *codersdk.WorkspaceAgent, _ chan []codersdk.WorkspaceAgentStartupLog) error {
agent.Status = codersdk.WorkspaceAgentTimeout
return nil
},
func(_ context.Context, agent *codersdk.WorkspaceAgent, logs chan []codersdk.WorkspaceAgentStartupLog) error {
agent.Status = codersdk.WorkspaceAgentConnected
agent.FirstConnectedAt = ptrTime(time.Now())
agent.LifecycleState = codersdk.WorkspaceAgentLifecycleReady
agent.ReadyAt = ptrTime(time.Now())
close(logs)
return nil
},
},
want: []string{
"⧗ Waiting for the workspace agent to connect",
"The workspace agent is having trouble connecting, wait for it to connect or restart your workspace.",
"For more information and troubleshooting, see",
"✔ Waiting for the workspace agent to connect",
"⧗ Running workspace agent startup script (non-blocking)",
"✔ Running workspace agent startup script (non-blocking)",
},
},
{
name: "Disconnected",
opts: cliui.AgentOptions{
FetchInterval: 1 * time.Millisecond,
},
iter: []func(context.Context, *codersdk.WorkspaceAgent, chan []codersdk.WorkspaceAgentStartupLog) error{
func(_ context.Context, agent *codersdk.WorkspaceAgent, _ chan []codersdk.WorkspaceAgentStartupLog) error {
agent.Status = codersdk.WorkspaceAgentDisconnected
agent.FirstConnectedAt = ptrTime(time.Now().Add(-1 * time.Minute))
agent.LastConnectedAt = ptrTime(time.Now().Add(-1 * time.Minute))
agent.DisconnectedAt = ptrTime(time.Now())
agent.LifecycleState = codersdk.WorkspaceAgentLifecycleReady
agent.StartedAt = ptrTime(time.Now().Add(-1 * time.Minute))
agent.ReadyAt = ptrTime(time.Now())
return nil
},
func(_ context.Context, agent *codersdk.WorkspaceAgent, _ chan []codersdk.WorkspaceAgentStartupLog) error {
agent.Status = codersdk.WorkspaceAgentConnected
agent.LastConnectedAt = ptrTime(time.Now())
return nil
},
func(_ context.Context, _ *codersdk.WorkspaceAgent, logs chan []codersdk.WorkspaceAgentStartupLog) error {
close(logs)
return nil
},
},
want: []string{
"⧗ The workspace agent lost connection",
"Wait for it to reconnect or restart your workspace.",
"For more information and troubleshooting, see",
"✔ The workspace agent lost connection",
},
},
{
name: "Startup script logs",
opts: cliui.AgentOptions{
FetchInterval: time.Millisecond,
Wait: true,
},
iter: []func(context.Context, *codersdk.WorkspaceAgent, chan []codersdk.WorkspaceAgentStartupLog) error{
func(_ context.Context, agent *codersdk.WorkspaceAgent, logs chan []codersdk.WorkspaceAgentStartupLog) error {
agent.Status = codersdk.WorkspaceAgentConnected
agent.FirstConnectedAt = ptrTime(time.Now())
agent.LifecycleState = codersdk.WorkspaceAgentLifecycleStarting
agent.StartedAt = ptrTime(time.Now())
logs <- []codersdk.WorkspaceAgentStartupLog{
{
CreatedAt: time.Now(),
Output: "Hello world",
},
}
return nil
},
func(_ context.Context, agent *codersdk.WorkspaceAgent, logs chan []codersdk.WorkspaceAgentStartupLog) error {
agent.LifecycleState = codersdk.WorkspaceAgentLifecycleReady
agent.ReadyAt = ptrTime(time.Now())
logs <- []codersdk.WorkspaceAgentStartupLog{
{
CreatedAt: time.Now(),
Output: "Bye now",
},
}
close(logs)
return nil
},
},
want: []string{
"⧗ Running workspace agent startup script",
"Hello world",
"Bye now",
"✔ Running workspace agent startup script",
},
},
{
name: "Startup script exited with error",
opts: cliui.AgentOptions{
FetchInterval: time.Millisecond,
Wait: true,
},
iter: []func(context.Context, *codersdk.WorkspaceAgent, chan []codersdk.WorkspaceAgentStartupLog) error{
func(_ context.Context, agent *codersdk.WorkspaceAgent, logs chan []codersdk.WorkspaceAgentStartupLog) error {
agent.Status = codersdk.WorkspaceAgentConnected
agent.FirstConnectedAt = ptrTime(time.Now())
agent.StartedAt = ptrTime(time.Now())
agent.LifecycleState = codersdk.WorkspaceAgentLifecycleStartError
agent.ReadyAt = ptrTime(time.Now())
logs <- []codersdk.WorkspaceAgentStartupLog{
{
CreatedAt: time.Now(),
Output: "Hello world",
},
}
close(logs)
return nil
},
},
want: []string{
"⧗ Running workspace agent startup script",
"Hello world",
"✘ Running workspace agent startup script",
"Warning: The startup script exited with an error and your workspace may be incomplete.",
"For more information and troubleshooting, see",
},
},
{
name: "Error when shutting down",
opts: cliui.AgentOptions{
FetchInterval: time.Millisecond,
},
iter: []func(context.Context, *codersdk.WorkspaceAgent, chan []codersdk.WorkspaceAgentStartupLog) error{
func(_ context.Context, agent *codersdk.WorkspaceAgent, logs chan []codersdk.WorkspaceAgentStartupLog) error {
agent.Status = codersdk.WorkspaceAgentDisconnected
agent.LifecycleState = codersdk.WorkspaceAgentLifecycleOff
close(logs)
return nil
},
},
wantErr: true,
},
{
name: "Error when shutting down while waiting",
opts: cliui.AgentOptions{
FetchInterval: time.Millisecond,
Wait: true,
},
iter: []func(context.Context, *codersdk.WorkspaceAgent, chan []codersdk.WorkspaceAgentStartupLog) error{
func(_ context.Context, agent *codersdk.WorkspaceAgent, logs chan []codersdk.WorkspaceAgentStartupLog) error {
agent.Status = codersdk.WorkspaceAgentConnected
agent.FirstConnectedAt = ptrTime(time.Now())
agent.LifecycleState = codersdk.WorkspaceAgentLifecycleStarting
agent.StartedAt = ptrTime(time.Now())
logs <- []codersdk.WorkspaceAgentStartupLog{
{
CreatedAt: time.Now(),
Output: "Hello world",
},
}
return nil
},
func(_ context.Context, agent *codersdk.WorkspaceAgent, logs chan []codersdk.WorkspaceAgentStartupLog) error {
agent.ReadyAt = ptrTime(time.Now())
agent.LifecycleState = codersdk.WorkspaceAgentLifecycleShuttingDown
close(logs)
return nil
},
},
want: []string{
"⧗ Running workspace agent startup script",
"Hello world",
"✔ Running workspace agent startup script",
},
wantErr: true,
},
{
name: "Error during fetch",
opts: cliui.AgentOptions{
FetchInterval: time.Millisecond,
Wait: true,
},
iter: []func(context.Context, *codersdk.WorkspaceAgent, chan []codersdk.WorkspaceAgentStartupLog) error{
func(_ context.Context, agent *codersdk.WorkspaceAgent, _ chan []codersdk.WorkspaceAgentStartupLog) error {
agent.Status = codersdk.WorkspaceAgentConnecting
return nil
},
func(_ context.Context, agent *codersdk.WorkspaceAgent, _ chan []codersdk.WorkspaceAgentStartupLog) error {
return xerrors.New("bad")
},
},
want: []string{
"⧗ Waiting for the workspace agent to connect",
},
wantErr: true,
},
{
name: "Shows agent troubleshooting URL",
opts: cliui.AgentOptions{
FetchInterval: time.Millisecond,
Wait: true,
},
iter: []func(context.Context, *codersdk.WorkspaceAgent, chan []codersdk.WorkspaceAgentStartupLog) error{
func(_ context.Context, agent *codersdk.WorkspaceAgent, _ chan []codersdk.WorkspaceAgentStartupLog) error {
agent.Status = codersdk.WorkspaceAgentTimeout
agent.TroubleshootingURL = "https://troubleshoot"
return nil
},
func(_ context.Context, agent *codersdk.WorkspaceAgent, _ chan []codersdk.WorkspaceAgentStartupLog) error {
return xerrors.New("bad")
},
},
want: []string{
"⧗ Waiting for the workspace agent to connect",
"The workspace agent is having trouble connecting, wait for it to connect or restart your workspace.",
"https://troubleshoot",
},
wantErr: true,
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
defer cancel()
var buf bytes.Buffer
agent := codersdk.WorkspaceAgent{
ID: uuid.New(),
Status: codersdk.WorkspaceAgentConnecting,
StartupScriptBehavior: codersdk.WorkspaceAgentStartupScriptBehaviorNonBlocking,
CreatedAt: time.Now(),
LifecycleState: codersdk.WorkspaceAgentLifecycleCreated,
}
logs := make(chan []codersdk.WorkspaceAgentStartupLog, 1)
cmd := &clibase.Cmd{
Handler: func(inv *clibase.Invocation) error {
tc.opts.Fetch = func(_ context.Context) (codersdk.WorkspaceAgent, error) {
var err error
if len(tc.iter) > 0 {
err = tc.iter[0](ctx, &agent, logs)
tc.iter = tc.iter[1:]
}
return agent, err
}
tc.opts.FetchLogs = func(_ context.Context, _ uuid.UUID, _ int64, _ bool) (<-chan []codersdk.WorkspaceAgentStartupLog, io.Closer, error) {
return logs, closeFunc(func() error { return nil }), nil
}
err := cliui.Agent(inv.Context(), &buf, tc.opts)
return err
},
}
inv := cmd.Invoke()
w := clitest.StartWithWaiter(t, inv)
if tc.wantErr {
w.RequireError()
} else {
w.RequireSuccess()
}
s := bufio.NewScanner(&buf)
for s.Scan() {
line := s.Text()
t.Log(line)
if len(tc.want) == 0 {
require.Fail(t, "unexpected line: "+line)
}
require.Contains(t, line, tc.want[0])
tc.want = tc.want[1:]
}
require.NoError(t, s.Err())
if len(tc.want) > 0 {
require.Fail(t, "missing lines: "+strings.Join(tc.want, ", "))
}
})
}
cmd.SetOutput(ptty.Output())
cmd.SetIn(ptty.Input())
done := make(chan struct{})
go func() {
defer close(done)
err := cmd.Execute()
assert.NoError(t, err)
}()
ptty.ExpectMatch("lost connection")
disconnected.Store(true)
<-done
}
+48 -31
View File
@@ -1,27 +1,20 @@
package cliui
import (
"os"
"github.com/charmbracelet/charm/ui/common"
"github.com/charmbracelet/lipgloss"
"github.com/muesli/termenv"
"golang.org/x/xerrors"
)
var (
Canceled = xerrors.New("canceled")
var Canceled = xerrors.New("canceled")
defaultStyles = common.DefaultStyles()
)
// DefaultStyles compose visual elements of the UI.
var DefaultStyles Styles
// ValidateNotEmpty is a helper function to disallow empty inputs!
func ValidateNotEmpty(s string) error {
if s == "" {
return xerrors.New("Must be provided!")
}
return nil
}
// Styles compose visual elements of the UI!
var Styles = struct {
type Styles struct {
Bold,
Checkmark,
Code,
@@ -38,21 +31,45 @@ var Styles = struct {
Logo,
Warn,
Wrap lipgloss.Style
}{
Bold: lipgloss.NewStyle().Bold(true),
Checkmark: defaultStyles.Checkmark,
Code: defaultStyles.Code,
Crossmark: defaultStyles.Error.Copy().SetString("✘"),
DateTimeStamp: defaultStyles.LabelDim,
Error: defaultStyles.Error,
Field: defaultStyles.Code.Copy().Foreground(lipgloss.AdaptiveColor{Light: "#000000", Dark: "#FFFFFF"}),
Keyword: defaultStyles.Keyword,
Paragraph: defaultStyles.Paragraph,
Placeholder: lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#585858", Dark: "#4d46b3"}),
Prompt: defaultStyles.Prompt.Foreground(lipgloss.AdaptiveColor{Light: "#9B9B9B", Dark: "#5C5C5C"}),
FocusedPrompt: defaultStyles.FocusedPrompt.Foreground(lipgloss.Color("#651fff")),
Fuchsia: defaultStyles.SelectedMenuItem.Copy(),
Logo: defaultStyles.Logo.SetString("Coder"),
Warn: lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#04B575", Dark: "#ECFD65"}),
Wrap: lipgloss.NewStyle().Width(80),
}
func init() {
lipgloss.SetDefaultRenderer(
lipgloss.NewRenderer(os.Stdout, termenv.WithColorCache(true)),
)
// All Styles are set after we change the DefaultRenderer so that the ColorCache
// is in effect, mitigating the severe performance issue seen here:
// https://github.com/coder/coder/issues/7884.
charmStyles := common.DefaultStyles()
DefaultStyles = Styles{
Bold: lipgloss.NewStyle().Bold(true),
Checkmark: charmStyles.Checkmark,
Code: charmStyles.Code,
Crossmark: charmStyles.Error.Copy().SetString("✘"),
DateTimeStamp: charmStyles.LabelDim,
Error: charmStyles.Error,
Field: charmStyles.Code.Copy().Foreground(lipgloss.AdaptiveColor{Light: "#000000", Dark: "#FFFFFF"}),
Keyword: charmStyles.Keyword,
Paragraph: charmStyles.Paragraph,
Placeholder: lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#585858", Dark: "#4d46b3"}),
Prompt: charmStyles.Prompt.Copy().Foreground(lipgloss.AdaptiveColor{Light: "#9B9B9B", Dark: "#5C5C5C"}),
FocusedPrompt: charmStyles.FocusedPrompt.Copy().Foreground(lipgloss.Color("#651fff")),
Fuchsia: charmStyles.SelectedMenuItem.Copy(),
Logo: charmStyles.Logo.Copy().SetString("Coder"),
Warn: lipgloss.NewStyle().Foreground(
lipgloss.AdaptiveColor{Light: "#04B575", Dark: "#ECFD65"},
),
Wrap: lipgloss.NewStyle().Width(80),
}
}
// ValidateNotEmpty is a helper function to disallow empty inputs!
func ValidateNotEmpty(s string) error {
if s == "" {
return xerrors.New("Must be provided!")
}
return nil
}
+72
View File
@@ -0,0 +1,72 @@
package cliui
import (
"context"
"fmt"
"io"
"time"
"github.com/briandowns/spinner"
"github.com/coder/coder/codersdk"
)
type GitAuthOptions struct {
Fetch func(context.Context) ([]codersdk.TemplateVersionGitAuth, error)
FetchInterval time.Duration
}
func GitAuth(ctx context.Context, writer io.Writer, opts GitAuthOptions) error {
if opts.FetchInterval == 0 {
opts.FetchInterval = 500 * time.Millisecond
}
gitAuth, err := opts.Fetch(ctx)
if err != nil {
return err
}
spin := spinner.New(spinner.CharSets[78], 100*time.Millisecond, spinner.WithColor("fgHiGreen"))
spin.Writer = writer
spin.ForceOutput = true
spin.Suffix = " Waiting for Git authentication..."
defer spin.Stop()
ticker := time.NewTicker(opts.FetchInterval)
defer ticker.Stop()
for _, auth := range gitAuth {
if auth.Authenticated {
return nil
}
_, _ = fmt.Fprintf(writer, "You must authenticate with %s to create a workspace with this template. Visit:\n\n\t%s\n\n", auth.Type.Pretty(), auth.AuthenticateURL)
ticker.Reset(opts.FetchInterval)
spin.Start()
for {
select {
case <-ctx.Done():
return ctx.Err()
case <-ticker.C:
}
gitAuth, err := opts.Fetch(ctx)
if err != nil {
return err
}
var authed bool
for _, a := range gitAuth {
if !a.Authenticated || a.ID != auth.ID {
continue
}
authed = true
break
}
// The user authenticated with the provider!
if authed {
break
}
}
spin.Stop()
_, _ = fmt.Fprintf(writer, "Successfully authenticated with %s!\n\n", auth.Type.Pretty())
}
return nil
}
+56
View File
@@ -0,0 +1,56 @@
package cliui_test
import (
"context"
"sync/atomic"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/coder/coder/cli/clibase"
"github.com/coder/coder/cli/cliui"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/pty/ptytest"
"github.com/coder/coder/testutil"
)
func TestGitAuth(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
defer cancel()
ptty := ptytest.New(t)
cmd := &clibase.Cmd{
Handler: func(inv *clibase.Invocation) error {
var fetched atomic.Bool
return cliui.GitAuth(inv.Context(), inv.Stdout, cliui.GitAuthOptions{
Fetch: func(ctx context.Context) ([]codersdk.TemplateVersionGitAuth, error) {
defer fetched.Store(true)
return []codersdk.TemplateVersionGitAuth{{
ID: "github",
Type: codersdk.GitProviderGitHub,
Authenticated: fetched.Load(),
AuthenticateURL: "https://example.com/gitauth/github",
}}, nil
},
FetchInterval: time.Millisecond,
})
},
}
inv := cmd.Invoke().WithContext(ctx)
ptty.Attach(inv)
done := make(chan struct{})
go func() {
defer close(done)
err := inv.Run()
assert.NoError(t, err)
}()
ptty.ExpectMatchContext(ctx, "You must authenticate with")
ptty.ExpectMatchContext(ctx, "https://example.com/gitauth/github")
ptty.ExpectMatchContext(ctx, "Successfully authenticated with GitHub")
<-done
}
+43 -5
View File
@@ -10,17 +10,22 @@ import (
// cliMessage provides a human-readable message for CLI errors and messages.
type cliMessage struct {
Level string
Style lipgloss.Style
Header string
Prefix string
Lines []string
}
// String formats the CLI message for consumption by a human.
func (m cliMessage) String() string {
var str strings.Builder
_, _ = fmt.Fprintf(&str, "%s\r\n",
Styles.Bold.Render(m.Header))
if m.Prefix != "" {
_, _ = str.WriteString(m.Style.Bold(true).Render(m.Prefix))
}
_, _ = str.WriteString(m.Style.Bold(false).Render(m.Header))
_, _ = str.WriteString("\r\n")
for _, line := range m.Lines {
_, _ = fmt.Fprintf(&str, " %s %s\r\n", m.Style.Render("|"), line)
}
@@ -30,9 +35,42 @@ func (m cliMessage) String() string {
// Warn writes a log to the writer provided.
func Warn(wtr io.Writer, header string, lines ...string) {
_, _ = fmt.Fprint(wtr, cliMessage{
Level: "warning",
Style: Styles.Warn,
Style: DefaultStyles.Warn.Copy(),
Prefix: "WARN: ",
Header: header,
Lines: lines,
}.String())
}
// Warn writes a formatted log to the writer provided.
func Warnf(wtr io.Writer, fmtStr string, args ...interface{}) {
Warn(wtr, fmt.Sprintf(fmtStr, args...))
}
// Info writes a log to the writer provided.
func Info(wtr io.Writer, header string, lines ...string) {
_, _ = fmt.Fprint(wtr, cliMessage{
Header: header,
Lines: lines,
}.String())
}
// Infof writes a formatted log to the writer provided.
func Infof(wtr io.Writer, fmtStr string, args ...interface{}) {
Info(wtr, fmt.Sprintf(fmtStr, args...))
}
// Error writes a log to the writer provided.
func Error(wtr io.Writer, header string, lines ...string) {
_, _ = fmt.Fprint(wtr, cliMessage{
Style: DefaultStyles.Error.Copy(),
Prefix: "ERROR: ",
Header: header,
Lines: lines,
}.String())
}
// Errorf writes a formatted log to the writer provided.
func Errorf(wtr io.Writer, fmtStr string, args ...interface{}) {
Error(wtr, fmt.Sprintf(fmtStr, args...))
}
+226
View File
@@ -0,0 +1,226 @@
package cliui
import (
"context"
"encoding/json"
"fmt"
"reflect"
"strings"
"golang.org/x/xerrors"
"github.com/coder/coder/cli/clibase"
)
type OutputFormat interface {
ID() string
AttachOptions(opts *clibase.OptionSet)
Format(ctx context.Context, data any) (string, error)
}
type OutputFormatter struct {
formats []OutputFormat
formatID string
}
// NewOutputFormatter creates a new OutputFormatter with the given formats. The
// first format is the default format. At least two formats must be provided.
func NewOutputFormatter(formats ...OutputFormat) *OutputFormatter {
if len(formats) < 2 {
panic("at least two output formats must be provided")
}
formatIDs := make(map[string]struct{}, len(formats))
for _, format := range formats {
if format.ID() == "" {
panic("output format ID must not be empty")
}
if _, ok := formatIDs[format.ID()]; ok {
panic("duplicate format ID: " + format.ID())
}
formatIDs[format.ID()] = struct{}{}
}
return &OutputFormatter{
formats: formats,
formatID: formats[0].ID(),
}
}
// AttachOptions attaches the --output flag to the given command, and any
// additional flags required by the output formatters.
func (f *OutputFormatter) AttachOptions(opts *clibase.OptionSet) {
for _, format := range f.formats {
format.AttachOptions(opts)
}
formatNames := make([]string, 0, len(f.formats))
for _, format := range f.formats {
formatNames = append(formatNames, format.ID())
}
*opts = append(*opts,
clibase.Option{
Flag: "output",
FlagShorthand: "o",
Default: f.formats[0].ID(),
Value: clibase.StringOf(&f.formatID),
Description: "Output format. Available formats: " + strings.Join(formatNames, ", ") + ".",
},
)
}
// Format formats the given data using the format specified by the --output
// flag. If the flag is not set, the default format is used.
func (f *OutputFormatter) Format(ctx context.Context, data any) (string, error) {
for _, format := range f.formats {
if format.ID() == f.formatID {
return format.Format(ctx, data)
}
}
return "", xerrors.Errorf("unknown output format %q", f.formatID)
}
type tableFormat struct {
defaultColumns []string
allColumns []string
sort string
columns []string
}
var _ OutputFormat = &tableFormat{}
// TableFormat creates a table formatter for the given output type. The output
// type should be specified as an empty slice of the desired type.
//
// E.g.: TableFormat([]MyType{}, []string{"foo", "bar"})
//
// defaultColumns is optional and specifies the default columns to display. If
// not specified, all columns are displayed by default.
func TableFormat(out any, defaultColumns []string) OutputFormat {
v := reflect.Indirect(reflect.ValueOf(out))
if v.Kind() != reflect.Slice {
panic("DisplayTable called with a non-slice type")
}
// Get the list of table column headers.
headers, defaultSort, err := typeToTableHeaders(v.Type().Elem())
if err != nil {
panic("parse table headers: " + err.Error())
}
tf := &tableFormat{
defaultColumns: headers,
allColumns: headers,
sort: defaultSort,
}
if len(defaultColumns) > 0 {
tf.defaultColumns = defaultColumns
}
return tf
}
// ID implements OutputFormat.
func (*tableFormat) ID() string {
return "table"
}
// AttachOptions implements OutputFormat.
func (f *tableFormat) AttachOptions(opts *clibase.OptionSet) {
*opts = append(*opts,
clibase.Option{
Flag: "column",
FlagShorthand: "c",
Default: strings.Join(f.defaultColumns, ","),
Value: clibase.StringArrayOf(&f.columns),
Description: "Columns to display in table output. Available columns: " + strings.Join(f.allColumns, ", ") + ".",
},
)
}
// Format implements OutputFormat.
func (f *tableFormat) Format(_ context.Context, data any) (string, error) {
return DisplayTable(data, f.sort, f.columns)
}
type jsonFormat struct{}
var _ OutputFormat = jsonFormat{}
// JSONFormat creates a JSON formatter.
func JSONFormat() OutputFormat {
return jsonFormat{}
}
// ID implements OutputFormat.
func (jsonFormat) ID() string {
return "json"
}
// AttachOptions implements OutputFormat.
func (jsonFormat) AttachOptions(_ *clibase.OptionSet) {}
// Format implements OutputFormat.
func (jsonFormat) Format(_ context.Context, data any) (string, error) {
outBytes, err := json.MarshalIndent(data, "", " ")
if err != nil {
return "", xerrors.Errorf("marshal output to JSON: %w", err)
}
return string(outBytes), nil
}
type textFormat struct{}
var _ OutputFormat = textFormat{}
// TextFormat is a formatter that just outputs unstructured text.
// It uses fmt.Sprintf under the hood.
func TextFormat() OutputFormat {
return textFormat{}
}
func (textFormat) ID() string {
return "text"
}
func (textFormat) AttachOptions(_ *clibase.OptionSet) {}
func (textFormat) Format(_ context.Context, data any) (string, error) {
return fmt.Sprintf("%s", data), nil
}
// DataChangeFormat allows manipulating the data passed to an output format.
// This is because sometimes the data needs to be manipulated before it can be
// passed to the output format.
// For example, you may want to pass something different to the text formatter
// than what you pass to the json formatter.
type DataChangeFormat struct {
format OutputFormat
change func(data any) (any, error)
}
// ChangeFormatterData allows manipulating the data passed to an output
// format.
func ChangeFormatterData(format OutputFormat, change func(data any) (any, error)) *DataChangeFormat {
return &DataChangeFormat{format: format, change: change}
}
func (d *DataChangeFormat) ID() string {
return d.format.ID()
}
func (d *DataChangeFormat) AttachOptions(opts *clibase.OptionSet) {
d.format.AttachOptions(opts)
}
func (d *DataChangeFormat) Format(ctx context.Context, data any) (string, error) {
newData, err := d.change(data)
if err != nil {
return "", err
}
return d.format.Format(ctx, newData)
}

Some files were not shown because too many files have changed in this diff Show More