Skip to content

Commit

Permalink
Setup services
Browse files Browse the repository at this point in the history
  • Loading branch information
louisroyer committed Feb 1, 2024
1 parent 8601b70 commit 8ec3d12
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
7 changes: 5 additions & 2 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ subnets:
ipv4_address: 10.1.5.129
r1:
ipv4_address: 10.1.5.130
s1:
s0:
ipv4_address: 10.1.5.131
s2:
s1:
ipv4_address: 10.1.5.132
srgw0:
srgw0:
ipv4_address: 10.3.0.1
service:
s:
ipv4_address: 10.4.0.1
slice0:
subnet:
ipv4_address: 10.2.0.0/24
28 changes: 28 additions & 0 deletions scripts/jinja/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,22 @@ def ipv6(host: str, subnet: str, context: _Context) -> str:
raise('Unknown ip address')
return addr

@function
def ipv4_subnet(subnet: str, context: _Context) -> str:
try:
addr = context.dict['subnets'][subnet]['subnet']['ipv4_address']
except:
raise('Unknown ip subnet')
return addr

@function
def ipv6_subnet(subnet: str, context: _Context) -> str:
try:
addr = context.dict['subnets'][subnet]['subnet']['ipv6_address']
except:
raise('Unknown ip subnet')
return addr

@function(output='json')
def container(name: str, image: str, ipv6: typing.Optional[bool] = False, iface_tun: typing.Optional[bool] = False,
command: typing.Optional[str|bool] = None,
Expand Down Expand Up @@ -203,3 +219,15 @@ def container(name: str, image: str, ipv6: typing.Optional[bool] = False, iface_
if iface_tun:
containers[name]['devices'] = ["/dev/net/tun:/dev/net/tun"]
return json.dumps(containers)

@function(output='json')
def container_setup(name: str) -> str:
containers = {}
containers[f'{name}-setup'] = {
"container_name": f'{name}-setup',
"network_mode": f'service{name}',
"image": 'louisroyer/docker-setup',
"cap_add": ['NET_ADMIN',],
"restart": "no",
}
return json.dumps(containers)
24 changes: 16 additions & 8 deletions templates/compose.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -340,29 +340,37 @@ services:
# srgw0:


# TODO: s1 docker-setup
{{ container_s(name='s1', image='nginx', command=False) }}
{{ container_setup_s(name='s0') }}
environment:
ONESHOT: "true"
ROUTES_INIT: |-
- add {{ ipv4_subnet('slice0') }} via {{ ipv4('r0', 'edge') }}
{{ container_s(name='s0', image='nginx', command=False) }}
volumes:
{{ volume_ro('nginx/instance.conf.template', '/etc/nginx/templates/instance.conf') }}
environment:
NGINX_PORT: "80"
NGINX_SERVICE_ID: "{{ ipv4('s', 'service') }}"
NGINX_INSTANCE_ID: "{{ ipv4('s1', 'edge') }}"
NGINX_INSTANCE_ID: "{{ ipv4('s0', 'edge') }}"
networks:
edge:
ipv4_address: "{{ ipv4('s1', 'edge') }}"
ipv4_address: "{{ ipv4('s0', 'edge') }}"

# TODO: s2 docker-setup
{{ container_s(name='s2', image='nginx', command=False) }}
{{ container_setup_s(name='s1') }}
environment:
ONESHOT: "true"
ROUTES_INIT: |-
- add {{ ipv4_subnet('slice0') }} via {{ ipv4('r1', 'edge') }}
{{ container_s(name='s1', image='nginx', command=False) }}
volumes:
{{ volume_ro('nginx/instance.conf.template', '/etc/nginx/templates/instance.conf') }}
environment:
NGINX_PORT: "80"
NGINX_SERVICE_ID: "{{ ipv4('s', 'service') }}"
NGINX_INSTANCE_ID: "{{ ipv4('s2', 'edge') }}"
NGINX_INSTANCE_ID: "{{ ipv4('s1', 'edge') }}"
networks:
edge:
ipv4_address: "{{ ipv4('s2', 'edge') }}"
ipv4_address: "{{ ipv4('s1', 'edge') }}"

networks:
ran:
Expand Down

0 comments on commit 8ec3d12

Please sign in to comment.