Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f84f5ea

Browse files
committed
Merge branch 'readclose' into apps
2 parents c88df46 + d327df7 commit f84f5ea

File tree

269 files changed

+3324
-1374
lines changed

Some content is hidden

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

269 files changed

+3324
-1374
lines changed

.editorconfig

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
charset = utf-8
6+
trim_trailing_whitespace = true
7+
insert_final_newline = true
8+
indent_style = tab
9+
10+
[*.{md,json,yaml,tf,tfvars}]
11+
indent_style = space
12+
indent_size = 2
13+
14+
[coderd/database/dump.sql]
15+
indent_style = space
16+
indent_size = 4

.github/codecov.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ ignore:
2929
- peerbroker/proto
3030
- provisionerd/proto
3131
- provisionersdk/proto
32-
- scripts/datadog-cireport
32+
- scripts
3333
- site/.storybook
3434
- rules.go

.github/workflows/coder.yaml

+17-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ jobs:
4444
with:
4545
version: v1.46.0
4646

47+
style-lint-shellcheck:
48+
name: style/lint/shellcheck
49+
timeout-minutes: 5
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v3
53+
- name: Run ShellCheck
54+
uses: ludeeus/[email protected]
55+
with:
56+
ignore: node_modules
57+
4758
style-lint-typescript:
4859
name: "style/lint/typescript"
4960
timeout-minutes: 5
@@ -133,7 +144,12 @@ jobs:
133144
- name: Install node_modules
134145
run: ./scripts/yarn_install.sh
135146

136-
- run: "make --output-sync -j -B fmt"
147+
- name: Install shfmt
148+
run: go install mvdan.cc/sh/v3/cmd/[email protected]
149+
150+
- run: |
151+
export PATH=${PATH}:$(go env GOPATH)/bin
152+
make --output-sync -j -B fmt
137153
138154
test-go:
139155
name: "test/go"

Makefile

+22-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ INSTALL_DIR=$(shell go env GOPATH)/bin
44
GOOS=$(shell go env GOOS)
55
GOARCH=$(shell go env GOARCH)
66

7-
bin: $(shell find . -not -path './vendor/*' -type f -name '*.go') go.mod go.sum
7+
bin: $(shell find . -not -path './vendor/*' -type f -name '*.go') go.mod go.sum $(shell find ./examples/templates)
88
@echo "== This builds binaries for command-line usage."
99
@echo "== Use \"make build\" to embed the site."
1010
goreleaser build --snapshot --rm-dist --single-target
@@ -24,7 +24,7 @@ dev:
2424
./scripts/develop.sh
2525
.PHONY: dev
2626

27-
dist/artifacts.json: site/out/index.html $(shell find . -not -path './vendor/*' -type f -name '*.go') go.mod go.sum
27+
dist/artifacts.json: site/out/index.html $(shell find . -not -path './vendor/*' -type f -name '*.go') go.mod go.sum $(shell find ./examples/templates)
2828
goreleaser release --snapshot --rm-dist --skip-sign
2929

3030
fmt/prettier:
@@ -41,20 +41,37 @@ fmt/terraform: $(wildcard *.tf)
4141
terraform fmt -recursive
4242
.PHONY: fmt/terraform
4343

44-
fmt: fmt/prettier fmt/terraform
44+
fmt/shfmt: $(shell shfmt -f .)
45+
@echo "--- shfmt"
46+
# Only do diff check in CI, errors on diff.
47+
ifdef CI
48+
shfmt -d $(shell shfmt -f .)
49+
else
50+
shfmt -w $(shell shfmt -f .)
51+
endif
52+
53+
fmt: fmt/prettier fmt/terraform fmt/shfmt
4554
.PHONY: fmt
4655

4756
gen: coderd/database/querier.go peerbroker/proto/peerbroker.pb.go provisionersdk/proto/provisioner.pb.go provisionerd/proto/provisionerd.pb.go site/src/api/typesGenerated.ts
4857

