service: Add support for native sockets for http
This commit is contained in:
@@ -1,4 +1,11 @@
|
|||||||
---
|
---
|
||||||
|
- name: Restart socket for {{ service_name }}
|
||||||
|
ansible.builtin.systemd_service:
|
||||||
|
name: "{{ service_name }}.socket"
|
||||||
|
state: restarted
|
||||||
|
daemon_reload: true
|
||||||
|
ignore_errors: '{{ ansible_check_mode }}'
|
||||||
|
|
||||||
- name: Restart socat socket for {{ service_name }}
|
- name: Restart socat socket for {{ service_name }}
|
||||||
ansible.builtin.systemd_service:
|
ansible.builtin.systemd_service:
|
||||||
name: "{{ service_name }}-socat.socket"
|
name: "{{ service_name }}-socat.socket"
|
||||||
|
|||||||
@@ -28,8 +28,10 @@ argument_specs:
|
|||||||
elements: str
|
elements: str
|
||||||
service_container_http_port:
|
service_container_http_port:
|
||||||
description:
|
description:
|
||||||
- Port inside the container where http requests will be proxied to.
|
- Port inside the container where http requests are proxied to.
|
||||||
- Required if service_domains is not empty.
|
- >-
|
||||||
|
If set to 0, /run/{{ service_name }}.sock on the host is bind mounted to /run/{{ service_name }}.sock inside the container
|
||||||
|
and http requests are proxied to it.
|
||||||
type: int
|
type: int
|
||||||
required: false
|
required: false
|
||||||
default: 0
|
default: 0
|
||||||
|
|||||||
@@ -22,6 +22,10 @@
|
|||||||
ansible.builtin.include_tasks: additional.yaml
|
ansible.builtin.include_tasks: additional.yaml
|
||||||
when: _service_additional_containers | length > 0
|
when: _service_additional_containers | length > 0
|
||||||
|
|
||||||
|
- name: Native socket for {{ service_name }}
|
||||||
|
ansible.builtin.include_tasks: native_socket.yaml
|
||||||
|
when: _service_native_socket
|
||||||
|
|
||||||
- name: Main container for {{ service_name }}
|
- name: Main container for {{ service_name }}
|
||||||
ansible.builtin.import_role:
|
ansible.builtin.import_role:
|
||||||
name: container
|
name: container
|
||||||
|
|||||||
7
roles/service/tasks/native_socket.yaml
Normal file
7
roles/service/tasks/native_socket.yaml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
- name: Socket for {{ service_name }}
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: service.socket.j2
|
||||||
|
dest: /etc/systemd/system/{{ service_name }}.socket
|
||||||
|
mode: "0644"
|
||||||
|
notify: Restart socket for {{ service_name }}
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
vhost_id: "{{ service_name }}"
|
vhost_id: "{{ service_name }}"
|
||||||
vhost_domains: "{{ service_domains }}"
|
vhost_domains: "{{ service_domains }}"
|
||||||
vhost_proxy_target_netproto: unix
|
vhost_proxy_target_netproto: unix
|
||||||
vhost_proxy_target_socket: "/run/{{ service_name }}-socat.sock"
|
vhost_proxy_target_socket: "{{ _service_socket_path }}"
|
||||||
vhost_proxy_headers: "{{ _service_proxy_headers }}"
|
vhost_proxy_headers: "{{ _service_proxy_headers }}"
|
||||||
vhost_proxy_auth_socket: "{{ _service_oauth2_socket }}"
|
vhost_proxy_auth_socket: "{{ _service_oauth2_socket }}"
|
||||||
vhost_proxy_auth_uri: /oauth2/auth
|
vhost_proxy_auth_uri: /oauth2/auth
|
||||||
|
|||||||
6
roles/service/templates/service.socket.j2
Normal file
6
roles/service/templates/service.socket.j2
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# {{ ansible_managed }}
|
||||||
|
[Unit]
|
||||||
|
Description={{ service_name }} socket
|
||||||
|
|
||||||
|
[Socket]
|
||||||
|
ListenStream=/run/{{ service_name }}.sock
|
||||||
@@ -5,8 +5,9 @@ _service_static_ip: "{{ service_container_ip | length > 0 }}"
|
|||||||
_service_container_requires: >-
|
_service_container_requires: >-
|
||||||
{{
|
{{
|
||||||
service_requires
|
service_requires
|
||||||
+ ([_service_database_name + '.service'] if _service_setup_database else [])
|
+ ([_service_database_name ~ '.service'] if _service_setup_database else [])
|
||||||
+ ([service_name + '-redis.service'] if service_redis else [])
|
+ ([service_name ~ '-redis.service'] if service_redis else [])
|
||||||
|
+ ([service_name ~ '.socket'] if _service_native_socket else [])
|
||||||
}}
|
}}
|
||||||
_service_container_wants: >-
|
_service_container_wants: >-
|
||||||
{{
|
{{
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
---
|
---
|
||||||
|
_service_container_socket_mount:
|
||||||
|
type: bind
|
||||||
|
source: /run/{{ service_name }}
|
||||||
|
destination: /run/{{ service_name }}
|
||||||
|
|
||||||
_service_volume_mounts: "{{ service_container_mounts | selectattr('type', '==', 'volume') }}"
|
_service_volume_mounts: "{{ service_container_mounts | selectattr('type', '==', 'volume') }}"
|
||||||
_service_template_mounts: "{{ service_container_mounts | selectattr('type', '==', 'template') }}"
|
_service_template_mounts: "{{ service_container_mounts | selectattr('type', '==', 'template') }}"
|
||||||
_service_copy_mounts: "{{ service_container_mounts | selectattr('type', '==', 'copy') }}"
|
_service_copy_mounts: "{{ service_container_mounts | selectattr('type', '==', 'copy') }}"
|
||||||
@@ -15,7 +20,11 @@ _service_container_volume_mounts: >-
|
|||||||
) |
|
) |
|
||||||
map('combine')
|
map('combine')
|
||||||
}}
|
}}
|
||||||
_service_container_bind_mounts: "{{ service_container_mounts | selectattr('type', '==', 'bind') }}"
|
_service_container_bind_mounts: >-
|
||||||
|
{{
|
||||||
|
service_container_mounts | selectattr('type', '==', 'bind') +
|
||||||
|
([ _service_container_socket_mount ] if _service_native_socket else [])
|
||||||
|
}}
|
||||||
_service_container_template_mounts: >-
|
_service_container_template_mounts: >-
|
||||||
{{
|
{{
|
||||||
([{'readonly': true}] * _service_template_mounts | length) |
|
([{'readonly': true}] * _service_template_mounts | length) |
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
---
|
---
|
||||||
|
_service_native_socket: "{{ service_domains | length > 0 and service_container_http_port == 0 }}"
|
||||||
|
|
||||||
|
_service_socket_path: >-
|
||||||
|
/run/{{ service_name ~ ('-socat' if not _service_native_socket else '' ) }}.sock
|
||||||
|
|
||||||
_service_replacement_host_header:
|
_service_replacement_host_header:
|
||||||
Host: "{{ service_name }}:{{ service_container_http_port }}"
|
Host: "{{ service_name }}:{{ service_container_http_port }}"
|
||||||
_service_proxy_headers: "{{ _service_replacement_host_header if not service_proxy_pass_host_header else {} }}"
|
_service_proxy_headers: "{{ _service_replacement_host_header if not service_proxy_pass_host_header else {} }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user