Skip to content

Commit a7547c8

Browse files
authored
improve dev container (#19757)
1 parent 5fdedd9 commit a7547c8

File tree

7 files changed

+139
-6
lines changed

7 files changed

+139
-6
lines changed

Diff for: .devcontainer/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,5 @@ ENV PRE_COMMIT_HOME=/workspace/.pre-commit
323323

324324
# Setting the environment variable here so that it will be accessible to all tasks and
325325
# terminal sessions in Gitpod workspaces.
326-
ENV PREVIEW_ENV_DEV_SA_KEY_PATH=
326+
ENV PREVIEW_ENV_DEV_SA_KEY_PATH=/root/.config/gcloud/sa.json
327+
ENV GOOGLE_EXTERNAL_ACCOUNT_ALLOW_EXECUTABLES=1

Diff for: .devcontainer/devcontainer.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
"dockerfile": "./Dockerfile"
66
},
77
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace/gitpod,type=bind",
8-
"workspaceFolder": "/workspace/gitpod",
9-
"updateContentCommand": "dev/install-dependencies.sh",
8+
"workspaceFolder": "/workspace/gitpod/",
9+
"postCreateCommand": "dev/install-dependencies.sh",
10+
"mounts": [
11+
"source=/usr/local/gitpod/config/,target=/usr/local/gitpod/config/,type=bind"
12+
],
1013
"remoteEnv": {
1114
"GIT_EDITOR": "code --wait",
1215
"KUBE_EDITOR": "code --wait"

Diff for: .pre-commit-config.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ repos:
55
#- id: check-yaml
66
# args: [--allow-multiple-documents]
77
- id: check-json
8+
exclude: ^.devcontainer/devcontainer.json$
89
- id: end-of-file-fixer
910
- id: trailing-whitespace
1011
- id: check-symlinks
@@ -80,5 +81,10 @@ repos:
8081
language: system
8182
pass_filenames: false
8283
files: ^components/dashboard/
84+
- repo: https://gitlab.com/bmares/check-json5
85+
rev: v1.0.0
86+
hooks:
87+
- id: check-json5
88+
files: ^.devcontainer/devcontainer.json$
8389

8490
exclude: ^install/installer/.*/.*\.golden$

Diff for: dev/BUILD.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,36 @@ packages:
2626
image:
2727
- ${imageRepoBase}/dev-utils:${version}
2828
- ${imageRepoBase}/dev-utils:commit-${__git_commit}
29+
- name: "install"
30+
type: "generic"
31+
deps:
32+
- dev/gpctl:app
33+
- dev/kubecdl:app
34+
- dev/gp-gcloud:app
35+
config:
36+
commands:
37+
- [ "sh", "-c", "sudo mv dev-gpctl--app/gpctl /usr/local/bin/gpctl" ]
38+
- [ "sh", "-c", "sudo mv dev-kubecdl--app/kubecdl /usr/local/bin/kubecdl" ]
39+
- [ "sh", "-c", "sudo mv dev-gp-gcloud--app/gp-gcloud /usr/local/bin/gp-gcloud" ]
40+
2941
scripts:
3042
- name: preview
3143
description: Build Gitpod, create a preview environment, and deploy to it
3244
script: ./preview/workflow/preview/preview.sh
45+
- name: prepare
46+
description: Prepare the repository for development
47+
script: |
48+
leeway run dev:prepare-go dev:prepare-ts
49+
- name: prepare-go
50+
description: Prepare go packages
51+
script: |
52+
./components/gitpod-protocol/go/scripts/generate-config.sh
53+
leeway exec --filter-type go -v -- go mod verify
54+
- name: prepare-ts
55+
description: Prepare typescript packages
56+
script: |
57+
yarn --network-timeout 100000 && yarn build
58+
- name: install-dev-utils
59+
description: Install dev-utils
60+
script: |
61+
leeway build dev:install --dont-test --cache=remote-pull

Diff for: dev/install-dependencies.sh

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/bash
22

3+
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
4+
leeway run dev/preview:configure-workspace
5+
leeway run dev:install-dev-utils
36
leeway run dev/preview/previewctl:install
47
pre-commit install --install-hooks

Diff for: dev/next-oidc/oidc.js

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
const fs = require("fs");
2+
const http2 = require("http2");
3+
4+
const getIDToken = async () => {
5+
return new Promise((resolve, reject) => {
6+
try {
7+
const configPath = "/usr/local/gitpod/config/initial-spec.json";
8+
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
9+
10+
const controlPlaneApiEndpoint = config.controlPlaneApiEndpoint;
11+
const workspaceToken = config.workspaceToken;
12+
13+
const url = new URL(controlPlaneApiEndpoint);
14+
const client = http2.connect(url.origin);
15+
16+
const req = client.request({
17+
":method": "POST",
18+
"content-type": "application/json",
19+
authorization: `Bearer ${workspaceToken}`,
20+
":path": `${url.pathname}/gitpod.v1.IdentityService/GetIDToken`,
21+
});
22+
23+
let responseData = "";
24+
25+
req.on("data", (chunk) => {
26+
responseData += chunk;
27+
});
28+
29+
req.on("end", () => {
30+
try {
31+
const result = JSON.parse(responseData);
32+
const token = result.token;
33+
resolve(token);
34+
} catch (error) {
35+
reject(new Error("Error parsing response: " + error.message));
36+
} finally {
37+
client.close();
38+
}
39+
});
40+
41+
req.on("error", (error) => {
42+
reject(new Error(error.message));
43+
client.close();
44+
});
45+
46+
req.end(
47+
JSON.stringify({
48+
audience: ["accounts.google.com"],
49+
}),
50+
);
51+
} catch (e) {
52+
reject(new Error(e.message));
53+
}
54+
});
55+
};
56+
57+
(async () => {
58+
try {
59+
const token = await getIDToken();
60+
console.log(
61+
JSON.stringify({
62+
version: 1,
63+
success: true,
64+
token_type: "urn:ietf:params:oauth:token-type:id_token",
65+
id_token: token,
66+
}),
67+
);
68+
} catch (error) {
69+
console.log(
70+
JSON.stringify({
71+
version: 1,
72+
success: false,
73+
code: "401",
74+
message: error.message,
75+
}),
76+
);
77+
}
78+
})();

Diff for: dev/preview/workflow/preview/configure-workspace.sh

+16-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,28 @@ if { [[ "${auth}" != "(unset)" ]] || [ -n "${auth:-}" ]; } && [ -f "${PREVIEW_EN
1313
exit 0
1414
fi
1515

16-
if [[ -z "${PREVIEW_ENV_DEV_CRED:-}" ]] || [[ -z "${PREVIEW_ENV_DEV_SA_KEY_PATH:-}" ]]; then
17-
log_warn "Neither PREVIEW_ENV_DEV_CRED, nor PREVIEW_ENV_DEV_SA_KEY_PATH is set. Skipping workspace setup."
16+
if [ -z "${PREVIEW_ENV_DEV_SA_KEY_PATH:-}" ]; then
17+
log_warn "PREVIEW_ENV_DEV_SA_KEY_PATH is not set. Skipping workspace setup."
1818
exit 0
1919
fi
2020

21-
if [ ! -f "${PREVIEW_ENV_DEV_SA_KEY_PATH}" ]; then
21+
if [ -f "/usr/local/gitpod/config/initial-spec.json" ]; then
22+
gcloud iam workload-identity-pools create-cred-config \
23+
projects/184212049955/locations/global/workloadIdentityPools/gitpod-next/providers/gitpod-next-provider \
24+
--service-account=preview-environmnet-dev@gitpod-dev-preview.iam.gserviceaccount.com \
25+
--service-account-token-lifetime-seconds=1h \
26+
--output-file="${PREVIEW_ENV_DEV_SA_KEY_PATH}" \
27+
--executable-command='node /workspace/gitpod/dev/next-oidc/oidc.js' \
28+
--executable-timeout-millis=5000
29+
elif [[ -n "${PREVIEW_ENV_DEV_CRED:-}" ]]; then
2230
echo "${PREVIEW_ENV_DEV_CRED}" >"${PREVIEW_ENV_DEV_SA_KEY_PATH}"
2331
fi
2432

33+
if [ ! -f "${PREVIEW_ENV_DEV_SA_KEY_PATH}" ]; then
34+
log_warn "Neither PREVIEW_ENV_DEV_CRED, nor PREVIEW_ENV_DEV_SA_KEY_PATH is set. Skipping workspace setup."
35+
exit 0
36+
fi
37+
2538
gcloud auth login --cred-file "${PREVIEW_ENV_DEV_SA_KEY_PATH}" --activate --quiet
2639

2740
if [[ -n "${INSTALL_CONTEXT:-}" ]]; then

0 commit comments

Comments
 (0)