Skip to content

Commit a8c650a

Browse files
committed
Merge branch 'main' into bryphe/feat/workspaces-page-skeleton
2 parents 1cd5cf3 + 2e254a0 commit a8c650a

File tree

114 files changed

+5795
-2539
lines changed

Some content is hidden

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

114 files changed

+5795
-2539
lines changed

.github/workflows/coder.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ jobs:
239239
.eslintcache
240240
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
241241

242+
# Go is required for uploading the test results to datadog
243+
- uses: actions/setup-go@v2
244+
with:
245+
go-version: "^1.17"
246+
242247
- uses: actions/setup-node@v2
243248
with:
244249
node-version: "14"
@@ -262,3 +267,11 @@ jobs:
262267
files: ./site/coverage/lcov.info
263268
flags: unittest-js
264269
fail_ci_if_error: true
270+
271+
- name: Upload DataDog Trace
272+
if: (success() || failure()) && github.actor != 'dependabot[bot]'
273+
env:
274+
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
275+
DD_DATABASE: postgresql
276+
GIT_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
277+
run: go run scripts/datadog-cireport/main.go site/test_results/junit.xml

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ site/.eslintcache
2020
site/.next/
2121
site/node_modules/
2222
site/storybook-static/
23+
site/test_results/
2324
site/yarn-error.log
2425
coverage/
2526

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,23 @@
3131
"drpcconn",
3232
"drpcmux",
3333
"drpcserver",
34+
"fatih",
3435
"goleak",
3536
"hashicorp",
3637
"httpmw",
38+
"isatty",
3739
"Jobf",
40+
"kirsle",
41+
"manifoldco",
42+
"mattn",
3843
"moby",
3944
"nhooyr",
4045
"nolint",
4146
"nosec",
47+
"ntqry",
4248
"oneof",
4349
"parameterscopeid",
50+
"promptui",
4451
"protobuf",
4552
"provisionerd",
4653
"provisionersdk",

Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
INSTALL_DIR=$(shell go env GOPATH)/bin
2+
3+
bin/coder:
4+
mkdir -p bin
5+
go build -o bin/coder cmd/coder/main.go
6+
.PHONY: bin/coder
7+
18
bin/coderd:
29
mkdir -p bin
310
go build -o bin/coderd cmd/coderd/main.go
411
.PHONY: bin/coderd
512

6-
build: site/out bin/coderd
13+
build: site/out bin/coder bin/coderd
714
.PHONY: build
815

916
# Runs migrations to output a dump of the database.
@@ -46,6 +53,12 @@ fmt: fmt/prettier fmt/sql
4653
gen: database/generate peerbroker/proto provisionersdk/proto provisionerd/proto
4754
.PHONY: gen
4855

56+
install:
57+
@echo "--- Copying from bin to $(INSTALL_DIR)"
58+
cp -r ./bin $(INSTALL_DIR)
59+
@echo "-- CLI available at $(shell ls $(INSTALL_DIR)/coder*)"
60+
.PHONY: install
61+
4962
peerbroker/proto: peerbroker/proto/peerbroker.proto
5063
protoc \
5164
--go_out=. \
@@ -74,6 +87,7 @@ provisionersdk/proto: provisionersdk/proto/provisioner.proto
7487
.PHONY: provisionersdk/proto
7588

7689
site/out:
90+
cd site && yarn install
7791
cd site && yarn build
7892
cd site && yarn export
7993
.PHONY: site/out

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,33 @@ This repository contains source code for Coder V2. Additional documentation:
1313
- [`semantic.yaml`](./github/semantic.yaml): Configuration for [semantic pull requests](https://github.com/apps/semantic-pull-requests)
1414
- `site`: Front-end UI code.
1515

16+
## Development
17+
18+
### Pre-requisites
19+
20+
- `git`
21+
- `go` version 1.17, with the `GOPATH` environment variable set
22+
- `node`
23+
- `yarn`
24+
25+
### Cloning
26+
27+
- `git clone https://github.com/coder/coder`
28+
- `cd coder`
29+
30+
### Building
31+
32+
- `make build`
33+
- `make install`
34+
35+
The `coder` CLI binary will now be available at `$GOPATH/bin/coder`
36+
37+
### Development
38+
39+
- `./develop.sh`
40+
41+
The `develop.sh` script runs the server locally on port `3000`, and runs a hot-reload server for front-end code on `8080`.
42+
1643
## Front-End Plan
1744

1845
For the front-end team, we're planning on 2 phases to the 'v2' work:

cli/clitest/clitest.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package clitest
2+
3+
import (
4+
"archive/tar"
5+
"bytes"
6+
"errors"
7+
"io"
8+
"os"
9+
"path/filepath"
10+
"testing"
11+
12+
"github.com/spf13/cobra"
13+
"github.com/stretchr/testify/require"
14+
15+
"github.com/coder/coder/cli"
16+
"github.com/coder/coder/cli/config"
17+
"github.com/coder/coder/codersdk"
18+
"github.com/coder/coder/provisioner/echo"
19+
)
20+
21+
// New creates a CLI instance with a configuration pointed to a
22+
// temporary testing directory.
23+
func New(t *testing.T, args ...string) (*cobra.Command, config.Root) {
24+
cmd := cli.Root()
25+
dir := t.TempDir()
26+
root := config.Root(dir)
27+
cmd.SetArgs(append([]string{"--global-config", dir}, args...))
28+
return cmd, root
29+
}
30+
31+
// SetupConfig applies the URL and SessionToken of the client to the config.
32+
func SetupConfig(t *testing.T, client *codersdk.Client, root config.Root) {
33+
err := root.Session().Write(client.SessionToken)
34+
require.NoError(t, err)
35+
err = root.URL().Write(client.URL.String())
36+
require.NoError(t, err)
37+
}
38+
39+
// CreateProjectVersionSource writes the echo provisioner responses into a
40+
// new temporary testing directory.
41+
func CreateProjectVersionSource(t *testing.T, responses *echo.Responses) string {
42+
directory := t.TempDir()
43+
data, err := echo.Tar(responses)
44+
require.NoError(t, err)
45+
extractTar(t, data, directory)
46+
return directory
47+
}
48+
49+
func extractTar(t *testing.T, data []byte, directory string) {
50+
reader := tar.NewReader(bytes.NewBuffer(data))
51+
for {
52+
header, err := reader.Next()
53+
if errors.Is(err, io.EOF) {
54+
break
55+
}
56+
require.NoError(t, err)
57+
// #nosec
58+
path := filepath.Join(directory, header.Name)
59+
mode := header.FileInfo().Mode()
60+
if mode == 0 {
61+
mode = 0600
62+
}
63+
switch header.Typeflag {
64+
case tar.TypeDir:
65+
err = os.MkdirAll(path, mode)
66+
require.NoError(t, err)
67+
case tar.TypeReg:
68+
file, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, mode)
69+
require.NoError(t, err)
70+
// Max file size of 10MB.
71+
_, err = io.CopyN(file, reader, (1<<20)*10)
72+
if errors.Is(err, io.EOF) {
73+
err = nil
74+
}
75+
require.NoError(t, err)
76+
err = file.Close()
77+
require.NoError(t, err)
78+
}
79+
}
80+
}

