generated from devcontainers/feature-starter
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upload gcloud-cli feature (with tests)
- Loading branch information
1 parent
34fc94b
commit 7dfd7e7
Showing
6 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## OS and Architecture Support | ||
|
||
Architectures: `amd` and `arm`. | ||
OS: `ubuntu`, `debian` | ||
|
||
## Changelog | ||
|
||
| Version | Notes | | ||
| ------- | --------------- | | ||
| 0.0.0 | Initial Version | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "Google Cloud CLI Persistence", | ||
"id": "gcloud-cli-persistence", | ||
"version": "0.0.0", | ||
"documentationURL": "https://github.com/joshuanianji/devcontainer-features/tree/main/src/gcloud-cli-persistence", | ||
"description": "Avoid extra logins from the Google Cloud CLI by preserving the `~/.config/gcloud` folder across container instances.", | ||
"options": {}, | ||
"mounts": [ | ||
{ | ||
"source": "${devcontainerId}-gcloud-cli", | ||
"target": "/dc/gcloud-cli", | ||
"type": "volume" | ||
} | ||
], | ||
"installsAfter": [ | ||
"ghcr.io/dhoeric/features/google-cloud-cli" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
echo "Activating feature 'gcloud-cli-persistence'" | ||
echo "User: ${_REMOTE_USER} User home: ${_REMOTE_USER_HOME}" | ||
|
||
if [ -z "$_REMOTE_USER" ] || [ -z "$_REMOTE_USER_HOME" ]; then | ||
echo "***********************************************************************************" | ||
echo "*** Require _REMOTE_USER and _REMOTE_USER_HOME to be set (by dev container CLI) ***" | ||
echo "***********************************************************************************" | ||
exit 1 | ||
fi | ||
|
||
# make ~/.config folder if doesn't exist | ||
mkdir -p "$_REMOTE_USER_HOME/.config" | ||
mkdir -p "/dc/gcloud-cli" | ||
|
||
# if `.config/gcloud` already exists, the `ln -s` command will create an extra | ||
# folder *inside* `.config/gcloud` that symlinks to `gcloud-cli` | ||
# Thus, we want to make sure the folder does NOT exist so the symlink will actually be to ~/.config/gcloud | ||
if [ -e "$_REMOTE_USER_HOME/.config/gcloud" ]; then | ||
echo "Moving existing gcloud folder to gcloud-old" | ||
mv "$_REMOTE_USER_HOME/.config/gcloud" "$_REMOTE_USER_HOME/.config/gcloud-old" | ||
fi | ||
|
||
ln -s /dc/gcloud-cli "$_REMOTE_USER_HOME/.config/gcloud" | ||
# chown the entire `.config` folder because devcontainers creates | ||
# a `~/.config/vscode-dev-containers` folder later on | ||
chown -R "${_REMOTE_USER}:${_REMOTE_USER}" "$_REMOTE_USER_HOME/.config" | ||
|
||
# chown mount (only attached on startup) | ||
cat <<EOF >>"$_REMOTE_USER_HOME/.bashrc" | ||
sudo chown -R "${_REMOTE_USER}:${_REMOTE_USER}" /dc/gcloud-cli | ||
EOF | ||
chown -R $_REMOTE_USER $_REMOTE_USER_HOME/.bashrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"with_node": { | ||
"image": "mcr.microsoft.com/devcontainers/javascript-node:1-18", | ||
"features": { | ||
"github-cli-persistence": {}, | ||
"ghcr.io/devcontainers/features/github-cli": {} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Optional: Import test library | ||
source dev-container-features-test-lib | ||
|
||
# NOTE: this is an "auto-generated" test, which means it will be | ||
# executed against an auto-generated devcontainer.json that | ||
# includes the 'gcloud-cli-persistence' Feature with no options. | ||
# | ||
# https://github.com/devcontainers/cli/blob/main/docs/features/test.md | ||
# | ||
# From my tests, this means the `gcloud` CLI will not be installed: | ||
# Thus, here, I only check basic directory existence | ||
|
||
# check that `~/.config/gcloud` and `/dc/gcloud-cli` exist` | ||
check "config" bash -c "ls -la ~/.config | grep 'gcloud'" | ||
check "dc" bash -c "ls -la /dc | grep 'gcloud-cli'" | ||
|
||
# check that `~/.config/gcloud` is a symlink | ||
# https://unix.stackexchange.com/a/96910 | ||
check "~/.config/gcloud is a symlink" bash -c "test -L ~/.config/gcloud && test -d ~/.config/gcloud" | ||
|
||
# Report result | ||
reportResults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Optional: Import test library | ||
source dev-container-features-test-lib | ||
|
||
# check that `gcloud --help` works | ||
check "help" bash -c "gcloud --help | grep 'NAME'" | ||
|
||
# check that `.config/gcloud` and `/dc/gcloud-cli` exist under the user (should be node) | ||
check "config" bash -c "ls -la ~/.config | grep 'gloud'" | ||
check "dc" bash -c "ls -la /dc | grep 'gcloud-cli'" | ||
|
||
# check that the folders are owned by the user | ||
# `stat -c "%U %G" ~/.config` returns "$USER $GROUP", in this case "node node" | ||
# https://askubuntu.com/a/175060 | ||
check "~/.config/gloud owned by user" bash -c "test \"$(stat -c "%U %G" ~/.config)\" = 'node node'" | ||
check "/dc/gcloud-cli owned by user" bash -c "test \"$(stat -c "%U %G" /dc/gcloud-cli)\" = 'node node'" | ||
|
||
# Report result | ||
reportResults |