generated from devcontainers/feature-starter
-
Notifications
You must be signed in to change notification settings - Fork 3
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 azure-cli-persistence copied from was-cli-persistence #59
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,17 @@ | ||
## OS and Architecture Support | ||
|
||
Architectures: `amd` and `arm` | ||
|
||
OS: `ubuntu`, `debian` | ||
|
||
Shells: `bash`, `zsh`, `fish` | ||
|
||
## Changelog | ||
|
||
| Version | Notes | | ||
| ------- | ----------------------------------------------- | | ||
| 0.0.1 | Initial Version | | ||
|
||
## References | ||
|
||
- [stuartleeks/azure-cli-persistence](https://github.com/stuartleeks/dev-container-features/tree/main/src/azure-cli-persistence) |
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,41 @@ | ||
|
||
# Azure CLI Persistence (azure-cli-persistence) | ||
|
||
Avoid extra logins from the Azure CLI by preserving the `~/.azure` folder across container instances. | ||
|
||
## Example Usage | ||
|
||
```json | ||
"features": { | ||
"ghcr.io/joshuanianji/devcontainer-features/azure-cli-persistence:1": {} | ||
} | ||
``` | ||
|
||
## Options | ||
|
||
| Options Id | Description | Type | Default Value | | ||
|-----|-----|-----|-----| | ||
|
||
|
||
## OS and Architecture Support | ||
|
||
Architectures: `amd` and `arm` | ||
|
||
OS: `ubuntu`, `debian` | ||
|
||
Shells: `bash`, `zsh`, `fish` | ||
|
||
## Changelog | ||
|
||
| Version | Notes | | ||
| ------- | ----------------------------------------------- | | ||
| 0.0.1 | Initial Version | | ||
|
||
## References | ||
|
||
- [stuartleeks/azure-cli-persistence](https://github.com/stuartleeks/dev-container-features/tree/main/src/azure-cli-persistence) | ||
|
||
|
||
--- | ||
|
||
_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/joshuanianji/devcontainer-features/blob/main/src/azure-cli-persistence/devcontainer-feature.json). Add additional notes to a `NOTES.md`._ |
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,23 @@ | ||
{ | ||
"name": "Azure CLI Persistence", | ||
"id": "azure-cli-persistence", | ||
"version": "0.0.1", | ||
"documentationURL": "https://github.com/joshuanianji/devcontainer-features/tree/main/src/azure-cli-persistence", | ||
"description": "Avoid extra logins from the Azure CLI by preserving the `~/.azure` folder across container instances.", | ||
"options": {}, | ||
"mounts": [ | ||
{ | ||
"source": "${devcontainerId}-azure-cli", | ||
"target": "/dc/azure-cli", | ||
"type": "volume" | ||
} | ||
], | ||
"installsAfter": [ | ||
"ghcr.io/devcontainers/features/azure-cli", | ||
"ghcr.io/devcontainers/features/common-utils", | ||
"ghcr.io/meaningful-ooo/devcontainer-features/fish" | ||
], | ||
"onCreateCommand": { | ||
"azure-cli-persistence-setup": "/usr/local/share/azure-cli-persistence/scripts/oncreate.sh" | ||
} | ||
} |
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,52 @@ | ||
#!/bin/sh | ||
|
||
USERNAME=${USERNAME:-${_REMOTE_USER}} | ||
FEATURE_ID="azure-cli-persistence" | ||
LIFECYCLE_SCRIPTS_DIR="/usr/local/share/${FEATURE_ID}/scripts" | ||
|
||
set -e | ||
|
||
create_cache_dir() { | ||
if [ -d "$1" ]; then | ||
echo "Cache directory $1 already exists. Skip creation..." | ||
else | ||
echo "Create cache directory $1..." | ||
mkdir -p "$1" | ||
fi | ||
|
||
if [ -z "$2" ]; then | ||
echo "No username provided. Skip chown..." | ||
else | ||
echo "Change owner of $1 to $2..." | ||
chown -R "$2:$2" "$1" | ||
fi | ||
} | ||
|
||
create_symlink_dir() { | ||
local local_dir=$1 | ||
local cache_dir=$2 | ||
local username=$3 | ||
|
||
runuser -u "$username" -- mkdir -p "$(dirname "$local_dir")" | ||
runuser -u "$username" -- mkdir -p "$cache_dir" | ||
|
||
# if the folder we want to symlink already exists, the ln -s command will create a folder inside the existing folder | ||
if [ -e "$local_dir" ]; then | ||
echo "Moving existing $local_dir folder to $local_dir-old" | ||
mv "$local_dir" "$local_dir-old" | ||
fi | ||
|
||
echo "Symlink $local_dir to $cache_dir for $username..." | ||
runuser -u "$username" -- ln -s "$cache_dir" "$local_dir" | ||
} | ||
|
||
create_cache_dir "/dc/azure-cli" "${USERNAME}" | ||
create_symlink_dir "$_REMOTE_USER_HOME/.azure" "/dc/azure-cli" "${USERNAME}" | ||
|
||
# Set Lifecycle scripts | ||
if [ -f oncreate.sh ]; then | ||
mkdir -p "${LIFECYCLE_SCRIPTS_DIR}" | ||
cp oncreate.sh "${LIFECYCLE_SCRIPTS_DIR}/oncreate.sh" | ||
fi | ||
|
||
echo "Finished installing $FEATURE_ID" |
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 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
# if the user is not root, chown /dc/azure-cli to the user | ||
if [ "$(id -u)" != "0" ]; then | ||
echo "Running oncreate.sh for user $USER" | ||
sudo chown -R "$USER:$USER" /dc/azure-cli | ||
fi |
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 | ||
|
||
# This script is the "default" test script for the azure-cli-persistence feature. | ||
# It is not run as a scenario, but is run by other test scripts. | ||
|
||
# Optional: Import test library | ||
source dev-container-features-test-lib | ||
|
||
# check that `azure --help` works | ||
check "help" bash -c "azure help | grep 'usage'" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think tests are failing because this should be `az help, but other than that the tests seem good |
||
|
||
# check that `.azure` and `/dc/azure-cli` exist under the user (should be node) | ||
check "~/.azure existence" bash -c "ls -la ~ | grep '.azure'" | ||
check "/dc/azure-cli existence" bash -c "ls -la /dc | grep 'azure-cli'" | ||
|
||
# check that the folders are owned by the user | ||
# https://askubuntu.com/a/175060 | ||
echo "Checking ownership of ~/.azure and /dc/azure-cli (ensure it is owned by $USER)" | ||
|
||
check "~/.azure owned by user" bash -c "test \"$(stat -c "%U" ~/.azure)\" = $USER" | ||
check "/dc/azure-cli owned by user" bash -c "test \"$(stat -c "%U" /dc/azure-cli)\" = $USER" | ||
|
||
# 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,7 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Run default test script (in same folder) | ||
# See: https://github.com/devcontainers/features/blob/562305d37b97d47331d96306ffc2a0a3cce55e64/test/azure-cli/install_extensions_bookworm.sh | ||
./_default.sh |
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 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
source dev-container-features-test-lib | ||
|
||
# Run default test script (in same folder) | ||
# See: https://github.com/devcontainers/features/blob/562305d37b97d47331d96306ffc2a0a3cce55e64/test/azure-cli/install_extensions_bookworm.sh | ||
./_default.sh |
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 @@ | ||
{ | ||
"with_node": { | ||
"image": "mcr.microsoft.com/devcontainers/javascript-node:1-18", | ||
"features": { | ||
"ghcr.io/devcontainers/features/azure-cli": {}, | ||
"azure-cli-persistence": {} | ||
} | ||
}, | ||
"zsh_shell": { | ||
"image": "mcr.microsoft.com/devcontainers/base:debian", | ||
"features": { | ||
"ghcr.io/devcontainers/features/common-utils:2": { | ||
"configureZshAsDefaultShell": true | ||
}, | ||
"ghcr.io/devcontainers/features/azure-cli": {}, | ||
"azure-cli-persistence": {} | ||
} | ||
}, | ||
"fish_shell": { | ||
"image": "mcr.microsoft.com/devcontainers/base:debian", | ||
"features": { | ||
"ghcr.io/meaningful-ooo/devcontainer-features/fish:1": {}, | ||
"ghcr.io/devcontainers/features/azure-cli": {}, | ||
"azure-cli-persistence": {} | ||
} | ||
}, | ||
"root_user": { | ||
"image": "mcr.microsoft.com/devcontainers/base:debian", | ||
"features": { | ||
"ghcr.io/devcontainers/features/azure-cli": {}, | ||
"azure-cli-persistence": {} | ||
}, | ||
"remoteUser": "root" | ||
} | ||
} |
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,21 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Optional: Import test library | ||
source dev-container-features-test-lib | ||
|
||
# NOTE: azure is not installed inside the `test.sh` run | ||
# see: test/github-cli-persistence/test.sh | ||
|
||
|
||
# check that `~/.azure` and `/dc/azure-cli` exist` | ||
check "~/.azure existence" bash -c "ls -la ~ | grep '.azure'" | ||
check "/dc/azure-cli existence" bash -c "ls -la /dc | grep 'azure-cli'" | ||
|
||
# check that `~/.azure` is a symlink | ||
# https://unix.stackexchange.com/a/96910 | ||
check "~/.azure is a symlink" bash -c "test -L ~/.azure && test -d ~/.azure" | ||
|
||
# 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,7 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Run default test script (in same folder) | ||
# See: https://github.com/devcontainers/features/blob/562305d37b97d47331d96306ffc2a0a3cce55e64/test/azure-cli/install_extensions_bookworm.sh | ||
./_default.sh |
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,7 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Run default test script (in same folder) | ||
# See: https://github.com/devcontainers/features/blob/562305d37b97d47331d96306ffc2a0a3cce55e64/test/azure-cli/install_extensions_bookworm.sh | ||
./_default.sh |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think devcontainer feature IDs need to be unique - maybe change this to
azure-cli-persistence-new
or something similar? I think the name can stay the same.We can also update the description field to something similar to "(fork of stuartleeks): "