From 92fbd0b4c5a7b6bf3ac46e2a93868c39776162b9 Mon Sep 17 00:00:00 2001 From: lub Date: Sun, 11 Aug 2019 11:36:57 +0200 Subject: [PATCH] working parsing --- example.yml | 63 +++++++++++++++++++++++++++++++++++++++++++++ expose_forwards.ps1 | 55 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 example.yml create mode 100644 expose_forwards.ps1 diff --git a/example.yml b/example.yml new file mode 100644 index 0000000..a3029c6 --- /dev/null +++ b/example.yml @@ -0,0 +1,63 @@ +version: "3.2" + +services: + teamspeak: + image: docker.io/teamspeak + deploy: + replicas: 1 + placement: + constraints: [node.labels.gluster == true] + depends_on: + - mariadb + environment: + - TS3SERVER_DB_PLUGIN=ts3db_mariadb + - TS3SERVER_DB_SQLCREATEPATH=create_mariadb + - TS3SERVER_DB_HOST=mariadb + - TS3SERVER_DB_USER=teamspeak + - TS3SERVER_DB_NAME=teamspeak + - TS3SERVER_LICENSE=accept + ports: + - target: 9987 + published: "145.239.119.128:42842" + protocol: udp + mode: ingress + - target: 30033 + mode: ingress + volumes: + - "/gluster/docker/gamemodeon-teamspeak_teamspeak/var/ts3server/:/var/ts3server/" + networks: + - database + - teamspeak + mariadb: + image: docker.io/mariadb + deploy: + replicas: 1 + placement: + constraints: [node.hostname == stan.lubi.link] + environment: + - MYSQL_USER=teamspeak + - MYSQL_DATABASE=teamspeak + - MYSQL_RANDOM_ROOT_PASSWORD=yes + volumes: + - "/mnt/gamemodeon-teamspeak_mariadb/var/lib/mysql/:/var/lib/mysql/" + networks: + - database + synapse: + image: matrixdotorg/synapse + deploy: + replicas: 1 + placement: + constraints: [node.labels.gluster == true] + depends_on: + - postgres + environment: + - SYNAPSE_CONFIG_PATH=/data/homeserver.yaml + volumes: + - "/gluster/docker/imninja_synapse/data/:/data/" + ports: + - "145.239.119.128:8448:8448" + - "145.239.119.128:42933:443" + networks: + - homeserver + - database + - lubiland-lb \ No newline at end of file diff --git a/expose_forwards.ps1 b/expose_forwards.ps1 new file mode 100644 index 0000000..857f2a1 --- /dev/null +++ b/expose_forwards.ps1 @@ -0,0 +1,55 @@ +#Requires -Modules powershell-yaml +$ErrorActionPreference = 'Stop' + +foreach($yaml in (Get-ChildItem -Filter '*.yml')) { + Write-Output ('Processing {0}' -f $yaml) + $definition = Get-Content -Path $yaml -Raw | ConvertFrom-Yaml + + foreach($port in $definition.services.Values.ports) { + $nat = @{ + protocol = $null + public_ip = $null + public_port = $null + internal_port = $null + } + + if($port.Count -eq 4) { + #long form + $published_splitted = $port.published -split ':' + + $nat.protocol = $port.protocol + $nat.public_ip = $published_splitted[0] + $nat.public_port = $port.target + $nat.internal_port = $published_splitted[1] + } else { + #short form + $ports_splitted = $port -split ':' + + $nat.public_ip = $ports_splitted[0] + $nat.public_port = $ports_splitted[2] + $nat.internal_port = $ports_splitted[1] + } + + if(!$nat.protocol) { + #this is also Docker's default + $nat.protocol = 'tcp' + } + if($nat.Values -contains $null) { + #if $nat doesn't conatain all needed attributes skip the port + $error_message = 'Skipping port, because $nat contains $null: {0}' ` + -f ($nat | ConvertTo-Json) + Write-Error -Message $error_message ` + -ErrorAction Continue + continue + } + + if($nat.internal_port -ne $nat.public_port) { + Write-Output ('Additional NAT rule required, because published {0} and target {1} differ' ` + -f $nat.internal_port,$nat.public_port) + $nat.protocol + $nat.public_ip + $nat.public_port + $nat.internal_port + } + } +} \ No newline at end of file