Skip to content

Commit ed46ee7

Browse files
committed
Merge branch 'main' into bq/one-click-workspace
2 parents 37e6dd3 + 30e1605 commit ed46ee7

File tree

153 files changed

+9148
-3696
lines changed

Some content is hidden

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

153 files changed

+9148
-3696
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Generated files
22
coderd/apidoc/docs.go linguist-generated=true
3+
docs/api/*.md linguist-generated=true
4+
docs/cli/*.md linguist-generated=true
35
coderd/apidoc/swagger.json linguist-generated=true
46
coderd/database/dump.sql linguist-generated=true
57
peerbroker/proto/*.go linguist-generated=true
@@ -9,3 +11,4 @@ provisionersdk/proto/*.go linguist-generated=true
911
*.tfstate.json linguist-generated=true
1012
*.tfstate.dot linguist-generated=true
1113
*.tfplan.dot linguist-generated=true
14+
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: "Setup Node"
22
description: |
33
Sets up the node environment for tests, builds, etc.
4+
inputs:
5+
directory:
6+
description: |
7+
The directory to run the setup in.
8+
required: false
9+
default: "site"
410
runs:
511
using: "composite"
612
steps:
@@ -10,8 +16,8 @@ runs:
1016
node-version: 16.20.1
1117
# See https://github.com/actions/setup-node#caching-global-packages-data
1218
cache: "yarn"
13-
cache-dependency-path: "site/yarn.lock"
19+
cache-dependency-path: ${{ inputs.directory }}/yarn.lock
1420
- name: Install node_modules
1521
shell: bash
1622
run: ../scripts/yarn_install.sh
17-
working-directory: site
23+
working-directory: ${{ inputs.directory }}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Setup sqlc
2+
description: |
3+
Sets up the sqlc environment for tests, builds, etc.
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Setup sqlc
8+
uses: sqlc-dev/setup-sqlc@v3
9+
with:
10+
sqlc-version: "1.19.1"

.github/dependabot.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,28 @@ updates:
123123
- "@swc/jest"
124124
- "@types/jest"
125125

126+
- package-ecosystem: "npm"
127+
directory: "/offlinedocs/"
128+
schedule:
129+
interval: "monthly"
130+
time: "06:00"
131+
timezone: "America/Chicago"
132+
reviewers:
133+
- "coder/ts"
134+
commit-message:
135+
prefix: "chore"
136+
labels: []
137+
ignore:
138+
# Ignore patch updates for all dependencies
139+
- dependency-name: "*"
140+
update-types:
141+
- version-update:semver-patch
142+
# Ignore major updates to Node.js types, because they need to
143+
# correspond to the Node.js engine version
144+
- dependency-name: "@types/node"
145+
update-types:
146+
- version-update:semver-major
147+
126148
# Update dogfood.
127149
- package-ecosystem: "docker"
128150
directory: "/dogfood/"

.github/workflows/ci.yaml

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ jobs:
3535
ts: ${{ steps.filter.outputs.ts }}
3636
k8s: ${{ steps.filter.outputs.k8s }}
3737
ci: ${{ steps.filter.outputs.ci }}
38+
offlinedocs-only: ${{ steps.filter.outputs.offlinedocs_count == steps.filter.outputs.all_count }}
39+
offlinedocs: ${{ steps.filter.outputs.offlinedocs }}
3840
steps:
3941
- name: Checkout
4042
uses: actions/checkout@v3
@@ -93,11 +95,16 @@ jobs:
9395
ci:
9496
- ".github/actions/**"
9597
- ".github/workflows/ci.yaml"
98+
offlinedocs:
99+
- "offlinedocs/**"
100+
96101
- id: debug
97102
run: |
98103
echo "${{ toJSON(steps.filter )}}"
99104
100105
lint:
106+
needs: changes
107+
if: needs.changes.outputs.offlinedocs-only == 'false' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
101108
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
102109
steps:
103110
- name: Checkout
@@ -163,9 +170,7 @@ jobs:
163170
uses: ./.github/actions/setup-go
164171

165172
- name: Setup sqlc
166-
uses: sqlc-dev/setup-sqlc@v3
167-
with:
168-
sqlc-version: "1.19.1"
173+
uses: ./.github/actions/setup-sqlc
169174

170175
- name: go install tools
171176
run: |
@@ -195,6 +200,8 @@ jobs:
195200
run: ./scripts/check_unstaged.sh
196201

197202
fmt:
203+
needs: changes
204+
if: needs.changes.outputs.offlinedocs-only == 'false' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
198205
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
199206
timeout-minutes: 5
200207
steps:
@@ -591,9 +598,68 @@ jobs:
591598
projectToken: 695c25b6cb65
592599
workingDir: "./site"
593600

601+
offlinedocs:
602+
name: offlinedocs
603+
needs: changes
604+
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
605+
if: needs.changes.outputs.offlinedocs == 'true' || needs.changes.outputs.ci == 'true'
606+
steps:
607+
- name: Checkout
608+
uses: actions/checkout@v3
609+
with:
610+
fetch-depth: 0
611+
612+
- name: Setup Node
613+
uses: ./.github/actions/setup-node
614+
with:
615+
directory: offlinedocs
616+
617+
- name: Setup Go
618+
uses: ./.github/actions/setup-go
619+
620+
- name: Install go tools
621+
run: |
622+
go install github.com/golang/mock/mockgen@v1.6.0
623+
624+
- name: Setup sqlc
625+
uses: sqlc-dev/setup-sqlc@v3
626+
with:
627+
sqlc-version: "1.19.1"
628+
629+
- name: Install dependencies
630+
run: |
631+
cd offlinedocs
632+
yarn
633+
# Install prettier globally
634+
prettier_version=$(jq -r '.devDependencies.prettier' < package.json)
635+
yarn global add "prettier@${prettier_version}"
636+
637+
- name: Format
638+
run: |
639+
cd offlinedocs
640+
yarn format:check
641+
642+
- name: Lint
643+
run: |
644+
cd offlinedocs
645+
yarn lint
646+
647+
- name: Build
648+
run: |
649+
version="$(./scripts/version.sh)"
650+
make -j build/coder_docs_"$version".tgz
651+
594652
required:
595653
runs-on: ubuntu-latest
596-
needs: [fmt, lint, gen, test-go, test-go-pg, test-go-race, test-js]
654+
needs:
655+
- fmt
656+
- lint
657+
- gen
658+
- test-go
659+
- test-go-pg
660+
- test-go-race
661+
- test-js
662+
- offlinedocs
597663
# Allow this job to run even if the needed jobs fail, are skipped or
598664
# cancelled.
599665
if: always()

.github/workflows/pr-deploy.yaml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name: Deploy PR
33
on:
44
issue_comment:
5+
types: [created, edited]
56
workflow_dispatch:
67
inputs:
78
pr_number:
@@ -97,9 +98,7 @@ jobs:
9798
uses: ./.github/actions/setup-go
9899

99100
- name: Setup sqlc
100-
uses: sqlc-dev/setup-sqlc@v3
101-
with:
102-
sqlc-version: "1.19.1"
101+
uses: ./.github/actions/setup-sqlc
103102

104103
- name: GHCR Login
105104
uses: docker/login-action@v2
@@ -137,32 +136,33 @@ jobs:
137136
- name: Checkout
138137
uses: actions/checkout@v3
139138

140-
- name: "Set up kubeconfig"
139+
- name: Set up kubeconfig
141140
run: |
142141
set -euxo pipefail
143142
mkdir -p ~/.kube
144143
echo "${{ secrets.DELIVERYBOT_KUBECONFIG }}" > ~/.kube/config
145144
export KUBECONFIG=~/.kube/config
146145
147-
- name: "Create PR namespace"
146+
- name: Create PR namespace
148147
run: |
149148
set -euxo pipefail
150149
# try to delete the namespace, but don't fail if it doesn't exist
151150
kubectl delete namespace "pr${{ env.PR_NUMBER }}" || true
152151
kubectl create namespace "pr${{ env.PR_NUMBER }}"
153152
154-
- name: "Install Helm chart"
153+
- name: Install Helm chart
155154
run: |
156155
helm upgrade --install pr${{ env.PR_NUMBER }} ./helm \
157156
--namespace "pr${{ env.PR_NUMBER }}" \
158157
--set coder.image.repo=${{ env.REPO }} \
159158
--set coder.image.tag=pr${{ env.PR_NUMBER }} \
160159
--set coder.service.type=ClusterIP \
160+
--set coder.serviceAccount.enableDeployments=true \
161161
--set coder.env[0].name=CODER_ACCESS_URL \
162162
--set coder.env[0].value="" \
163163
--force
164164
165-
- name: "Get deployment URL"
165+
- name: Get deployment URL
166166
id: deployment_url
167167
run: |
168168
set -euo pipefail
@@ -172,6 +172,13 @@ jobs:
172172
echo "::add-mask::$CODER_ACCESS_URL"
173173
echo "CODER_ACCESS_URL=$CODER_ACCESS_URL" >> $GITHUB_OUTPUT
174174
175+
- name: Install coder-logstream-kube
176+
run: |
177+
helm repo add coder-logstream-kube https://helm.coder.com/logstream-kube
178+
helm install coder-logstream-kube coder-logstream-kube/coder-logstream-kube \
179+
--namespace "pr${{ env.PR_NUMBER }}" \
180+
--set url="${{ steps.deployment_url.outputs.CODER_ACCESS_URL }}"
181+
175182
- name: Send Slack notification
176183
run: |
177184
curl -s -o /dev/null -X POST -H 'Content-type: application/json' \

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
set -euo pipefail
7777
ref=HEAD
7878
old_version="$(git describe --abbrev=0 "$ref^1")"
79-
version="$(./scripts/version.sh)"
79+
version="v$(./scripts/version.sh)"
8080
8181
# Generate notes.
8282
release_notes_file="$(mktemp -t release_notes.XXXXXX)"

.github/workflows/security.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ jobs:
8181
js-${{ runner.os }}-
8282
8383
- name: Setup sqlc
84-
uses: sqlc-dev/setup-sqlc@v3
85-
with:
86-
sqlc-version: "1.19.1"
84+
uses: ./.github/actions/setup-sqlc
8785

8886
- name: Install yq
8987
run: go run github.com/mikefarah/yq/v4@v4.30.6

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,14 @@ else
410410
endif
411411
.PHONY: fmt/shfmt
412412

413-
lint: lint/shellcheck lint/go lint/ts lint/helm
413+
lint: lint/shellcheck lint/go lint/ts lint/helm lint/site-icons
414414
.PHONY: lint
415415

416+
lint/site-icons:
417+
./scripts/check_site_icons.sh
418+
419+
.PHONY: lint/site-icons
420+
416421
lint/ts:
417422
cd site
418423
yarn && yarn lint

agent/agent.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func New(options Options) Agent {
108108
}
109109
}
110110
if options.ReportMetadataInterval == 0 {
111-
options.ReportMetadataInterval = 1 * time.Minute
111+
options.ReportMetadataInterval = time.Second
112112
}
113113
if options.ServiceBannerRefreshInterval == 0 {
114114
options.ServiceBannerRefreshInterval = 2 * time.Minute
@@ -339,15 +339,19 @@ func (a *agent) reportMetadataLoop(ctx context.Context) {
339339
// baseInterval to run.
340340
flight := trySingleflight{m: map[string]struct{}{}}
341341

342+
postMetadata := func(mr metadataResultAndKey) {
343+
err := a.client.PostMetadata(ctx, mr.key, *mr.result)
344+
if err != nil {
345+
a.logger.Error(ctx, "agent failed to report metadata", slog.Error(err))
346+
}
347+
}
348+
342349
for {
343350
select {
344351
case <-ctx.Done():
345352
return
346353
case mr := <-metadataResults:
347-
err := a.client.PostMetadata(ctx, mr.key, *mr.result)
348-
if err != nil {
349-
a.logger.Error(ctx, "agent failed to report metadata", slog.Error(err))
350-
}
354+
postMetadata(mr)
351355
continue
352356
case <-baseTicker.C:
353357
}
@@ -409,8 +413,14 @@ func (a *agent) reportMetadataLoop(ctx context.Context) {
409413
if md.Interval == 0 {
410414
return
411415
}
416+
intervalUnit := time.Second
417+
// reportMetadataInterval is only less than a second in tests,
418+
// so adjust the interval unit for them.
419+
if a.reportMetadataInterval < time.Second {
420+
intervalUnit = 100 * time.Millisecond
421+
}
412422
// The last collected value isn't quite stale yet, so we skip it.
413-
if collectedAt.Add(a.reportMetadataInterval).After(time.Now()) {
423+
if collectedAt.Add(time.Duration(md.Interval) * intervalUnit).After(time.Now()) {
414424
return
415425
}
416426
}

cli/clistat/cgroup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func readInt64Prefix(fs afero.Fs, path, prefix string) (int64, error) {
338338

339339
scn := bufio.NewScanner(bytes.NewReader(data))
340340
for scn.Scan() {
341-
line := scn.Text()
341+
line := strings.TrimSpace(scn.Text())
342342
if !strings.HasPrefix(line, prefix) {
343343
continue
344344
}

cli/clistat/container.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import (
1010
)
1111

1212
const (
13-
procMounts = "/proc/mounts"
14-
procOneCgroup = "/proc/1/cgroup"
13+
procMounts = "/proc/mounts"
14+
procOneCgroup = "/proc/1/cgroup"
15+
kubernetesDefaultServiceAccountToken = "/var/run/secrets/kubernetes.io/serviceaccount/token" //nolint:gosec
1516
)
1617

1718
// IsContainerized returns whether the host is containerized.
@@ -38,6 +39,14 @@ func IsContainerized(fs afero.Fs) (ok bool, err error) {
3839
}
3940
}
4041

42+
// Sometimes the above method of sniffing /proc/1/cgroup isn't reliable.
43+
// If a Kubernetes service account token is present, that's
44+
// also a good indication that we are in a container.
45+
_, err = afero.ReadFile(fs, kubernetesDefaultServiceAccountToken)
46+
if err == nil {
47+
return true, nil
48+
}
49+
4150
// Last-ditch effort to detect Sysbox containers.
4251
// Check if we have anything mounted as type sysboxfs in /proc/mounts
4352
mountsData, err := afero.ReadFile(fs, procMounts)

0 commit comments

Comments
 (0)