Skip to content

Commit 4dcd047

Browse files
Add Google Cloud CLI feature and tests (#6)
2 parents 13007fb + 38d8031 commit 4dcd047

File tree

7 files changed

+147
-0
lines changed

7 files changed

+147
-0
lines changed

src/google-cloud-cli/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# google-cloud-cli
2+
3+
Install the [Google Cloud CLI](https://cloud.google.com/cli).
4+
5+
## Usage
6+
7+
```json
8+
"features": {
9+
"ghcr.io/CargoSense/devcontainer-features/google-cloud-cli:1": {}
10+
}
11+
```
12+
13+
## Options
14+
15+
| Option ID | Description | Type | Default Value |
16+
|:----------|:-----------------------------------------|:-------|:--------------|
17+
| `version` | The google-cloud-cli version to install. | string | `latest` |
18+
19+
## OS Support
20+
21+
This Feature should work on recent versions of Debian/Ubuntu and Linux distributions using the [apt](https://wiki.debian.org/AptCLI) management tool.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "Google Cloud CLI",
3+
"id": "google-cloud-cli",
4+
"version": "1.1.0",
5+
"description": "Install Google Cloud CLI, a tool for creating and managing Google Cloud resources and services.",
6+
"options": {
7+
"version": {
8+
"type": "string",
9+
"proposals": [
10+
"latest"
11+
],
12+
"default": "latest",
13+
"description": "Select or enter a Google Cloud CLI version."
14+
}
15+
},
16+
"installsAfter": [
17+
"ghcr.io/devcontainers/features/common-utils"
18+
]
19+
}

src/google-cloud-cli/install.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env sh
2+
3+
set -e
4+
5+
GOOGLE_CLOUD_CLI_VERSION="${VERSION:-"latest"}"
6+
7+
if [ "$(id -u)" -ne 0 ]; then
8+
printf 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
9+
exit 1
10+
fi
11+
12+
curl_installed=""
13+
gpg_installed=""
14+
15+
if ! type curl >/dev/null 2>&1; then
16+
apt-get update --yes
17+
apt-get install --no-install-recommends --yes curl ca-certificates
18+
19+
curl_installed="true"
20+
fi
21+
22+
if ! type gpg >/dev/null 2>&1; then
23+
apt-get update --yes
24+
apt-get install --no-install-recommends --yes gpg
25+
26+
gpg_installed="true"
27+
fi
28+
29+
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg
30+
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
31+
32+
apt-get update --yes
33+
34+
if [ "${GOOGLE_CLOUD_CLI_VERSION}" = "latest" ]; then
35+
apt-get install --no-install-recommends --yes postgresql-client
36+
else
37+
apt-get install --no-install-recommends --yes google-cloud-cli="${GOOGLE_CLOUD_CLI_VERSION}"
38+
fi
39+
40+
if [ -n "${curl_installed}" ]; then
41+
apt purge curl --autoremove --yes
42+
fi
43+
44+
if [ -n "${gpg_installed}" ]; then
45+
apt purge gpg --autoremove --yes
46+
fi
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# Optional: Import test library bundled with the devcontainer CLI
6+
# shellcheck source=/dev/null
7+
source dev-container-features-test-lib
8+
9+
# Feature-specific tests
10+
check "version" bash -c "gcloud --version | grep 1.6.20"
11+
check "which gcloud" bash -c "which gcloud | grep /usr/bin/gcloud"
12+
13+
# Report result
14+
reportResults
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# Optional: Import test library bundled with the devcontainer CLI
6+
# shellcheck source=/dev/null
7+
source dev-container-features-test-lib
8+
9+
# Feature-specific tests
10+
check "version" gcloud --version
11+
check "which gcloud" bash -c "which gcloud | grep /usr/bin/gcloud"
12+
13+
# Report result
14+
reportResults

test/google-cloud-cli/scenarios.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"install-bookworm": {
3+
"image": "debian:bookworm",
4+
"features": {
5+
"google-cloud-cli": {
6+
"version": "latest"
7+
}
8+
}
9+
},
10+
11+
"install-bookworm-with-settings": {
12+
"image": "debian:bookworm",
13+
"features": {
14+
"google-cloud-cli": {
15+
"version": "371.0.0-0"
16+
}
17+
}
18+
}
19+
}

test/google-cloud-cli/test.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# Optional: Import test library bundled with the devcontainer CLI
6+
# shellcheck source=/dev/null
7+
source dev-container-features-test-lib
8+
9+
# Feature-specific tests
10+
check "version" gcloud --version
11+
check "which gcloud" bash -c "which gcloud | grep /usr/bin/gcloud"
12+
13+
# Report result
14+
reportResults

0 commit comments

Comments
 (0)