From 395ecade0d87ca2a67c580421d4d8b05ac45dcac Mon Sep 17 00:00:00 2001 From: Caleb Bartholomew Date: Wed, 9 Aug 2023 12:05:09 +0000 Subject: [PATCH 1/2] Fixed environment variable for installing GKE auth plugin --- src/google-cloud-cli/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google-cloud-cli/install.sh b/src/google-cloud-cli/install.sh index dfdb1a0..dd8bc99 100644 --- a/src/google-cloud-cli/install.sh +++ b/src/google-cloud-cli/install.sh @@ -6,7 +6,7 @@ set -e rm -rf /var/lib/apt/lists/* GCLOUD_VERSION=${VERSION:-"latest"} -INSTALL_GKEGCLOUDAUTH_PLUGIN="${INSTALL_GKEGCLOUDAUTH_PLUGIN:-"false"}" +INSTALL_GKEGCLOUDAUTH_PLUGIN="${INSTALLGKEGCLOUDAUTHPLUGIN:-"false"}" if [ "$(id -u)" -ne 0 ]; then echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' From eb25f420a6c8d9f1b28490c776e74533f9904a31 Mon Sep 17 00:00:00 2001 From: Caleb Bartholomew Date: Wed, 9 Aug 2023 12:05:53 +0000 Subject: [PATCH 2/2] Added option to install pubsub emulator. Also added comprehensive tests for google-cloud-cli feature. --- .../devcontainer-feature.json | 5 ++++ src/google-cloud-cli/install.sh | 7 +++++ .../install_gke_auth_plugin.sh | 11 ++++++++ .../install_pubsub_emulator.sh | 11 ++++++++ .../install_specific_version.sh | 11 ++++++++ test/google-cloud-cli/scenarios.json | 26 +++++++++++++++++++ test/google-cloud-cli/test.sh | 2 ++ 7 files changed, 73 insertions(+) create mode 100644 test/google-cloud-cli/install_gke_auth_plugin.sh create mode 100644 test/google-cloud-cli/install_pubsub_emulator.sh create mode 100644 test/google-cloud-cli/install_specific_version.sh create mode 100644 test/google-cloud-cli/scenarios.json diff --git a/src/google-cloud-cli/devcontainer-feature.json b/src/google-cloud-cli/devcontainer-feature.json index 017a0e4..2aa3352 100644 --- a/src/google-cloud-cli/devcontainer-feature.json +++ b/src/google-cloud-cli/devcontainer-feature.json @@ -14,6 +14,11 @@ "type": "boolean", "default": false, "description": "Install 'gke-gcloud-auth-plugin' plugin?" + }, + "installPubSubEmulator": { + "type": "boolean", + "default": false, + "description": "Install the 'google-cloud-cli-pubsub-emulator'?" } }, "installsAfter": [ diff --git a/src/google-cloud-cli/install.sh b/src/google-cloud-cli/install.sh index dd8bc99..a7db9f7 100644 --- a/src/google-cloud-cli/install.sh +++ b/src/google-cloud-cli/install.sh @@ -7,6 +7,7 @@ rm -rf /var/lib/apt/lists/* GCLOUD_VERSION=${VERSION:-"latest"} INSTALL_GKEGCLOUDAUTH_PLUGIN="${INSTALLGKEGCLOUDAUTHPLUGIN:-"false"}" +INSTALL_PUBSUB_EMULATOR="${INSTALLPUBSUBEMULATOR:-"false"}" if [ "$(id -u)" -ne 0 ]; then echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' @@ -94,6 +95,12 @@ install_using_apt() { echo "(*) Installing 'gke-gcloud-auth-plugin' plugin..." check_packages google-cloud-sdk-gke-gcloud-auth-plugin fi + + # Install pubsub emulator if needed + if [ "${INSTALL_PUBSUB_EMULATOR}" = "true" ]; then + echo "(*) Installing 'pubsub-emulator' plugin..." + check_packages google-cloud-cli-pubsub-emulator + fi } echo "(*) Installing google-cloud CLI..." diff --git a/test/google-cloud-cli/install_gke_auth_plugin.sh b/test/google-cloud-cli/install_gke_auth_plugin.sh new file mode 100644 index 0000000..79392cf --- /dev/null +++ b/test/google-cloud-cli/install_gke_auth_plugin.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +check "gke-gcloud-auth-plugin is installed" grep "gke-gcloud-auth-plugin" <(gcloud --version) + +# Report result +reportResults \ No newline at end of file diff --git a/test/google-cloud-cli/install_pubsub_emulator.sh b/test/google-cloud-cli/install_pubsub_emulator.sh new file mode 100644 index 0000000..210e6dc --- /dev/null +++ b/test/google-cloud-cli/install_pubsub_emulator.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +check "pubsub-emulator is installed" grep "pubsub-emulator" <(gcloud --version) + +# Report result +reportResults \ No newline at end of file diff --git a/test/google-cloud-cli/install_specific_version.sh b/test/google-cloud-cli/install_specific_version.sh new file mode 100644 index 0000000..a31f3ae --- /dev/null +++ b/test/google-cloud-cli/install_specific_version.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +check "gcloud version 430.0.0 installed" grep "430.0.0" <(gcloud --version) + +# Report result +reportResults \ No newline at end of file diff --git a/test/google-cloud-cli/scenarios.json b/test/google-cloud-cli/scenarios.json new file mode 100644 index 0000000..820b220 --- /dev/null +++ b/test/google-cloud-cli/scenarios.json @@ -0,0 +1,26 @@ +{ + "install_specific_version": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "google-cloud-cli": { + "version": "430.0.0" + } + } + }, + "install_gke_auth_plugin": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "google-cloud-cli": { + "installGkeGcloudAuthPlugin": true + } + } + }, + "install_pubsub_emulator": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "google-cloud-cli": { + "installPubsubEmulator": true + } + } + } +} \ No newline at end of file diff --git a/test/google-cloud-cli/test.sh b/test/google-cloud-cli/test.sh index f1202fb..061eb4e 100644 --- a/test/google-cloud-cli/test.sh +++ b/test/google-cloud-cli/test.sh @@ -13,6 +13,8 @@ source dev-container-features-test-lib # Feature-specific tests # The 'check' command comes from the dev-container-features-test-lib. check "gcloud version" gcloud --version +check "gke-gcloud-auth-plugin is not installed" [ "$(grep "gke-gcloud-auth-plugin" <(gcloud --version))" = "" ] +check "pubsub-emulator is not installed" [ "$(grep "pubsub-emulator" <(gcloud --version))" = "" ] # Report result # If any of the checks above exited with a non-zero exit code, the test will fail.