Skip to content

Commit

Permalink
feat: var BACKUP_SERVER to tag server as backup
Browse files Browse the repository at this point in the history
  • Loading branch information
pini-gh committed Jun 6, 2024
1 parent 50608d7 commit 249dc66
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
7 changes: 6 additions & 1 deletion nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,13 @@ upstream {{ $vpath.upstream }} {
{{- $args = dict "container" $container "path" $path "port" $port }}
{{- template "container_port" $args }}
{{- if $ip }}
{{- $servers = add1 $servers }}
{{- $backup := parseBool (coalesce $container.Env.BACKUP_SERVER "false") }}
{{- if not $backup }}
{{- $servers = add1 $servers }}
server {{ $ip }}:{{ $args.port }};
{{- else }}
server {{ $ip }}:{{ $args.port }} backup;
{{- end }}
{{- end }}
{{- end }}
{{- end }}
Expand Down
14 changes: 14 additions & 0 deletions test/test_backup-server/test_backup-server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest


def test_web1_is_backup(docker_compose, nginxproxy):
for i in range(1, 10):
r = nginxproxy.get("http://web1.nginx-proxy.tld/port")
assert r.status_code == 200
assert r.text == "answer from port 91\n"

def test_web2_is_production(docker_compose, nginxproxy):
for i in range(1, 10):
r = nginxproxy.get("http://web2.nginx-proxy.tld/port")
assert r.status_code == 200
assert r.text == "answer from port 82\n"
44 changes: 44 additions & 0 deletions test/test_backup-server/test_backup-server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: "2"

services:
web1:
image: web
expose:
- "81"
environment:
WEB_PORTS: 81
VIRTUAL_HOST: web1.nginx-proxy.tld
network_mode: "none"

web1_backup:
image: web
expose:
- "91"
environment:
WEB_PORTS: 91
VIRTUAL_HOST: web1.nginx-proxy.tld
BACKUP_SERVER: "true"

web2:
image: web
expose:
- "82"
environment:
WEB_PORTS: 82
VIRTUAL_HOST: web2.nginx-proxy.tld

web2_backup:
image: web
expose:
- "92"
environment:
WEB_PORTS: 92
VIRTUAL_HOST: web2.nginx-proxy.tld
BACKUP_SERVER: "true"

sut:
image: nginxproxy/nginx-proxy:test
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
environment:
HTTPS_METHOD: nohttps

0 comments on commit 249dc66

Please sign in to comment.