Skip to content

Commit

Permalink
fix: WebSocket Container fix ( Fixes #96 )
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Feb 11, 2025
1 parent c2a0ec0 commit 7ab7f2f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
15 changes: 6 additions & 9 deletions Container.init.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@
# Thank you Microsoft! Thank you PowerShell! Thank you Docker!
FROM mcr.microsoft.com/powershell
# Set the shell to PowerShell (thanks again, Docker!)
SHELL ["/bin/pwsh", "-nologo", "-command"]
# Run the initialization script. This will do all remaining initialization in a single layer.
RUN --mount=type=bind,src=./,target=/Initialize ./Initialize/Container.init.ps1
# Copy the module into the container
RUN --mount=type=bind,src=./,target=/Initialize /bin/pwsh -nologo -command /Initialize/Container.init.ps1
# Set the entrypoint to the script we just created.
ENTRYPOINT [ "/bin/pwsh","-nologo","-noexit","-file","/Container.start.ps1" ]
~~~
The scripts arguments can be provided with either an `ARG` or `ENV` instruction in the Dockerfile.
.NOTES
Did you know that in PowerShell you can 'use' namespaces that do not really exist?
This seems like a nice way to describe a relationship to a container image.
That is why this file is using the namespace 'mcr.microsoft.com/powershell'.
(this does nothing, but most likely will be used in the future)
#>
using namespace 'mcr.microsoft.com/powershell AS powerShell'

#use container mcr.microsoft.com/powershell

param(
# The name of the module to be installed.
Expand Down
5 changes: 3 additions & 2 deletions Container.start.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
That is why this file is using the namespace 'mcr.microsoft.com/powershell'.
(this does nothing, but most likely will be used in the future)
#>
using namespace 'ghcr.io/powershellweb/websocket'

#use container ghcr.io/powershellweb/websocket

param()

Expand Down Expand Up @@ -62,7 +63,7 @@ if ($args) {
# If a single drive is mounted, start the socket files.
$webSocketFiles = $mountedFolders | Get-ChildItem -Filter *.WebSocket.ps1
foreach ($webSocketFile in $webSocketFiles) {
Start-ThreadJob -Name $webSocketFile.Name -ScriptBlock {param($webSocketFile) . $using:webSocketFile.FullName } -ArgumentList $webSocketFile
Start-ThreadJob -Name $webSocketFile.Name -ScriptBlock { . $using:webSocketFile.FullName }
. $webSocketFile.FullName
}
}
Expand Down
2 changes: 1 addition & 1 deletion Container.stop.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
It can be used to perform any necessary cleanup before the container is stopped.
#>
"Container now exiting, thank you for using WebSocket!" | Out-Host
"Container now exiting, thank you for using $env:ModuleName!" | Out-Host
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Thank you Microsoft! Thank you PowerShell! Thank you Docker!
FROM mcr.microsoft.com/powershell AS powershell
FROM mcr.microsoft.com/powershell

# Set the module name to the name of the module we are building
ENV ModuleName=WebSocket
Expand Down

0 comments on commit 7ab7f2f

Please sign in to comment.