Skip to content

Commit ead73a2

Browse files
committed
azure-cli-persistence: Add marker file to avoid double installation
1 parent 4b50f82 commit ead73a2

5 files changed

Lines changed: 30 additions & 20 deletions

File tree

src/azure-cli-persistence/NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
| Version | Notes |
55
| ------- | ------------------------------------------------------------ |
6+
| 0.0.7 | Add marker files to prevent double installation when a feature is [https://code.visualstudio.com/docs/devcontainers/containers#_always-installed-features](always installed) and in a devcontainer.json file. |
67
| 0.0.6 | Add symlink for cliextensions folder |
78
| 0.0.5 | Use lifecycle scripts |
89
| 0.0.4 | Fix test for existing ~/.azure folder |

src/azure-cli-persistence/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Azure CLI Persistence",
33
"id": "azure-cli-persistence",
4-
"version": "0.0.6",
4+
"version": "0.0.7",
55
"description": "Preserve ~/.azure folder across container instances (avoids needing to login after rebuilding)",
66
"options": {},
77
"mounts": [

src/azure-cli-persistence/install.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ log() {
1717
log "Activating feature 'azure-cli-persistence'"
1818
log "User: ${_REMOTE_USER} User home: ${_REMOTE_USER_HOME}"
1919

20+
# check if marker file exists to avoid re-running oncreate script actions
21+
if [ -f "$_REMOTE_USER_HOME/.stuartleeks/azure-cli-persistence-install" ]; then
22+
log "Feature 'azure-cli-persistence' already installed, skipping oncreate actions"
23+
exit 0
24+
fi
25+
2026
got_old_azure_folder=false
2127
if [ -e "$_REMOTE_USER_HOME/.azure" ]; then
2228
log "Moving existing .azure folder to .azure-old"
@@ -31,3 +37,7 @@ if [ -f oncreate.sh ]; then
3137
mkdir -p "${LIFECYCLE_SCRIPTS_DIR}"
3238
cp oncreate.sh "${LIFECYCLE_SCRIPTS_DIR}/oncreate.sh"
3339
fi
40+
41+
log "Adding marker file to indicate persistence is installed"
42+
mkdir -p "$_REMOTE_USER_HOME/.stuartleeks"
43+
touch "$_REMOTE_USER_HOME/.stuartleeks/azure-cli-persistence-install"

src/azure-cli-persistence/oncreate.sh

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,12 @@ else
1717
fi
1818

1919
log "In OnCreate script"
20-
21-
FEATURE_DIR="/usr/local/share/stuartleeks-devcontainer-features/azure-cli-persistence"
22-
LOG_FILE="$FEATURE_DIR/log.txt"
23-
24-
log() {
25-
echo "$1"
26-
echo "$1" >> "$LOG_FILE"
27-
}
28-
29-
if command -v sudo > /dev/null; then
30-
sudo chown -R "$(id -u):$(id -g)" "$LOG_FILE"
31-
else
32-
chown -R "$(id -u):$(id -g)" "$LOG_FILE"
20+
# check if marker file exists to avoid re-running oncreate script actions
21+
if [ -f "$HOME/.stuartleeks/azure-cli-persistence-oncreate" ]; then
22+
log "Feature 'azure-cli-persistence' oncreate actions already run, skipping"
23+
exit 0
3324
fi
3425

35-
log "In OnCreate script"
3626

3727
fix_permissions() {
3828
local dir
@@ -92,7 +82,7 @@ else
9282
# 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
9383
# And if so, remove the symlink
9484
# This can happen if the user has installed the azure-cli feature and specified extensions to install
95-
# and then later removed the extensions.
85+
# and then later removed the extensions.cd
9686
if [ -L "$new_cliextensions_folder" ]; then
9787
symlink_target=$(readlink "$new_cliextensions_folder")
9888
if [ "$symlink_target" = "$old_cliextensions_folder" ]; then
@@ -101,3 +91,12 @@ else
10191
fi
10292
fi
10393
fi
94+
95+
96+
log "Adding marker file to indicate oncreate actions have been run"
97+
mkdir -p "$HOME/.stuartleeks"
98+
if command -v sudo > /dev/null; then
99+
sudo touch "$HOME/.stuartleeks/azure-cli-persistence-oncreate"
100+
else
101+
touch "$HOME/.stuartleeks/azure-cli-persistence-oncreate"
102+
fi
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
22
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/ubuntu
33
{
4-
"name": "devcontainer-features-playground-test1",
4+
"name": "devcontainer-features-testproject",
55
"image": "mcr.microsoft.com/vscode/devcontainers/base:0-jammy",
66
// Use 'forwardPorts' to make a list of ports inside the container available locally.
77
// "forwardPorts": [],
@@ -13,12 +13,12 @@
1313
"ghcr.io/devcontainers/features/azure-cli": {
1414
// "extensions": "containerapp,ssh"
1515
},
16-
"ghcr.io/devcontainers-extra/features/fish-apt-get": {},
16+
// "ghcr.io/devcontainers-extra/features/fish-apt-get": {},
1717
"ghcr.io/devcontainers/features/azure-cli:1": {
18-
"extensions": "containerapp,ssh"
18+
// "extensions": "containerapp,ssh"
1919
},
2020
"./src/shell-history": {},
2121
"./src/azure-cli-persistence": {},
22-
"./src/dev-tunnels" : {}
22+
// "./src/dev-tunnels" : {}
2323
}
2424
}

0 commit comments

Comments
 (0)