4958
install: build
59+
mkdir -p $(INSTALL_DIR)
5060
@echo "--- Copying from bin to $(INSTALL_DIR)"
5161
cp -r ./dist/coder-$(GOOS)_$(GOOS)_$(GOARCH)*/* $(INSTALL_DIR)
5262
@echo "-- CLI available at $(shell ls $(INSTALL_DIR)/coder*)"
5363
.PHONY: install
5464

55-
lint:
65+
lint: lint/shellcheck lint/go
66+
67+
lint/go:
5668
golangci-lint run
57-
.PHONY: lint
69+
.PHONY: lint/go
70+
71+
# Use shfmt to determine the shell files, takes editorconfig into consideration.
72+
lint/shellcheck: $(shell shfmt -f .)
73+
@echo "--- shellcheck"
74+
shellcheck $(shell shfmt -f .)
5875

5976
peerbroker/proto/peerbroker.pb.go: peerbroker/proto/peerbroker.proto
6077
protoc \

README.md

+40-15
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ Discord"](https://img.shields.io/badge/join-us%20on%20Discord-gray.svg?longCache
88
Follow](https://img.shields.io/twitter/follow/CoderHQ?label=%40CoderHQ&style=social)](https://twitter.com/coderhq)
99
[![codecov](https://codecov.io/gh/coder/coder/branch/main/graph/badge.svg?token=TNLW3OAP6G)](https://codecov.io/gh/coder/coder)
1010

11-
Coder creates remote development machines so you can develop your code from anywhere
11+
Coder creates remote development machines so you can develop your code from anywhere. #coder
12+
13+
> **Note**:
14+
> Coder is in an alpha state, but any serious bugs are P1 for us so [please report them](https://github.com/coder/coder/issues/new/choose).
1215
1316
<p align="center">
1417
<img src="./docs/images/hero-image.png">
@@ -58,16 +61,18 @@ release](https://github.com/coder/coder/releases) on a system with at least 1
5861
CPU core and 2 GB RAM:
5962

6063
1. Download the [release asset](https://github.com/coder/coder/releases) appropriate for your operating system
61-
1. Unzip the folder you just downloaded, and move the `coder` executable to a
62-
location that's on your `PATH`
64+
1. Unzip the folder you just downloaded, and move the `coder` executable to a location that's on your `PATH`
65+
66+
```sh
67+
# ex. MacOS and Linux
68+
mv coder /usr/local/bin
69+
```
6370

64-
> Make sure you have the appropriate credentials for your cloud provider (e.g.,
65-
> access key ID and secret access key for AWS).
71+
Windows: see [this guide](https://answers.microsoft.com/en-us/windows/forum/all/adding-path-variable/97300613-20cb-4d85-8d0e-cc9d3549ba23) on adding a folder to `PATH`
6672

67-
You can set up a temporary deployment, a production deployment, or a system service:
73+
There are a few ways to run Coder:
6874

69-
- To set up a **temporary deployment**, start with dev mode (all data is in-memory and is
70-
destroyed on exit):
75+
- To run a **temporary deployment**, start with dev mode (all data is in-memory and destroyed on exit):
7176

7277
```bash
7378
coder server --dev
@@ -80,19 +85,20 @@ You can set up a temporary deployment, a production deployment, or a system serv
8085
coder server
8186
```
8287

83-
- To run as a **system service**, install with `.deb` (Debian, Ubuntu) or `.rpm`
84-
(Fedora, CentOS, RHEL, SUSE):
88+
- To run as a **system service**, install with `.deb` (Debian, Ubuntu) or `.rpm` (Fedora, CentOS, RHEL, SUSE):
8589

8690
```bash
8791
# Edit the configuration!
8892
sudo vim /etc/coder.d/coder.env
8993
sudo service coder restart
9094
```
9195

92-
> Use `coder --help` to get a complete list of flags and environment
93-
> variables.
96+
> macOS and Windows users: You'll need to write your own
97+
> configuration to run Coder as a system service.
98+
99+
- See the [installation guide](./docs/install.md) for additional ways to run Coder (e.g., docker-compose)
94100
95-
See the [installation guide](./docs/install.md) for additional ways to deploy Coder.
101+
Use `coder --help` to get a complete list of flags and environment variables.
96102
97103
## Creating your first template and workspace
98104
@@ -147,10 +153,29 @@ coder templates update gcp-linux
147153
- [Workspace lifecycle](./docs/workspaces.md#workspace-lifecycle)
148154
- [Updating workspaces](./docs/workspaces.md#updating-workspaces)
149155
156+
## Community
157+
158+
Join the community on [Discord](https://discord.gg/coder) and [Twitter](https://twitter.com/coderhq) #coder!
159+
160+
[Suggest improvements and report problems](https://github.com/coder/coder/issues/new/choose)
161+
162+
## Comparison
163+
164+
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](./docs/about.md#what-coder-is-not).
165+
166+
| Tool | Type | Delivery Model | Cost | Environments |
167+
| :---------------------------------------------------------- | :------- | :----------------- | :---------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- |
168+
| [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 |
169+
| [code-server](https://github.com/cdr/code-server) | Web IDE | OSS + Self-Managed | Pay your cloud | Linux, Mac, Windows, containers, VMs, amd64, arm64 |
170+
| [Coder (Classic)](https://coder.com/docs) | Platform | Self-Managed | Pay your cloud + license fees | Kubernetes Linux Containers |
171+
| [GitHub Codespaces](https://github.com/features/codespaces) | Platform | SaaS | 2x Azure Compute | Linux containers |
172+
173+
---
174+
175+
_As of 5/27/22_
176+
150177
## Contributing
151178
152179
Read the [contributing docs](./docs/CONTRIBUTING.md).
153180
154-
## Contributors
155-
156181
Find our list of contributors [here](./docs/CONTRIBUTORS.md).

agent/agent.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, rawID string, conn ne
456456

457457
// The ID format is referenced in conn.go.
458458
// <uuid>:<height>:<width>
459-
idParts := strings.Split(rawID, ":")
460-
if len(idParts) != 3 {
459+
idParts := strings.SplitN(rawID, ":", 4)
460+
if len(idParts) != 4 {
461461
a.logger.Warn(ctx, "client sent invalid id format", slog.F("raw-id", rawID))
462462
return
463463
}
@@ -489,7 +489,7 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, rawID string, conn ne
489489
}
490490
} else {
491491
// Empty command will default to the users shell!
492-
cmd, err := a.createCommand(ctx, "", nil)
492+
cmd, err := a.createCommand(ctx, idParts[3], nil)
493493
if err != nil {
494494
a.logger.Warn(ctx, "create reconnecting pty command", slog.Error(err))
495495
return

agent/agent_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func TestAgent(t *testing.T) {
221221

222222
conn := setupAgent(t, agent.Metadata{}, 0)
223223
id := uuid.NewString()
224-
netConn, err := conn.ReconnectingPTY(id, 100, 100)
224+
netConn, err := conn.ReconnectingPTY(id, 100, 100, "/bin/bash")
225225
require.NoError(t, err)
226226
bufRead := bufio.NewReader(netConn)
227227

@@ -259,7 +259,7 @@ func TestAgent(t *testing.T) {
259259
expectLine(matchEchoOutput)
260260

261261
_ = netConn.Close()
262-
netConn, err = conn.ReconnectingPTY(id, 100, 100)
262+
netConn, err = conn.ReconnectingPTY(id, 100, 100, "/bin/bash")
263263
require.NoError(t, err)
264264
bufRead = bufio.NewReader(netConn)
265265

agent/conn.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ type Conn struct {
3434

3535
// ReconnectingPTY returns a connection serving a TTY that can
3636
// be reconnected to via ID.
37-
func (c *Conn) ReconnectingPTY(id string, height, width uint16) (net.Conn, error) {
38-
channel, err := c.CreateChannel(context.Background(), fmt.Sprintf("%s:%d:%d", id, height, width), &peer.ChannelOptions{
37+
//
38+
// The command is optional and defaults to start a shell.
39+
func (c *Conn) ReconnectingPTY(id string, height, width uint16, command string) (net.Conn, error) {
40+
channel, err := c.CreateChannel(context.Background(), fmt.Sprintf("%s:%d:%d:%s", id, height, width, command), &peer.ChannelOptions{
3941
Protocol: ProtocolReconnectingPTY,
4042
})
4143
if err != nil {

cli/bump.go

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
"time"
7+
8+
"github.com/spf13/cobra"
9+
"golang.org/x/xerrors"
10+
11+
"github.com/coder/coder/codersdk"
12+
)
13+
14+
const (
15+
bumpDescriptionLong = `To extend the autostop deadline for a workspace.
16+
If no unit is specified in the duration, we assume minutes.`
17+
defaultBumpDuration = 90 * time.Minute
18+
)
19+
20+
func bump() *cobra.Command {
21+
bumpCmd := &cobra.Command{
22+
Args: cobra.RangeArgs(1, 2),
23+
Annotations: workspaceCommand,
24+
Use: "bump <workspace-name> [duration]",
25+
Short: "Extend the autostop deadline for a workspace.",
26+
Long: bumpDescriptionLong,
27+
Example: "coder bump my-workspace 90m",
28+
RunE: func(cmd *cobra.Command, args []string) error {
29+
bumpDuration := defaultBumpDuration
30+
if len(args) > 1 {
31+
d, err := tryParseDuration(args[1])
32+
if err != nil {
33+
return err
34+
}
35+
bumpDuration = d
36+
}
37+
38+
if bumpDuration < time.Minute {
39+
return xerrors.New("minimum bump duration is 1 minute")
40+
}
41+
42+
client, err := createClient(cmd)
43+
if err != nil {
44+
return xerrors.Errorf("create client: %w", err)
45+
}
46+
organization, err := currentOrganization(cmd, client)
47+
if err != nil {
48+
return xerrors.Errorf("get current org: %w", err)
49+
}
50+
51+
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, args[0])
52+
if err != nil {
53+
return xerrors.Errorf("get workspace: %w", err)
54+
}
55+
56+
if workspace.LatestBuild.Deadline.IsZero() {
57+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "no deadline set\n")
58+
return nil
59+
}
60+
61+
newDeadline := workspace.LatestBuild.Deadline.Add(bumpDuration)
62+
if err := client.PutExtendWorkspace(cmd.Context(), workspace.ID, codersdk.PutExtendWorkspaceRequest{
63+
Deadline: newDeadline,
64+
}); err != nil {
65+
return err
66+
}
67+
68+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Workspace %q will now stop at %s\n", workspace.Name, newDeadline.Format(time.RFC3339))
69+
70+
return nil
71+
},
72+
}
73+
74+
return bumpCmd
75+
}
76+
77+
func tryParseDuration(raw string) (time.Duration, error) {
78+
// If the user input a raw number, assume minutes
79+
if isDigit(raw) {
80+
raw = raw + "m"
81+
}
82+
d, err := time.ParseDuration(raw)
83+
if err != nil {
84+
return 0, err
85+
}
86+
return d, nil
87+
}
88+
89+
func isDigit(s string) bool {
90+
return strings.IndexFunc(s, func(c rune) bool {
91+
return c < '0' || c > '9'
92+
}) == -1
93+
}

0 commit comments

Comments
 (0)