-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Container.start.ps1
48 lines (41 loc) · 1.75 KB
/
Container.start.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<#
.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 'ghcr.io/startautomating/ugit'.
(this does nothing, but most likely will be used in the future)
#>
using namespace 'ghcr.io/startautomating/ugit'
param()
if ($args) {
# If there are arguments, output them (you could handle them in a more complex way).
"$args" | Out-Host
} else {
# If there are no arguments, see if there is a Microservice.ps1
if (Test-Path './Microservice.ps1') {
# If there is a Microservice.ps1, run it.
. ./Microservice.ps1
}
}
# 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