Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Google Cloud CLI feature and tests #6

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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