Cross-Platform PowerShell framework that allows you to host REST APIs, Web Sites, and TCP/SMTP Servers
Badgerati on Issue-1046
#1046: minor tweak to version s… (compare)
Badgerati on Issue-1046
#1046: update packaging to refe… (compare)
Badgerati on Issue-1046
#1046: add a Pode.Internal modu… (compare)
Badgerati on Issue-1007
#1007: set originating redirect… (compare)
Badgerati on Issue-1046
#1046: re-filter module list fo… (compare)
Hey @samuelleb11, that is strange 🤔 it should be working; I've got a couple containers running in k8s running fine. I was just playing with one in minikube this morning haha, it's server.ps1 looks like:
Start-PodeServer {
Add-PodeEndpoint -Address * -Port 80 -Protocol Http
Add-PodeRoute -Method Get -Path '/' -ScriptBlock {
# logic
}
}
and it's dockerfile:
FROM badgerati/pode:latest
COPY ./server.ps1 /usr/src/app/
EXPOSE 80
CMD [ "pwsh", "-c", "cd /usr/src/app; ./server.ps1" ]
in raw docker I have to have docker run -p 9000:80
, or in compose:
ports:
- "9000:80"
Are you able to show an example of your dockerfile/compose file? And is the issue that you run the container and then can't hit it from the host (but can from the container itself), or you can hit it from the host but not from another machine?
And as per Robin's comment, make sure it's running as admin :)
Hey @Badgerati,
I am currently testing Pode as REST API for custom checks to be carried out via the monitoring systems (in our case, PRTG). We don't want to enter highly privileged credentials into the monitoring system so a REST API with certain endpoints on the servers would be a good fit.
However the memory footprint is quite important as it would run on 400 systems, I can't really get it under 90mb with atm 4 Routes and 2 Threads, I tried with both PowerShell 7.1.x and 5.1. Do you see any chance how I can tweak it to use less memory?
I already disabled all module imports and ran it with -NoProfile:
@{
Server = @{
FileMonitor = @{
Enable = $false
Include = @("*.ps1", "*.pode")
}
AutoImport = @{
Modules = @{
Enable = $false
}
Snapins = @{
Enable = $false
}
Functions = @{
Enable = $false
}
}
}
Web = @{
TransferEncoding = @{
Default = "gzip"
}
Static = @{
Cache = @{
Enable = $false
Include = @(
"*"
)
MaxAge = 604800
}
}
}
}
$powerShell = $svr.PowerShell
$scriptPath = $svr.ScriptPath
Write-Host " Installing " -NoNewLine -ForegroundColor Green
Write-Host $serviceName -NoNewline -ForegroundColor Yellow
Write-Host " as a Windows service" -ForegroundColor Green
$nssm = (Get-Command nssm).Source
$pscmd = (Get-Command $powerShell).Source
$arguments = '-ExecutionPolicy Bypass -NoProfile -File "{0}"' -f $scriptPath
& $nssm install $serviceName $pscmd $arguments
& $nssm status $serviceName
Hey @cadayton, that should be about all that's needed. Few questions though, is $scriptPath
a relative or literal path? In the docs I used -Command
instead of -File
- any difference there if you change it?
On the last line you've got nssm status <name>
is that a typo here and meant to be nssm start <name>
?
Failing all of that, there's a change an error could be being thrown, so wrapping the whole server.ps1 in a try/catch could give some hints; something like:
try {
Start-PodeServer, etc, etc
}
catch {
$_.Exception.Message | Out-File C:/temp/pode_errors.txt
}
-Command
option and the try/catch combo too. Thanks again.
Import-Module Pode -Global
. So stumped as to why it is not being found.The term 'Start-PodeServer' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
get-module Pode -All -ListAvailable
Reset-PodeWebPage
in a Modal ?Date: 2021-10-12 16:16:01
at Invoke-PodeScriptBlock, C:\Users\sgagnon\Documents\PowerShell\Modules\Pode\2.4.2\Public\Utilities.ps1: line 662
at <ScriptBlock>, <No file>: line 107
Date: 2021-10-12 16:16:01
Level: Error
ThreadId: 3
Server: WH-DESK04
Category: System.Private.CoreLib
Message: Collection was modified; enumeration operation may not execute.
StackTrace: at System.Collections.Hashtable.HashtableEnumerator.MoveNext()
at System.Management.Automation.EnumerableOps.FlattenResults(Object o, List`1 result)
at System.Management.Automation.EnumerableOps.PropertyGetterWorker(CallSite`1 getMemberBinderSite, IEnumerator enumerator, ExecutionContext context, List`1 result)
at System.Management.Automation.EnumerableOps.PropertyGetter(PSGetMemberBinder binder, IEnumerator enumerator)
at Get-PodeRoute(Closure , FunctionContext )
$RoomList = Import-Csv -Path D:\Deployment\Rooms.csv -Delimiter ";" -Encoding UTF8
$Tabs = @( Foreach ( $Room in $RoomList )
{
New-PodeWebTab -Name $Room.Name -Icon $Room.Icon -Layouts @(
New-PodeWebCard -Content @(
New-PodeWebText -Value 'Here is some Normal text.'
)
)
} )
Add-PodeWebPage -Name 'Rooms' -Icon google-classroom -ArgumentList $Tabs -ScriptBlock {
param ($Tabs)
New-PodeWebTabs -Tabs @($Tabs)
}
-AccessGroup
or -AccessUser
in add-PodeWebPage
cmdlet. Is there anything equivalent for AAD? Thank you!
-AccessUsers
with AAD, though you might need to set -UsernameProperty
on Set-PodeWebLoginPage
to either "preferred_username" or "email" to force a username property, rather than just use Pode.Web's default. For groups, it breaks a little bit there at the moment. The access_token I think should be a JWT and contains claims like the groups, but will need parsing - in the next version of Pode its ConvertFrom-PodeJwt
should hopefully be moved to public :)
Hey @majkinetor :D, the lowest Pode's can go down to is a minute using cron; I've never stress tested it to extreme limits but I do have a health probe running on numerous web servers which runs a minutely schedule and it's not suffered any; plus another, which is a timer, that runs every 20secs, which does the bulk of CPU/IIS/Service checks, and also running fine. The most schedules I've seen was in a Pingdom-esque site someone built, which was running like 10-20 minutely schedules without issue.
As Pode triggers schedules, they're run in their own runspace, in a pool which allows up to a max of 10 to run at the same time (we could allow this to be customised), and then queues them if the pool is full. If you did have a schedule run every minute, and one of the times it triggered it did happen to run for 2mins, then Pode would trigger the schedule another 2 times during the running one.
I've been thinking about building a scheduler like this as well in Pode, so will be interesting to see how schedules/timers perform under load 🤔