Skip to content

Commit

Permalink
feat: EZOut Container.start.ps1 ( Fixes #243 )
Browse files Browse the repository at this point in the history
  • Loading branch information
StartAutomating committed Sep 6, 2024
1 parent 6057944 commit ee47c9f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
42 changes: 42 additions & 0 deletions Container.start.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<#
.SYNOPSIS
Starts the container.
.DESCRIPTION
Starts a container.
This script should be called from the Dockerfile as the ENTRYPOINT (or from within the ENTRYPOINT).
It should be deployed to the root of the container image.
~~~Dockerfile
# 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
ENTRYPOINT ["pwsh", "-nologo", "-file", "/Container.start.ps1"]
~~~
.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 'ghcr.io/startautomating/rocker'

param()

if ($args) {
# If there are arguments, output them (you could handle them in a more complex way).
"$args" | Out-Host
}

# If you want to do something when the container is stopped, you can register an event.
# This can call a script that does some cleanup, or sends a message as the service is exiting.
Register-EngineEvent -SourceIdentifier PowerShell.Exiting -Action {
if (Test-Path /Container.stop.ps1) {
& /Container.stop.ps1
}
} | Out-Null
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ FROM mcr.microsoft.com/powershell
SHELL ["/bin/pwsh", "-nologo", "-command"]

# Run the initialization script
RUN --mount=type=bind,src=./,target=/Initialize ./Initialize/Container.init.ps1
RUN --mount=type=bind,src=./,target=/Initialize ./Initialize/Container.init.ps1

# Set the entry point
ENTRYPOINT ["/bin/pwsh", "-nologo", "-noexit", "-file", "/Container.start.ps1"]

0 comments on commit ee47c9f

Please sign in to comment.