Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
strategy:
matrix:
features:
- dev-tunnels
- azure-cli-persistence
- shell-history
steps:
- uses: actions/checkout@v4
Expand Down
31 changes: 21 additions & 10 deletions src/azure-cli-persistence/oncreate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ fi

log "In OnCreate script"

FEATURE_DIR="/usr/local/share/stuartleeks-devcontainer-features/azure-cli-persistence"
LOG_FILE="$FEATURE_DIR/log.txt"

log() {
echo "$1"
echo "$1" >> "$LOG_FILE"
}

if command -v sudo > /dev/null; then
sudo chown -R "$(id -u):$(id -g)" "$LOG_FILE"
else
chown -R "$(id -u):$(id -g)" "$LOG_FILE"
fi

log "In OnCreate script"

fix_permissions() {
local dir
dir="${1}"
Expand Down Expand Up @@ -47,11 +63,8 @@ old_cliextensions_folder="$HOME/.azure-old/cliextensions"
new_cliextensions_folder="$HOME/.azure/cliextensions"
new_cliextensions_folder_parent="$HOME/.azure"

got_old_extensions_folder=false

if [ "$got_old_azure_folder" = true ]; then
if [ -d "$old_cliextensions_folder" ]; then
got_old_extensions_folder=true
log "cliextensions folder found in old .azure folder"
if [ -d "$new_cliextensions_folder" ]; then
if [ -L "$new_cliextensions_folder" ]; then
Expand All @@ -75,13 +88,11 @@ if [ "$got_old_azure_folder" = true ]; then
fi
fi
fi
fi

# If we haven't got an old .azure folder with a cliextensions folder in it, check if the new cliextensions folder is a symlink to the old one
# And if so, remove the symlink
# This can happen if the user has installed the azure-cli feature and specified extensions to install
# and then later removed the extensions.
if [ "$got_old_extensions_folder" = false ]; then
else
# If we haven't got an old .azure folder with a cliextensions folder in it, check if the new cliextensions folder is a symlink to the old one
# And if so, remove the symlink
# This can happen if the user has installed the azure-cli feature and specified extensions to install
# and then later removed the extensions.
if [ -L "$new_cliextensions_folder" ]; then
symlink_target=$(readlink "$new_cliextensions_folder")
if [ "$symlink_target" = "$old_cliextensions_folder" ]; then
Expand Down
3 changes: 3 additions & 0 deletions test-project/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
// "extensions": "containerapp,ssh"
},
"ghcr.io/devcontainers-extra/features/fish-apt-get": {},
"ghcr.io/devcontainers/features/azure-cli:1": {
"extensions": "containerapp,ssh"
},
"./src/shell-history": {},
"./src/azure-cli-persistence": {}
}
Expand Down
13 changes: 13 additions & 0 deletions test/azure-cli-persistence/_default.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -e

# Optional: Import test library bundled with the devcontainer CLI
source dev-container-features-test-lib

# Feature-specific tests
check "cache dir permission" bash -c "test -w /dc/azure"
check "check symlink" bash -c 'test $(readlink "$HOME/.azure") == "/dc/azure/"'

# Report result
reportResults
5 changes: 5 additions & 0 deletions test/azure-cli-persistence/root_user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -e

source _default.sh
19 changes: 19 additions & 0 deletions test/azure-cli-persistence/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"with_extensions": {
"image": "mcr.microsoft.com/devcontainers/base:debian",
"features": {
"ghcr.io/devcontainers/features/azure-cli:1": {
"extensions": "containerapp,ssh"
},
"azure-cli-persistence": {}
}
},
"root_user": {
"image": "mcr.microsoft.com/devcontainers/base:debian",
"features": {
"ghcr.io/devcontainers/features/azure-cli:1": {},
"azure-cli-persistence": {}
},
"remoteUser": "root"
}
}
9 changes: 1 addition & 8 deletions test/azure-cli-persistence/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,4 @@

set -e

# Optional: Import test library bundled with the devcontainer CLI
source dev-container-features-test-lib

# Feature-specific tests
check "cache dir permission" bash -c "test -w /dc/azure"

# Report result
reportResults
source _default.sh
12 changes: 12 additions & 0 deletions test/azure-cli-persistence/with_extensions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -e

source dev-container-features-test-lib

check "cache dir permission" bash -c "test -w /dc/azure"
check "check symlink" bash -c 'test $(readlink "$HOME/.azure") == "/dc/azure/"'

check "check cliextensions" bash -c 'test $(az extension list --output tsv --query "length(@)") -eq 2'

reportResults