cli/clitest/clitest_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package clitest_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/coder/coder/cli/clitest"
7+
"github.com/coder/coder/coderd/coderdtest"
8+
"github.com/coder/coder/expect"
9+
"github.com/stretchr/testify/require"
10+
"go.uber.org/goleak"
11+
)
12+
13+
func TestMain(m *testing.M) {
14+
goleak.VerifyTestMain(m)
15+
}
16+
17+
func TestCli(t *testing.T) {
18+
t.Parallel()
19+
clitest.CreateProjectVersionSource(t, nil)
20+
client := coderdtest.New(t)
21+
cmd, config := clitest.New(t)
22+
clitest.SetupConfig(t, client, config)
23+
console := expect.NewTestConsole(t, cmd)
24+
go func() {
25+
err := cmd.Execute()
26+
require.NoError(t, err)
27+
}()
28+
_, err := console.ExpectString("coder")
29+
require.NoError(t, err)
30+
}

cli/config/file.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package config
2+
3+
import (
4+
"io/ioutil"
5+
"os"
6+
"path/filepath"
7+
)
8+
9+
// Root represents the configuration directory.
10+
type Root string
11+
12+
func (r Root) Session() File {
13+
return File(filepath.Join(string(r), "session"))
14+
}
15+
16+
func (r Root) URL() File {
17+
return File(filepath.Join(string(r), "url"))
18+
}
19+
20+
func (r Root) Organization() File {
21+
return File(filepath.Join(string(r), "organization"))
22+
}
23+
24+
// File provides convenience methods for interacting with *os.File.
25+
type File string
26+
27+
// Delete deletes the file.
28+
func (f File) Delete() error {
29+
return os.Remove(string(f))
30+
}
31+
32+
// Write writes the string to the file.
33+
func (f File) Write(s string) error {
34+
return write(string(f), 0600, []byte(s))
35+
}
36+
37+
// Read reads the file to a string.
38+
func (f File) Read() (string, error) {
39+
byt, err := read(string(f))
40+
return string(byt), err
41+
}
42+
43+
// open opens a file in the configuration directory,
44+
// creating all intermediate directories.
45+
func open(path string, flag int, mode os.FileMode) (*os.File, error) {
46+
err := os.MkdirAll(filepath.Dir(path), 0750)
47+
if err != nil {
48+
return nil, err
49+
}
50+
51+
return os.OpenFile(path, flag, mode)
52+
}
53+
54+
func write(path string, mode os.FileMode, dat []byte) error {
55+
fi, err := open(path, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, mode)
56+
if err != nil {
57+
return err
58+
}
59+
defer fi.Close()
60+
_, err = fi.Write(dat)
61+
return err
62+
}
63+
64+
func read(path string) ([]byte, error) {
65+
fi, err := open(path, os.O_RDONLY, 0)
66+
if err != nil {
67+
return nil, err
68+
}
69+
defer fi.Close()
70+
return ioutil.ReadAll(fi)
71+
}

cli/config/file_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package config_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
8+
"github.com/coder/coder/cli/config"
9+
)
10+
11+
func TestFile(t *testing.T) {
12+
t.Parallel()
13+
14+
t.Run("Write", func(t *testing.T) {
15+
t.Parallel()
16+
err := config.Root(t.TempDir()).Session().Write("test")
17+
require.NoError(t, err)
18+
})
19+
20+
t.Run("Read", func(t *testing.T) {
21+
t.Parallel()
22+
root := config.Root(t.TempDir())
23+
err := root.Session().Write("test")
24+
require.NoError(t, err)
25+
data, err := root.Session().Read()
26+
require.NoError(t, err)
27+
require.Equal(t, "test", data)
28+
})
29+
30+
t.Run("Delete", func(t *testing.T) {
31+
t.Parallel()
32+
root := config.Root(t.TempDir())
33+
err := root.Session().Write("test")
34+
require.NoError(t, err)
35+
err = root.Session().Delete()
36+
require.NoError(t, err)
37+
})
38+
}

0 commit comments

Comments
 (0)