Skip to content

Commit 9ad326b

Browse files
committed
Merge branch 'main' into ssh
2 parents c91b3cc + 620c889 commit 9ad326b

File tree

8 files changed

+489
-75
lines changed

8 files changed

+489
-75
lines changed

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ install: bin
5050
@echo "-- CLI available at $(shell ls $(INSTALL_DIR)/coder*)"
5151
.PHONY: install
5252

53+
lint:
54+
golangci-lint run
55+
.PHONY: lint
56+
5357
peerbroker/proto: peerbroker/proto/peerbroker.proto
5458
protoc \
5559
--go_out=. \
@@ -89,6 +93,6 @@ site/out:
8993
git checkout HEAD site/out
9094
.PHONY: site/out
9195

92-
lint:
93-
golangci-lint run
94-
.PHONY: lint
96+
test:
97+
gotestsum -- -v -short ./...
98+

README.md

Lines changed: 43 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,64 @@
1-
[![coder](https://github.com/coder/coder/actions/workflows/coder.yaml/badge.svg)](https://github.com/coder/coder/actions/workflows/coder.yaml)
2-
[![codecov](https://codecov.io/gh/coder/coder/branch/main/graph/badge.svg?token=TNLW3OAP6G)](https://codecov.io/gh/coder/coder)
1+
# Coder
32

4-
# Coder v2
3+
[!["GitHub Discussions"](https://img.shields.io/badge/%20GitHub-%20Discussions-gray.svg?longCache=true&logo=github&colorB=purple)](https://github.com/coder/coder/discussions) [!["Join us on Slack"](https://img.shields.io/badge/join-us%20on%20slack-gray.svg?longCache=true&logo=slack&colorB=brightgreen)](https://coder.com/community) [![Twitter Follow](https://img.shields.io/twitter/follow/CoderHQ?label=%40CoderHQ&style=social)](https://twitter.com/coderhq) [![codecov](https://codecov.io/gh/coder/coder/branch/main/graph/badge.svg?token=TNLW3OAP6G)](https://codecov.io/gh/coder/coder)
54

6-
This repository contains source code for Coder V2. Additional documentation:
5+
Provision remote development environments with Terraform.
76

8-
- [Workspaces V2 RFC](https://www.notion.so/coderhq/b48040da8bfe46eca1f32749b69420dd?v=a4e7d23495094644b939b08caba8e381&p=e908a8cd54804ddd910367abf03c8d0a)
7+
## Highlights
98

10-
## Directory Structure
9+
- Automate development environments for Linux, Windows, and MacOS in your cloud
10+
- Start writing code with a single command
11+
- Use one of many [examples](./examples) to get started
1112

12-
- `.github/`: Settings for [Dependabot for updating dependencies](https://docs.github.com/en/code-security/supply-chain-security/customizing-dependency-updates) and [build/deploy pipelines with GitHub Actions](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions).
13-
- [`semantic.yaml`](./github/semantic.yaml): Configuration for [semantic pull requests](https://github.com/apps/semantic-pull-requests)
14-
- `examples`: Example terraform project templates.
15-
- `site`: Front-end UI code.
13+
## Getting Started
1614

17-
## Development
18-
19-
### Pre-requisites
20-
21-
- `git`
22-
- `go` version 1.17, with the `GOPATH` environment variable set
23-
- `node`
24-
- `yarn`
25-
26-
### Cloning
27-
28-
- `git clone https://github.com/coder/coder`
29-
- `cd coder`
30-
31-
### Building
32-
33-
- `make build`
34-
- `make install`
15+
Install [the latest release](https://github.com/coder/coder/releases).
3516

36-
The `coder` CLI binary will now be available at `$GOPATH/bin/coder`
17+
To tinker, start with dev-mode (all data is in-memory, and is destroyed on exit):
3718

38-
### Running
19+
```bash
20+
$ coder start --dev
21+
```
3922

40-
After building, the binaries will be available at:
41-
- `dist/coder_{os}_{arch}/coder`
23+
To run a production deployment with PostgreSQL:
4224

43-
For the purpose of these steps, an OS of `linux` and an arch of `amd64` is assumed.
25+
```bash
26+
$ CODER_PG_CONNECTION_URL="postgres://<username>@<host>/<database>?password=<password>" \
27+
coder start
28+
```
4429

45-
To manually run the server and go through first-time set up, run the following commands in separate terminals:
46-
- `dist/coder_linux_amd64/coder daemon` <-- starts the Coder server on port 3000
47-
- `dist/coder_linux_amd64/coder login http://localhost:3000` <-- runs through first-time setup, creating a user and org
30+
To run as a system service, install with `.deb` or `.rpm`:
4831

49-
You'll now be able to login and access the server.
32+
```bash
33+
# Edit the configuration!
34+
$ sudo vim /etc/coder.d/coder.env
35+
$ sudo service coder restart
36+
```
5037

51-
- `dist/coder_linux_amd64/coder projects create -d /path/to/project`
38+
### Your First Workspace
5239

53-
### Development
40+
In a new terminal, create a new project (eg. Develop in Linux on Google Cloud):
5441

55-
- `./develop.sh`
42+
```
43+
$ coder projects init
44+
$ coder projects create
45+
```
5646

57-
The `develop.sh` script does three things:
47+
Create a new workspace and SSH in:
5848

59-
- runs `coder daemon` locally on port `3000`
60-
- runs `webpack-dev-server` on port `8080`
61-
- sets up an initial user and organization
49+
```
50+
$ coder workspaces create my-first-workspace
51+
$ coder ssh my-first-workspace
52+
```
6253

63-
This is the recommend flow for working on the front-end, as hot-reload is set up as part of the webpack config.
64-
65-
Note that `./develop.sh` creates a user and allows you to log into the UI, but does not log you into the CLI, which is required for creating a project. Use the `login` command above before the `projects create` command.
66-
67-
While we're working on automating XState typegen, you may need to run `yarn typegen` from `site`.
68-
69-
## Front-End Plan
70-
71-
For the front-end team, we're planning on 2 phases to the 'v2' work:
72-
73-
### Phase 1
74-
75-
Phase 1 is the 'new-wine-in-an-old-bottle' approach - we want to preserve the look and feel (UX) of v1, while testing and validating the market fit of our new v2 provisioner model. This means that we'll preserve Material UI and re-use components from v1 (porting them over to the v2 codebase).
54+
## Development
7655

77-
### Phase 2
56+
The code structure is inspired by [Basics of Unix Philosophy](https://homepage.cs.uri.edu/~thenry/resources/unix_art/ch01s06.html) and [Effective Go](https://go.dev/doc/effective_go).
7857

79-
Phase 2 is the 'new-wine-in-a-new-bottle' - which we can do once we've successfully packaged the new wine in the old bottle.
58+
Coder requires Go 1.18+, Node 14+, and GNU Make.
8059

81-
In other words, once we've validated that the new strategy fits and is desirable for our customers, we'd like to build a new, v2-native UI (leveraging designers on the team to build a first-class experience around the new provisioner model).
60+
- `make bin` builds binaries
61+
- `make install` installs binaries to `$GOPATH/bin`
62+
- `make test`
63+
- `make release` dry-runs a new release
64+
- `./develop.sh` hot-reloads for frontend development

cli/start.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,9 @@ import (
1616
"path/filepath"
1717
"time"
1818

19-
"github.com/briandowns/spinner"
20-
"github.com/coreos/go-systemd/daemon"
21-
"github.com/spf13/cobra"
22-
"golang.org/x/xerrors"
23-
"google.golang.org/api/idtoken"
24-
"google.golang.org/api/option"
25-
2619
"cdr.dev/slog"
2720
"cdr.dev/slog/sloggers/sloghuman"
21+
"github.com/briandowns/spinner"
2822
"github.com/coder/coder/cli/cliflag"
2923
"github.com/coder/coder/cli/cliui"
3024
"github.com/coder/coder/cli/config"
@@ -37,6 +31,12 @@ import (
3731
"github.com/coder/coder/provisionerd"
3832
"github.com/coder/coder/provisionersdk"
3933
"github.com/coder/coder/provisionersdk/proto"
34+
"github.com/coreos/go-systemd/daemon"
35+
"github.com/spf13/cobra"
36+
"golang.org/x/xerrors"
37+
"google.golang.org/api/idtoken"
38+
"google.golang.org/api/option"
39+
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
4040
)
4141

4242
func start() *cobra.Command {
@@ -55,12 +55,17 @@ func start() *cobra.Command {
5555
tlsKeyFile string
5656
tlsMinVersion string
5757
useTunnel bool
58+
traceDatadog bool
5859
)
5960
root := &cobra.Command{
6061
Use: "start",
6162
RunE: func(cmd *cobra.Command, args []string) error {
62-
printLogo(cmd)
63+
if traceDatadog {
64+
tracer.Start()
65+
defer tracer.Stop()
66+
}
6367

68+
printLogo(cmd)
6469
listener, err := net.Listen("tcp", address)
6570
if err != nil {
6671
return xerrors.Errorf("listen %q: %w", address, err)
@@ -326,8 +331,9 @@ func start() *cobra.Command {
326331
"Specifies the path to the private key for the certificate. It requires a PEM-encoded file")
327332
cliflag.StringVarP(root.Flags(), &tlsMinVersion, "tls-min-version", "", "CODER_TLS_MIN_VERSION", "tls12",
328333
`Specifies the minimum supported version of TLS. Accepted values are "tls10", "tls11", "tls12" or "tls13"`)
329-
cliflag.BoolVarP(root.Flags(), &useTunnel, "tunnel", "", "CODER_DEV_TUNNEL", false, "Serve dev mode through a Cloudflare Tunnel for easy setup")
334+
cliflag.BoolVarP(root.Flags(), &useTunnel, "tunnel", "", "CODER_DEV_TUNNEL", true, "Serve dev mode through a Cloudflare Tunnel for easy setup")
330335
_ = root.Flags().MarkHidden("tunnel")
336+
cliflag.BoolVarP(root.Flags(), &traceDatadog, "trace-datadog", "", "CODER_TRACE_DATADOG", false, "Send tracing data to a datadog agent")
331337

332338
return root
333339
}

cli/start_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"time"
2020

2121
"github.com/stretchr/testify/require"
22+
"go.uber.org/goleak"
2223

2324
"github.com/coder/coder/cli/clitest"
2425
"github.com/coder/coder/coderd/coderdtest"
@@ -199,6 +200,21 @@ func TestStart(t *testing.T) {
199200
require.NoError(t, err)
200201
<-done
201202
})
203+
t.Run("DatadogTracerNoLeak", func(t *testing.T) {
204+
t.Parallel()
205+
ctx, cancelFunc := context.WithCancel(context.Background())
206+
defer cancelFunc()
207+
root, _ := clitest.New(t, "start", "--dev", "--tunnel=false", "--address", ":0", "--trace-datadog=true")
208+
done := make(chan struct{})
209+
go func() {
210+
defer close(done)
211+
err := root.ExecuteContext(ctx)
212+
require.ErrorIs(t, err, context.Canceled)
213+
}()
214+
cancelFunc()
215+
<-done
216+
require.Error(t, goleak.Find())
217+
})
202218
}
203219

204220
func generateTLSCertificate(t testing.TB) (certPath, keyPath string) {

cli/workspaceagent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func workspaceAgent() *cobra.Command {
114114

115115
cliflag.StringVarP(cmd.Flags(), &auth, "auth", "", "CODER_AUTH", "token", "Specify the authentication type to use for the agent")
116116
cliflag.StringVarP(cmd.Flags(), &rawURL, "url", "", "CODER_URL", "", "Specify the URL to access Coder")
117-
cliflag.StringVarP(cmd.Flags(), &auth, "token", "", "CODER_TOKEN", "", "Specifies the authentication token to access Coder")
117+
cliflag.StringVarP(cmd.Flags(), &token, "token", "", "CODER_TOKEN", "", "Specifies the authentication token to access Coder")
118118

119119
return cmd
120120
}

coderd/coderd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/coder/coder/coderd/httpapi"
1616
"github.com/coder/coder/coderd/httpmw"
1717
"github.com/coder/coder/site"
18+
chitrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-chi/chi.v5"
1819
)
1920

2021
// Options are requires parameters for Coder to start.
@@ -43,6 +44,7 @@ func New(options *Options) (http.Handler, func()) {
4344

4445
r := chi.NewRouter()
4546
r.Route("/api/v2", func(r chi.Router) {
47+
r.Use(chitrace.Middleware())
4648
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
4749
httpapi.Write(w, http.StatusOK, httpapi.Response{
4850
Message: "👋",

go.mod

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ replace github.com/urfave/cli/v2 => github.com/ipostelnik/cli/v2 v2.3.1-0.202103
2525

2626
replace github.com/rivo/tview => github.com/kylecarbs/tview v0.0.0-20220309202238-8464256e10a1
2727

28+
// glog has a single goroutine leak on start that we removed in a fork: https://github.com/coder/glog/pull/1.
29+
replace github.com/golang/glog => github.com/coder/glog v1.0.1-0.20220322161911-7365fe7f2cd1
30+
2831
require (
2932
cdr.dev/slog v1.4.1
3033
cloud.google.com/go/compute v1.5.0
@@ -90,6 +93,10 @@ require (
9093
require (
9194
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
9295
github.com/BurntSushi/toml v1.0.0 // indirect
96+
github.com/DataDog/datadog-agent/pkg/obfuscate v0.0.0-20211129110424-6491aa3bf583 // indirect
97+
github.com/DataDog/datadog-go v4.8.2+incompatible // indirect
98+
github.com/DataDog/datadog-go/v5 v5.0.2 // indirect
99+
github.com/DataDog/sketches-go v1.0.0 // indirect
93100
github.com/Microsoft/go-winio v0.5.2 // indirect
94101
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
95102
github.com/agext/levenshtein v1.2.3 // indirect
@@ -114,13 +121,15 @@ require (
114121
github.com/coredns/coredns v1.9.0 // indirect
115122
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
116123
github.com/davecgh/go-spew v1.1.1 // indirect
124+
github.com/dgraph-io/ristretto v0.1.0 // indirect
117125
github.com/dhui/dktest v0.3.9 // indirect
118126
github.com/dlclark/regexp2 v1.4.0 // indirect
119127
github.com/docker/cli v20.10.13+incompatible // indirect
120128
github.com/docker/distribution v2.8.0+incompatible // indirect
121129
github.com/docker/docker v20.10.13+incompatible // indirect
122130
github.com/docker/go-connections v0.4.0 // indirect
123131
github.com/docker/go-units v0.4.0 // indirect
132+
github.com/dustin/go-humanize v1.0.0 // indirect
124133
github.com/facebookgo/grace v0.0.0-20180706040059-75cf19382434 // indirect
125134
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
126135
github.com/francoispqt/gojay v1.2.13 // indirect
@@ -137,6 +146,7 @@ require (
137146
github.com/gobwas/ws v1.1.0 // indirect
138147
github.com/gogo/protobuf v1.3.2 // indirect
139148
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 // indirect
149+
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
140150
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
141151
github.com/golang/protobuf v1.5.2 // indirect
142152
github.com/google/go-cmp v0.5.7 // indirect
@@ -151,6 +161,7 @@ require (
151161
github.com/hashicorp/terraform-json v0.13.0 // indirect
152162
github.com/imdario/mergo v0.3.12 // indirect
153163
github.com/inconshreveable/mousetrap v1.0.0 // indirect
164+
github.com/josharian/intern v1.0.0 // indirect
154165
github.com/json-iterator/go v1.1.12 // indirect
155166
github.com/juju/ansiterm v0.0.0-20210929141451-8b71cc96ebdc // indirect
156167
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
@@ -159,6 +170,7 @@ require (
159170
github.com/lucas-clemente/quic-go v0.25.1-0.20220307142123-ad1cb27c1b64 // indirect
160171
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
161172
github.com/lunixbochs/vtclean v1.0.0 // indirect
173+
github.com/mailru/easyjson v0.7.7 // indirect
162174
github.com/marten-seemann/qtls-go1-16 v0.1.4 // indirect
163175
github.com/marten-seemann/qtls-go1-17 v0.1.0 // indirect
164176
github.com/marten-seemann/qtls-go1-18 v0.1.0-beta.1 // indirect
@@ -183,6 +195,7 @@ require (
183195
github.com/opencontainers/runc v1.1.0 // indirect
184196
github.com/opentracing/opentracing-go v1.2.0 // indirect
185197
github.com/pelletier/go-toml/v2 v2.0.0-beta.6 // indirect
198+
github.com/philhofer/fwd v1.1.1 // indirect
186199
github.com/pion/dtls/v2 v2.1.3 // indirect
187200
github.com/pion/ice/v2 v2.2.2 // indirect
188201
github.com/pion/interceptor v0.1.10 // indirect
@@ -210,6 +223,7 @@ require (
210223
github.com/spf13/afero v1.8.1 // indirect
211224
github.com/spf13/cast v1.4.1 // indirect
212225
github.com/spf13/jwalterweatherman v1.1.0 // indirect
226+
github.com/tinylib/msgp v1.1.2 // indirect
213227
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
214228
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
215229
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
@@ -220,10 +234,12 @@ require (
220234
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
221235
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
222236
golang.org/x/text v0.3.7 // indirect
237+
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
223238
golang.org/x/tools v0.1.9 // indirect
224239
google.golang.org/appengine v1.6.7 // indirect
225240
google.golang.org/genproto v0.0.0-20220310185008-1973136f34c6 // indirect
226241
google.golang.org/grpc v1.45.0 // indirect
242+
gopkg.in/DataDog/dd-trace-go.v1 v1.37.0
227243
gopkg.in/coreos/go-oidc.v2 v2.2.1 // indirect
228244
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
229245
gopkg.in/square/go-jose.v2 v2.6.0 // indirect

0 commit comments

Comments
 (0)