diff --git a/src/google-cloud-cli/README.md b/src/google-cloud-cli/README.md new file mode 100644 index 0000000..94b2ac9 --- /dev/null +++ b/src/google-cloud-cli/README.md @@ -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. diff --git a/src/google-cloud-cli/devcontainer-feature.json b/src/google-cloud-cli/devcontainer-feature.json new file mode 100644 index 0000000..df5ecf7 --- /dev/null +++ b/src/google-cloud-cli/devcontainer-feature.json @@ -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" + ] +} diff --git a/src/google-cloud-cli/install.sh b/src/google-cloud-cli/install.sh new file mode 100755 index 0000000..c51b72e --- /dev/null +++ b/src/google-cloud-cli/install.sh @@ -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 diff --git a/test/google-cloud-cli/install-bookworm-with-settings.sh b/test/google-cloud-cli/install-bookworm-with-settings.sh new file mode 100755 index 0000000..a559545 --- /dev/null +++ b/test/google-cloud-cli/install-bookworm-with-settings.sh @@ -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 diff --git a/test/google-cloud-cli/install-bookworm.sh b/test/google-cloud-cli/install-bookworm.sh new file mode 100755 index 0000000..c2e56e6 --- /dev/null +++ b/test/google-cloud-cli/install-bookworm.sh @@ -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 diff --git a/test/google-cloud-cli/scenarios.json b/test/google-cloud-cli/scenarios.json new file mode 100644 index 0000000..fc0ed96 --- /dev/null +++ b/test/google-cloud-cli/scenarios.json @@ -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" + } + } + } +} diff --git a/test/google-cloud-cli/test.sh b/test/google-cloud-cli/test.sh new file mode 100755 index 0000000..c2e56e6 --- /dev/null +++ b/test/google-cloud-cli/test.sh @@ -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