Skip to content

Commit

Permalink
Add Google Cloud CLI feature and tests (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarber623-cargosense authored Oct 10, 2024
2 parents 13007fb + 38d8031 commit 4dcd047
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/google-cloud-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# google-cloud-cli

Install the [Google Cloud CLI](https://cloud.google.com/cli).

## Usage

```json
"features": {
"ghcr.io/CargoSense/devcontainer-features/google-cloud-cli:1": {}
}
```

## Options

| Option ID | Description | Type | Default Value |
|:----------|:-----------------------------------------|:-------|:--------------|
| `version` | The google-cloud-cli version to install. | string | `latest` |

## OS Support

This Feature should work on recent versions of Debian/Ubuntu and Linux distributions using the [apt](https://wiki.debian.org/AptCLI) management tool.
19 changes: 19 additions & 0 deletions src/google-cloud-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "Google Cloud CLI",
"id": "google-cloud-cli",
"version": "1.1.0",
"description": "Install Google Cloud CLI, a tool for creating and managing Google Cloud resources and services.",
"options": {
"version": {
"type": "string",
"proposals": [
"latest"
],
"default": "latest",
"description": "Select or enter a Google Cloud CLI version."
}
},
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
]
}
46 changes: 46 additions & 0 deletions src/google-cloud-cli/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env sh

set -e

GOOGLE_CLOUD_CLI_VERSION="${VERSION:-"latest"}"

if [ "$(id -u)" -ne 0 ]; then
printf 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1
fi

curl_installed=""
gpg_installed=""

if ! type curl >/dev/null 2>&1; then
apt-get update --yes
apt-get install --no-install-recommends --yes curl ca-certificates

curl_installed="true"
fi

if ! type gpg >/dev/null 2>&1; then
apt-get update --yes
apt-get install --no-install-recommends --yes gpg

gpg_installed="true"
fi

curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg
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

apt-get update --yes

if [ "${GOOGLE_CLOUD_CLI_VERSION}" = "latest" ]; then
apt-get install --no-install-recommends --yes postgresql-client
else
apt-get install --no-install-recommends --yes google-cloud-cli="${GOOGLE_CLOUD_CLI_VERSION}"
fi

if [ -n "${curl_installed}" ]; then
apt purge curl --autoremove --yes
fi

if [ -n "${gpg_installed}" ]; then
apt purge gpg --autoremove --yes
fi
14 changes: 14 additions & 0 deletions test/google-cloud-cli/install-bookworm-with-settings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -e

# Optional: Import test library bundled with the devcontainer CLI
# shellcheck source=/dev/null
source dev-container-features-test-lib

# Feature-specific tests
check "version" bash -c "gcloud --version | grep 1.6.20"
check "which gcloud" bash -c "which gcloud | grep /usr/bin/gcloud"

# Report result
reportResults
14 changes: 14 additions & 0 deletions test/google-cloud-cli/install-bookworm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -e

# Optional: Import test library bundled with the devcontainer CLI
# shellcheck source=/dev/null
source dev-container-features-test-lib

# Feature-specific tests
check "version" gcloud --version
check "which gcloud" bash -c "which gcloud | grep /usr/bin/gcloud"

# Report result
reportResults
19 changes: 19 additions & 0 deletions test/google-cloud-cli/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"install-bookworm": {
"image": "debian:bookworm",
"features": {
"google-cloud-cli": {
"version": "latest"
}
}
},

"install-bookworm-with-settings": {
"image": "debian:bookworm",
"features": {
"google-cloud-cli": {
"version": "371.0.0-0"
}
}
}
}
14 changes: 14 additions & 0 deletions test/google-cloud-cli/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -e

# Optional: Import test library bundled with the devcontainer CLI
# shellcheck source=/dev/null
source dev-container-features-test-lib

# Feature-specific tests
check "version" gcloud --version
check "which gcloud" bash -c "which gcloud | grep /usr/bin/gcloud"

# Report result
reportResults

0 comments on commit 4dcd047

Please sign in to comment.