Skip to content

Commit 7d4ad5c

Browse files
committed
Merge branch 'main' into 8128-new-user-state-dormant
2 parents 05cd577 + b7ced94 commit 7d4ad5c

File tree

82 files changed

+7150
-2677
lines changed

Some content is hidden

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

82 files changed

+7150
-2677
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/workflows/ci.yaml

Lines changed: 70 additions & 5 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
@@ -85,7 +87,6 @@ jobs:
8587
ts:
8688
- "site/**"
8789
- "Makefile"
88-
- "offlinedocs/**"
8990
k8s:
9091
- "helm/**"
9192
- "scripts/Dockerfile"
@@ -94,11 +95,16 @@ jobs:
9495
ci:
9596
- ".github/actions/**"
9697
- ".github/workflows/ci.yaml"
98+
offlinedocs:
99+
- "offlinedocs/**"
100+
97101
- id: debug
98102
run: |
99103
echo "${{ toJSON(steps.filter )}}"
100104
101105
lint:
106+
needs: changes
107+
if: needs.changes.outputs.offlinedocs-only == 'false' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
102108
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
103109
steps:
104110
- name: Checkout
@@ -164,9 +170,7 @@ jobs:
164170
uses: ./.github/actions/setup-go
165171

166172
- name: Setup sqlc
167-
uses: sqlc-dev/setup-sqlc@v3
168-
with:
169-
sqlc-version: "1.19.1"
173+
uses: ./.github/actions/setup-sqlc
170174

171175
- name: go install tools
172176
run: |
@@ -196,6 +200,8 @@ jobs:
196200
run: ./scripts/check_unstaged.sh
197201

198202
fmt:
203+
needs: changes
204+
if: needs.changes.outputs.offlinedocs-only == 'false' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
199205
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
200206
timeout-minutes: 5
201207
steps:
@@ -592,9 +598,68 @@ jobs:
592598
projectToken: 695c25b6cb65
593599
workingDir: "./site"
594600

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+
595652
required:
596653
runs-on: ubuntu-latest
597-
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
598663
# Allow this job to run even if the needed jobs fail, are skipped or
599664
# cancelled.
600665
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

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)

cli/dotfiles.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,18 @@ func (r *RootCmd) dotfiles() *clibase.Cmd {
193193
}
194194

195195
_, _ = fmt.Fprintf(inv.Stdout, "Running %s...\n", script)
196+
197+
// Check if the script is executable and notify on error
198+
scriptPath := filepath.Join(dotfilesDir, script)
199+
fi, err := os.Stat(scriptPath)
200+
if err != nil {
201+
return xerrors.Errorf("stat %s: %w", scriptPath, err)
202+
}
203+
204+
if fi.Mode()&0o111 == 0 {
205+
return xerrors.Errorf("script %q is not executable. See https://coder.com/docs/v2/latest/dotfiles for information on how to resolve the issue.", script)
206+
}
207+
196208
// it is safe to use a variable command here because it's from
197209
// a filtered list of pre-approved install scripts
198210
// nolint:gosec

cli/server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,9 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
596596
IgnoreUserInfo: cfg.OIDC.IgnoreUserInfo.Value(),
597597
GroupField: cfg.OIDC.GroupField.String(),
598598
GroupMapping: cfg.OIDC.GroupMapping.Value,
599+
UserRoleField: cfg.OIDC.UserRoleField.String(),
600+
UserRoleMapping: cfg.OIDC.UserRoleMapping.Value,
601+
UserRolesDefault: cfg.OIDC.UserRolesDefault.GetSlice(),
599602
SignInText: cfg.OIDC.SignInText.String(),
600603
IconURL: cfg.OIDC.IconURL.String(),
601604
IgnoreEmailVerified: cfg.OIDC.IgnoreEmailVerified.Value(),

cli/server_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,8 @@ func TestServer(t *testing.T) {
10951095
require.False(t, deploymentConfig.Values.OIDC.IgnoreUserInfo.Value())
10961096
require.Empty(t, deploymentConfig.Values.OIDC.GroupField.Value())
10971097
require.Empty(t, deploymentConfig.Values.OIDC.GroupMapping.Value)
1098+
require.Empty(t, deploymentConfig.Values.OIDC.UserRoleField.Value())
1099+
require.Empty(t, deploymentConfig.Values.OIDC.UserRoleMapping.Value)
10981100
require.Equal(t, "OpenID Connect", deploymentConfig.Values.OIDC.SignInText.Value())
10991101
require.Empty(t, deploymentConfig.Values.OIDC.IconURL.Value())
11001102
})

cli/testdata/coder_server_--help.golden

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,20 @@ can safely ignore these settings.
337337
--oidc-scopes string-array, $CODER_OIDC_SCOPES (default: openid,profile,email)
338338
Scopes to grant when authenticating with OIDC.
339339

340+
--oidc-user-role-default string-array, $CODER_OIDC_USER_ROLE_DEFAULT
341+
If user role sync is enabled, these roles are always included for all
342+
authenticated users. The 'member' role is always assigned.
343+
344+
--oidc-user-role-field string, $CODER_OIDC_USER_ROLE_FIELD
345+
This field must be set if using the user roles sync feature. Set this
346+
to the name of the claim used to store the user's role. The roles
347+
should be sent as an array of strings.
348+
349+
--oidc-user-role-mapping struct[map[string][]string], $CODER_OIDC_USER_ROLE_MAPPING (default: {})
350+
A map of the OIDC passed in user roles and the groups in Coder it
351+
should map to. This is useful if the group names do not match. If
352+
mapped to the empty string, the role will ignored.
353+
340354
--oidc-username-field string, $CODER_OIDC_USERNAME_FIELD (default: preferred_username)
341355
OIDC claim field to use as the username.
342356

cli/testdata/coder_users_list_--output_json.golden

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"display_name": "Owner"
1616
}
1717
],
18-
"avatar_url": ""
18+
"avatar_url": "",
19+
"login_type": "password"
1920
},
2021
{
2122
"id": "[second user ID]",
@@ -28,6 +29,7 @@
2829
"[first org ID]"
2930
],
3031
"roles": [],
31-
"avatar_url": ""
32+
"avatar_url": "",
33+
"login_type": "password"
3234
}
3335
]

0 commit comments

Comments
 (0)