diff --git a/features/src/gcloud/README.md b/features/src/gcloud/README.md new file mode 100644 index 0000000..17b3e37 --- /dev/null +++ b/features/src/gcloud/README.md @@ -0,0 +1,29 @@ +# Google Cloud CLI (gcloud) + +Installs [Google Cloud CLI](https://cloud.google.com/sdk/gcloud) via the official tarball. + +## Usage + +```json +"features": { + "ghcr.io/shokkunrf/devcontainer-features/gcloud": {} +} +``` + +## Requirements + +- `curl` and `tar` must be available in the container +- Linux (x86_64 or aarch64) +- aarch64: Python 3.9-3.14 must be installed (x86_64 bundles Python) + +## Using host credentials + +To forward your host's gcloud credentials into the container, add the following to `devcontainer.json`: + +```json +"mounts": [ + "source=${localEnv:HOME}/.config/gcloud,target=/home/vscode/.config/gcloud,type=bind,consistency=cached" +] +``` + +Replace `/home/vscode` with the appropriate home directory for your container user. diff --git a/features/src/gcloud/devcontainer-feature.json b/features/src/gcloud/devcontainer-feature.json new file mode 100644 index 0000000..ded28e3 --- /dev/null +++ b/features/src/gcloud/devcontainer-feature.json @@ -0,0 +1,12 @@ +{ + "id": "gcloud", + "version": "1.0.0", + "name": "Google Cloud CLI", + "documentationURL": "https://github.com/shokkunrf/devcontainer/tree/develop/features/src/gcloud/README.md", + "description": "Installs Google Cloud CLI via the official tarball", + "options": {}, + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils", + "ghcr.io/devcontainers/features/python" + ] +} diff --git a/features/src/gcloud/install.sh b/features/src/gcloud/install.sh new file mode 100755 index 0000000..ee8fc7c --- /dev/null +++ b/features/src/gcloud/install.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# References: +# - https://cloud.google.com/sdk/docs/install-sdk + +set -eu + +echo "Activating feature 'gcloud'" + +# Determine architecture +ARCH="$(uname -m)" +case "$ARCH" in + x86_64) ARCH_SUFFIX="x86_64" ;; + aarch64) ARCH_SUFFIX="arm" ;; + *) + echo "ERROR: Unsupported architecture: $ARCH" + exit 1 + ;; +esac + +INSTALL_DIR="/usr/local" +TARBALL="google-cloud-cli-linux-${ARCH_SUFFIX}.tar.gz" +curl -fsSL "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/${TARBALL}" | tar -xz -C "$INSTALL_DIR" + +"${INSTALL_DIR}/google-cloud-sdk/install.sh" --quiet --path-update false --command-completion false + +ln -s "${INSTALL_DIR}/google-cloud-sdk/bin/gcloud" /usr/local/bin/gcloud + +echo "Google Cloud CLI installed successfully!" diff --git a/features/test/gcloud/devcontainer-base-debian.sh b/features/test/gcloud/devcontainer-base-debian.sh new file mode 120000 index 0000000..61a58b0 --- /dev/null +++ b/features/test/gcloud/devcontainer-base-debian.sh @@ -0,0 +1 @@ +test.sh \ No newline at end of file diff --git a/features/test/gcloud/devcontainer-base-ubuntu-remote-user.sh b/features/test/gcloud/devcontainer-base-ubuntu-remote-user.sh new file mode 120000 index 0000000..61a58b0 --- /dev/null +++ b/features/test/gcloud/devcontainer-base-ubuntu-remote-user.sh @@ -0,0 +1 @@ +test.sh \ No newline at end of file diff --git a/features/test/gcloud/devcontainer-base-ubuntu-root.sh b/features/test/gcloud/devcontainer-base-ubuntu-root.sh new file mode 120000 index 0000000..61a58b0 --- /dev/null +++ b/features/test/gcloud/devcontainer-base-ubuntu-root.sh @@ -0,0 +1 @@ +test.sh \ No newline at end of file diff --git a/features/test/gcloud/official-debian.sh b/features/test/gcloud/official-debian.sh new file mode 120000 index 0000000..61a58b0 --- /dev/null +++ b/features/test/gcloud/official-debian.sh @@ -0,0 +1 @@ +test.sh \ No newline at end of file diff --git a/features/test/gcloud/scenarios.json b/features/test/gcloud/scenarios.json new file mode 100644 index 0000000..a53c886 --- /dev/null +++ b/features/test/gcloud/scenarios.json @@ -0,0 +1,29 @@ +{ + "official-debian": { + "image": "debian:trixie", + "features": { + "ghcr.io/devcontainers/features/common-utils:2": {}, + "gcloud": {} + } + }, + "devcontainer-base-debian": { + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "gcloud": {} + }, + "remoteUser": "vscode" + }, + "devcontainer-base-ubuntu-root": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "gcloud": {} + } + }, + "devcontainer-base-ubuntu-remote-user": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "gcloud": {} + }, + "remoteUser": "vscode" + } +} diff --git a/features/test/gcloud/test.sh b/features/test/gcloud/test.sh new file mode 100644 index 0000000..d27e032 --- /dev/null +++ b/features/test/gcloud/test.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Definition specific tests +check "gcloud is installed" gcloud --version +check "gcloud is upgradable" gcloud components update --quiet + +# Report result +reportResults