read params from $env

master
lub 5 years ago
parent 88641b27ec
commit aa34420c42

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

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