This commit is contained in:
Muayyad alsadi 2023-04-09 12:00:45 +03:00
parent ef55067834
commit 9046f7eee0
2 changed files with 20 additions and 10 deletions

View File

@ -792,7 +792,7 @@ def get_net_args(compose, cnt):
ip = None ip = None
ip6 = None ip6 = None
if cnt_nets and is_dict(cnt_nets): if cnt_nets and is_dict(cnt_nets):
cnt_nets_prioritized = dict() prioritized_cnt_nets = []
# cnt_nets is {net_key: net_value, ...} # cnt_nets is {net_key: net_value, ...}
for net_key, net_value in cnt_nets.items(): for net_key, net_value in cnt_nets.items():
net_value = net_value or {} net_value = net_value or {}
@ -802,16 +802,10 @@ def get_net_args(compose, cnt):
if not ip6: if not ip6:
ip6 = net_value.get("ipv6_address", None) ip6 = net_value.get("ipv6_address", None)
net_priority = net_value.get("priority", 0) net_priority = net_value.get("priority", 0)
if not net_priority in cnt_nets_prioritized: prioritized_cnt_nets.append((net_priority, net_key,))
cnt_nets_prioritized[net_priority] = list()
cnt_nets_prioritized[net_priority].append(net_key)
# sort each priority list alphabetically
for prio in cnt_nets_prioritized:
cnt_nets_prioritized[prio].sort()
# sort dict by priority # sort dict by priority
cnt_nets_prioritized = dict(sorted(cnt_nets_prioritized.items(), reverse=True)) prioritized_cnt_nets.sort(reverse=True)
# flatten the priority dict to a list cnt_nets = [ net_key for _, net_key in prioritized_cnt_nets ]
cnt_nets = [name for prios in cnt_nets_prioritized.values() for name in prios]
cnt_nets = norm_as_list(cnt_nets or default_net) cnt_nets = norm_as_list(cnt_nets or default_net)
net_names = list() net_names = list()
for net in cnt_nets: for net in cnt_nets:

View File

@ -0,0 +1,16 @@
---
# https://github.com/compose-spec/compose-spec/blob/master/spec.md#priority
services:
app:
image: busybox
command: top
networks:
app_net_1:
app_net_2:
priority: 1000
app_net_3:
priority: 100
networks:
app_net_1:
app_net_2:
app_net_3: