read params from $env

master
lub 5 years ago
parent 88641b27ec
commit aa34420c42

@ -1,11 +1,16 @@
FROM mcr.microsoft.com/powershell:latest
VOLUME /stacks
ENV CHAIN="SWARM-NAT" \
STACKS="/stacks"
WORKDIR /
RUN pwsh -c 'Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted' \
&& pwsh -c 'Install-Module powershell-yaml' \
&& apt-get update \
&& apt-get -y install iptables \
&& apt-get -y install iptables docker.io \
&& rm -rf /var/cache/apt
COPY expose_forwards.ps1 docker/entrypoint.sh ./

@ -1,4 +1,8 @@
#Requires -Modules powershell-yaml
param (
[string]$Chain = $env:CHAIN,
[string]$Stacks = $env:STACKS
)
$ErrorActionPreference = 'Stop'
function Start-IptablesProcess {
@ -92,16 +96,15 @@ function Get-DockerIngressAddress {
}
# setup SWARM-NAT chain
$chain = 'SWARM-NAT'
Write-Output ('Create chain {0}' -f $chain)
Add-IptablesChain -Chain $chain
Add-IptablesRule -Chain 'PREROUTING' -Rule '-m','addrtype','--dst-type','LOCAL','-j',$chain
Write-Output ('Create chain {0}' -f $Chain)
Add-IptablesChain -Chain $Chain
Add-IptablesRule -Chain 'PREROUTING' -Rule '-m','addrtype','--dst-type','LOCAL','-j',$Chain
$ingress_address = Get-DockerIngressAddress
foreach($yaml in (Get-ChildItem -Filter '*.yml')) {
foreach($yaml in (Get-ChildItem -Path $Stacks -Include '*.yml','*.yaml' -Recurse)) {
Write-Output ('Processing {0}' -f $yaml)
$definition = Get-Content -Path $yaml -Raw | ConvertFrom-Yaml
@ -156,7 +159,7 @@ foreach($yaml in (Get-ChildItem -Filter '*.yml')) {
'-j','DNAT'
'--to-destination','"{0}:{1}"' -f $ingress_address,$nat.port
)
Add-IptablesRule -Chain $chain -Rule $rule
Add-IptablesRule -Chain $Chain -Rule $rule
}
}
}
Loading…
Cancel
Save