Skip to content

Commit

Permalink
Add support for including PowerShell profile (#804)
Browse files Browse the repository at this point in the history
* Add support for including PowerShell profile

* Update version in devcontainer-feature.json

* Add powershellProfileURL  to options

* Update src/powershell/devcontainer-feature.json

Co-authored-by: Samruddhi Khandale <samruddhikhandale@github.com>

* Update README.md

* Create testProfile.ps1

Added a Profile for testing

* Add powershell profile test

* Update install_modules.sh

* Undo README.md changes

* Update scenarios.json

* Delete test/powershell/testProfile.ps1

---------

Co-authored-by: Samruddhi Khandale <samruddhikhandale@github.com>
Co-authored-by: Samruddhi Khandale <skhandale@microsoft.com>
  • Loading branch information
3 people authored Feb 23, 2024
1 parent 403c896 commit c04ead0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/powershell/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "powershell",
"version": "1.2.0",
"version": "1.3.0",
"name": "PowerShell",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/powershell",
"description": "Installs PowerShell along with needed dependencies. Useful for base Dockerfiles that often are missing required install dependencies like gpg.",
Expand All @@ -19,6 +19,11 @@
"type": "string",
"default": "",
"description": "Optional comma separated list of PowerShell modules to install."
},
"powershellProfileURL ": {
"type": "string",
"default": "",
"description": "Optional (publicly accessible) URL to download PowerShell profile."
}
},
"customizations": {
Expand All @@ -31,4 +36,4 @@
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
]
}
}
7 changes: 7 additions & 0 deletions src/powershell/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ rm -rf /var/lib/apt/lists/*

POWERSHELL_VERSION=${VERSION:-"latest"}
POWERSHELL_MODULES="${MODULES}"
POWERSHELL_PROFILE_URL="${PROFILE_URL}"

MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc"
POWERSHELL_ARCHIVE_ARCHITECTURES="amd64"
Expand Down Expand Up @@ -162,6 +163,12 @@ if [ ${#POWERSHELL_MODULES[@]} -gt 0 ]; then
done
fi

# If URL for powershell profile is provided, download it to '/opt/microsoft/powershell/7/profile.ps1'
if [ -n "$POWERSHELL_PROFILE_URL" ]; then
echo "Downloading PowerShell Profile from: $POWERSHELL_PROFILE_URL"
curl -sSL -o "/opt/microsoft/powershell/7/profile.ps1" "$POWERSHELL_PROFILE_URL"
fi

# Clean up
rm -rf /var/lib/apt/lists/*

Expand Down
1 change: 1 addition & 0 deletions test/powershell/install_modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ source dev-container-features-test-lib
# Extension-specific tests
check "az.resources" pwsh -Command "(Get-Module -ListAvailable -Name Az.Resources).Version.ToString()"
check "az.storage" pwsh -Command "(Get-Module -ListAvailable -Name Az.Storage).Version.ToString()"
check "profile" pwsh -Command "(Get-Variable $env:ProfileLoaded).Value"

# Report result
reportResults
3 changes: 2 additions & 1 deletion test/powershell/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"image": "mcr.microsoft.com/devcontainers/base:jammy",
"features": {
"powershell": {
"modules": "az.resources, az.storage"
"modules": "az.resources, az.storage",
"powershellProfileURL": "https://raw.githubusercontent.com/codspace/powershell-profile/main/Test-Profile.ps1"
}
}
}
Expand Down

0 comments on commit c04ead0

Please sign in to comment.