Skip to content

Commit a4d9684

Browse files
authored
Add gcloud devcontainer feature (#15)
1 parent 57b94db commit a4d9684

9 files changed

Lines changed: 115 additions & 0 deletions

features/src/gcloud/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Google Cloud CLI (gcloud)
2+
3+
Installs [Google Cloud CLI](https://cloud.google.com/sdk/gcloud) via the official tarball.
4+
5+
## Usage
6+
7+
```json
8+
"features": {
9+
"ghcr.io/shokkunrf/devcontainer-features/gcloud": {}
10+
}
11+
```
12+
13+
## Requirements
14+
15+
- `curl` and `tar` must be available in the container
16+
- Linux (x86_64 or aarch64)
17+
- aarch64: Python 3.9-3.14 must be installed (x86_64 bundles Python)
18+
19+
## Using host credentials
20+
21+
To forward your host's gcloud credentials into the container, add the following to `devcontainer.json`:
22+
23+
```json
24+
"mounts": [
25+
"source=${localEnv:HOME}/.config/gcloud,target=/home/vscode/.config/gcloud,type=bind,consistency=cached"
26+
]
27+
```
28+
29+
Replace `/home/vscode` with the appropriate home directory for your container user.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"id": "gcloud",
3+
"version": "1.0.0",
4+
"name": "Google Cloud CLI",
5+
"documentationURL": "https://github.com/shokkunrf/devcontainer/tree/develop/features/src/gcloud/README.md",
6+
"description": "Installs Google Cloud CLI via the official tarball",
7+
"options": {},
8+
"installsAfter": [
9+
"ghcr.io/devcontainers/features/common-utils",
10+
"ghcr.io/devcontainers/features/python"
11+
]
12+
}

features/src/gcloud/install.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
# References:
3+
# - https://cloud.google.com/sdk/docs/install-sdk
4+
5+
set -eu
6+
7+
echo "Activating feature 'gcloud'"
8+
9+
# Determine architecture
10+
ARCH="$(uname -m)"
11+
case "$ARCH" in
12+
x86_64) ARCH_SUFFIX="x86_64" ;;
13+
aarch64) ARCH_SUFFIX="arm" ;;
14+
*)
15+
echo "ERROR: Unsupported architecture: $ARCH"
16+
exit 1
17+
;;
18+
esac
19+
20+
INSTALL_DIR="/usr/local"
21+
TARBALL="google-cloud-cli-linux-${ARCH_SUFFIX}.tar.gz"
22+
curl -fsSL "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/${TARBALL}" | tar -xz -C "$INSTALL_DIR"
23+
24+
"${INSTALL_DIR}/google-cloud-sdk/install.sh" --quiet --path-update false --command-completion false
25+
26+
ln -s "${INSTALL_DIR}/google-cloud-sdk/bin/gcloud" /usr/local/bin/gcloud
27+
28+
echo "Google Cloud CLI installed successfully!"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.sh
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.sh
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.sh
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.sh
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"official-debian": {
3+
"image": "debian:trixie",
4+
"features": {
5+
"ghcr.io/devcontainers/features/common-utils:2": {},
6+
"gcloud": {}
7+
}
8+
},
9+
"devcontainer-base-debian": {
10+
"image": "mcr.microsoft.com/devcontainers/base:debian",
11+
"features": {
12+
"gcloud": {}
13+
},
14+
"remoteUser": "vscode"
15+
},
16+
"devcontainer-base-ubuntu-root": {
17+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
18+
"features": {
19+
"gcloud": {}
20+
}
21+
},
22+
"devcontainer-base-ubuntu-remote-user": {
23+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
24+
"features": {
25+
"gcloud": {}
26+
},
27+
"remoteUser": "vscode"
28+
}
29+
}

features/test/gcloud/test.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Definition specific tests
9+
check "gcloud is installed" gcloud --version
10+
check "gcloud is upgradable" gcloud components update --quiet
11+
12+
# Report result
13+
reportResults

0 commit comments

Comments
 (0)