From aa34420c4286d451bf8922ab69f3677627e6ba6a Mon Sep 17 00:00:00 2001 From: lub Date: Wed, 21 Aug 2019 14:14:19 +0200 Subject: [PATCH] read params from $env --- Dockerfile | 7 ++++++- expose_forwards.ps1 | 15 +++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 438f8ba..7eadfa9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 ./ diff --git a/expose_forwards.ps1 b/expose_forwards.ps1 index 9ef613a..7086c3b 100644 --- a/expose_forwards.ps1 +++ b/expose_forwards.ps1 @@ -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 } } } \ No newline at end of file