Skip to content

Commit

Permalink
add devcontainer support
Browse files Browse the repository at this point in the history
  • Loading branch information
connorcarnes committed Feb 13, 2024
1 parent 0869b7e commit 3eb8f20
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 8 deletions.
12 changes: 12 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM mcr.microsoft.com/devcontainers/base:ubuntu
# https://learn.microsoft.com/en-us/powershell/scripting/install/install-ubuntu?view=powershell-7.4
COPY bootstrap.ps1 bootstrap.ps1
RUN apt-get update \
&& apt-get install -y wget apt-transport-https software-properties-common \
&& wget -q https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb \
&& dpkg -i packages-microsoft-prod.deb \
&& rm packages-microsoft-prod.deb \
&& apt-get update \
&& apt-get install -y powershell \
&& pwsh -File bootstrap.ps1
COPY profile.ps1 /opt/microsoft/powershell/7/profile.ps1
41 changes: 41 additions & 0 deletions .devcontainer/bootstrap.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.psresourceget/install-psresource?view=powershellget-3.x
# https://devblogs.microsoft.com/powershell/psresourceget-is-generally-available/
# https://github.com/PowerShell/PSResourceGet
# https://hub.docker.com/_/microsoft-powershell
# https://devblogs.microsoft.com/powershell/powershellget-in-powershell-7-4-updates/
# http://dahlbyk.github.io/posh-git/
$ErrorActionPreference = 'Stop'
#$ProgressPreference = 'SilentlyContinue'
#Set-PSResourceRepository -Name PSGallery -Trusted:$true -Scope AllUsers
#Install-PSResource -RequiredResourceFile ./.devcontainer/RequiredResourceFile.psd1
# PSResourceGet is brand new, posh-git installation is giving me trouble. Not sure if it's a mistake on my part
# or bug with PSResourceGet or posh-git. Leaving it like this for now.
# Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
# Install-Module posh-git -Scope CurrentUser -Force
Install-PSResource -TrustRepository -Scope AllUsers -RequiredResource @{
'Microsoft.PowerShell.PSResourceGet' = @{
version = '1.0.2'
repository = 'PSGallery'
}
'Pester' = @{
version = '5.4.0'
repository = 'PSGallery'
}
'InvokeBuild' = @{
version = '5.10.2'
repository = 'PSGallery'
}
'PSScriptAnalyzer' = @{
version = '1.21.0'
repository = 'PSGallery'
}
'platyPS' = @{
version = '0.12.0'
repository = 'PSGallery'
}
'posh-git' = @{
version = '1.1.0'
repository = 'PSGallery'
}
}

26 changes: 26 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/powershell
{
"name": "PowerShell",
"build": {
"dockerfile": "Dockerfile"
},
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.defaultProfile.linux": "pwsh"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-vscode.powershell",
"ryanluker.vscode-coverage-gutters",
"DavidAnson.vscode-markdownlint",
"eriklynd.json-tools",
"redhat.vscode-xml",
"ms-azuretools.vscode-docker"
]
}
}
}
40 changes: 40 additions & 0 deletions .devcontainer/profile.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Write-Host 'Loading profile...' -ForegroundColor Cyan
Import-Module posh-git
# PSReadline
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -Colors @{ InlinePrediction = '#2F7004' } #green
Set-PSReadLineOption -PredictionViewStyle ListView #you may prefer InlineView
# Custom prompt function
function prompt {
<#
.SYNOPSIS
Custom prompt function.
.EXAMPLE
[2022-JUL-30 21:18][..project-starters\aws\aws-backup-automation][main ≡]
>>
#>
$global:promptDateTime = [datetime]::Now
$Global:promptDate = $global:promptDateTime.ToString('yyyy-MMM-dd').ToUpper()
$Global:promptTime = $global:promptDateTime.ToString('HH:mm')
# truncate the current location if too long
$currentDirectory = $executionContext.SessionState.Path.CurrentLocation.Path
$consoleWidth = [Console]::WindowWidth
$maxPath = [int]($consoleWidth / 4.5)
if ($currentDirectory.Length -gt $maxPath) {
$currentDirectory = '..' + $currentDirectory.SubString($currentDirectory.Length - $maxPath)
}
$global:promptPath = $currentDirectory

$InGitRepo = Write-VcsStatus
if ($InGitRepo) {
Write-Host "[$global:promptDate $global:promptTime]" -ForegroundColor Green -NoNewline
Write-Host "[$global:promptPath]" -ForegroundColor Magenta -NoNewline
Write-Host $InGitRepo.Trim() -NoNewline
"`r`n>>"
}
else {
Write-Host "[$global:promptDate $global:promptTime]" -ForegroundColor Green -NoNewline
Write-Host "[$global:promptPath]" -ForegroundColor Magenta -NoNewline
"`r`n>>"
}
}
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# https://code.visualstudio.com/docs/devcontainers/tips-and-tricks#_resolving-git-line-ending-issues-in-containers-resulting-in-many-modified-files
* text=auto eol=lf
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
20 changes: 12 additions & 8 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"ms-vscode.PowerShell",
"ryanluker.vscode-coverage-gutters",
"DavidAnson.vscode-markdownlint"
]
}
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"ms-vscode.PowerShell",
"ms-vscode-remote.remote-containers",
"ryanluker.vscode-coverage-gutters",
"DavidAnson.vscode-markdownlint",
"eriklynd.json-tools",
"redhat.vscode-xml",
"ms-azuretools.vscode-docker"
]
}

0 comments on commit 3eb8f20

Please sign in to comment.